Ejemplo n.º 1
0
        internal static void ConfigureMatches(IConfigSectionNode confNode,
                                              OrderedRegistry <WorkMatch> showDumpMatches,
                                              OrderedRegistry <WorkMatch> logMatches,
                                              OrderedRegistry <WorkMatch> securityRedirectMatches,
                                              string from)
        {
            if (showDumpMatches != null)
            {
                foreach (var cn in confNode[CONFIG_SHOW_DUMP_SECTION].Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
                {
                    if (!showDumpMatches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                    {
                        throw new WaveException(StringConsts.CONFIG_OTHER_DUPLICATE_MATCH_NAME_ERROR.Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value, "{0}.ShowDump".Args(from)));
                    }
                }
            }

            if (logMatches != null)
            {
                foreach (var cn in confNode[CONFIG_LOG_SECTION].Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
                {
                    if (!logMatches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                    {
                        throw new WaveException(StringConsts.CONFIG_OTHER_DUPLICATE_MATCH_NAME_ERROR.Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value, "{0}.Log".Args(from)));
                    }
                }
            }

            if (securityRedirectMatches != null)
            {
                foreach (var cn in confNode[CONFIG_SECURITY_REDIRECT_SECTION].Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
                {
                    if (!securityRedirectMatches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                    {
                        throw new WaveException(StringConsts.CONFIG_OTHER_DUPLICATE_MATCH_NAME_ERROR.Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value, "{0}.SecurityRedirect".Args(from)));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void run(ServiceBaseApplication app)
        {
            if (app.CommandArgs["?", "h", "help"].Exists)
            {
                //GetText is an extension method that reads an embedded resource
                //relative to the specfied type location
                ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt"));
                return;
            }

            var silent = app.CommandArgs["s", "silent"].Exists;

            if (!silent)
            {
                ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt"));
            }

            if (!silent)
            {
                Console.WriteLine();
            }

            //Get logic switch ' -logic' from command args line as config section
            //notice no if statements, if nodes does not exist, sentinels are returned
            //we could use if (cfgLogic.Exists)....
            var cfgLogic = app.CommandArgs["logic"];

            //Inject the logic from config, use DefaultLogic if type is not specified
            //this will call Configure(cfgLogic) on the Logic instance
            var logic = FactoryUtils.MakeAndConfigure <Logic>(cfgLogic, typeof(DefaultLogic));

            //execute injected logic module
            logic.Execute();

            if (!silent)
            {
                ConsoleUtils.Info("The End");
            }
        }
Ejemplo n.º 3
0
        public static void Run()
        {
            var tplSource = typeof(NHTTemplate).GetText("Template.htm");
            var config    = CONFIG.AsLaconicConfig();
            var type      = typeof(NHTCompiler);
            var args      = new object[] { new TemplateStringContentSource(tplSource) };

            var cmp = FactoryUtils.MakeAndConfigure <NHTCompiler>(config, type, args);

            cmp.Compile();

            var unit = cmp.First();

            if (unit.CompilationException != null)
            {
                Console.WriteLine(unit.CompilationException.ToMessageWithType());
            }
            else
            {
                Console.Write(unit.CompiledSource);
            }
        }
Ejemplo n.º 4
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);
            deleteVolumes();
            if (node == null || !node.Exists)
            {
                return;
            }

            var nHost = node[CONFIG_TRENDING_HOST_SECTION];

            m_TrendingHost = FactoryUtils.Make <TrendingSystemHost>(nHost, args: new object[] { this, nHost });

            foreach (var cnode in node.Children.Where(cn => cn.IsSameName(CONFIG_VOLUME_SECTION)))
            {
                var volume = FactoryUtils.MakeAndConfigure <Volume>(cnode, args: new object[] { this });
                if (!m_Volumes.Register(volume))
                {
                    throw new WebMessagingException(StringConsts.TS_SERVICE_DUPLICATE_VOLUMES_ERROR.Args(GetType().Name, volume.Name));
                }
            }
        }
Ejemplo n.º 5
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            if (node == null)
            {
                node = App.ConfigRoot[CONFIG_PROCESS_CONTROLLER_SECTION];
            }

            base.DoConfigure(node);

            if (node == null)
            {
                return;
            }

            DisposeAndNull(ref m_ProcessStore);
            var queueStoreNode = node[CONFIG_PROCESS_STORE_SECTION];

            if (queueStoreNode.Exists)
            {
                m_ProcessStore = FactoryUtils.Make <ProcessStore>(queueStoreNode, args: new object[] { this, queueStoreNode });
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 绑定车间。
        /// </summary>
        private void BindFactoryRoom(LookUpEdit lueFactory)
        {
            lueFactory.EditValue = string.Empty;
            string    strLines = PropertyService.Get(PROPERTY_FIELDS.LINES);
            DataTable dt       = FactoryUtils.GetFactoryRoomByLines(strLines);

            if (dt != null)
            {
                lueFactory.Properties.DataSource    = dt;
                lueFactory.Properties.DisplayMember = "LOCATION_NAME";
                lueFactory.Properties.ValueMember   = "LOCATION_KEY";
                if (dt.Rows.Count > 0)
                {
                    lueFactory.ItemIndex = 0;
                }
            }
            else
            {
                lueFactory.Properties.DataSource = null;
                lueFactory.EditValue             = string.Empty;
            }
        }
Ejemplo n.º 7
0
Archivo: Event.cs Proyecto: ame89/nfx
        public virtual void Configure(IConfigSectionNode config)
        {
            if (config == null)
            {
                return;
            }
            ConfigAttribute.Apply(this, config);

            var loc = config[TimeLocation.CONFIG_TIMELOCATION_SECTION];

            if (loc.Exists)
            {
                m_TimeLocation = FactoryUtils.MakeAndConfigure <TimeLocation>(loc, typeof(TimeLocation));
            }

            var ehnode = config[CONFIG_HANDLER_SECTION];

            if (ehnode.Exists)
            {
                EventHandler = FactoryUtils.MakeUsingCtor <IEventHandler>(ehnode);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 绑定车间。
        /// </summary>
        private void BindFactoryRoom()
        {
            this.lueFactoryRoom.EditValue = string.Empty;
            string    strLines = PropertyService.Get(PROPERTY_FIELDS.LINES);
            DataTable dt       = FactoryUtils.GetFactoryRoomByLines(strLines);

            if (dt != null)
            {
                this.lueFactoryRoom.Properties.DataSource    = dt;
                this.lueFactoryRoom.Properties.DisplayMember = "LOCATION_NAME";
                this.lueFactoryRoom.Properties.ValueMember   = "LOCATION_KEY";
                if (dt.Rows.Count > 0)
                {
                    this.lueFactoryRoom.EditValue = dt.Rows[0]["LOCATION_KEY"].ToString();
                }
            }
            else
            {
                this.lueFactoryRoom.Properties.DataSource = null;
                this.lueFactoryRoom.EditValue             = string.Empty;
            }
        }
Ejemplo n.º 9
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);

            m_Filters = new OrderedRegistry <WorkFilter>();//clear existing
            foreach (var fNode in node.Children.Where(cn => cn.IsSameName(WorkFilter.CONFIG_FILTER_SECTION)))
            {
                if (!m_Filters.Register(FactoryUtils.Make <WorkFilter>(fNode, args: new object[] { this, fNode })))
                {
                    throw new WaveException(StringConsts.CONFIG_DUPLICATE_FILTER_NAME_ERROR.Args(fNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value));
                }
            }

            m_Handlers = new OrderedRegistry <WorkHandler>();//clear existing
            foreach (var hNode in node.Children.Where(cn => cn.IsSameName(WorkHandler.CONFIG_HANDLER_SECTION)))
            {
                if (!m_Handlers.Register(FactoryUtils.Make <WorkHandler>(hNode, args: new object[] { this, hNode })))
                {
                    throw new WaveException(StringConsts.CONFIG_DUPLICATE_HANDLER_NAME_ERROR.Args(hNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value));
                }
            }
        }
Ejemplo n.º 10
0
        //数据绑定-------------------------------------------------------------------------------
        /// <summary>
        /// 绑定工厂车间。
        /// </summary>
        private void BindFactoryRoom()
        {
            string    stores = PropertyService.Get(PROPERTY_FIELDS.STORES);
            DataTable dt     = FactoryUtils.GetFactoryRoomByStores(stores);

            string[] columns = new string[] { "MESDATASOURCE", "ERPFACTORY" };
            KeyValuePair <string, string> category = new KeyValuePair <string, string>("CATEGORY_NAME", "MEScontrastERP");
            DataTable dtFac = BaseData.Get(columns, category);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow drF = dt.Rows[i];
                for (int j = 0; j < dtFac.Rows.Count; j++)
                {
                    DataRow drFac = dtFac.Rows[j];
                    if (drFac["MESDATASOURCE"].ToString().Trim() == drF["LOCATION_NAME"].ToString().Trim())
                    {
                        this.cbeWerks.Text = drFac["ERPFACTORY"].ToString();
                    }
                }
            }
        }
Ejemplo n.º 11
0
        void IConfigurable.Configure(IConfigSectionNode node)
        {
            if (node == null || !node.Exists)
            {
                throw new WaveException(StringConsts.CONFIG_PORTAL_HUB_NODE_ERROR);
            }

            foreach (var cn in node.Children.Where(cn => cn.IsSameName(CONFIG_PORTAL_SECTION)))
            {
                m_Portals.Register(FactoryUtils.Make <Portal>(cn, typeof(Portal), args: new object[] { cn }));
            }

            //Make File System
            var fsNode = node[CONFIG_CONTENT_FS_SECTION];

            m_ContentFS = FactoryUtils.MakeAndConfigure <FileSystem>(fsNode,
                                                                     typeof(NFX.IO.FileSystem.Local.LocalFileSystem),
                                                                     args: new object[] { GetType().Name, fsNode });
            var fsPNode = fsNode[CONFIG_FS_CONNECT_PARAMS_SECTION];

            if (fsPNode.Exists)
            {
                m_ContentFSConnect = FileSystemSessionConnectParams.Make <FileSystemSessionConnectParams>(fsPNode);
            }
            else
            {
                m_ContentFSConnect = new FileSystemSessionConnectParams()
                {
                    User = NFX.Security.User.Fake
                };
            }

            m_ContentFSRootPath = fsNode.AttrByName(CONFIG_FS_ROOT_PATH_ATTR).Value;
            if (m_ContentFSRootPath.IsNullOrWhiteSpace())
            {
                throw new WaveException(StringConsts.CONFIG_PORTAL_HUB_FS_ROOT_PATH_ERROR.Args(CONFIG_CONTENT_FS_SECTION, CONFIG_FS_ROOT_PATH_ATTR));
            }
        }
Ejemplo n.º 12
0
        protected virtual void InitTimeSource()
        {
            var node = m_ConfigRoot[CONFIG_TIMESOURCE_SECTION];

            if (!node.Exists)
            {
                WriteLog(MessageType.Trace, INIT_FROM, "Using default time source");

                m_StartTime = LocalizedTime;
                WriteLog(MessageType.Info, INIT_FROM, "App start time is {0}".Args(m_StartTime));
                return;
            }

            try
            {
                m_TimeSource = FactoryUtils.MakeAndConfigureComponent <ITimeSourceImplementation>(this, node);

                WriteLog(MessageType.Trace, INIT_FROM, "TimeSource made");

                if (m_TimeSource is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "TimeSource daemon started");
                    }
                }

                WriteLog(MessageType.Info, INIT_FROM, "Log msg time is supplied by time source now");
                m_StartTime = LocalizedTime;
                WriteLog(MessageType.Info, INIT_FROM, "App start time is {0}".Args(m_StartTime));
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_TIMESOURCE_INIT_ERROR + error.ToMessageWithType();
                WriteLog(MessageType.CatastrophicError, INIT_FROM, msg, error);
                throw new AzosException(msg, error);
            }
        }
Ejemplo n.º 13
0
        public void ThrottleConfigTest()
        {
            var xml = @"
                <my-config ns='NFX.Throttling' type='$(/$ns).ThrottlingService' name='MyTestService'>
                    <throttle type='$(/$ns).TimeSpacingThrottle'   name='t1' limit='10' interval='1'/>
                    <throttle type='$(/$ns).TimeSpacingThrottle'   name='t2' limit='5'  interval='2'/>
                    <throttle type='$(/$ns).SlidingWindowThrottle' name='t3' limit='10' interval='1' buckets-per-sec='4'/>
                </my-config>";

            var conf = NFX.Environment.XMLConfiguration.CreateFromXML(xml);

            var svc = FactoryUtils.MakeAndConfigure(conf.Root) as ThrottlingService;

            svc.Start();

            var t1 = svc.Get <TimeSpacingThrottle>("t1");

            Assert.AreEqual(10, t1.Limit);
            Assert.AreEqual(1, t1.Interval);

            var t2 = svc.Get <TimeSpacingThrottle>("t2");

            Assert.AreEqual(5, t2.Limit);
            Assert.AreEqual(2, t2.Interval);

            var t3 = svc.Get <SlidingWindowThrottle>("t3");

            Assert.AreEqual(10, t3.Limit);
            Assert.AreEqual(1, t3.Interval);
            Assert.AreEqual(4, t3.BucketsPerSec);

            new TimeSpacingThrottle("t4", 100, unit: "kaka").Register(svc);
            var t4 = svc.Get <TimeSpacingThrottle>("t4");

            Assert.AreEqual("kaka", t4.Unit);

            svc.WaitForCompleteStop();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 绑定车间。
        /// </summary>
        private void BindFactoryRoom()
        {
            this.lueFactoryRoom.EditValue = string.Empty;
            string strLines = PropertyService.Get(PROPERTY_FIELDS.LINES);

            System.Data.DataTable dt = FactoryUtils.GetFactoryRoomByLines(strLines);
            if (dt != null)
            {
                this.lueFactoryRoom.Properties.DataSource    = dt;
                this.lueFactoryRoom.Properties.DisplayMember = "LOCATION_NAME";
                this.lueFactoryRoom.Properties.ValueMember   = "LOCATION_KEY";
                this.lueFactoryRoom.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("LOCATION_NAME"));
                if (dt.Rows.Count > 0)
                {
                    this.lueFactoryRoom.EditValue = dt.Rows[0]["LOCATION_KEY"].ToString();
                }
            }
            else
            {
                this.lueFactoryRoom.Properties.DataSource = null;
                this.lueFactoryRoom.EditValue             = string.Empty;
            }
        }
Ejemplo n.º 15
0
        public void Configure(IConfigSectionNode node)
        {
            ConfigAttribute.Apply(this, node);

            var mnodes = node[CONFIG_METHODS_SECTION].Children.Where(n => n.IsSameName(CONFIG_METHOD_SECTION));

            foreach (var mnode in mnodes)
            {
                var method = FactoryUtils.MakeAndConfigure <Method>(mnode, typeof(Method), new object[] { this });
                m_Methods.Register(method);
            }

            var templates = new List <Package>();
            var tnodes    = node[CONFIG_PACKAGES_SECTION].Children.Where(n => n.IsSameName(CONFIG_PACKAGE_SECTION));

            foreach (var tnode in tnodes)
            {
                var template = FactoryUtils.MakeAndConfigure <Package>(tnode, typeof(Package), new object[] { this });
                m_Packages.Register(template);
            }

            NLSName = new NLSMap(node[CONFIG_NLS_SECTION]);
        }
Ejemplo n.º 16
0
                                              protected override void DoConfigure(IConfigSectionNode node)
                                              {
                                                  base.DoConfigure(node);

                                                  if (node == null)
                                                  {
                                                      return;
                                                  }

                                                  DisposeAndNull(ref m_QueueStore);
                                                  var queueStoreNode = node[CONFIG_QUEUE_STORE_SECTION];

                                                  if (queueStoreNode.Exists)
                                                  {
                                                      m_QueueStore = FactoryUtils.Make <TodoQueueStore>(queueStoreNode, args: new object[] { this, queueStoreNode });
                                                  }

                                                  m_Queues.Clear();
                                                  foreach (var queueNode in node.Children.Where(n => n.IsSameName(CONFIG_QUEUE_SECTION)))
                                                  {
                                                      m_Queues.Register(new TodoQueue(this, queueNode));
                                                  }
                                              }
Ejemplo n.º 17
0
        public CompositeWorkMatch(IConfigSectionNode confNode) : base(confNode)
        {
            if (confNode == null)
            {
                throw new WaveException(StringConsts.ARGUMENT_ERROR + GetType().FullName + ".ctor(confNode==null)");
            }

            foreach (var cn in confNode[CONFIG_AND_SECTION].Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
            {
                if (!m_ANDMatches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                {
                    throw new WaveException(StringConsts.CONFIG_COMPOSITE_MATCH_DUPLICATE_MATCH_NAME_ERROR.Args("and: '{0}'".Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value)));
                }
            }

            foreach (var cn in confNode[CONFIG_OR_SECTION].Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
            {
                if (!m_ORMatches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                {
                    throw new WaveException(StringConsts.CONFIG_COMPOSITE_MATCH_DUPLICATE_MATCH_NAME_ERROR.Args("or: '{0}'".Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value)));
                }
            }
        }
Ejemplo n.º 18
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);

            if (node == null || !node.Exists)
            {
                return;
            }

            //Make File System
            var fsNode = node[CONFIG_CONTENT_FS_SECTION];

            DisposeAndNull(ref m_Session);
            DisposeAndNull(ref m_Fs);

            m_Fs = FactoryUtils.MakeAndConfigureComponent <FileSystem>(App, fsNode, typeof(IO.FileSystem.Local.LocalFileSystem));

            var pnode = fsNode[CONFIG_FS_CONNECT_PARAMS_SECTION];

            DisposeIfDisposableAndNull(ref m_FsConnectParams);

            if (pnode.Exists)
            {
                m_FsConnectParams = FileSystemSessionConnectParams.Make <FileSystemSessionConnectParams>(pnode);
            }
            else
            {
                m_FsConnectParams = new FileSystemSessionConnectParams()
                {
                    User = Security.User.Fake
                }
            };


            m_Session = m_Fs.StartSession(m_FsConnectParams);
        }
    }
Ejemplo n.º 19
0
        public void Configure(IConfigSectionNode node)
        {
            if (node == null || !node.Exists)
            {
                return;
            }

            //making FileSystem instance along with connect parameters
            var fsNode = node[CONFIG_FILE_SYSTEM_SECTION];

            DisposeAndNull(ref m_FS);//dispose existing

            //make new virtual FS instance
            m_FS = FactoryUtils.MakeAndConfigureDirectedComponent <FileSystem>(this, fsNode, typeof(Azos.IO.FileSystem.Local.LocalFileSystem));

            var paramsNode = fsNode[CONFIG_SESSION_CONNECT_PARAMS_SECTION];

            if (paramsNode.Exists)
            {
                m_FSConnectParams = FileSystemSessionConnectParams.Make <FileSystemSessionConnectParams>(paramsNode);
            }
            else
            {
                m_FSConnectParams = new FileSystemSessionConnectParams()
                {
                    User = User.Fake
                }
            };

            m_FSRootPath = fsNode.AttrByName(CONFIG_ROOT_PATH_ATTR)
                           .ValueAsString()
                           .NonBlank(CONFIG_ROOT_PATH_ATTR);

            WriteLog(MessageType.Trace,
                     nameof(FileSystemCmsSource),
                     $"Configured FS: '{m_FS.GetType().FullName}' type, using '{m_FSConnectParams.GetType().Name}' connect parameters. Root path: '{m_FSRootPath}'");
        }
Ejemplo n.º 20
0
        public void FromConf(IConfigSectionNode def, bool expect)
        {
            // def.See();

            var filter = FactoryUtils.MakeAndConfigure <LogMessageFilter>(def, typeof(LogMessageFilter));
            var msg    = new Message
            {
                Topic   = "apple",
                From    = "Hydra.Records",
                Text    = "Lenin loved mushrooms",
                Host    = "cleveland.com",
                Channel = Atom.Encode("meduza"),
                App     = Atom.Encode("dud")
            };

            //var cnt = 500_000;
            //var time = Timeter.StartNew();
            //for (var i = 0; i < cnt; i++)
            //{
            //  var got = filter.Evaluate(msg);
            //  Aver.AreEqual(expect, got);
            //}
            //"Rate {0:n0} ops/sec".Args(cnt / (time.ElapsedMs / 1000d)).See();
        }
Ejemplo n.º 21
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            if (node == null)
            {
                node = App.ConfigRoot[CONFIG_DAEMON_COMPOSITE_SECTION];
            }

            foreach (var snode in node.Children
                     .Where(cn => cn.IsSameName(CONFIG_DAEMON_SECTION))
                     .OrderBy(cn => cn.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0)))         //the order here is needed so that child services get CREATED in order,
                                                                                                           // not only launched in order
            {
                var ignored = snode.AttrByName(CONFIG_IGNORE_THIS_DAEMON_ATTR).ValueAsBool(false);
                if (ignored)
                {
                    WriteLog(MessageType.Warning, nameof(DoConfigure), "Service {0} is ignored".Args(snode.AttrByName("name").Value));
                    continue;
                }

                var svc   = FactoryUtils.MakeAndConfigureDirectedComponent <Daemon>(this, snode);
                var abort = snode.AttrByName(CONFIG_ABORT_START_ATTR).ValueAsBool(true);
                RegisterService(svc, snode.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0), abort);
            }
        }
