Esempio n. 1
0
        public static OmaEventWithDuration ToOmaEventWithDuration(OmaReaderResult OmaReaderResult)
        {
            OmaEventWithDuration OmaEvent        = default;
            OmaParameter         leftDesignName  = default;
            OmaParameter         rightDesignName = default;

            switch (OmaReaderResult)
            {
            case OmaReaderDoubleResult OmaReaderDoubleResult:
                leftDesignName  = OmaReaderDoubleResult.Left.ContainsKey(OmaParameter.LDNAM) ? OmaParameter.LDNAM : OmaParameter.LNAM;
                rightDesignName = OmaReaderDoubleResult.Left.ContainsKey(OmaParameter.LDNAM) ? OmaParameter.LDNAM : OmaParameter.LNAM;
                OmaEvent        = new OmaEventWithDuration(OmaReaderDoubleResult.Left[OmaParameter.JOB], OmaReaderDoubleResult.Left[leftDesignName], OmaReaderDoubleResult.Right[rightDesignName], StringConverter.ExtractBoolValue(OmaReaderDoubleResult.Left, OmaParameter._PRECALC), DateTime.Now);
                break;

            case OmaReaderLeftResult OmaReaderLeftResult:
                leftDesignName = OmaReaderLeftResult.Result.ContainsKey(OmaParameter.LDNAM) ? OmaParameter.LDNAM : OmaParameter.LNAM;
                OmaEvent       = new OmaEventWithDuration(OmaReaderLeftResult.Result[OmaParameter.JOB], OmaReaderLeftResult.Result[leftDesignName], default, StringConverter.ExtractBoolValue(OmaReaderLeftResult.Result, OmaParameter._PRECALC), DateTime.Now);
                break;

            case OmaReaderRightResult OmaReaderRightResult:
                rightDesignName = OmaReaderRightResult.Result.ContainsKey(OmaParameter.LDNAM) ? OmaParameter.LDNAM : OmaParameter.LNAM;
                OmaEvent        = new OmaEventWithDuration(OmaReaderRightResult.Result[OmaParameter.JOB], default, OmaReaderRightResult.Result[rightDesignName], StringConverter.ExtractBoolValue(OmaReaderRightResult.Result, OmaParameter._PRECALC), DateTime.Now);
                break;
            }
            return(OmaEvent);
        }
Esempio n. 2
0
        public static OmaReaderResult Read(string path)
        {
            IDictionary <OmaParameter, string> right = new Dictionary <OmaParameter, string>();
            IDictionary <OmaParameter, string> left  = new Dictionary <OmaParameter, string>();

            string DO_VALUE = default;

            using (StreamReader sr = new StreamReader(path))
            {
                for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())
                {
                    if (ldsKeyRegex.IsMatch(line) && ldsKeyRegex.Match(line) is Match keyMatch && Enum.TryParse(keyMatch.Groups[1].Value, out OmaParameter key))
                    {
                        if (ldsDoubleValueRegex.IsMatch(line) && ldsDoubleValueRegex.Match(line) is Match doubleValueMatch)
                        {
                            DictionaryUtils.SafeAdd(right, key, doubleValueMatch.Groups[1].Value);
                            DictionaryUtils.SafeAdd(left, key, doubleValueMatch.Groups[2].Value);
                        }
                        else if (ldsSingleValueRegex.IsMatch(line) && ldsSingleValueRegex.Match(line) is Match singleValueMatch && singleValueMatch.Groups[1].Value is string value)
                        {
                            DictionaryUtils.SafeAdd(right, key, value);
                            DictionaryUtils.SafeAdd(left, key, value);
                            if (OmaParameter.DO.Equals(key))
                            {
                                DO_VALUE = value;
                            }
                        }
                    }
                }
            }

            OmaReaderResult result = default;

            switch (DO_VALUE)
            {
            case "B":
                result = new OmaReaderDoubleResult
                {
                    Left  = left,
                    Right = right
                };
                CheckRequiredParameters(left, side.LEFT);
                CheckRequiredParameters(right, side.RIGHT);
                break;

            case "L":
                result = new OmaReaderLeftResult
                {
                    Result = left
                };
                CheckRequiredParameters(left, side.LEFT);
                break;

            case "R":
                result = new OmaReaderRightResult
                {
                    Result = right
                };
                CheckRequiredParameters(right, side.RIGHT);
                break;

            default:
                throw new OmaException("Missing Required Parameter: DO", null, side.UNKNOWN, OmaStatusCode.MissingRequiredParameter);
            }

            return(result);
        }
        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));
            }
        }