public override void EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)
        {
            GetUserAvailabilityResponse getUserAvailabilityResponse = service.EndGetUserAvailability(asyncResult);

            FreeBusyResponse[] array = null;
            if (getUserAvailabilityResponse != null)
            {
                array = getUserAvailabilityResponse.FreeBusyResponseArray;
            }
            if (array == null)
            {
                Application.ProxyWebRequestTracer.TraceError((long)proxyWebRequest.GetHashCode(), "{0}: Proxy web request returned NULL FreeBusyResponseArray.", new object[]
                {
                    TraceContext.Get()
                });
            }
            for (int i = 0; i < queryList.Count; i++)
            {
                FreeBusyQuery    freeBusyQuery    = (FreeBusyQuery)queryList[i];
                FreeBusyResponse freeBusyResponse = null;
                if (array != null && i < array.Length)
                {
                    freeBusyResponse = array[i];
                    if (freeBusyResponse == null)
                    {
                        Application.ProxyWebRequestTracer.TraceDebug <object, EmailAddress>((long)proxyWebRequest.GetHashCode(), "{0}: Proxy web request returned NULL FreeBusyResponse for mailbox {1}.", TraceContext.Get(), freeBusyQuery.Email);
                    }
                }
                FreeBusyQueryResult resultOnFirstCall;
                if (freeBusyResponse == null)
                {
                    resultOnFirstCall = new FreeBusyQueryResult(new ProxyNoResultException(Strings.descProxyNoResultError(freeBusyQuery.Email.Address, service.Url), 60732U));
                }
                else
                {
                    resultOnFirstCall = FreeBusyApplication.CopyViewAndResponseToResult(service.Url, freeBusyResponse.FreeBusyView, freeBusyResponse.ResponseMessage, freeBusyQuery.Email);
                }
                freeBusyQuery.SetResultOnFirstCall(resultOnFirstCall);
            }
        }
        public override BaseQuery CreateFromGroup(RecipientData recipientData, BaseQuery[] groupMembers, bool groupCapped)
        {
            bool flag  = (this.queryType & QueryType.FreeBusy) != (QueryType)0;
            bool flag2 = (this.queryType & QueryType.MeetingSuggestions) != (QueryType)0 && !groupCapped;

            FreeBusyQuery[] groupMembersForFreeBusy    = null;
            FreeBusyQuery[] groupMembersForSuggestions = null;
            if (flag)
            {
                if (groupCapped)
                {
                    Application.ProxyWebRequestTracer.TraceDebug <object, RecipientData>((long)this.GetHashCode(), "{0}:Not generating requests for members of group {1} because the group is larger than the allowed group size.", TraceContext.Get(), recipientData);
                    return(FreeBusyQuery.CreateFromGroup(recipientData, new FreeBusyDLLimitReachedException(Configuration.MaximumGroupMemberCount)));
                }
                groupMembersForFreeBusy = FreeBusyApplication.ConvertBaseToFreeBusyQuery(groupMembers);
            }
            if (flag2)
            {
                groupMembersForSuggestions = FreeBusyApplication.ConvertBaseToFreeBusyQuery(groupMembers);
            }
            return(FreeBusyQuery.CreateFromGroup(recipientData, groupMembersForFreeBusy, groupMembersForSuggestions));
        }