Ejemplo n.º 22
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            if (node == null)
            {
                node = App.ConfigRoot[CONFIG_SERVICE_HOST_SECTION];
            }

            foreach (var snode in node.Children
                     .Where(cn => cn.IsSameName(CONFIG_SERVICE_SECTION))
                     .OrderBy(cn => cn.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0)))           //the order here is needed so that child services get CREATED in order,
                                                                                                             // not only launched in order
            {
                var ignored = snode.AttrByName(CONFIG_IGNORE_THIS_SERVICE_ATTR).ValueAsBool(false);
                if (ignored)
                {
                    log(MessageType.Warning, "DoConfigure()", "Service {0} is ignored".Args(snode.AttrByName("name").Value));
                    continue;
                }

                var svc   = FactoryUtils.MakeAndConfigure <Service>(snode, args: new object[] { this });
                var abort = snode.AttrByName(CONFIG_ABORT_START_ATTR).ValueAsBool(true);
                RegisterService(svc, snode.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0), abort);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 绑定工厂车间名称
        /// </summary>
        private void BindFactoryRoom()
        {
            string    stores = PropertyService.Get(PROPERTY_FIELDS.STORES);//拥有权限的线上仓。
            DataTable dt     = FactoryUtils.GetFactoryRoomByStores(stores);

            //绑定工厂车间数据到窗体控件。
            if (dt != null)
            {
                this.cbFactoryRoom.Properties.DataSource    = dt;
                this.cbFactoryRoom.Properties.DisplayMember = "LOCATION_NAME";
                this.cbFactoryRoom.Properties.ValueMember   = "LOCATION_KEY";
                this.cbFactoryRoom.ItemIndex = 0;
            }
            else
            {
                this.cbFactoryRoom.Properties.DataSource = null;
                this.cbFactoryRoom.EditValue             = string.Empty;
            }
            //禁用领料车间
            if (dt == null || dt.Rows.Count <= 1)
            {
                this.cbFactoryRoom.Properties.ReadOnly = true;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Automatically starts systems designated in config with auto-start attribute
        /// </summary>
        public static void AutoStartSystems()
        {
            App.Instance.RegisterAppFinishNotifiable(PayProcessingFinisher.Instance);

            WebSettings.RequireInitializedSettings();

            var pHost = App.ConfigRoot[WebSettings.CONFIG_WEBSETTINGS_SECTION][CONFIG_PAYMENT_PROCESSING_SECTION][CONFIG_PAY_SYSTEM_HOST_SECTION];

            if (pHost.Exists)
            {
                var host = FactoryUtils.MakeAndConfigure <PaySystemHost>(pHost, typeof(PaySystemHost), new object[] { null, pHost });
                host.Start();
                ___SetPaySystemHost(host);
            }

            foreach (var psNode in App.ConfigRoot[WebSettings.CONFIG_WEBSETTINGS_SECTION][CONFIG_PAYMENT_PROCESSING_SECTION]
                     .Children
                     .Where(cn => cn.IsSameName(CONFIG_PAY_SYSTEM_SECTION)))
            {
                var name = psNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;

                if (!psNode.AttrByName(CONFIG_AUTO_START_ATTR).ValueAsBool())
                {
                    continue;
                }

                var system = FactoryUtils.MakeAndConfigure <PaySystem>(psNode, typeof(PaySystem), new object[] { null, psNode });

                if (s_Instances[system.Name] != null) // already started
                {
                    throw new PaymentException("AutoStart: " + StringConsts.PAYMENT_SYSTEM_DUPLICATE_NAME_ERROR.Args(system.GetType().FullName, system.Name));
                }

                system.Start();
            }
        }
Ejemplo n.º 25
0
 public static TParams Make <TParams>(IConfigSectionNode node) where TParams : FileSystemSessionConnectParams
 {
     return(FactoryUtils.MakeAndConfigure <TParams>(node, typeof(TParams), args: new object[] { node }));
 }
Ejemplo n.º 26
0
 public void MakeUsingCtor_5()
 {
     var made = FactoryUtils.MakeUsingCtor <CTORClass>("node{arg0=1}".AsLaconicConfig());
 }
Ejemplo n.º 27
0
 public static TSystem Make <TSystem>(string name, IConfigSectionNode node)
     where TSystem : CloudSystem
 {
     return(FactoryUtils.MakeAndConfigure <TSystem>(node, typeof(TSystem), new object[] { name, node }));
 }
Ejemplo n.º 28
0
        protected virtual void DoInitApplication()
        {
            const string FROM = "app.init";

            ConfigAttribute.Apply(this, m_ConfigRoot);

            m_Name = m_ConfigRoot.AttrByName(CONFIG_APP_NAME_ATTR).ValueAsString(GetType().FullName);

            Debugging.DefaultDebugAction = Debugging.ReadDefaultDebugActionFromConfig();
            Debugging.TraceDisabled      = Debugging.ReadTraceDisableFromConfig();

            var node = m_ConfigRoot[CONFIG_LOG_SECTION];

            if (node.Exists)
            {
                try
                {
                    m_Log = FactoryUtils.MakeAndConfigure(node, typeof(LogService)) as ILogImplementation;

                    if (m_Log == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Log made");

                    BeforeLogStart(m_Log);

                    if (m_Log is Service)
                    {
                        if (((Service)m_Log).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Log started, msg times are localized of machine-local time until time source starts");
                        }
                    }
                }
                catch (Exception error)
                {
                    throw new NFXException(StringConsts.APP_LOG_INIT_ERROR + error.ToMessageWithType(), error);
                }
            }


            node = m_ConfigRoot[CONFIG_TIMESOURCE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_TimeSource = FactoryUtils.MakeAndConfigure(node, null) as ITimeSourceImplementation;

                    if (m_TimeSource == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "TimeSource made");

                    BeforeTimeSourceStart(m_TimeSource);

                    if (m_TimeSource is Service)
                    {
                        if (((Service)m_TimeSource).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "TimeSource started");
                        }
                    }

                    WriteLog(MessageType.Info, FROM, "Log msg time is time source-supplied now");

                    m_StartTime = LocalizedTime;
                    WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime));
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_TIMESOURCE_INIT_ERROR + error.ToMessageWithType();
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }
            else
            {
                WriteLog(MessageType.Info, FROM, "Using default time source");

                m_StartTime = LocalizedTime;
                WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime));
            }


            node = m_ConfigRoot[CONFIG_EVENT_TIMER_SECTION];
            //20150827 DKh event timer must allocate even if it is absent in config
            //// if (node.Exists)
            {
                try
                {
                    m_EventTimer = FactoryUtils.MakeAndConfigure(node, typeof(EventTimer)) as IEventTimerImplementation;

                    if (m_EventTimer == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "EventTimer made");

                    BeforeEventTimerStart(m_EventTimer);

                    if (m_EventTimer is Service)
                    {
                        if (((Service)m_EventTimer).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "EventTimer started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_EVENT_TIMER_INIT_ERROR + error.ToMessageWithType();
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }



            node = m_ConfigRoot[CONFIG_SECURITY_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_SecurityManager = FactoryUtils.MakeAndConfigure(node, typeof(ConfigSecurityManager)) as ISecurityManagerImplementation;

                    if (m_SecurityManager == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Security Manager made");

                    BeforeSecurityManagerStart(m_SecurityManager);

                    if (m_SecurityManager is Service)
                    {
                        if (((Service)m_SecurityManager).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Security Manager started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_SECURITY_MANAGER_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }

            try
            {
                Behavior.ApplyConfiguredBehaviors(this, m_ConfigRoot);
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_APPLY_BEHAVIORS_ERROR + error;
                WriteLog(MessageType.Error, FROM, msg, error);
                throw new NFXException(msg, error);
            }


            node = m_ConfigRoot[CONFIG_INSTRUMENTATION_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Instrumentation = FactoryUtils.MakeAndConfigure(node, typeof(InstrumentationService)) as IInstrumentationImplementation;

                    if (m_Instrumentation == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Instrumentation made");

                    BeforeInstrumentationStart(m_Instrumentation);

                    if (m_Instrumentation is Service)
                    {
                        if (((Service)m_Instrumentation).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Instrumentation started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_INSTRUMENTATION_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }


            node = m_ConfigRoot[CONFIG_THROTTLING_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Throttling = FactoryUtils.MakeAndConfigure(node, typeof(ThrottlingService)) as IThrottlingImplementation;

                    if (m_Throttling == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Throttling made");

                    BeforeThrottlingStart(m_Throttling);

                    if (m_Throttling is Service)
                    {
                        if (((Service)m_Throttling).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Throttling started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_THROTTLING_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }



            node = m_ConfigRoot[CONFIG_DATA_STORE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_DataStore = FactoryUtils.MakeAndConfigure(node) as IDataStoreImplementation;

                    if (m_DataStore == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "DataStore made");


                    BeforeDataStoreStart(m_DataStore);

                    if (m_DataStore is Service)
                    {
                        if (((Service)m_DataStore).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "DataStore started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_DATA_STORE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }

            node = m_ConfigRoot[CONFIG_OBJECT_STORE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_ObjectStore = FactoryUtils.MakeAndConfigure(node, typeof(ObjectStoreService)) as IObjectStoreImplementation;

                    if (m_ObjectStore == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "ObjectStore made");

                    BeforeObjectStoreStart(m_ObjectStore);

                    if (m_ObjectStore is Service)
                    {
                        if (((Service)m_ObjectStore).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "ObjectStore started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_OBJECT_STORE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }

            node = m_ConfigRoot[CONFIG_GLUE_SECTION];
            if (node.Exists)
            {
                try
                {
                    m_Glue = FactoryUtils.MakeAndConfigure(node, typeof(NFX.Glue.Implementation.GlueService)) as IGlueImplementation;

                    if (m_Glue == null)
                    {
                        throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR +
                                               node
                                               .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR)
                                               .ValueAsString(CoreConsts.UNKNOWN));
                    }

                    WriteLog(MessageType.Info, FROM, "Glue made");

                    BeforeGlueStart(m_Glue);

                    if (m_Glue is Service)
                    {
                        if (((Service)m_Glue).StartByApplication())
                        {
                            WriteLog(MessageType.Info, FROM, "Glue started");
                        }
                    }
                }
                catch (Exception error)
                {
                    var msg = StringConsts.APP_GLUE_INIT_ERROR + error;
                    WriteLog(MessageType.CatastrophicError, FROM, msg, error);
                    throw new NFXException(msg, error);
                }
            }



            WriteLog(MessageType.Info, FROM, "Common application initialized in '{0}' time location".Args(this.TimeLocation));
            WriteLog(MessageType.Info, FROM, "Component dump:");
            foreach (var cmp in ApplicationComponent.AllComponents)
            {
                WriteLog(MessageType.Info, FROM, "  -> Component: {0}  '{1}'  '{2}' ".Args(cmp.ComponentSID, cmp.GetType().FullName, cmp.ComponentCommonName));
            }
        }
Ejemplo n.º 29
0
        protected override void DoInitApplication()
        {
            base.DoInitApplication();

            var FROM = GetType().FullName + ".DoInitApplication()";

            var metabase = m_BootLoader.Metabase;

            try
            {
                m_GDIDProvider = new GdidGenerator(this, "Sky");

                foreach (var ah in metabase.GDIDAuthorities)
                {
                    m_GDIDProvider.AuthorityHosts.Register(ah);
                    WriteLog(MessageType.Info, FROM + "{GDIDProvider init}", "Registered GDID authority host: " + ah.ToString());
                }

                WriteLog(MessageType.Info, FROM, "GDIProvider made");
            }
            catch (Exception error)
            {
                WriteLog(MessageType.CatastrophicError, FROM + "{GDIDProvider init}", error.ToMessageWithType());
                try
                {
                    m_GDIDProvider.Dispose();
                }
                catch { }

                m_GDIDProvider = null;
            }

            var wmSection = ConfigRoot[CONFIG_WEB_MANAGER_SECTION];

            if (wmSection.Exists && wmSection.AttrByName(CONFIG_ENABLED_ATTR).ValueAsBool(false))
            {
                try
                {
                    m_WebManagerServer = new WaveServer(this);
                    m_WebManagerServer.Configure(wmSection);
                    m_WebManagerServer.Start();
                }
                catch (Exception error)
                {
                    WriteLog(MessageType.CatastrophicError, FROM + "{WebManagerServer start}", error.ToMessageWithType());
                    try
                    {
                        m_WebManagerServer.Dispose();
                    }
                    catch {}

                    m_WebManagerServer = null;
                }
            }

            var lockSection = ConfigRoot[CONFIG_LOCK_MANAGER_SECTION];

            try
            {
                m_LockManager = FactoryUtils.MakeAndConfigure <ILockManagerImplementation>(lockSection, typeof(LockManager));

                WriteLog(MessageType.Info, FROM, "Lock Manager made");

                if (m_LockManager is Daemon)
                {
                    ((Daemon)m_LockManager).Start();
                    WriteLog(MessageType.Info, FROM, "Lock Manager STARTED");
                }
            }
            catch (Exception error)
            {
                WriteLog(MessageType.CatastrophicError, FROM + "{LockManager start}", error.ToMessageWithType());
                try
                {
                    m_LockManager.Dispose();
                }
                catch {}

                m_LockManager = null;
            }

            var procSection = ConfigRoot[CONFIG_PROCESS_MANAGER_SECTION];

            try
            {
                m_ProcessManager = FactoryUtils.MakeAndConfigure <IProcessManagerImplementation>(procSection, typeof(ProcessManager), new object[] { this });

                WriteLog(MessageType.Info, FROM, "Process Manager made");

                if (m_ProcessManager is Daemon)
                {
                    ((Daemon)m_ProcessManager).Start();
                    WriteLog(MessageType.Info, FROM, "Process Manager STARTED");
                }
            }
            catch (Exception error)
            {
                WriteLog(MessageType.CatastrophicError, FROM + "{ProcessManager start}", error.ToMessageWithType());
                try
                {
                    m_ProcessManager.Dispose();
                }
                catch {}

                m_ProcessManager = null;
            }

            var hostSection = ConfigRoot[CONFIG_HOST_MANAGER_SECTION];

            try
            {
                m_DynamicHostManager = FactoryUtils.MakeAndConfigure <IHostManagerImplementation>(procSection, typeof(HostManager), new object[] { this });

                WriteLog(MessageType.Info, FROM, "Dynamic Host Manager made");

                if (m_DynamicHostManager is Daemon)
                {
                    ((Daemon)m_DynamicHostManager).Start();
                    WriteLog(MessageType.Info, FROM, "Dynamic Host Manager STARTED");
                }
            }
            catch (Exception error)
            {
                WriteLog(MessageType.CatastrophicError, FROM + "{HostManager start}", error.ToMessageWithType());
                try
                {
                    m_DynamicHostManager.Dispose();
                }
                catch {}

                m_DynamicHostManager = null;
            }
        }
Ejemplo n.º 30
0
 public static new ServerTextChannel GetCached(ulong channelId)
 {
     return(FactoryUtils.GetCached(_cache, channelId));
 }