private void Manage(string fullPath)
 {
     try
     {
         Logger.LogEvent("Manage " + Path.GetFileName(fullPath));
         Manage(fullPath, OmaReader.Read(fullPath));
     }
     catch (OmaException OmaException)
     {
         OmaEventWithDuration OmaEvent = OmaEvent = new OmaEventWithDuration(null, null, null, false, DateTime.Now);
         for (Exception e = OmaException; e is object; e = e.InnerException)
         {
             Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
             Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
         }
         OmaEvent.Result    = OmaException.Message;
         OmaEvent.HasErrors = true;
         OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
         WriteError(fullPath, OmaException.Message, OmaException.Side, OmaException.OmaStatusCode, OmaEvent);
     }
     catch (Exception UnspecifiedException)
     {
         OmaEventWithDuration OmaEvent = new OmaEventWithDuration(null, null, null, false, DateTime.Now);
         for (Exception e = UnspecifiedException; e is object; e = e.InnerException)
         {
             Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
             Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
         }
         OmaEvent.Result    = "ERROR";
         OmaEvent.HasErrors = true;
         OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
         WriteError(fullPath, null, Org.Visiontech.Compute.side.UNKNOWN, OmaStatusCode.General, OmaEvent);
     }
 }
        private void Manage(string fullPath, OmaReaderResult omaReaderResult)
        {
            OmaEventWithDuration OmaEvent = EventUtils.ToOmaEventWithDuration(omaReaderResult);

            try
            {
                LoginManager.RefreshServiceTicket();

                switch (omaReaderResult)
                {
                case OmaReaderDoubleResult OmaReaderDoubleResult:
                    Task <computeLensResponseDTO> leftTask  = RequestBuilder.BuildComputeTask(OmaReaderDoubleResult.Left, Org.Visiontech.Compute.side.LEFT);
                    Task <computeLensResponseDTO> rightTask = RequestBuilder.BuildComputeTask(OmaReaderDoubleResult.Right, Org.Visiontech.Compute.side.RIGHT);
                    Task.WhenAll(leftTask, rightTask).ContinueWith(tasks => {
                        if (tasks.IsFaulted)
                        {
                            tasks.Exception.Handle(Exception => {
                                for (Exception e = Exception; e is object; e = e.InnerException)
                                {
                                    Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
                                    Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
                                }
                                if (Exception is OmaException OmaException)
                                {
                                    OmaEvent.Result    = OmaException.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, OmaException.Message, OmaException.Side, OmaException.OmaStatusCode, OmaEvent);
                                }
                                else
                                {
                                    OmaEvent.Result    = Exception.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, Exception.Message, Org.Visiontech.Compute.side.UNKNOWN, OmaStatusCode.General, OmaEvent);
                                }
                                return(true);
                            });
                            return;
                        }
                        OmaEvent.Result    = "SUCCESS";
                        OmaEvent.HasErrors = false;
                        OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                        Write(OmaReaderDoubleResult, leftTask.Result, rightTask.Result, OmaEvent);
                        File.Delete(Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                        File.Move(fullPath, Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                    });
                    break;

                case OmaReaderLeftResult OmaReaderLeftResult:
                    RequestBuilder.BuildComputeTask(OmaReaderLeftResult.Result, Org.Visiontech.Compute.side.LEFT).ContinueWith(task => {
                        if (task.IsFaulted)
                        {
                            task.Exception.Handle(Exception => {
                                for (Exception e = Exception; e is object; e = e.InnerException)
                                {
                                    Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
                                    Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
                                }
                                if (Exception is OmaException OmaException)
                                {
                                    OmaEvent.Result    = OmaException.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, OmaException.Message, OmaException.Side, OmaException.OmaStatusCode, OmaEvent);
                                }
                                else
                                {
                                    OmaEvent.Result    = Exception.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, Exception.Message, Org.Visiontech.Compute.side.UNKNOWN, OmaStatusCode.General, OmaEvent);
                                }
                                return(true);
                            });
                            return;
                        }
                        OmaEvent.Result    = "SUCCESS";
                        OmaEvent.HasErrors = false;
                        OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                        Write(OmaReaderLeftResult, task.Result, OmaEvent);
                        File.Delete(Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                        File.Move(fullPath, Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                    });
                    break;

                case OmaReaderRightResult OmaReaderRightResult:
                    RequestBuilder.BuildComputeTask(OmaReaderRightResult.Result, Org.Visiontech.Compute.side.RIGHT).ContinueWith(task => {
                        if (task.IsFaulted)
                        {
                            task.Exception.Handle(Exception => {
                                for (Exception e = Exception; e is object; e = e.InnerException)
                                {
                                    Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
                                    Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
                                }
                                if (Exception is OmaException OmaException)
                                {
                                    OmaEvent.Result    = OmaException.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, OmaException.Message, OmaException.Side, OmaException.OmaStatusCode, OmaEvent);
                                }
                                else
                                {
                                    OmaEvent.Result    = Exception.Message;
                                    OmaEvent.HasErrors = true;
                                    OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                                    WriteError(fullPath, Exception.Message, Org.Visiontech.Compute.side.UNKNOWN, OmaStatusCode.General, OmaEvent);
                                }
                                return(true);
                            });
                            return;
                        }
                        OmaEvent.Result    = "SUCCESS";
                        OmaEvent.HasErrors = false;
                        OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                        Write(OmaReaderRightResult, task.Result, OmaEvent);
                        File.Delete(Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                        File.Move(fullPath, Path.Combine(configuration.AppSettings.Settings[PROCESSED_PATH].Value, Path.GetFileName(fullPath)));
                    });
                    break;
                }
            }
            catch (OmaException OmaException)
            {
                for (Exception e = OmaException; e is object; e = e.InnerException)
                {
                    Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
                    Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
                }
                OmaEvent.Result    = OmaException.Message;
                OmaEvent.HasErrors = true;
                OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                WriteError(fullPath, OmaException.Message, OmaException.Side, OmaException.OmaStatusCode, OmaEvent);
            }
            catch (Exception UnspecifiedException)
            {
                for (Exception e = UnspecifiedException; e is object; e = e.InnerException)
                {
                    Logger.LogEvent("Exception " + e.GetType() + " " + e.Message, EventLogEntryType.Error);
                    Logger.LogEvent("StackTrace " + e.StackTrace, EventLogEntryType.Error);
                }
                OmaEvent.Result    = "ERROR";
                OmaEvent.HasErrors = true;
                OmaEvent.Duration  = DateTime.Now.Subtract(OmaEvent.StartDateTime);
                WriteError(fullPath, null, Org.Visiontech.Compute.side.LEFT, OmaStatusCode.General, EventUtils.ToOmaEventWithDuration(omaReaderResult));
            }
        }