Exemplo n.º 1
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            ServiceEntity entity = null;

            try
            {
                entity = ((ServiceTimer)sender).ServiceEntity;
                if (entity.Running == false)
                {
                    Assembly assembly = Assembly.LoadFrom(entity.AssemblyPath);
                    Type     type     = assembly.GetType(entity.Type);
                    using (ICommand command = (ICommand)Activator.CreateInstance(type))
                    {
                        entity.Running = true;
                        command.NewTransactionCode();
                        ServiceResult sr = command.Run(RunMethod.Auto);
                        if (sr.Result == false)
                        {
                            EventLog.WriteEntry("Engine.timer_Elapsed", sr.Message + " Transaction Code:" + sr.TransactionCode, EventLogEntryType.Error);
                        }
                        entity.Running = false;
                    }
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Engine.timer_Elapsed", ex.Message, EventLogEntryType.Error);
                if (entity != null)
                {
                    entity.Running = false;
                }
            }
        }
Exemplo n.º 2
0
        internal static List <ServiceEntity> ServiceEntities(XmlElement element)
        {
            List <ServiceEntity> list       = new List <ServiceEntity>();
            XmlNodeList          entityList = element.GetElementsByTagName("ServiceEntity");

            foreach (XmlNode node in entityList)
            {
                ServiceEntity entity = Node2ServiceEntity(node);
                if (list.Find(new Predicate <ServiceEntity>(delegate(ServiceEntity se)
                {
                    if (string.Compare(se.Key, entity.Key, true) == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                })) == null)
                {
                    list.Add(entity);
                }
            }
            return(list);
        }
Exemplo n.º 3
0
        private static ServiceEntity Node2ServiceEntity(XmlNode node)
        {
            ServiceEntity entity = new ServiceEntity();

            entity.m_AssemblyPath = node.Attributes["AssemblyPath"].Value;
            entity.m_Type         = node.Attributes["Type"].Value;
            entity.m_Key          = node.Attributes["Key"].Value;
            entity.m_Interval     = int.Parse(node.Attributes["Interval"].Value);
            return(entity);
        }
Exemplo n.º 4
0
        private ServiceTimer CreateTimer(ServiceEntity entity)
        {
            ServiceTimer timer = new ServiceTimer(entity.Interval * 1000);

            timer.ServiceEntity = entity;
            timer.AutoReset     = true;
            timer.Elapsed      += new ElapsedEventHandler(timer_Elapsed);
            timer.Enabled       = true;
            timer.Start();

            this.timer_Elapsed(timer, null);

            return(timer);
        }
Exemplo n.º 5
0
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            List <ServiceEntity> serviceEntityes = new List <ServiceEntity>();

            try
            {
                XmlElement element = null;
                element         = (XmlElement)section;
                serviceEntityes = ServiceEntity.ServiceEntities(element);
            }
            catch
            {
                throw new System.Configuration.ConfigurationErrorsException("Invalid service entity configuration");
            }
            return(serviceEntityes);
        }