protected override void OnStart(string[] args)
        {
            LoggedApplication.Start(this.ServiceName);
            Logger.LogInfo("Service preparing to start ...");

            TicToc ticToc = new TicToc("Persistence.Service.OnStart", 1);

            try
            {
                ticToc.Tic();

                StartServiceHelper();
                Logger.LogInfo("Service started with success.");
            }
            catch (Exception ex)
            {
                Logger.LogInfo("Service failed to start correctly. {0}", ex.Message);
                Stop();
            }
            finally
            {
                ticToc.Toc();
            }
        }
        protected override void OnStop()
        {
            Logger.LogInfo("Service preparing to stop ...");

            TicToc ticToc = new TicToc("Persistence.Service.OnStop", 1);

            try
            {
                ticToc.Tic();

                StopServiceHelper();
                Logger.LogInfo("Service stopped with success.");
            }
            catch (Exception ex)
            {
                Logger.LogInfo("Service failed to stop correctly. {0}", ex.Message);
            }
            finally
            {
                ticToc.Toc();
            }

            LoggedApplication.Stop();
        }
Пример #3
0
        public static void APIExample()
        {
            //set value
            // will throw if given value is not (int)
            Setting[MySetting.KEY_INT_VALUE].Value = 5;

            //get value
            // will throw if value type is not (int)
            int i = Setting[MySetting.KEY_INT_VALUE];

            //Setting.ToJson():

            //Logger usage

            Logger.Log("normal log message");
            Logger.Debug("debug message");
            Logger.Trace("trace message");
            Logger.Warn("warn message");
            Logger.Info("info message");
            Logger.Error("error message");
            Logger.Fatal("fatal error message");


            //Measure time
            TicToc tt = new TicToc();

            tt.Tic();
            //Do something that takes time
            // ....
            var elapsed_ms = tt.Toc();

            Logger.Debug($"Working time: {elapsed_ms}ms");


            //DATABASE

            Database db = null;

            //SQLite database init
            db = new SqliteDatabase("D:/dbfile.db");

            //SQLite database init
            db = new SqlExpressDatabase(
                "localhost\\SQLEXPRESS", //host name
                "DbName",                //db name
                "..."                    //(optional) extra string ...
                );

            //usage
            //Define a table with given name
            Table tbl = new Table("MyTable");

            //Define columns names
            const string COL_ID   = "ID";
            const string COL_DATE = "DATE";
            const string COL_X    = "X";
            const string COL_Y    = "Y";
            const string COL_Z    = "Z";
            const string COL_OK   = "OK";
            const string COL_PATH = "PATH";

            //add columns to table
            tbl.AddColumns(new Column[] {
                new IntColumn(COL_ID),
                new DatetimeColumn(COL_DATE),
                new FloatColumn(COL_X),
                new FloatColumn(COL_Y),
                new FloatColumn(COL_Z),
                new BoolColumn(COL_OK),
                new TextColumn(COL_PATH),
            });

            //Create a new row
            var row = tbl.NewRow();

            row[COL_ID]   = 0;
            row[COL_DATE] = DateTime.Now;
            row[COL_X]    = 0.123;
            row[COL_Y]    = 0.456;
            row[COL_Z]    = 0.789;
            row[COL_OK]   = true;
            row[COL_PATH] = "somewhere i belong";
            //and insert to the database
            tbl.InsertRow(row);
            //
        }