protected virtual void InitGlue()
        {
            var node = m_ConfigRoot[CONFIG_GLUE_SECTION];

            if (!node.Exists)
            {
                return;
            }

            try
            {
                m_Glue = FactoryUtils.MakeAndConfigureComponent <IGlueImplementation>(this, node, typeof(Glue.Implementation.GlueDaemon));

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

                if (m_Glue is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "Glue daemon started");
                    }
                }
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_GLUE_INIT_ERROR + error.ToMessageWithType();
                WriteLog(MessageType.CatastrophicError, INIT_FROM, msg, error);
                throw new AzosException(msg, error);
            }
        }
        protected virtual void InitDependencyInjector()
        {
            var node = m_ConfigRoot[CONFIG_DEPENDENCY_INJECTOR_SECTION];

            if (!node.Exists)
            {
                return;
            }

            try
            {
                m_DependencyInjector = FactoryUtils.MakeAndConfigureComponent <IApplicationDependencyInjectorImplementation>(this, node, typeof(ApplicationDependencyInjector));

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

                if (m_DependencyInjector is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "DI daemon started");
                    }
                }
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_DI_INIT_ERROR + error.ToMessageWithType();
                WriteLog(MessageType.CatastrophicError, INIT_FROM, msg, error);
                throw new AzosException(msg, error);
            }
        }
        protected virtual void InitEventTimer()
        {
            var node = m_ConfigRoot[CONFIG_EVENT_TIMER_SECTION];

            //Event timer must be allocated even if it is absent in config
            try
            {
                m_EventTimer = FactoryUtils.MakeAndConfigureComponent <IEventTimerImplementation>(this, node, typeof(EventTimer));

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

                if (m_EventTimer is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "EventTimer daemon started");
                    }
                }
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_EVENT_TIMER_INIT_ERROR + error.ToMessageWithType();
                WriteLog(MessageType.CatastrophicError, INIT_FROM, msg, error);
                throw new AzosException(msg, error);
            }
        }
        protected virtual void InitSecurityManager()
        {
            var node = m_ConfigRoot[CONFIG_SECURITY_SECTION];

            if (!node.Exists)
            {
                return;
            }

            try
            {
                m_SecurityManager = FactoryUtils.MakeAndConfigureComponent <ISecurityManagerImplementation>(this, node, typeof(ConfigSecurityManager));

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

                if (m_SecurityManager is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "Secman daemon started");
                    }
                }
            }
            catch (Exception error)
            {
                var msg = StringConsts.APP_SECURITY_MANAGER_INIT_ERROR + error.ToMessageWithType();
                WriteLog(MessageType.CatastrophicError, INIT_FROM, msg, error);
                throw new AzosException(msg, error);
            }
        }
        //Must be called first to boot log before all other components
        protected virtual void InitLog()
        {
            var node = m_ConfigRoot[CONFIG_LOG_SECTION];

            if (!node.Exists)
            {
                return;
            }

            try
            {
                m_Log = FactoryUtils.MakeAndConfigureComponent <ILogImplementation>(this, node, typeof(LogDaemon));

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

                if (m_Log is Daemon daemon)
                {
                    if (daemon.StartByApplication())
                    {
                        WriteLog(MessageType.Trace, INIT_FROM, "Log daemon started, msg times are localized to machine-local time until time source starts");
                    }
                }
            }
            catch (Exception error)
            {
                //this is log, so we cant log anywhere but throw
                throw new AzosException(StringConsts.APP_LOG_INIT_ERROR + error.ToMessageWithType(), error);
            }
        }
示例#6
0
        public override void Configure(IConfigSectionNode config)
        {
            base.Configure(config);

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

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

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

            var fsPNode = fsNode[CONFIG_FS_CONNECT_PARAMS_SECTION];

            FileSystemSessionConnectParams fsc;

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

            var fsp = fsNode.AttrByName(CONFIG_FS_ROOT_PATH_ATTR).Value;

            BindFS(fs, fsc, fsp);
        }
