/// <summary>
        /// Initializes a new instance of the LogoutCommandMessage class
        /// </summary>
        /// <param name="clientTranId">Client transaction identifier</param>
        public LogoutCommandMessage(string clientTranId)
            : base(CommandType.Logout, false, clientTranId)
        {
            var logoutElement = new XElement(EppNs.GetName("logout"));

            this.CommandElement.AddFirst(logoutElement);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the GreetingMessage class with specified body
        /// </summary>
        /// <param name="messageDocument">Message body</param>
        internal GreetingMessage(XDocument messageDocument)
            : base(messageDocument, MessageType.Greeting)
        {
            // ReSharper disable PossibleNullReferenceException
            var greetingElement = this.EppElement.Element(EppNs.GetName("greeting"));

            this.ServiceId   = greetingElement.Element(EppNs.GetName("svID")).Value;
            this.ServiceDate = DateTime.Parse(greetingElement.Element(EppNs.GetName("svDate")).Value);

            var svcMenuElement = greetingElement.Element(EppNs.GetName("svcMenu"));

            this.Languages = svcMenuElement
                             .Elements(EppNs.GetName("lang"))
                             .Select(elem => elem.Value)
                             .ToList();
            this.Versions = svcMenuElement
                            .Elements(EppNs.GetName("version"))
                            .Select(elem => elem.Value)
                            .ToList();
            this.ObjectURIs = svcMenuElement
                              .Elements(EppNs.GetName("objURI"))
                              .Select(elem => elem.Value)
                              .ToList();

            var svcExtensionElement = svcMenuElement.Element(EppNs.GetName("svcExtension"));

            this.ExtensionURIs = svcExtensionElement != null?svcExtensionElement
                                 .Elements(EppNs.GetName("extURI"))
                                 .Select(elem => elem.Value).ToList() : new List <string>();

            // ReSharper restore PossibleNullReferenceException
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the LoginCommandMessage class based on greeting with specified client identifier, password and client transaction identifier
        /// </summary>
        /// <param name="greeting">Greeting message</param>
        /// <param name="clientId">Сlient identifier</param>
        /// <param name="password">Password for login</param>
        /// <param name="clientTranId">Client transaction identifier</param>
        public LoginCommandMessage(GreetingMessage greeting, string clientId, string password, string clientTranId)
            : base(CommandType.Login, false, clientTranId)
        {
            var clientIDElement = new XElement(EppNs.GetName("clID"), clientId);
            var passwordElement = new XElement(EppNs.GetName("pw"), password);

            var versionElement = new XElement(EppNs.GetName("version"), greeting.Versions.First());
            var langElement    = new XElement(EppNs.GetName("lang"), greeting.Languages.First());

            var optionsElement = new XElement(EppNs.GetName("options"), versionElement, langElement);

            var objURIElements = greeting.ObjectURIs.Select(objUri => new XElement(EppNs.GetName("objURI"), objUri));
            var svcsElement    = new XElement(EppNs.GetName("svcs"), objURIElements);

            if (greeting.ExtensionURIs.Any())
            {
                var extURIElements      = greeting.ExtensionURIs.Select(extUri => new XElement(EppNs.GetName("extURI"), extUri));
                var svcExtensionElement = new XElement(EppNs.GetName("svcExtension"), extURIElements);
                svcsElement.Add(svcExtensionElement);
            }

            var loginElement = new XElement(EppNs.GetName("login"), clientIDElement, passwordElement, optionsElement, svcsElement);

            this.CommandElement.AddFirst(loginElement);
        }
Пример #4
0
            /// <summary>
            /// Initializes a new instance of the ResponseResult class
            /// </summary>
            /// <param name="resultElement">XML element responsed from the server</param>
            internal ResponseResult(XElement resultElement)
            {
                this.Code = Int32.Parse(resultElement.Attribute("code").Value);

                var msgElement = resultElement.Element(EppNs.GetName("msg"));
                var langAttr   = msgElement.Attribute("lang");

                this.Language = langAttr == null ? "en" : langAttr.Value;
                this.Message  = msgElement.Value;

                var extraMessages = resultElement.Elements(EppNs.GetName("value"));

                if (extraMessages != null && extraMessages.Count() > 0)
                {
                    this.ExtraMessages = new List <string>();
                    foreach (var extraMessage in extraMessages)
                    {
                        var text = extraMessage.Element(EppNs.GetName("text"));
                        if (text != null)
                        {
                            this.ExtraMessages.Add(text.Value);
                        }
                    }
                }

                var extValueElement = resultElement.Element(EppNs.GetName("extValue"));

                if (extValueElement != null)
                {
                    var reasonElement = extValueElement.Element(EppNs.GetName("reason"));
                    this.Reason = (reasonElement == null) ? null : reasonElement.Value;
                }
            }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the ResponseMessageBase class.
        /// </summary>
        /// <param name="messageDocument">Message body</param>
        public ResponseMessageBase(XDocument messageDocument)
            : base(messageDocument, MessageType.Response)
        {
            this.Results = this.ResponseElement
                           .Elements(EppNs.GetName("result"))
                           .Select(resElement => new ResponseResult(resElement))
                           .ToList().AsReadOnly();

            var idElem = this.ResponseElement.Element(EppNs.GetName("trID"));

            if (idElem == null)
            {
                return;
            }

            var clientTRIDElem = idElem.Element(EppNs.GetName("clTRID"));

            this.ClientTranId = (clientTRIDElem == null) ? null : clientTRIDElem.Value;

            var serviceIdElem = idElem.Element(EppNs.GetName("svTRID"));

            this.ServerTranId = (serviceIdElem == null) ? null : serviceIdElem.Value;

            var msgQElement = this.ResponseElement.Element(EppNs.GetName("msgQ"));

            if (msgQElement != null)
            {
                this.MessageQueue = new ResponseMessageQueue(msgQElement);
            }

            var extensionElement = this.ResponseElement.Element(EppNs.GetName("extension"));

            if (extensionElement != null)
            {
                this.extensions = extensionElement
                                  .Elements()
                                  .Select(objElem => ExtensionManager.CreateObject(objElem))
                                  .Where(obj => obj != null)
                                  .ToList();
            }
            else
            {
                this.extensions = new List <object>();
            }
        }
Пример #6
0
        /// <summary>
        /// Sets the extension of the command
        /// </summary>
        /// <param name="extension">Command extension object</param>
        public void SetExtension(ICommandExtension extension)
        {
            if (this.ExtensionElement == null)
            {
                var extensionElement = new XElement(EppNs.GetName("extension"));
                //this.CommandElement.Add(extensionElement);

                //fix: extension should be placed before TranId
                var clTRIDElement = this.ClientTranIdElement;
                if (clTRIDElement != null)
                {
                    clTRIDElement.AddBeforeSelf(extensionElement);
                }
                else
                {
                    this.CommandElement.Add(extensionElement);
                }
            }

            //this.ExtensionElement.RemoveAll();
            extension.Fill(this.ExtensionElement);
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the CommandMessageBase class with specified command type and initial options
        /// </summary>
        /// <param name="commandType">Command type</param>
        /// <param name="hasExtension">Specifies whether the message would be contain the extension element</param>
        /// <param name="clientTranId">Client transaction identifier</param>
        public CommandMessageBase(CommandType commandType, bool hasExtension, string clientTranId)
            : base(SchemaHelper.CreateEppBaseDocument(), MessageType.Command)
        {
            this.CommandType = commandType;
            var commandElement = new XElement(EppNs.GetName("command"));

            this.EppElement.Add(commandElement);
            if (hasExtension)
            {
                var extensionElement = new XElement(EppNs.GetName("extension"));
                commandElement.Add(extensionElement);
            }

            if (clientTranId != null)
            {
                if (clientTranId.Length < 4 || clientTranId.Length > 64)
                {
                    throw new ArgumentException("Invalid length of clientTranID", "clientTranId");
                }

                var clientTranIdElem = new XElement(EppNs.GetName("clTRID"), clientTranId);
                commandElement.Add(clientTranIdElem);
            }
        }