public RedmineClientForm()
 {
     InitializeComponent();
     if (!IsRunningOnMono())
     {
         this.Icon                = (Icon)Properties.Resources.ResourceManager.GetObject("clock");
         this.notifyIcon1.Icon    = (Icon)Properties.Resources.ResourceManager.GetObject("clock");
         this.notifyIcon1.Visible = true;
     }
     else
     {
         this.DataGridViewIssues.Click += new System.EventHandler(this.DataGridViewIssues_SelectionChanged);
     }
     redmine = new Redmine();
     LoadConfig();
     redmine.RedmineBaseUri = RedmineURL;
     redmine.CacheLifetime  = new TimeSpan(0, 0, CacheLifetime, 0);
     if (RedmineAuthentication)
     {
         redmine.RedmineUser     = RedmineUser;
         redmine.RedminePassword = RedminePassword;
     }
     this.Cursor = Cursors.AppStarting;
     this.BtnCommitButton.Enabled   = false;
     this.BtnRefreshButton.Enabled  = false;
     this.BtnNewIssueButton.Enabled = false;
     if (this.CheckForUpdates)
     {
         backgroundWorker2.RunWorkerAsync();
     }
     backgroundWorker1.RunWorkerAsync(0);
 }
 public RedmineClientForm()
 {
     InitializeComponent();
     if (!IsRunningOnMono())
     {
         this.Icon = (Icon)Properties.Resources.ResourceManager.GetObject("clock");
         this.notifyIcon1.Icon = (Icon)Properties.Resources.ResourceManager.GetObject("clock");
         this.notifyIcon1.Visible = true;
     }
     else
     {
         this.DataGridViewIssues.Click += new System.EventHandler(this.DataGridViewIssues_SelectionChanged);
     }
     redmine = new Redmine();
     LoadConfig();
     redmine.RedmineBaseUri = RedmineURL;
     redmine.CacheLifetime = new TimeSpan(0, 0, CacheLifetime, 0);
     if (RedmineAuthentication)
     {
         redmine.RedmineUser = RedmineUser;
         redmine.RedminePassword = RedminePassword;
     }
     this.Cursor = Cursors.AppStarting;
     this.BtnCommitButton.Enabled = false;
     this.BtnRefreshButton.Enabled = false;
     this.BtnNewIssueButton.Enabled = false;
     if (this.CheckForUpdates)
     {
         backgroundWorker2.RunWorkerAsync();
     }
     backgroundWorker1.RunWorkerAsync(0);
 }