示例#7
0
        public void CreateByConfigurationOwnDaemonWithTwoSinks()
        {
            var conf = @"
log
{
  name='YourFriendLogger'
  write-interval-ms=0

  sink
  {
    name='CatchAll'
    order=100
    type='Azos.Log.Sinks.MemoryBufferSink, Azos'
  }

  sink
  {
    name='Problems'
    min-level=Warning
    order=0
    type='Azos.Log.Sinks.MemoryBufferSink, Azos'
  }
}".AsLaconicConfig();

            using (var logger = FactoryUtils.MakeAndConfigureComponent <LogDaemon>(NOPApplication.Instance, conf, typeof(LogDaemon)))
            {
                Aver.AreEqual("YourFriendLogger", logger.Name);                   //name got set
                Aver.AreEqual(LogDaemon.MIN_INTERVAL_MSEC, logger.WriteInterval); //got set the minimum flush period from config
                Aver.AreEqual(2, logger.Sinks.Count);

                logger.Start();
                Aver.IsTrue(logger.Running);

                var s0 = logger.Sinks["Problems"] as MemoryBufferSink;
                var s1 = logger.Sinks["CatchAll"] as MemoryBufferSink;//catchall order =100

                Aver.IsNotNull(s0);
                Aver.IsNotNull(s1);
                Aver.AreSameRef(s0, logger.Sinks[0]);
                Aver.AreSameRef(s1, logger.Sinks[1]);

                Aver.IsNull(logger.Sinks["TheOneWhich isNotthere"]);
                Aver.IsNull(logger.Sinks[324234]);

                logger.Write(MessageType.Info, "This was info");
                logger.Write(MessageType.Debug, "Now debug");
                logger.Write(MessageType.Error, "And now error");

                Thread.Sleep(DAEMON_FLUSH_WAIT_MS);//make sure async flush happens

                Aver.AreEqual(3, s1.Buffered.Count());
                Aver.AreEqual(1, s0.Buffered.Count());

                Aver.AreEqual("And now error", s0.Buffered.FirstOrDefault().Text);
                Aver.AreEqual("This was info", s1.Buffered.FirstOrDefault().Text);
                Aver.AreEqual("Now debug", s1.Buffered.Skip(1).FirstOrDefault().Text);
                Aver.AreEqual("And now error", s1.Buffered.Skip(2).FirstOrDefault().Text);
            }
        }
示例#8
0
 protected override void DoConfigure(IConfigSectionNode node)
 {
     base.DoConfigure(node);
     m_Config          = node;
     m_PasswordManager = FactoryUtils.MakeAndConfigureComponent <IPasswordManagerImplementation>(
         App,
         node[CONFIG_PASSWORD_MANAGER_SECTION],
         typeof(DefaultPasswordManager));
 }
示例#9
0
        public static void Start(string[] args)
        {
            s_Application = new AzosApplication(args, null);

            var nBoot = s_Application.ConfigRoot[CONFIG_BOOT_SECTION];

            s_Server = FactoryUtils.MakeAndConfigureComponent <Daemon>(s_Application, nBoot, typeof(WaveServer));
            s_Server.Start();
        }
示例#10
0
        /// <summary>
        /// Starts the application container, used by daemons directly
        /// </summary>
        public static void Start(BootArgs args)
        {
            s_Args = args;
            if (args.IsGoverned)
            {
                s_Sipc = new GovernorSipcClient(args.GovPort, args.GovApp, () => s_Application);
                s_Sipc.Start();
            }

            s_Application = new AzosApplication(args.ForApplication, null);
            s_AppId       = s_Application.AppId.ToString();
            var nBoot = s_Application.ConfigRoot[CONFIG_BOOT_SECTION];

            s_Server = FactoryUtils.MakeAndConfigureComponent <Daemon>(s_Application, nBoot, typeof(WaveServer));
            s_Server.Start();
        }
示例#11
0
        public void CreateByConfigurationOwnDaemon()
        {
            var conf = @"
log
{
  name='YourFriendLogger'
  write-interval-ms=0

  sink
  {
    name='Memorizer'
    type='Azos.Log.Sinks.MemoryBufferSink, Azos'
  }
}".AsLaconicConfig();

            using (var logger = FactoryUtils.MakeAndConfigureComponent <LogDaemon>(NOPApplication.Instance, conf, typeof(LogDaemon)))
            {
                Aver.AreEqual("YourFriendLogger", logger.Name);                   //name got set
                Aver.AreEqual(LogDaemon.MIN_INTERVAL_MSEC, logger.WriteInterval); //got set the minimum flush period from config
                Aver.IsTrue(logger.Sinks.Any());

                logger.Start();
                Aver.IsTrue(logger.Running);

                var sink = logger.Sinks.FirstOrDefault();
                Aver.IsNotNull(sink);
                Aver.AreEqual("Memorizer", sink.Name);
                Aver.IsTrue(sink.Running);//it was auto-started by the logger

                var memsink = sink as MemoryBufferSink;
                Aver.IsNotNull(memsink);

                logger.Write(new Message {
                    Type = MessageType.DebugC, Text = "Yes #1"
                });                                             //so this messages goes in it

                Thread.Sleep(DAEMON_FLUSH_WAIT_MS);             //make sure async flush happens

                Aver.IsTrue(memsink.Buffered.Any());            //because sink was now turned on

                var logged = memsink.Buffered.FirstOrDefault(); // get the first message

                Aver.AreEqual("Yes #1", logged.Text);
                Aver.IsTrue(MessageType.DebugC == logged.Type);
            }
        }
        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);
            }
        }
