Esempio n. 1
0
        //
        // GET: /Admin/General/

        public ActionResult Index()
        {
            List <SchedulerDto> list = new List <SchedulerDto>();

            try
            {
                using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
                {
                    if (factory.State != CommunicationState.Faulted)
                    {
                        IImportAxapta channel = factory.CreateChannel();
                        factory.Faulted  += new EventHandler(factory_Faulted);
                        list              = channel.GetSummaryInfo();
                        ViewBag.IsService = true;
                    }
                }
            }
            catch (Exception e)
            {
                ViewBag.IsService = false;
            }
            var model =
                Db <WebEnvironmentFiact> .Get <Sheduler>().Select(
                    x =>
                    new SchedulerDto
            {
                CountLaunches = x.Iteration,
                LastDuration  = x.Duration ?? 0,
                LastRun       = x.LastRun,
                NextRun       = x.NextRun ?? new DateTime(),
                Id            = x.Id,
                State         = TaskExecutionType.Idle,
                Name          = x.Name,
                Type          = x.Type
            }).ToList();

            model = model.GroupJoin(list, x => x.Id, y => y.Id, (x, y) => new SchedulerDto
            {
                CountLaunches = x.CountLaunches,
                LastDuration  = x.LastDuration,
                LastRun       = y.FirstOrDefault() != null?y.FirstOrDefault().LastRun:x.LastRun,
                NextRun       = y.FirstOrDefault() != null?y.FirstOrDefault().NextRun:x.NextRun,
                Id            = x.Id,
                State         = y.FirstOrDefault() != null?y.FirstOrDefault().State:x.State,
                Name          = x.Name,
                Type          = x.Type
            }).ToList();
            return(View(model.AsQueryable()));
        }
