Esempio n. 1
0
        /// <summary>
        /// Выполняет поиск входящих писем с подтверждением об обработке файлов за указанный период
        /// </summary>
        /// <param name="begin">Дата начиная с которой будет происходить поиск писем</param>
        /// <returns></returns>
        public static ItemType[] GetMessages(DateTime begin)
        {
            ExchangeServiceBinding bind = new ExchangeServiceBinding();

            bind.Credentials = new NetworkCredential(AppHelper.Configuration.Exchange.Username.GetDecryptedString(),
                                                     AppHelper.Configuration.Exchange.Password.GetDecryptedString(), AppHelper.Configuration.Exchange.Domain);
            bind.Url = "https://" + AppHelper.Configuration.Exchange.ServerName + "/EWS/Exchange.asmx";

            FindItemType findType = new FindItemType();

            findType.Traversal           = ItemQueryTraversalType.Shallow;
            findType.ItemShape           = new ItemResponseShapeType();
            findType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();

            folder.Id = DistinguishedFolderIdNameType.inbox;
            findType.ParentFolderIds = new BaseFolderIdType[] { folder };

            IsEqualToType            isEq  = new IsEqualToType();
            PathToUnindexedFieldType uPath = new PathToUnindexedFieldType();

            uPath.FieldURI = UnindexedFieldURIType.messageFrom;
            FieldURIOrConstantType constType  = new FieldURIOrConstantType();
            ConstantValueType      constValue = new ConstantValueType();

            constValue.Value        = AppHelper.Configuration.Exchange.SenderName;
            constType.Item          = constValue;
            isEq.Item               = uPath;
            isEq.FieldURIOrConstant = constType;

            IsGreaterThanOrEqualToType isGrEq = new IsGreaterThanOrEqualToType();
            PathToUnindexedFieldType   uPath2 = new PathToUnindexedFieldType();

            uPath2.FieldURI = UnindexedFieldURIType.itemDateTimeSent;
            FieldURIOrConstantType constType2  = new FieldURIOrConstantType();
            ConstantValueType      constValue2 = new ConstantValueType();

            constValue2.Value         = string.Format("{0}-{1}-{2}T00:00:00Z", begin.Year, begin.Month.ToString("D2"), begin.Day.ToString("D2"));
            constType2.Item           = constValue2;
            isGrEq.Item               = uPath2;
            isGrEq.FieldURIOrConstant = constType2;

            AndType and = new AndType();

            and.Items = new SearchExpressionType[] { isEq, isGrEq };

            findType.Restriction      = new RestrictionType();
            findType.Restriction.Item = and;

            FindItemResponseType        findResp = bind.FindItem(findType);
            FindItemResponseMessageType resMes   = findResp.ResponseMessages.Items[0] as FindItemResponseMessageType;

            if (resMes.ResponseClass != ResponseClassType.Success)
            {
                throw new Exception("Ошибка при получении ответа от сервера Exchange:\n" + resMes.MessageText);
            }
            ItemType[] messages = (resMes.RootFolder.Item as ArrayOfRealItemsType).Items;

            return(messages);
        }
        /// <summary>
        /// A new, improved ContactsView method (Listing 6-16)
        /// </summary>
        /// <param name="folderId">Folder to perform FindItem in</param>
        /// <param name="responseShape">ResponseShape for returned contacts</param>
        /// <param name="pathForRestriction">The property path to compare against</param>
        /// <param name="lowerBounds">lower bounds string (inclusive)</param>
        /// <param name="upperBounds">upper bounds string (exclusive)</param>
        /// <param name="offset">For indexed paging, the offset into the result set to start at</param>
        /// <param name="maxEntries">Max entries to return for each page.  Zero for unbounded</param>
        /// <returns>FindItemResponseMessageType</returns>
        /// 
        public FindItemResponseMessageType SuperContactsView(
										BaseFolderIdType folderId,
										ItemResponseShapeType responseShape,
										BasePathToElementType pathForRestriction,
										string lowerBounds,
										string upperBounds,
										int offset,
										int maxEntries)
        {
            FindItemType request = new FindItemType();
            request.ItemShape = responseShape;
            // If they set a maxEntries > 0, use indexed paging just to limit the results.
            //
            if (maxEntries > 0)
            {
                IndexedPageViewType paging = new IndexedPageViewType();
                paging.BasePoint = IndexBasePointType.Beginning;
                paging.Offset = offset;
                paging.MaxEntriesReturned = maxEntries;
                paging.MaxEntriesReturnedSpecified = true;
                request.Item = paging;
            }
            request.ParentFolderIds = new BaseFolderIdType[] { folderId };
            request.Traversal = ItemQueryTraversalType.Shallow;

            // Build up our restriction
            //
            AndType and = new AndType();
            IsGreaterThanOrEqualToType lowerBoundsFilter = new IsGreaterThanOrEqualToType();
            lowerBoundsFilter.Item = pathForRestriction;
            lowerBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType();
            ConstantValueType lowerBoundsValue = new ConstantValueType();
            lowerBoundsValue.Value = lowerBounds;
            lowerBoundsFilter.FieldURIOrConstant.Item = lowerBoundsValue;

            IsLessThanType upperBoundsFilter = new IsLessThanType();
            upperBoundsFilter.Item = pathForRestriction;
            upperBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType();
            ConstantValueType upperBoundsValue = new ConstantValueType();
            upperBoundsValue.Value = upperBounds;
            upperBoundsFilter.FieldURIOrConstant.Item = upperBoundsValue;

            and.Items = new SearchExpressionType[] { lowerBoundsFilter, upperBoundsFilter };
            request.Restriction = new RestrictionType();
            request.Restriction.Item = and;

            // Make the request
            //
            FindItemResponseType response = this.FindItem(request);
            return response.ResponseMessages.Items[0] as FindItemResponseMessageType;
        }