Example #3
0
        private void ExecuteFreeBusyQuery(AvailabilityQueryResult availabilityQueryResult)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            AvailabilityQuery.CalendarViewTracer.TraceDebug((long)this.GetHashCode(), "{0}: Entering AvailabilityQuery.ExecuteFreeBusyQuery()", new object[]
            {
                TraceContext.Get()
            });
            base.RequestLogger.AppendToLog <int>("AddressCount", this.MailboxArray.Length);
            base.RequestLogger.AppendToLog <string>("MessageId", base.ClientContext.MessageId);
            base.RequestLogger.AppendToLog <string>("Requester", base.ClientContext.IdentityForFilteredTracing);
            try
            {
                Guid           serverRequestId = Microsoft.Exchange.Diagnostics.Trace.TraceCasStart(this.casTraceEventType);
                QueryType      queryType       = ((this.desiredFreeBusyView != null) ? QueryType.FreeBusy : ((QueryType)0)) | ((this.desiredSuggestionsView != null) ? QueryType.MeetingSuggestions : ((QueryType)0));
                ADObjectId     adobjectId      = null;
                OrganizationId organizationId  = OrganizationId.ForestWideOrgId;
                if (base.ClientContext is InternalClientContext && !this.IsCrossForestRequest)
                {
                    adobjectId     = base.ClientContext.QueryBaseDN;
                    organizationId = base.ClientContext.OrganizationId;
                }
                if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& (organizationId == null || organizationId == OrganizationId.ForestWideOrgId))
                {
                    AvailabilityQuery.CalendarViewTracer.TraceDebug <object, EmailAddress>((long)this.GetHashCode(), "{0}: Looking up the OrgId for address {1}", TraceContext.Get(), this.mailboxArray[0].Email);
                    organizationId = this.GetTargetOrganizationIdFromCache(this.mailboxArray[0].Email);
                }
                if (organizationId != null && organizationId.OrganizationalUnit != null)
                {
                    base.RequestLogger.AppendToLog <string>("ORG", organizationId.OrganizationalUnit.Name);
                }
                AvailabilityQuery.CalendarViewTracer.TraceDebug((long)this.GetHashCode(), "{0}: Ad scoping for the requester {1}: QueryBaseDN: {2}, OrganizationId: {3}", new object[]
                {
                    TraceContext.Get(),
                    base.ClientContext.ToString(),
                    (adobjectId == null) ? "<NULL>" : adobjectId.ToString(),
                    organizationId
                });
                FreeBusyApplication freeBusyApplication = new FreeBusyApplication(base.ClientContext, this.internalFreeBusyView, this.defaultFreeBusyOnly, queryType);
                try
                {
                    this.queryPrepareDeadline      = this.queryPrepareDeadline.AddMilliseconds(-this.PreExecutionTimeTaken);
                    this.requestProcessingDeadline = this.requestProcessingDeadline.AddMilliseconds(-this.PreExecutionTimeTaken);
                    using (RequestDispatcher requestDispatcher = new RequestDispatcher(base.RequestLogger))
                    {
                        FreeBusyRecipientQuery freeBusyRecipientQuery = new FreeBusyRecipientQuery(base.ClientContext, adobjectId, organizationId, this.queryPrepareDeadline);
                        RecipientQueryResults  recipientQueryResults  = freeBusyRecipientQuery.Query(this.mailboxArray);
                        QueryGenerator         queryGenerator         = new QueryGenerator(freeBusyApplication, base.ClientContext, base.RequestLogger, requestDispatcher, this.queryPrepareDeadline, this.requestProcessingDeadline, recipientQueryResults);
                        bool flag = false;
                        try
                        {
                            BaseQuery[] queries = queryGenerator.GetQueries();
                            this.freeBusyQueryArray = FreeBusyApplication.ConvertBaseToFreeBusyQuery(queries);
                            if (base.ClientContext.Budget != null)
                            {
                                base.ClientContext.Budget.EndLocal();
                                flag = true;
                            }
                            requestDispatcher.Execute(this.requestProcessingDeadline, base.HttpResponse);
                            this.individualMailboxesProcessed = queryGenerator.UniqueQueriesCount;
                        }
                        finally
                        {
                            if (flag)
                            {
                                base.ClientContext.Budget.StartLocal("AvailabilityQuery.ExecuteFreeBusyQuery", default(TimeSpan));
                            }
                            requestDispatcher.LogStatistics(base.RequestLogger);
                        }
                    }
                }
                finally
                {
                    freeBusyApplication.LogThreadsUsage(base.RequestLogger);
                }
                foreach (FreeBusyQuery freeBusyQuery in this.freeBusyQueryArray)
                {
                    if (freeBusyQuery.AttendeeKind == AttendeeKind.Group)
                    {
                        FreeBusyQueryResult resultOnFirstCall;
                        if (freeBusyQuery.GroupMembersForFreeBusy != null)
                        {
                            resultOnFirstCall = MergedFreeBusy.MergeGroupMemberResults(base.ClientContext.TimeZone, this.internalFreeBusyView.MergedFreeBusyIntervalInMinutes, new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.StartTime), new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.EndTime), freeBusyQuery.GroupMembersForFreeBusy, base.ClientContext.RequestSchemaVersion);
                        }
                        else
                        {
                            resultOnFirstCall = new FreeBusyQueryResult(FreeBusyViewType.None, null, null, null);
                        }
                        freeBusyQuery.SetResultOnFirstCall(resultOnFirstCall);
                    }
                }
                availabilityQueryResult.FreeBusyResults = new FreeBusyQueryResult[this.freeBusyQueryArray.Length];
                for (int j = 0; j < this.freeBusyQueryArray.Length; j++)
                {
                    availabilityQueryResult.FreeBusyResults[j] = this.freeBusyQueryArray[j].Result;
                }
                this.TraceExecuteFreeBusyQueryStop(serverRequestId);
                AvailabilityQuery.CalendarViewTracer.TraceDebug((long)this.GetHashCode(), "{0}: Leaving AvailabilityQuery.ExecuteFreeBusyQuery()", new object[]
                {
                    TraceContext.Get()
                });
            }
            finally
            {
                base.RequestLogger.CalculateQueryStatistics(this.freeBusyQueryArray);
                base.LogFailures(availabilityQueryResult, base.RequestLogger.ExceptionData);
                stopwatch.Stop();
                base.RequestLogger.AppendToLog <long>("TAQ", stopwatch.ElapsedMilliseconds);
            }
        }