Esempio n. 2
0
 public JsonResult KillShedule(int id)
 {
     try
     {
         using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
         {
             if (factory.State != CommunicationState.Faulted)
             {
                 factory.Faulted += new EventHandler(factory_Faulted);
                 IImportAxapta channel = factory.CreateChannel();
                 channel.KillShedule(id);
             }
             else
             {
                 return(Json(false, JsonRequestBehavior.AllowGet));
             }
         }
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 3
0
        public ActionResult Index(SchedulerModel model)
        {
            var session = Db <WebEnvironmentFiact> .NSession;

            if (model.Id == 0)
            {
                switch (model.Type)
                {
                case "import":
                    _shaper = new ImportSheduling();
                    break;

                case "export":
                    _shaper = new ExportSheduling();
                    break;

                default:
                    _shaper = new MoreSheduling();
                    break;
                }
            }
            else
            {
                _shaper = session.Get <Sheduler>(model.Id);
                try
                {
                    using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
                    {
                        IImportAxapta channel = factory.CreateChannel();
                        var           id      = _shaper.Id;
                        channel.RemoveShedule(id);
                    }
                    Thread.Sleep(2000);
                }catch (Exception e)
                {
                }
            }

            _shaper.IsEnabled   = model.IsEnabled;
            _shaper.IsKill      = model.IsKill;
            _shaper.Runtime     = model.Runtime;
            _shaper.Param       = model.Param;
            _shaper.TimeGetData = model.TimeGetData;
            _shaper.Name        = model.Name;
            SheduleFrequencyProperty oldFreq = _shaper.Frequency;

            session.Delete(oldFreq);
            _shaper.Frequency = ApplySheduling(model);
            _shaper.UpdateShedule();
            model           = LoadSheduling(_shaper.Frequency);
            model.IsEnabled = _shaper.IsEnabled;

            model.Name = _shaper.Name;
            if (_shaper.Frequency is SingleLanchFrequency)
            {
                model.FrequencyType = 0;
            }
            else
            {
                model.FrequencyType = 1;
            }
            model.Id          = _shaper.Id;
            model.Runtime     = _shaper.Runtime;
            model.IsKill      = _shaper.IsKill;
            model.Param       = _shaper.Param;
            model.TimeGetData = _shaper.TimeGetData;
            LoadEntity(model);
            ModelState.Clear();
            session.Save(_shaper);
            session.Flush();
            if (_shaper.IsEnabled)
            {
                try
                {
                    using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
                    {
                        IImportAxapta channel = factory.CreateChannel();
                        channel.AddShedule(_shaper.Id);
                    }
                }catch (Exception e)
                {
                }
            }
            return(View(model));
        }
Esempio n. 4
0
        private static void Main()
        {
            var shUri = new Uri("net.tcp://127.0.0.1:812/IImportAxapta");
            var host  = new HostContainer();

            host.StartServices("Жопа");
            //shHost.Open();
            Console.WriteLine("Шудулер запущен. Ждём 3 секунды");
            // Thread.CurrentThread.Join(TimeSpan.FromSeconds(3));
            //Console.WriteLine("Запуск зависимой службы");
            //ServiceHost host = new ServiceHost(typeof(PricelistLoader), new[] { uri });
            //host.Open();
            var binding = new NetTcpBinding();
            //binding.CloseTimeout = new TimeSpan(0,10,0);
            //binding.OpenTimeout = new TimeSpan(0, 10, 0);
            //binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            //binding.SendTimeout = new TimeSpan(0, 10, 0);
            //binding.ReliableSession.Enabled = false;
            //binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
            //binding.ReliableSession.Ordered = true;
            //binding.MaxConnections = 10;
            NetTcpBinding setting = new NetTcpBinding();

            setting.CloseTimeout           = new TimeSpan(0, 1, 0);
            setting.OpenTimeout            = new TimeSpan(0, 1, 0);
            setting.ReceiveTimeout         = new TimeSpan(0, 10, 0);
            setting.SendTimeout            = new TimeSpan(0, 1, 0);
            setting.TransactionFlow        = false;
            setting.TransferMode           = TransferMode.Buffered;
            setting.TransactionProtocol    = TransactionProtocol.OleTransactions;
            setting.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            setting.ListenBacklog          = 10;
            setting.MaxBufferPoolSize      = 2147483647;
            setting.MaxBufferSize          = 2147483647;
            setting.MaxConnections         = 10;
            setting.MaxReceivedMessageSize = 2147483647;
            setting.ReaderQuotas.MaxDepth  = 32;
            setting.ReaderQuotas.MaxStringContentLength = 800000000;
            setting.ReaderQuotas.MaxArrayLength         = 800000000;
            setting.ReaderQuotas.MaxBytesPerRead        = 4096;
            setting.ReaderQuotas.MaxNameTableCharCount  = 16384;
            setting.ReliableSession.Enabled             = false;
            setting.ReliableSession.Ordered             = true;
            setting.ReliableSession.InactivityTimeout   = new TimeSpan(0, 10, 0);
            //setting.Security.Mode = SecurityMode.None;
            setting.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            setting.Security.Transport.ProtectionLevel      = ProtectionLevel.EncryptAndSign;
            setting.Security.Message.ClientCredentialType   = MessageCredentialType.Windows;
StartOther:
            try
            {
                using (var factory = new ChannelFactory <IImportAxapta>(setting, new EndpointAddress(shUri)))
                {
                    IImportAxapta channel = factory.CreateChannel();
                    factory.Faulted += new EventHandler(factory_Faulted);
                    while (true)
                    {
                        //Thread.CurrentThread.Join(TimeSpan.FromSeconds(3));
                        var list = channel.GetSummaryInfo();
                        foreach (var item in list)
                        {
                            Console.WriteLine("{0} | {1} | {2} | {3}", item.State, item.LastRun, item.NextRun, item.State);
                        }

                        Thread.CurrentThread.Join(TimeSpan.FromSeconds(5));
                        list = channel.GetSummaryInfo();
                        foreach (var item in list)
                        {
                            Console.WriteLine("{0} | {1} | {2} | {3}", item.State, item.LastRun, item.NextRun, item.State);
                        }

                        Thread.CurrentThread.Join(TimeSpan.FromSeconds(9));
                        list = channel.GetSummaryInfo();
                        foreach (var item in list)
                        {
                            Console.WriteLine("{0} | {1} | {2} | {3}", item.State, item.LastRun, item.NextRun, item.State);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                goto StartOther;
            }

            //using (var session = NHibernateSessionManager.Instance.SessionFactory.OpenSession())
            //{
            //    var upl = new OriginalsUploader<RtPlanBuy, PlanItemBuy>(session);
            //    //var task = session.Get<PriceListTask>(39);
            //    var task = upl.SetUploaderTaskOnDelete(13254);
            //    upl.LoadByTask(ref task);
            //}

            //host.Close();
            host.StopServices();
        }