예제 #1
0
        internal static WacResult ExecuteWacRequest(string wacTemplateUrl, string owaTemplateUrl, ADUser user, StringBuilder diagnosticsDetails)
        {
            string          text            = string.Empty;
            string          text2           = string.Empty;
            string          text3           = string.Empty;
            WacRequestState wacRequestState = new WacRequestState();
            WacResult       wacResult       = new WacResult();

            try
            {
                string text4 = user.PrimarySmtpAddress.ToString();
                if (string.IsNullOrEmpty(text4))
                {
                    diagnosticsDetails.AppendLine(string.Format("Primary SMTP Address not found for user {0}", user.Alias));
                    wacResult.Error = wacRequestState.Error;
                    return(wacResult);
                }
                text = WacWorker.GenerateWopiSrcUrl(owaTemplateUrl, text4);
                LocalTokenIssuer localTokenIssuer = new LocalTokenIssuer(user.OrganizationId);
                TokenResult      wacCallbackToken = localTokenIssuer.GetWacCallbackToken(new Uri(text, UriKind.Absolute), text4, Guid.NewGuid().ToString());
                text3 = wacCallbackToken.TokenString;
                text2 = WacWorker.GenerateWacIFrameUrl(text, wacTemplateUrl, text4, text3);
                text  = string.Format("{0}&access_token={1}", text, text3);
                diagnosticsDetails.AppendLine("Probe Details:");
                diagnosticsDetails.AppendLine("WacIFrameUrl:");
                diagnosticsDetails.AppendLine(text2);
                diagnosticsDetails.AppendLine("ExchangeCheckFileUrl:");
                diagnosticsDetails.AppendLine(text);
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(text2);
                wacRequestState.Request            = httpWebRequest;
                wacRequestState.WacIFrameUrl       = text2;
                wacRequestState.WopiUrl            = text;
                wacRequestState.Error              = false;
                wacRequestState.DiagnosticsDetails = diagnosticsDetails;
                WacWorker.allDone.Reset();
                WacWorker.latencyMeasurementStart = DateTime.UtcNow;
                IAsyncResult asyncResult = httpWebRequest.BeginGetResponse(new AsyncCallback(WacWorker.ProcessWacResponse), wacRequestState);
                ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WacWorker.TimeoutCallback), httpWebRequest, 120000, true);
                WacWorker.allDone.WaitOne();
                if (wacRequestState.Response != null)
                {
                    wacRequestState.Response.Close();
                }
            }
            catch (WebException ex)
            {
                diagnosticsDetails.AppendLine("Stack Trace:");
                diagnosticsDetails.AppendLine(string.Format("Exception: {0}.", ex.ToString()));
                for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
                {
                    diagnosticsDetails.AppendLine(string.Format("Inner Exception: {0}.", innerException.ToString()));
                }
                diagnosticsDetails.AppendLine("Diagnostic Tip: There is an unhandled exception occured while running Wac Probe. Please look into the exception details.");
                wacRequestState.Error = true;
            }
            wacResult.Error = wacRequestState.Error;
            return(wacResult);
        }
예제 #2
0
        public static ResultType SendWacOAuthRequest(string wopiUrl, string wacTemplateUrl, ADUser user, out string diagnosticMessage)
        {
            StringBuilder stringBuilder = new StringBuilder();
            WacResult     wacResult     = null;

            try
            {
                wacResult = WacWorker.ExecuteWacRequest(wacTemplateUrl, wopiUrl, user, stringBuilder);
            }
            catch (Exception ex)
            {
                stringBuilder.AppendLine("Unhandled Exception while running Wac Probe.");
                stringBuilder.AppendLine(ex.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            diagnosticMessage = stringBuilder.ToString();
            if (wacResult.Error)
            {
                return(ResultType.Error);
            }
            return(ResultType.Success);
        }