示例#3
0
        static void Main(string[] args)
        {
            // init config
            Config cfg = new Config();
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("config.json");

            var devEnvironmentVariable = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT");
            var isDevelopment          = string.IsNullOrEmpty(devEnvironmentVariable) ||
                                         devEnvironmentVariable.ToLower() == "development";

            if (isDevelopment)
            {
                builder.AddUserSecrets <Program>();
            }

            IConfigurationSection configSection = builder.Build().GetSection("config");

            configSection.Bind(cfg);

            // init services
            IWiki   wiki   = new Redmine(cfg.RedmineKey, cfg.RedmineRoot);
            IMarkup markup = new TextileMarkup();

            // init DB adapters
            MsSqlDb    db  = new MsSqlDb(cfg.DbConnectionString, markup);
            GitSources git = new GitSources(cfg.GitRootPath, cfg.GitSourcesMask, markup);

            // init wiki sections
            DbObjectsList tables   = new DbObjectsList("Таблицы_AICS_AreaPassport", "table.txt");
            DbObjectsList routines = new DbObjectsList("Программы_AICS_AreaPassport", "routine.txt");

            // collect data
            db.GetTables(tables);
            db.GetRoutines(routines);
            git.AddCallers(routines);

            // save to wiki
            Task.WaitAll(
                SaveSection(tables, wiki),
                SaveSection(routines, wiki));
        }
        /// <summary>
        ///   Создание отказов для логов.
        /// </summary>
        /// <param name="session">Сессия Nhibernate</param>
        /// <param name="log">Лог, о получении документа</param>
        /// <param name="metaForRedmineErrorIssueList"></param>
        private static void ProcessReject(ISession session, DocumentReceiveLog log, List <MetadataOfLog> metaForRedmineErrorIssueList)
        {
            RejectHeader reject;
            //если есть назначенные поставщику правила разбора
            var parsers = session.Query <RejectDataParser>().Where(x => x.Supplier.Id == log.Supplier.Id).ToList();

            //попытка распарсить ими
            reject = RejectDataParser.Parse(log, parsers);
            //иначе, выбор из имеющихся парсеров
            if (reject == null)
            {
                var parser = GetRejectParser(log);
                if (parser == null)
                {
                    if (log.DocumentType == DocType.Reject)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, log);
                    }
                    return;
                }
                reject = parser.CreateReject(log);
                if (reject == null)
                {
                    if (log.DocumentType == DocType.Reject)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, log);
                    }
                    return;
                }
            }
            if (reject.Lines.Count > 0)
            {
                try {
                    reject.Normalize(session);
                } catch (Exception e) {
                    _log.Error(string.Format("Не удалось идентифицировать товары отказа {0}", log.GetFileName()), e);
                }
                session.Save(reject);
            }
        }
        private void loader_RemoveDestination(object sender, EventArgs e)
        {
            var loader = sender as PanelLoader;
            var idx    = 2;

            idx += this.panelLoaders.ToList().IndexOf(loader);

            if (!string.IsNullOrEmpty(loader.connString))
            {
                var       protocol = ConnectionStringParser.Parse(loader.connString)["Type"];
                IProtocol dest     = null;

                if (protocol == typeof(Mail).Name || protocol.ToLower() == "email" || protocol.ToLower() == "e-mail")
                {
                    dest = new Mail(loader.connString);
                }
                else if (protocol == typeof(Redmine).Name)
                {
                    dest = new Redmine(loader.connString);
                }
                else if (protocol == typeof(Ftp).Name)
                {
                    dest = new Redmine(loader.connString);
                }
                else if (protocol == typeof(Http).Name)
                {
                    dest = new Redmine(loader.connString);
                }

                if (dest != null)
                {
                    Settings.Destinations.Remove(dest);
                }
            }

            this.panelLoaders.Remove(loader);
            this.mainTabs.TabPages.RemoveAt(idx);
            return;
        }
        private IEnumerable <Document> ParseWaybills(List <DocumentReceiveLog> logs)
        {
            var metaForRedmineErrorIssueList = new List <MetadataOfLog>();
            var rejects = logs.Where(l => l.DocumentType == DocType.Reject).ToArray();

            foreach (var reject in rejects)
            {
                if (WaybillExcludeFile(reject))
                {
                    continue;
                }

                try {
                    SessionHelper.WithSession(s => ProcessReject(s, reject, metaForRedmineErrorIssueList));
                } catch (Exception e) {
                    _log.Error(string.Format("Не удалось разобрать отказ {0}", reject.FileName), e);
                    //создаем задачу на Redmine, прикрепляя файлы
                    Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, reject);
                }
            }

            var docsForParsing = MultifileDocument.Merge(logs);
            var docs           = docsForParsing.Select(d => {
                try {
                    if (WaybillExcludeFile(d.DocumentLog))
                    {
                        return(null);
                    }

                    var docToReturn = ProcessWaybill(d.DocumentLog, d.FileName);
                    //если не получилось распарсить документ
                    if (docToReturn == null && d.DocumentLog?.DocumentType == DocType.Waybill)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, d.DocumentLog);
                    }
                    return(docToReturn);
                } catch (Exception e) {
                    var filename   = d.FileName;
                    var errorTitle = string.Format("Не удалось разобрать накладную {0}", filename);
                    _log.Error(errorTitle, e);
                    SaveWaybill(filename);

                    if (d.DocumentLog?.DocumentType == DocType.Waybill)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, d.DocumentLog);
                    }
                    return(null);
                }
            }).Where(d => d != null).ToList();

            MultifileDocument.DeleteMergedFiles(docsForParsing);

            docs.Each(d => {
                if (d.Log.IsFake)
                {
                    d.Log.Save();
                }
                d.Save();
                d.CreateCertificateTasks();
            });
            return(docs);
        }