Esempio n. 3
0
 public static void SetAnd(AndType a)
 {
     andop = a;
 }
            /// <summary>
            /// The process and.
            /// </summary>
            /// <param name="andType">
            /// The and type.
            /// </param>
            /// <exception cref="SdmxNotImplementedException">
            /// DataWhere.And followed by AND is not supported
            ///     -or-
            ///     Multiple Time selection on DataWhere.And not supported
            /// </exception>
            /// <exception cref="SdmxSemmanticException">
            /// Query Selection Illegal And Codes In Same Dimensions
            /// </exception>
            /// <exception cref="SdmxSemmanticException">
            /// Multiple Data Structure Ids not supported on DataWhere
            /// </exception>
            private void ProcessAnd(AndType andType)
            {
                ISet<IDataQuerySelection> selections = new HashSet<IDataQuerySelection>();
                ISdmxDate dateFrom = null;
                ISdmxDate dateTo = null;

                if (andType != null)
                {
                    if (ObjectUtil.ValidCollection(andType.And))
                    {
                        throw new SdmxNotImplementedException("DataWhere.And followed by AND is not supported");
                    }

                    if (andType.Dimension != null)
                    {
                        /* foreach */
                        foreach (DimensionType currentDimension in andType.Dimension)
                        {
                            /* foreach */
                            foreach (IDataQuerySelection selection in selections)
                            {
                                // CAN NOT AND TWO DIMENSIONS WITH DIFFERNT VALUES
                                if (selection.ComponentId.Equals(currentDimension.id))
                                {
                                    throw new SdmxSemmanticException(
                                        ExceptionCode.QuerySelectionIllegalAndCodesInSameDimension, currentDimension.id);
                                }
                            }

                            AddComponentSelection(selections, currentDimension.id, currentDimension.TypedValue);
                        }
                    }

                    if (andType.Attribute != null)
                    {
                        /* foreach */
                        foreach (AttributeType currentDimension in andType.Attribute)
                        {
                            /* foreach */
                            foreach (IDataQuerySelection selection in selections)
                            {
                                // CAN NOT AND TWO DIMENSIONS WITH DIFFERNT VALUES
                                if (selection.ComponentId.Equals(currentDimension.id))
                                {
                                    throw new SdmxSemmanticException(
                                        ExceptionCode.QuerySelectionIllegalAndCodesInSameDimension, currentDimension.id);
                                }
                            }

                            AddComponentSelection(selections, currentDimension.id, currentDimension.TypedValue);
                        }
                    }

                    if (andType.Time != null)
                    {
                        if (andType.Time.Count > 1)
                        {
                            throw new SdmxNotImplementedException("Multiple Time selection on DataWhere.And not supported");
                        }

                        /* foreach */
                        foreach (TimeType time in andType.Time)
                        {
                            var t = new Time(time);
                            dateFrom = t.DateFrom;
                            dateTo = t.DateTo;
                        }
                    }

                    if (ObjectUtil.ValidCollection(andType.AgencyID))
                    {
                        if (andType.AgencyID.Count > 1)
                        {
                            throw new SdmxSemmanticException(ExceptionCode.QuerySelectionIllegalAndAgencyId);
                        }

                        if (this._agencyId != null && !andType.AgencyID[0].Equals(this._agencyId))
                        {
                            throw new SdmxSemmanticException(
                                "Multiple agency Ids not supported on DataWhere - got '" + this._agencyId + "' and '"
                                + andType.AgencyID[0] + "'");
                        }

                        this._agencyId = andType.AgencyID[0];
                    }

                    if (ObjectUtil.ValidCollection(andType.KeyFamily))
                    {
                        if (andType.KeyFamily.Count > 1)
                        {
                            throw new SdmxSemmanticException(ExceptionCode.QuerySelectionIllegalAndKeyfamily);
                        }

                        if (this._keyFamilyId != null && !andType.KeyFamily[0].Equals(this._keyFamilyId))
                        {
                            throw new SdmxSemmanticException(
                                "Multiple Data Structure Ids not supported on DataWhere - got '" + this._keyFamilyId
                                + "' and '" + andType.KeyFamily[0] + "'");
                        }

                        this._keyFamilyId = andType.KeyFamily[0];
                    }

                    if (ObjectUtil.ValidCollection(andType.Dataflow))
                    {
                        if (andType.Dataflow.Count > 1)
                        {
                            throw new SdmxNotImplementedException("Multiple Dataflow Ids not supported in an AND operation");
                        }

                        if (this._dataflowId != null && !andType.Dataflow[0].Equals(this._dataflowId))
                        {
                            throw new SdmxSemmanticException(
                                "Multiple Dataflow Ids not supported on DataWhere - got '" + this._dataflowId
                                + "' and '" + andType.Dataflow[0] + "'");
                        }

                        this._dataflowId = andType.Dataflow[0];
                    }

                    this.ProcessOr(andType.Or, selections);
                    this.AddGroupIfSelectionsExist(selections, dateFrom, dateTo);
                }
            }