コード例 #1
0
ファイル: LegionService.cs プロジェクト: arychj/Legion
 public static void DestroyAuthToken(string apikey, string token)
 {
     LegionService.GetReply(LEGION_URL, apikey, ReplyFormat.XML.ToString(), "__system", "DestroyAuthToken", new Dictionary <string, string>()
     {
         { "token", token }
     });
 }
コード例 #2
0
ファイル: LegionService.cs プロジェクト: arychj/Legion
        public static bool ReissueAuthToken()
        {
            Dictionary <string, string> packet = SessionItemContainer.Retrieve(SessionItemContainerKey.AuthPacket) as Dictionary <string, string>;

            if (packet != null)
            {
                string apiurl = packet["__apiurl"];
                string apikey = packet["__apikey"];
                Dictionary <string, string> parameters = packet.Where(p => !p.Key.StartsWith("__")).ToDictionary(p => p.Key, p => p.Value);

                XmlNode xToken = LegionService.GetReply(apiurl, apikey, ReplyFormat.XML.ToString(), "__system", "CreateAuthToken", parameters).ToXml().SelectSingleNode("//token");
                if (xToken != null)
                {
                    string token = xToken.InnerText;
                    SessionItemContainer.Store(SessionItemContainerKey.AuthPacket, packet);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: LegionService.cs プロジェクト: arychj/Legion
        public static bool HeartbeatAuthToken(string apikey, string token)
        {
            string tokenheartbeat = LegionService.GetReply(LEGION_URL, apikey, ReplyFormat.XML.ToString(), "__system", "HeartbeatAuthToken", new Dictionary <string, string>()
            {
                { "token", token }
            }).ToXml().SelectSingleNode("//tokenheartbeat").InnerText;

            return(tokenheartbeat.ToLower() == "Success");
        }
コード例 #4
0
ファイル: LegionService.cs プロジェクト: arychj/Legion
        /// <summary>
        ///
        /// </summary>
        /// <param name="apikey"></param>
        /// <param name="apiurl"></param>
        /// <param name="type"></param>
        /// <param name="identifier"></param>
        /// <param name="email"></param>
        /// <param name="givenname"></param>
        /// <param name="surname"></param>
        /// <returns></returns>
        public static string CreateAuthToken(string apikey, string apiurl, LegionAccountType type, string identifier)
        {
            Dictionary <string, string> packet = new Dictionary <string, string>()
            {
                { "AccountType", type.ToString() },
                { "AccountId", identifier },
                { "__apikey", apikey },
                { "__apiurl", apiurl }
            };

            Dictionary <string, string> parameters = packet.Where(p => !p.Key.StartsWith("__")).ToDictionary(p => p.Key, p => p.Value);

            XmlDocument xReply = LegionService.GetReply(apiurl, apikey, ReplyFormat.XML.ToString(), "__system", "CreateAuthToken", parameters).ToXml();

            XmlNode xToken = xReply.SelectSingleNode("//token");

            if (xToken != null)
            {
                string token = xToken.InnerText;
                SessionItemContainer.Store(SessionItemContainerKey.AuthPacket, packet);
                return(token);
            }
            else
            {
                XmlNode xFriendly = xReply.SelectSingleNode("//error/description[@type='friendly']");
                if (xFriendly != null)
                {
                    throw new LegionServiceException(string.Format("{0} ({1}:{2})", xFriendly.InnerText, type, identifier));
                }
                else
                {
                    XmlNode xError = xReply.SelectSingleNode("//error");
                    if (xError != null)
                    {
                        throw new LegionServiceException(string.Format("{0} ({1}:{2})", xFriendly.InnerText, type, identifier));
                    }
                    else
                    {
                        XmlNode xFault = xReply.SelectSingleNode("//fault");
                        if (xFault != null)
                        {
                            throw new LegionServiceException(string.Format("{0} ({1})", xFault.InnerText, xFault.Attributes["type"].Value));
                        }
                        else
                        {
                            throw new LegionServiceException("Unknown error. Unable to parse CreateAuthToken() response.");
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Calls a method in the Legion Service
        /// </summary>
        /// <param name="method">The method to call</param>
        /// <param name="methodParams">A Dictionary of the parameters to pass to the service</param>
        /// <param name="exceptionOnFault">Throw and excpetion if a fault occurs in the service call</param>
        /// <returns>An XML based LegionReply</returns>
        public LegionReply <XmlElement> Call(string method, Dictionary <string, string> methodParams, bool exceptionOnError)
        {
            LegionReply <XmlElement> reply = null;

            try {
                string sReply = base.GetReply(method, methodParams);
                reply = LegionReply <XmlElement> .BuildLegionXmlReply(sReply);
            }
            catch (Exception e) {
                //optional logging
                throw;
            }

            if (reply.HasFault)
            {
                if (reply.Fault.Type.StartsWith("ApiKey") || _service.ToLower() == "lumberjack")
                {
                    //opttional logging
                    throw new Exception(reply.Fault);
                }
                else if (reply.Fault.Type.StartsWith("AuthenticatedUserRequired"))
                {
                    LegionService.ReissueAuthToken();
                    return(Call(method, methodParams, exceptionOnError));
                }
                else
                {
                    throw new LegionServiceException(reply.Fault);
                }
            }
            else if (exceptionOnError && reply.HasError)
            {
                throw new LegionServiceErrorException(reply.Error);
            }

            return(reply);
        }
コード例 #6
0
 public static void DestoryAuthToken()
 {
     LegionService.DestroyAuthToken(APIKey, AuthToken);
     AuthToken = null;
 }
コード例 #7
0
 public static bool HeartbeatAuthToken()
 {
     return(LegionService.HeartbeatAuthToken(APIKey, AuthToken));
 }
コード例 #8
0
 public static string CreateAuthToken(LegionAccountType type, string identifier)
 {
     AuthToken = LegionService.CreateAuthToken(APIKey, APIURL, type, identifier);
     return(AuthToken);
 }
コード例 #9
0
ファイル: LegionService.cs プロジェクト: arychj/Legion
 /// <summary>
 /// Get the sReply from a method in a Legion Service
 /// </summary>
 /// <param name="method">The method to call</param>
 /// <param name="p">The parameters to pass to the method</param>
 /// <returns>the raw reponse from the Service</returns>
 public string GetReply(string method, Dictionary <string, string> p)
 {
     return(LegionService.GetReply(_apiurl, _apikey, _replyformat.ToString(), _service, method, p));
 }