Beispiel #1
0
        public ComparerClient OpenConnection()
        {
            Log.Write(TraceEventType.Information, "Opening connection...");
            ComparerClient cc = null;

            try
            {
                if (UseConfig())
                {
                    cc = new ComparerClient(AppConfig.EndpointConfig, AppConfig.EndpointAddress);
                }
                else
                {
                    DefaultCompareConfig config = new DefaultCompareConfig();
                    cc = new ComparerClient(config.GetBinding(), config.GetEndpointAddress());
                }
                cc.Open();
                if (cc.Authenticate("Domain", "UserName", "Password"))
                {
                    StoreVersions(cc.GetVersion(), cc.GetCompositorVersion());
                    return(cc);
                }
                else
                {
                    Log.Write(TraceEventType.Stop, "Authentication Error");
                    throw new System.ServiceModel.CommunicationException("Authentication Error");
                }
            }
            catch (System.ServiceModel.ServerTooBusyException ex)
            {
                Log.Write(TraceEventType.Stop, "Server Too Busy");
                throw ex;
            }
            catch (TimeoutException ex)
            {
                Log.Write(TraceEventType.Stop, "Faild to connect to server (Timeout)");
                throw ex;
            }
            catch (System.ServiceModel.FaultException ex)
            {
                Log.Write(TraceEventType.Stop, "FaultException: " + ex.Message);
                throw ex;
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                throw new Exception("Could not connect to server.");
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                if (ex.Message.Contains("request is unauthorized"))
                {
                    Log.Write(TraceEventType.Stop, @"Unauthorized issue arised, please check User Name and/or Password and/or domain!");
                }
                else
                {
                    Log.Write(TraceEventType.Stop, "CommunicationException: " + ex.Message);
                }
                throw ex;
            }
            catch (Exception ex)
            {
                ComparerResult result = new ComparerResult();
                Log.Write(TraceEventType.Stop, ex.Message);
                throw ex;
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 private void StoreConnection(ComparerClient cc)
 {
     _session[_connection] = cc;
 }