Esempio n. 1
0
        public SyncLinkProcessor()
        {
            List <int> linkIDs = DatabaseInterface.GetLinksToSync();

            foreach (int linkID in linkIDs)
            {
                try
                {
                    SyncAction sa = new SyncAction(linkID);
                    syncActions.Add(sa);
                    Task <bool> syncTask = sa.ProcessSyncAsync();
                    syncTasks.Add(syncTask);
                }
                catch (Exception ex)
                {
                    Log.AddLog("SyncAction error: " + ex.Message, ErrorLevels.Critical);
                }
            }
        }
        public OnboardingManager()
        {
            List <int> linkIDs = DatabaseInterface.GetLinksToSync();

            foreach (int linkID in linkIDs)
            {
                try
                {
                    OnboardingCheck obc = new OnboardingCheck(linkID);
                    onboardingChecks.Add(obc);
                    Task <bool> onboardingTask = obc.ProcessOBCheckAsync();
                    onboardingTasks.Add(onboardingTask);
                }
                catch (Exception ex)
                {
                    Log.AddLog("SyncAction error: " + ex.Message, ErrorLevels.Critical);
                }
            }
        }
        private void MapProject(TransactProjectList tp, ref List <AbstractProject> projects)
        {
            foreach (TransactProject transactProject in tp.data)
            {
                try
                {
                    AbstractProject abstractProject = new AbstractProject();

                    if (!String.IsNullOrEmpty(transactProject.number))
                    {
                        abstractProject.ExternalProjectCode = transactProject.number;
                    }

                    if (!String.IsNullOrEmpty(transactProject.status))
                    {
                        switch (transactProject.status)
                        {
                        case "Not confirmed":
                            abstractProject.Status = ProjectStatus.New;
                            break;

                        case "Confirmed":
                            abstractProject.Status = ProjectStatus.InProgress;
                            break;

                        case "Quality check started":
                            abstractProject.Status = ProjectStatus.QAinProgress;
                            break;

                        case "Invoiceable":
                            abstractProject.Status = ProjectStatus.Completed;
                            break;

                        case "Invoiced":
                            abstractProject.Status = ProjectStatus.Closed;
                            break;

                        case "Cancelled":
                            abstractProject.Status = ProjectStatus.Cancelled;
                            break;

                        case "Denied bill acceptance":
                            abstractProject.Status = ProjectStatus.Completed;
                            break;

                        case "Completeness check started":
                            abstractProject.Status = ProjectStatus.Completed;
                            break;

                        default:
                            abstractProject.Status = ProjectStatus.Undefined;
                            break;
                        }
                    }

                    if (abstractProject.Status == ProjectStatus.New && !DatabaseInterface.ProjectExists(abstractProject.ExternalProjectCode, link.linkID))
                    {
                        if (!String.IsNullOrEmpty(transactProject.your_processing_number))
                        {
                            abstractProject.InternalProjectCode = transactProject.your_processing_number;
                        }

                        DateTime tempDT = DateTime.MinValue;

                        if (DateTime.TryParse(transactProject.date_ordered, out tempDT))
                        {
                            abstractProject.DateOrdered = tempDT;
                        }
                        else
                        {
                            abstractProject.DateOrdered = DateTime.Now;
                        }

                        if (DateTime.TryParse(transactProject.date_confirmed, out tempDT))
                        {
                            abstractProject.DateApproved = tempDT;
                        }
                        else
                        {
                            abstractProject.DateApproved = DateTime.Now;
                        }

                        if (DateTime.TryParse(transactProject.date_delivery, out tempDT))
                        {
                            abstractProject.Deadline = tempDT;
                        }
                        else
                        {
                            abstractProject.Deadline = DateTime.Now;
                            Log.AddLog("Deadline could not be parsed.", ErrorLevels.Error);
                        }

                        if (!String.IsNullOrEmpty(transactProject.project_coordinator))
                        {
                            abstractProject.ExternalProjectManagerName = transactProject.project_coordinator;
                        }

                        if (!String.IsNullOrEmpty(transactProject.project_coordinator_mail))
                        {
                            abstractProject.ExternalProjectManagerEmail = transactProject.project_coordinator_mail;
                        }

                        if (!String.IsNullOrEmpty(transactProject.project_coordinator_phone))
                        {
                            abstractProject.ExternalProjectManagerPhone = transactProject.project_coordinator_phone;
                        }

                        if (!String.IsNullOrEmpty(transactProject.end_customer))
                        {
                            abstractProject.EndCustomer = transactProject.end_customer;
                        }

                        if (!String.IsNullOrEmpty(transactProject.specialty))
                        {
                            try
                            {
                                abstractProject.SpecialityID = MappingManager.DoMappingToAbstract(MapType.Speciality, link.DownlinkBTMSSystemTypeID, transactProject.specialty);
                            }
                            catch (Exception ex)
                            {
                                Log.AddLog("Transact speciality not mapped: " + transactProject.specialty + " - " + ex.Message, ErrorLevels.Warning);
                            }
                        }

                        if (!String.IsNullOrEmpty(transactProject.language_source))
                        {
                            try
                            {
                                abstractProject.SourceLanguageID = MappingManager.DoMappingToAbstract(MapType.Language, link.DownlinkBTMSSystemTypeID, transactProject.language_source);
                            }
                            catch (Exception ex)
                            {
                                Log.AddLog("Transact source language not mapped: " + transactProject.language_source + " - " + ex.Message, ErrorLevels.Warning);
                            }
                        }

                        if (!String.IsNullOrEmpty(transactProject.language_target))
                        {
                            try
                            {
                                abstractProject.TargetLanguageIDs.Add(MappingManager.DoMappingToAbstract(MapType.Language, link.DownlinkBTMSSystemTypeID, transactProject.language_target));
                            }
                            catch (Exception ex)
                            {
                                Log.AddLog("Transact target language not mapped: " + transactProject.language_target + " - " + ex.Message, ErrorLevels.Warning);
                            }
                        }

                        abstractProject.Workflow = "";
                        foreach (string to_do_item in transactProject.to_do)
                        {
                            if (abstractProject.Workflow == "")
                            {
                                abstractProject.Workflow += to_do_item;
                            }
                            else
                            {
                                abstractProject.Workflow += "¤" + to_do_item;
                            }
                        }

                        if (!String.IsNullOrEmpty(transactProject.system))
                        {
                            abstractProject.CATTool = transactProject.system;
                        }

                        Regex analysisLineMatcher = new Regex(@"^\s*(?<category>[\p{L}\d\s%-]+):\s*(?<wordcount>[\d,\.]+)\s*Words at\s*(?<weight>[\d\.]+)%;\s*$");

                        foreach (string analysisLine in transactProject.scaling)
                        {
                            if (analysisLineMatcher.IsMatch(analysisLine))
                            {
                                Match analysisLineParser   = analysisLineMatcher.Match(analysisLine);
                                WordCountAnalysisItem wcai = new WordCountAnalysisItem();

                                wcai.Weight    = Double.Parse(analysisLineParser.Groups["weight"].ToString());
                                wcai.WordCount = Double.Parse(analysisLineParser.Groups["wordcount"].ToString().Replace(",", ""));   // value can be 1,319 => 1319
                                string category = analysisLineParser.Groups["category"].ToString();

                                switch (category)
                                {
                                case "Repetitions":
                                    wcai.StartPc = -1;
                                    wcai.EndPc   = -1;
                                    break;

                                case "100%":
                                    wcai.StartPc = 100;
                                    wcai.EndPc   = 100;
                                    break;

                                case "No Match":
                                    wcai.StartPc = 0;
                                    wcai.EndPc   = 0;
                                    break;

                                default:
                                    Regex pcCategoryMatcher = new Regex(@"^\s*(?<startPc>\d+)%\s*-\s*(?<endPc>\d+)%\s*$");
                                    if (pcCategoryMatcher.IsMatch(category))
                                    {
                                        Match pcParser = pcCategoryMatcher.Match(category);
                                        wcai.StartPc = int.Parse(pcParser.Groups["startPc"].ToString());
                                        wcai.EndPc   = int.Parse(pcParser.Groups["endPc"].ToString());
                                    }
                                    break;
                                }

                                abstractProject.AnalysisCategories.Add(wcai);
                            }
                        }


                        double payableVolume = 0.0, priceTotal = 0.0, priceUnit = 0.0;

                        if (double.TryParse(transactProject.quantity, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out payableVolume))
                        {
                            abstractProject.PayableVolume = payableVolume;
                        }
                        else
                        {
                            abstractProject.PayableVolume = 0;
                        }

                        if (double.TryParse(transactProject.price_unit, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out priceUnit))
                        {
                            abstractProject.PriceUnit = priceUnit;
                        }
                        else
                        {
                            abstractProject.PriceUnit = 0;
                        }

                        if (double.TryParse(transactProject.prize_total, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out priceTotal))
                        {
                            abstractProject.PriceTotal = priceTotal;
                        }
                        else
                        {
                            abstractProject.PriceTotal = 0;
                        }

                        if (!String.IsNullOrEmpty(transactProject.quantity_unit))
                        {
                            try
                            {
                                abstractProject.PayableUnitID = MappingManager.DoMappingToAbstract(MapType.Unit, link.DownlinkBTMSSystemTypeID, transactProject.quantity_unit);
                            }
                            catch (Exception ex)
                            {
                                Log.AddLog("Transact unit not mapped: " + transactProject.quantity_unit + " - " + ex.Message, ErrorLevels.Warning);
                            }
                        }

                        if (!String.IsNullOrEmpty(transactProject.instructions))
                        {
                            abstractProject.VendorNotes = transactProject.instructions;
                        }

                        if (!String.IsNullOrEmpty(transactProject.customer_check_criteria))
                        {
                            abstractProject.PMNotes = transactProject.customer_check_criteria;
                        }

                        if (transactProject.feedback_deliveries.Count > 0 && !String.IsNullOrEmpty(transactProject.feedback_deliveries[0].link_download))
                        {
                            abstractProject.ClientNotes = transactProject.feedback_deliveries[0].link_download;
                        }

                        projects.Add(abstractProject);
                    }
                }
                catch (Exception ex)
                {
                    Log.AddLog("Processing Transact project failed:" + ex.Message, ErrorLevels.Error);
                }
            }
        }
Esempio n. 4
0
 internal static void AddLog(string message, ErrorLevels errorLevel = ErrorLevels.Information)
 {
     Console.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + " - " + errorLevel + " - " + message);
     DatabaseInterface.SaveLogMessageToDatabase(message, errorLevel.ToString());
 }