Ejemplo n.º 1
0
        public void GetIntegrationParameters()
        {
            using (DataSet1TableAdapters.INTEGRATOR_INTEGRATIONTableAdapter integrationTableAdapter = new DataSet1TableAdapters.INTEGRATOR_INTEGRATIONTableAdapter())
            {
                using (DataSet1.INTEGRATOR_INTEGRATIONDataTable integrationDataTable = new DataSet1.INTEGRATOR_INTEGRATIONDataTable())
                {
                    try
                    {
                        integrationTableAdapter.FillBySeq(integrationDataTable, seq);

                        int      intTemp;
                        DateTime dateTimeTemp;

                        if (DateTime.TryParseExact(integrationDataTable[0]["BASE_TIME"].ToString(), "dd/MM/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dateTimeTemp))
                        {
                            baseTime = dateTimeTemp;
                        }
                        else
                        {
                            baseTime = null;
                        }

                        paused = (integrationDataTable[0]["PAUSED"].ToString() == "Y") ? true : false;

                        if (paused)
                        {
                            //Quando pausado, a thread verificará a cada 15s se foi resumido
                            interval = 15;
                        }
                        else
                        {
                            if (int.TryParse(integrationDataTable[0]["INTERVAL"].ToString(), out intTemp))
                            {
                                interval = intTemp;
                            }
                        }

                        if (int.TryParse(integrationDataTable[0]["DELAY"].ToString(), out intTemp))
                        {
                            delay = intTemp;
                        }

                        if (int.TryParse(integrationDataTable[0]["MAX_TRIES"].ToString(), out intTemp))
                        {
                            maxTries = intTemp;
                        }
                        timer.Interval = interval * 1000;
                    }
                    catch (Exception ex)
                    {
                        Logger.AddToFile(ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Start()
        {
            Logger.AddToFile("Serviço iniciado.");

            if (integrationList.Count == 0)
            {
                using (DataSet1TableAdapters.INTEGRATOR_INTEGRATIONTableAdapter integrationTableAdapter = new DataSet1TableAdapters.INTEGRATOR_INTEGRATIONTableAdapter())
                {
                    using (DataSet1.INTEGRATOR_INTEGRATIONDataTable integrationDataTable = new DataSet1.INTEGRATOR_INTEGRATIONDataTable())
                    {
                        try
                        {
                            integrationTableAdapter.Fill(integrationDataTable);

                            foreach (var row in integrationDataTable)
                            {
                                Integration integration;
                                int intTemp;

                                if (int.TryParse(row["SEQ"].ToString(), out intTemp))
                                {
                                    if (row["INSTANCE_NAME"].ToString() == Properties.Settings.Default.InstanceName)
                                    {
                                        integration = new Integration(intTemp);

                                        integration.name = row["INTEGRATION_NAME"].ToString();
                                        integration.type = row["TYPE"].ToString();

                                        integrationList.Add(integration);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.AddToFile(ex.ToString());
                        }
                    }
                }

                if (integrationList.Count == 0)
                {
                    Logger.AddToFile("Nenhuma integração encontrada para essa instância. Verfique a tag InstanceName do arquivo .config e a tabela INTEGRATOR_INTEGRATION.");
                }
                else
                {
                    foreach (Integration integration in integrationList)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(integration.Start));
                    }
                }
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(Sender.Start));
        }