Ejemplo n.º 1
0
        /// <summary>
        /// Модель загрузки Шаблонов в БД по шаблону
        /// </summary>
        /// <typeparam name="T">Шаблон class to xml</typeparam>
        /// <param name="modelTemplate">Шаблон</param>
        /// <param name="idProcedureLoad">УН процедуры загрузки</param>
        /// <param name="idProcessBlock">УН процедуры процесса</param>
        /// <returns></returns>
        public ModelPathReport LoadModelToDataBase <T>(T modelTemplate, int idProcedureLoad, int idProcessBlock)
        {
            var report = new ModelPathReport();

            try
            {
                var isProcessTrue = Inventory.EventProcesses.FirstOrDefault(complete => complete.Id == idProcessBlock);
                if (isProcessTrue == null)
                {
                    throw new InvalidOperationException($"Фатальная ошибка отсутствует процесс Id - {idProcessBlock} в системе!");
                }
                if (isProcessTrue.IsComplete == true)
                {
                    var addObjectDb = new AddObjectDb.AddObjectDb();
                    var task        = Task.Run(() =>
                    {
                        ModelSelect model = new ModelSelect {
                            LogicaSelect = SqlSelectModel(idProcedureLoad)
                        };
                        XmlReadOrWrite xml = new XmlReadOrWrite();
                        addObjectDb.IsProcessComplete(idProcessBlock, false);
                        using (var transaction = Inventory.Database.BeginTransaction())
                        {
                            try
                            {
                                Inventory.Database.CommandTimeout = 18000;
                                Inventory.Database.ExecuteSqlCommand(model.LogicaSelect.SelectUser,
                                                                     new SqlParameter(model.LogicaSelect.SelectedParametr.Split(',')[0], SqlDbType.Xml)
                                {
                                    Value = new SqlXml(new XmlTextReader(xml.ClassToXml(modelTemplate, modelTemplate.GetType()), XmlNodeType.Document, null))
                                });
                                transaction.Commit();
                                Inventory.Dispose();
                            }
                            catch (Exception e)
                            {
                                transaction.Rollback();
                                Inventory.Dispose();
                                Loggers.Log4NetLogger.Error(e);
                            }
                        }
                    });
                    task.ConfigureAwait(true).GetAwaiter().OnCompleted((() =>
                    {
                        addObjectDb.IsProcessComplete(idProcessBlock, true);
                        addObjectDb.Dispose();
                    }));
                    report.Note = $"{isProcessTrue.NameProcess} запущен!";
                }
                else
                {
                    report.Note = $"{isProcessTrue.NameProcess} уже запущен ожидайте окончание процесса!";
                }
            }
            catch (Exception e)
            {
                report.Note = e.Message;
                Loggers.Log4NetLogger.Error(e);
            }
            return(report);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Процесс загрузки данных с PrintServer инспекции
 /// </summary>
 public List <SynchronizationPrintServer> SynchronizationPrintServerStart()
 {
     try
     {
         var selectProcess = new Select.Select();
         var process       = selectProcess.SelectProcess(IndexProcess);
         if (process.IsComplete != null && (bool)process.IsComplete)
         {
             var addObjectDb = new AddObjectDb.AddObjectDb();
             addObjectDb.IsProcessComplete(IndexProcess, false);
             var task = Task.Factory.StartNew(() =>
             {
                 try
                 {
                     var ping                 = new Ping();
                     var printServer          = new PrintServer(PrintServer);
                     var selectModel          = new Select.Select();
                     var allModel             = selectModel.AllFullModel();
                     var allSerialNumberModel = selectModel.AllSerNumber();
                     var prQueue              = printServer.GetPrintQueues();
                     var listPrinters         = (from printer in prQueue
                                                 select new SynchronizationPrintServer()
                     {
                         DescriptionPrinter = printer.Comment,
                         NamePrintServer = printer.Name,
                         IpPrintServer = UnderTheNetwork + Regex.Match(printer.QueuePort.Name, @"(\d+)(?!.*\d)").Value,
                         HasToner = printer.HasToner,
                         IsTonerLow = printer.IsTonerLow
                     }
                                                 ).ToList();
                     foreach (var model in allModel)
                     {
                         var findModelName = Regex.Match(model.NameModel, @"(\d+)(?!.*\d)").Value;
                         if (!string.IsNullOrWhiteSpace(findModelName))
                         {
                             foreach (var printer in listPrinters)
                             {
                                 if (printer.DescriptionPrinter.Contains(findModelName))
                                 {
                                     printer.FullUrl     = string.Format(string.IsNullOrWhiteSpace(model.UrlModel) ? "http://{0}" : model.UrlModel, printer.IpPrintServer);
                                     PingReply pingReply = ping.Send(printer.IpPrintServer);
                                     if (pingReply != null && pingReply.Status == IPStatus.Success)
                                     {
                                         if (findModelName == "7030")
                                         {
                                             SoapClientPrinter(allSerialNumberModel, printer);
                                             Dispose();
                                         }
                                         else
                                         {
                                             ClientSendWebForm(allSerialNumberModel, printer);
                                             Dispose();
                                         }
                                     }
                                     else
                                     {
                                         printer.IsErrorInfo = "Удаленный IP не пингуется!";
                                         printer.StatusFindPrintServerAndSynchronization = 4;
                                     }
                                 }
                             }
                         }
                     }
                     addObjectDb.AddListSynchronizationPrintServer(ref listPrinters);
                     selectModel.Dispose();
                     return(listPrinters);
                 }
                 catch (Exception e)
                 {
                     Loggers.Log4NetLogger.Error(e);
                 }
                 return(null);
             }, TaskCreationOptions.LongRunning);
             task.ConfigureAwait(true).GetAwaiter().OnCompleted(() =>
             {
                 addObjectDb.IsProcessComplete(IndexProcess, true);
                 addObjectDb.Dispose();
             });
             return(task.Result);
         }
         selectProcess.Dispose();
     }
     catch (Exception e)
     {
         Loggers.Log4NetLogger.Error(e);
     }
     return(null);
 }