Пример #1
0
        public void ParseResponse(string commandName, WebRequestResponse response)
        {
            if (response.Response.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new CommandAuthorizationException(string.Format("Authorization failed: {0}", response.Response.ReasonPhrase));
            }

            string xml = response.ResponseBody;

            XDocument xdoc = null;

            string xmlValidationErrorMessage;

            if (!EwsXmlHelper.IsValidXml(xml, out xmlValidationErrorMessage))
            {
                if (this.RequireValidXml)
                {
                    throw new CommandResponseXmlException(string.Format("Invalid xml content: {0}", xmlValidationErrorMessage));
                }
            }
            else
            {
                xdoc = XDocument.Load(new StringReader(xml));
            }

            this.ParseResponseCore(commandName, xdoc, response);
        }
Пример #2
0
        public void ParseResponse(string commandName, WebRequestResponse response)
        {
            if (response.Response.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new CommandAuthorizationException(string.Format("Authorization failed: {0}", response.Response.ReasonPhrase));
            }

            string xml = response.ResponseBody;

            string xmlValidationErrorMessage;

            if (!EwsXmlHelper.IsValidXml(xml, out xmlValidationErrorMessage))
            {
                throw new CommandResponseXmlException(string.Format("Invalid xml content: {0}", xmlValidationErrorMessage));
            }

            var root = XDocument.Load(new StringReader(xml)).Root;

            if (response.Response.IsSuccessStatusCode)
            {
                // read error section
                var error = root.XGetChild("Response/Error", NsEwsAutodiscover);
                if (error != null)
                {
                    string errorCode = error.XGetChildValue <string>("ErrorCode", NsEwsAutodiscover);
                    string message   = error.XGetChildValue <string>("Message", NsEwsAutodiscover);
                    string debugData = error.XGetChildValue <string>("DebugData", NsEwsAutodiscover);

                    LogService.Log("AutoDiscoverResult", string.Format("Error response code: {0} message: {1} debug data: {2}", errorCode, message, debugData));
                    return;
                }

                // read protocols section
                var nodes = root.XGetChildrenOf("Response/Account", NsEwsOutlookAutodiscover);
                foreach (var node in nodes)
                {
                    if (node.Name != null && node.Name.LocalName.Equals("Protocol", StringComparison.OrdinalIgnoreCase))
                    {
                        var type   = node.XGetChildValue <string>("Type", NsEwsOutlookAutodiscover);
                        var ewsUrl = node.XGetChildValue <string>("EwsUrl", NsEwsOutlookAutodiscover);

                        // read more about protocol type: http://blogs.technet.com/b/exchange/archive/2008/09/26/3406344.aspx
                        if (type.Equals("exch", StringComparison.OrdinalIgnoreCase))
                        {
                            this.InternalEwsUrl = ewsUrl;
                        }
                        else if (type.Equals("expr", StringComparison.OrdinalIgnoreCase))
                        {
                            this.ExternalEwsUrl = ewsUrl;
                        }
                    }
                    else if (node.Name != null && node.Name.LocalName.Equals("RedirectAddr", StringComparison.OrdinalIgnoreCase))
                    {
                        this.RedirectEmailAddress = node.Value;
                    }
                }
            }
        }
Пример #3
0
        public EwsTask BuildTask()
        {
            var task = new EwsTask();

            foreach (var property in this.properties)
            {
                int    propertyId = property.Item1;
                string value      = property.Item2;

                var definition = EwsTaskSchema.GetPropertyDefinition(propertyId);

                switch (definition.FieldUri)
                {
                case EwsFieldUri.TaskTitle:
                    task.Subject = EwsXmlHelper.ReadStringAs <string>(value);
                    break;

                case EwsFieldUri.TaskDueDate:
                    task.DueDate = EwsXmlHelper.ReadStringAs <DateTime>(value);
                    break;

                case EwsFieldUri.TaskStartDate:
                    task.StartDate = EwsXmlHelper.ReadStringAs <DateTime>(value);
                    break;

                case EwsFieldUri.TaskOrdinalDate:
                    task.OrdinalDate = EwsXmlHelper.ReadStringAs <DateTime>(value);
                    break;

                case EwsFieldUri.TaskSubOrdinalDate:
                    task.SubOrdinalDate = EwsXmlHelper.ReadStringAs <string>(value);
                    break;

                case EwsFieldUri.TaskCompletedDate:
                    task.CompleteDate = EwsXmlHelper.ReadStringAs <DateTime>(value);
                    break;

                case EwsFieldUri.TaskComplete:
                    task.Complete = EwsXmlHelper.ReadStringAs <bool>(value);
                    break;

                case EwsFieldUri.TaskIsRecurring:
                    task.IsRecurring = EwsXmlHelper.ReadStringAs <bool>(value);
                    break;

                case EwsFieldUri.TaskIsDeadOccurence:
                    task.IsDeadOccurence = EwsXmlHelper.ReadStringAs <bool>(value);
                    break;

                case EwsFieldUri.TaskPercentComplete:
                    task.PercentComplete = EwsXmlHelper.ReadStringAs <double>(value);
                    break;

                case EwsFieldUri.TaskStatus:
                    task.Status = EwsXmlHelper.ReadStringAs <EwsTaskStatus>(value);
                    break;

                default:
                    Debugger.Break();
                    break;
                }
            }

            return(task);
        }