示例#13
0
文件: VfsSink.cs 项目: erxdkh/azos
        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);
        }
    }
示例#14
0
        private static int run(AzosApplication app)
        {
            var config = app.CommandArgs;

            ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Welcome.txt"));


            if (config["?"].Exists ||
                config["h"].Exists ||
                config["help"].Exists)
            {
                ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Help.txt"));
                return(0);
            }


            var assemblies = config.Attributes
                             .Select(a => Assembly.LoadFrom(a.Value))
                             .ToArray();

            if (assemblies.Length == 0)
            {
                ConsoleUtils.Error("No assemblies to run");
                return(-2);
            }


            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write("Platform runtime: ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(Platform.Abstraction.PlatformAbstractionLayer.PlatformName);
            Console.ForegroundColor = ConsoleColor.Gray;

            var hnode = config["host"];
            var rnode = config["r", "runner"];

            var errors = 0;

            using (var host = FactoryUtils.MakeAndConfigureComponent <IRunnerHost>(app, hnode, typeof(TestRunnerConsoleHost)))
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write("Runner host: ");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(host.GetType().DisplayNameWithExpandedGenericArgs());
                Console.ForegroundColor = ConsoleColor.Gray;

                foreach (var asm in assemblies)
                {
                    using (var runner = FactoryUtils.MakeDirectedComponent <Runner>(host, rnode, typeof(Runner), new object[] { asm, rnode }))
                    {
                        Console.WriteLine("Assembly: {0}".Args(asm));
                        Console.WriteLine("Runner: {0}".Args(runner.GetType().DisplayNameWithExpandedGenericArgs()));
                        Console.WriteLine();

                        runner.Run();
                        errors += host.TotalErrors;

                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }
            }//using host

            return(errors > 0 ? -1 : 0);
        }
示例#15
0
        static void run(string[] args)
        {
            using (var app = new AzosApplication(args, null))
            {
                var silent = app.CommandArgs["s", "silent"].Exists;
                if (!silent)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Welcome.txt"));

                    ConsoleUtils.Info("Build information:");
                    Console.WriteLine(" Azos:     " + BuildInformation.ForFramework);
                    Console.WriteLine(" Tool:     " + new BuildInformation(typeof(agm.ProgramBody).Assembly));
                }

                if (app.CommandArgs["?", "h", "help"].Exists)
                {
                    ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Help.txt"));
                    return;
                }

                IGdidAuthorityAccessor accessor = null;
                string connectToAuthority       = null;
                var    authority = app.CommandArgs.AttrByIndex(0).Value;

                if (authority.StartsWith("@"))//use accessor instead
                {
                    authority = authority.Remove(0, 1);
                    var cfg = authority.AsLaconicConfig(handling: Data.ConvertErrorHandling.Throw);
                    accessor = FactoryUtils.MakeAndConfigureComponent <IGdidAuthorityAccessor>(app, cfg);
                }
                else
                {
                    connectToAuthority = authority.ToResolvedServiceNode(false).ConnectString;
                }

                var scope = app.CommandArgs.AttrByIndex(1).Value;
                var seq   = app.CommandArgs.AttrByIndex(2).Value;
                var bsize = app.CommandArgs.AttrByIndex(3).ValueAsInt(1);

                if (!silent)
                {
                    ConsoleUtils.Info("Authority:  " + authority);
                    ConsoleUtils.Info(accessor != null ? ("Connect via: {0}" + accessor.GetType().Name) : ("Connect to: {0}" + connectToAuthority));
                    ConsoleUtils.Info("Scope:      " + scope);
                    ConsoleUtils.Info("Sequence:   " + seq);
                    ConsoleUtils.Info("Block Size: " + bsize);
                }



                var w = System.Diagnostics.Stopwatch.StartNew();

                var generator = new GdidGenerator(app, accessor);
                if (connectToAuthority.IsNotNullOrWhiteSpace())
                {
                    generator.AuthorityHosts.Register(new GdidGenerator.AuthorityHost(app, connectToAuthority));
                }


                var json = app.CommandArgs["j", "json"].Exists;
                var arr  = app.CommandArgs["array"].Exists;


                if (arr)
                {
                    Console.WriteLine("[");
                }

                for (var i = 0; i < bsize; i++)
                {
                    var    gdid = generator.GenerateOneGdid(scope, seq, bsize - i, noLWM: true);
                    string line;

                    if (json)
                    {
                        line = new
                        {
                            Era       = gdid.Era,
                            ID        = gdid.ID,
                            Authority = gdid.Authority,
                            Counter   = gdid.Counter
                        }
                    }