/// <summary> /// Actually calls into Compare Service to perform comparison. Currently it used a hardcoded /// binding wsHttpBinding. After the call has returned successfully, it calls the results /// routine to display the results. /// </summary> /// <param name="sOriginalFile"></param> /// <param name="sModifiedFile"></param> /// <param name="sVirtualPath"></param> private void DoCompare(string sOriginalFile, string sModifiedFile, string sVirtualPath) { ResponseOptions responseOptions = ResponseOptions.Rtf; string password = (string)Session["Passw"]; password = CodePassword(password); // Hardcoded wsHttpBinding. Host info is picked from config file ComparerClient cp = new ComparerClient("CompareWebServiceWCF"); cp.ClientCredentials.Windows.ClientCredential.UserName = UserNameTextBox.Text; cp.ClientCredentials.Windows.ClientCredential.Password = password; cp.ClientCredentials.Windows.ClientCredential.Domain = RealmTextBox.Text; // Authenticate first. if (cp.Authenticate(RealmTextBox.Text, UserNameTextBox.Text, password)) { byte[] original = File.ReadAllBytes(sOriginalFile); byte[] modified = File.ReadAllBytes(sModifiedFile); string sRenderingSet = RenderingSetDropDownList.SelectedValue; string sOptionSet = File.ReadAllText(Request.MapPath(Path.Combine(sRenderSetPath, sRenderingSet))); ExecuteParams executeParams = new ExecuteParams() { CompareOptions = sOptionSet, ResponseOption = responseOptions, Original = original, Modified = modified, OriginalDocumentInfo = new DocumentInfo() { DocumentDescription = Path.GetFileName(sOriginalFile), DocumentSource = Path.GetFileName(sOriginalFile) }, ModifiedDocumentInfo = new DocumentInfo() { DocumentDescription = Path.GetFileName(sModifiedFile), DocumentSource = Path.GetFileName(sModifiedFile) }, }; // Peform comparison CompareResults results = cp.ExecuteEx(executeParams); // Prepare and Display results. HandleResults(results, responseOptions, sOriginalFile, sModifiedFile, sRenderingSet, sVirtualPath); } else { ShowMessage("Authentication failed."); } }
public ComparerResult DoComparison(IPrincipal principal, ComparerArguments arguments) { ComparerResult cResult = new ComparerResult(); try { /* Impersonation for connect to WCF using ASP.net Authenticated User */ System.Security.Principal.WindowsImpersonationContext impersonationContext = ((System.Security.Principal.WindowsIdentity)principal.Identity).Impersonate(); ComparerClient cc = GetComparerClient(); /* Uploaded files should be readed by ISS Application Pool User */ impersonationContext.Undo(); byte[] original = System.IO.File.ReadAllBytes(Path.Combine(UploadPath, arguments.OriginalDoc.ServerName)); // string resultPath = System.IO.Directory.GetParent(arguments.OriginalDoc.ServerName).FullName; foreach (ServerFile file in arguments.ModifiedDoc) { ComparisonResult result = new ComparisonResult(); CompareResults cr; try { result.File = file.ClientName; byte[] modified = System.IO.File.ReadAllBytes(Path.Combine(UploadPath, file.ServerName)); string sOptionSet = System.IO.File.ReadAllText(arguments.RenderingSet); Log.Write(TraceEventType.Information, "Comparing {0} and {1} files", arguments.OriginalDoc.ClientName, file.ClientName); var executeParams = new ExecuteParams() { CompareOptions = sOptionSet, Original = original, Modified = modified, ResponseOption = arguments.OutputFormat, OriginalDocumentInfo = CreateDocInfo(arguments.OriginalDoc.ClientName), ModifiedDocumentInfo = CreateDocInfo(file.ClientName) }; cr = cc.ExecuteEx(executeParams); if (cr != null) { string fileName = System.IO.Path.GetFileNameWithoutExtension(result.File); if (cr.Redline != null) { result.Redline = storeFileOnServer(cr.Redline, fileName + ".redline." + getExtension(arguments.OutputFormat)); } if (!string.IsNullOrEmpty(cr.RedlineMl)) { result.RedlineMl = storeFileOnServer(cr.RedlineMl, fileName + ".redlineml.xml"); } if (!string.IsNullOrEmpty(cr.Summary)) { result.Summary = storeFileOnServer(cr.Summary, fileName + ".summary.xml"); } } else { Log.Write(TraceEventType.Error, "Null result"); result.Error = "No results"; } } catch (System.Security.SecurityException ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = "Security Error: " + ex.Message; } catch (FileNotFoundException ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = "File not found on server"; } catch (Exception ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = ex.Message; } cResult.Comperisons.Add(result); } checkTimeOutFiles(); } catch (System.ServiceModel.ServerTooBusyException ex) { cResult.Errors.Add("Server Too Busy"); Log.Write(TraceEventType.Error, "{0}", ex); } catch (TimeoutException ex) { cResult.Errors.Add("Faild to connect to server (Timeout)"); Log.Write(TraceEventType.Error, "{0}", ex); } catch (System.ServiceModel.FaultException ex) { cResult.Errors.Add("FaultException: " + ex.Message); Log.Write(TraceEventType.Error, "{0}", ex); } catch (System.ServiceModel.CommunicationException ex) { if (ex.Message.Contains("request is unauthorized")) { cResult.Errors.Add(@"Unauthorized issue arised, please check User Name and/or Password and/or domain!"); } else { cResult.Errors.Add("CommunicationException: " + ex.Message); } Log.Write(TraceEventType.Error, "{0}", ex); } catch (FileNotFoundException ex) { Log.Write(TraceEventType.Error, "{0}", ex); throw new Exception("Original file not found on server"); } catch (Exception ex) { ComparerResult result = new ComparerResult(); cResult.Errors.Add(ex.Message); Log.Write(TraceEventType.Error, "{0}", ex); } return(cResult); }