using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Globalization;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Jayrock.Json;
using Jayrock.JsonRpc;
using Jayrock.JsonRpc.Web;
using mojoPortal.Business;
using mojoPortal.Web;
namespace SiteOffice.ExternalMail.Services{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[JsonRpcHelp("This is a JSON-RPC service that demonstrates the basic features of the Jayrock library.")]
public class JayRockTest : JsonRpcHandler
{
#region mojo stuff
//[JsonRpcMethod("GetCurrentUser", Idempotent = true)]
//[JsonRpcHelp("Returns the current user")]
//public SiteUser GetCurrentUser()
//{
// return SiteUtils.GetCurrentSiteUser();
//}
#endregion
[JsonRpcMethod("echo", Idempotent = true)]
[JsonRpcHelp("Echoes back the text sent as input.")]
public string Echo(string text)
{
return text;
}
[JsonRpcMethod("echoObject", Idempotent = true)]
[JsonRpcHelp("Echoes back the object sent as input.")]
public object EchoOject(object o)
{
return o;
}
[JsonRpcMethod("echoArgs", Idempotent = true)]
[JsonRpcHelp("Echoes back the arguments sent as input. This method demonstrates variable number of arguments.")]
public object EchoArgs(params object[] args)
{
return args;
}
[JsonRpcMethod("echoAsStrings", Idempotent = true)]
[JsonRpcHelp("Echoes back the arguments as an array of strings. This method demonstrates working with variable number of arguments.")]
public object EchoAsStrings(params object[] args)
{
string[] strings = new string[args.Length];
for (int i = 0; i < args.Length; i++)
{
if (args[i] != null)
strings[i] = args[i].ToString();
}
return strings;
}
//[JsonRpcMethod("echoGuid", Idempotent = true)]
//[JsonRpcHelp("Echoes back the given GUID. This method demonstrates working with an argument typed as System.Guid.")]
//public Guid EchoGuid(Guid id)
//{
// return id;
//}
//[JsonRpcMethod("sum", Idempotent = true)]
//[JsonRpcHelp("Return the sum of two integers.")]
//[JsonRpcObsolete("Use the total method instead.")]
//public int Sum(int a, int b)
//{
// return a + b;
//}
//[JsonRpcMethod("getStringArray", Idempotent = true)]
//[JsonRpcHelp("Returns an array of city names. Demonstrates returning a strongly-typed array.")]
//public string[] GetCities()
//{
// return new string[] { "London", "Zurich", "Paris", "New York" };
//}
[JsonRpcMethod("ServerTimeZone", Idempotent = true)]
[JsonRpcHelp("Returns the time zone of the server.")]
public string ServerTimeZone()
{
return TimeZone.CurrentTimeZone.DaylightName;
}
[JsonRpcMethod("ServerGMTOffset", Idempotent = true)]
[JsonRpcHelp("Returns the time zone of the server.")]
public string ServerGMTOffset()
{
return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).ToString();
}
[JsonRpcMethod("ServerLocalTime", Idempotent = true)]
[JsonRpcHelp("Returns the local time on the server. Demonstrates how DateTime is returned simply as a string using the ISO 8601 format.")]
public DateTime ServerLocalTime()
{
return DateTime.Now;
}
[JsonRpcMethod("newGuid", Idempotent = true)]
[JsonRpcHelp("Generates and returns a GUID as a string.")]
public Guid NewGuid()
{
return Guid.NewGuid();
}
[JsonRpcMethod("cookies", Idempotent = true)]
[JsonRpcHelp("Returns the cookie names seen by the server.")]
public HttpCookieCollection Cookies()
{
return Request.Cookies;
}
[JsonRpcMethod("serverVariables", Idempotent = true)]
[JsonRpcHelp("Returns the server variables collection at the server. Demonstrates returning NameValueCollection.")]
public NameValueCollection ServerVariables()
{
return Request.ServerVariables;
}
//[JsonRpcMethod("getAuthor", Idempotent = true)]
//[JsonRpcHelp("Returns information about the author. Demonstrates how a Hashtable from the server is automatically converted into an object on the client-side.")]
//public IDictionary GetAuthor()
//{
// Hashtable author = new Hashtable();
// author["FirstName"] = "Atif";
// author["LastName"] = "Aziz";
// return author;
//}
//[JsonRpcMethod("sleep", Idempotent = true)]
//[JsonRpcHelp("Blocks the request for the specified number of milliseconds (maximum 7 seconds).")]
//public void Sleep(int milliseconds)
//{
// System.Threading.Thread.Sleep(Math.Min(7000, milliseconds));
//}
[JsonRpcMethod("format", Idempotent = true)]
[JsonRpcHelp("Formats placeholders in a format specification with supplied replacements. This method demonstrates fixed and variable arguments.")]
public string Format(string format, params object[] args)
{
return string.Format(format, args);
}
[JsonRpcMethod("encode", Idempotent = true)]
[JsonRpcHelp("Returns the bytes of a string in a given encoding that are transmitted as a Base64 string.")]
public byte[] EncodeBytes(string s, string encoding)
{
return System.Text.Encoding.GetEncoding(encoding).GetBytes(s);
}
[JsonRpcMethod("decode", Idempotent = true)]
[JsonRpcHelp("Returns the string from encoded bytes (transmitted as a Base64 string).")]
public string DecodeString(byte[] bytes, string encoding)
{
return System.Text.Encoding.GetEncoding(encoding).GetString(bytes);
}
//[JsonRpcMethod("stypeof", Idempotent = true)]
//[JsonRpcHelp("Returns the CLR type that a given value converted to on the server.")]
//public string GetObjectType(object o)
//{
// return o != null ? o.GetType().FullName : null;
//}
[JsonRpcMethod("echoTime", Idempotent = true)]
[JsonRpcHelp("Echoes back the date/time sent as parameter.")]
public DateTime EchoTime(DateTime time)
{
return time;
}
//[JsonRpcMethod("getCouple", Idempotent = true)]
//[JsonRpcHelp("Returns a server-typed object representing a couple. Demonstrates to returning server-typed objects.")]
//public Marriage GetCouple()
//{
// return new Marriage(
// new Person("Mickey", "Mouse"),
// new Person("Minnie", "Mouse"));
//}
//[JsonRpcMethod("swapNames", Idempotent = true)]
//[JsonRpcHelp("Swaps first and last name of person. Demonstrates receiving and returning a server-typed object.")]
//public Person SwapPersonNames(Person p)
//{
// return p == null ? new Person() : new Person(p.LastName, p.FirstName);
//}
public bool IsReusable
{
get
{
return false;
}
}
}
}
|