Пример #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);
        }
Пример #3
0
        internal static void ProcessWacResponse(IAsyncResult asyncResult)
        {
            WacRequestState wacRequestState = (WacRequestState)asyncResult.AsyncState;
            int             num             = (int)(DateTime.UtcNow - WacWorker.latencyMeasurementStart).TotalMilliseconds;

            wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Latency: {0}.", num));
            HttpWebRequest request = wacRequestState.Request;

            if (request != null)
            {
                try
                {
                    HttpWebResponse httpWebResponse = (HttpWebResponse)request.EndGetResponse(asyncResult);
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("X-CorrelationId: {0}.", httpWebResponse.Headers.Get("X-CorrelationId")));
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("X-OfficeFE: {0}.", httpWebResponse.Headers.Get("X-OfficeFE")));
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("X-OfficeVersion: {0}.", httpWebResponse.Headers.Get("X-OfficeVersion")));
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Wac IFrameUrl Request's StatusDescription: {0}.", httpWebResponse.StatusDescription));
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Wac IFrameUrl Request's StatusCode: {0}.", (int)httpWebResponse.StatusCode));
                    if (httpWebResponse.StatusCode == HttpStatusCode.OK)
                    {
                        string text = null;
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream))
                            {
                                text = streamReader.ReadToEnd();
                            }
                        }
                        if (text.Contains(HttpUtility.UrlEncode("DummyAttachment")))
                        {
                            wacRequestState.DiagnosticsDetails.AppendLine(string.Format("WacProbe succeeded, we are successfully able to verify Wac server's connectivy to Exchange's server", new object[0]));
                            wacRequestState.Error = false;
                            WacWorker.allDone.Set();
                        }
                        else
                        {
                            wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Probe Error: {0}", WacWorker.knownIssuesForWacProbe[WacConnectivityErrors.WacInvalidResponse]));
                            wacRequestState.DiagnosticsDetails.AppendLine("Diagnostic Tip: Please determine the response from Exchange's CheckFile Wopi reqest");
                            wacRequestState.Error = true;
                            WacWorker.CheckExchangeWopiEndpoint(wacRequestState.WopiUrl, wacRequestState.DiagnosticsDetails);
                        }
                    }
                    else
                    {
                        wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Probe Error: {0}", WacWorker.knownIssuesForWacProbe[WacConnectivityErrors.WacUrlNetworkIssue]));
                        wacRequestState.DiagnosticsDetails.AppendLine("Diagnostic Tip: Please use the Wac IFrameUrl Request's StatusCode, X-CorrelationId and X-OfficeFE server while reaching out to Wac911");
                        wacRequestState.Error = true;
                        WacWorker.allDone.Set();
                    }
                }
                catch (WebException ex)
                {
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Wac Request Url: {0}.", wacRequestState.WacIFrameUrl));
                    wacRequestState.DiagnosticsDetails.AppendLine("Stack Trace:");
                    wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Exception: {0}.", ex.ToString()));
                    for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
                    {
                        wacRequestState.DiagnosticsDetails.AppendLine(string.Format("Inner Exception: {0}.", innerException.ToString()));
                    }
                    wacRequestState.DiagnosticsDetails.AppendLine("Diagnostic Tip: There is an unhandled exception occured while hitting Wac endpoint.");
                    wacRequestState.DiagnosticsDetails.AppendLine("Diagnostic Tip: Please look into the exception details.");
                    wacRequestState.Error = true;
                }
                WacWorker.allDone.Set();
            }
        }