Ejemplo n.º 1
0
        /// <summary>
        /// Appends text and scrolls down the log
        /// </summary>
        public void AppendOutput(string s, ErrorType errorType, ErrorOrigin origin)
        {
            if (errorType != ErrorType.Message)
            {
                s = "> (" + DateTime.Now.ToLongTimeString() + ") " + s;
            }
            TextEditor        editor = null;
            var               selTab = LogTab.System;
            TextMarkerService tms    = null;

            switch (origin)
            {
            default:
                editor = Text_Sys;
                selTab = LogTab.System;
                tms    = tms1;
                break;

            case ErrorOrigin.Build:
                editor = Text_Build;
                selTab = LogTab.Build;
                tms    = tms2;
                break;

            case ErrorOrigin.Debug:
            case ErrorOrigin.Program:
                selTab = LogTab.Output;
                editor = Text_Output;
                tms    = tms3;
                break;
            }

            if (editor == null)
            {
                return;
            }

            //TODO?: Find out why invoking the dispatcher thread blocks the entire application sometimes
            if (!Util.IsDispatcherThread)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    SelectedTab = selTab;
                    int off     = editor.Document.TextLength;
                    editor.AppendText(s + "\r\n");
                    editor.ScrollToEnd();

                    AddMarkerForOffsetUntilEnd(editor, tms, off, errorType);
                }), System.Windows.Threading.DispatcherPriority.Background);
            }
            else
            {
                int off = editor.Document.TextLength;
                SelectedTab = selTab;
                editor.AppendText(s + "\r\n");
                editor.ScrollToEnd();

                AddMarkerForOffsetUntilEnd(editor, tms, off, errorType);
            }
        }
Ejemplo n.º 2
0
    public void SetActiveTab(LogTab selectedTab)
    {
        //Close current tab
        if (currentlyActiveTab != null)
        {
            currentlyActiveTab.SetTabActive(false);
        }

        //Open selected tab
        currentlyActiveTab = selectedTab;
        currentlyActiveTab.SetTabActive(true);
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        switch (activeTab)
        {
        case TabType.Grain:
            currentlyActiveTab = tabs[(int)TabType.Grain];
            break;

        case TabType.Drink:
            currentlyActiveTab = tabs[(int)TabType.Drink];
            break;

        case TabType.MeatAlts:
            currentlyActiveTab = tabs[(int)TabType.MeatAlts];
            break;

        default:
            break;
        }
        currentlyActiveTab.SetTabActive(true);
    }
Ejemplo n.º 4
0
		/// <summary>
		/// Appends text and scrolls down the log
		/// </summary>
		public void AppendOutput(string s,ErrorType errorType,ErrorOrigin origin)
		{
			if(errorType!=ErrorType.Message)
				s = "> ("+DateTime.Now.ToLongTimeString()+") "+s;
			TextEditor editor=null;
			var selTab = LogTab.System;
			TextMarkerService tms = null ;
			switch (origin)
			{
				default:
					editor = Text_Sys;
					selTab = LogTab.System;
					tms = tms1;
					break;
				case ErrorOrigin.Build:
					editor = Text_Build;
					selTab = LogTab.Build;
					tms = tms2;
					break;
				case ErrorOrigin.Debug:
				case ErrorOrigin.Program:
					selTab = LogTab.Output;
					editor = Text_Output;
					tms = tms3;
					break;
			}

			if (editor == null)
				return;			

			//TODO?: Find out why invoking the dispatcher thread blocks the entire application sometimes
			if (!Util.IsDispatcherThread)
				Dispatcher.BeginInvoke(new Action(() =>
				{
					SelectedTab = selTab;
					int off=editor.Document.TextLength;
					editor.AppendText(s + "\r\n");
					editor.ScrollToEnd();

					AddMarkerForOffsetUntilEnd(editor, tms, off,errorType);
				}),System.Windows.Threading.DispatcherPriority.Background);
			else
			{
				int off = editor.Document.TextLength;
				SelectedTab = selTab;
				editor.AppendText(s + "\r\n");
				editor.ScrollToEnd();

				AddMarkerForOffsetUntilEnd(editor, tms, off,errorType);
			}
		}
Ejemplo n.º 5
0
        public static void Main()
        {
            //Initialize logger
            LogTab Tab = new LogTab("General");

            Log = Tab.GetLogger();
            RequestWorker.RequestLoggerTab = new LogTab("Workers");
            Log.Info("Server is starting!");

            //Create default config
            Log.Info("Loading configuration files...");
            Config.AddConfig(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Webserver.DefaultConfig.json")));
            Config.SaveDefaultConfig();

            //Load the configuration file
            Dictionary <string, List <string> > Missing = Config.LoadConfig();

            //Display all missing and/or invalid config settings, if any.
            if (Missing == null)
            {
                Log.Fatal("The config file could not be read. Ensure that it is a valid JSON file. Press any key to exit.");
                Console.ReadKey();
                return;
            }
            else if (Missing.Count > 0)
            {
                Log.Fatal("Found one or more invalid or missing configuration settings;");
                foreach (string Key in Missing.Keys)
                {
                    if (Missing[Key].Count == 0)
                    {
                        Console.Write(Key);
                    }
                    foreach (string Key2 in Missing[Key])
                    {
                        Log.Fatal(Key + "." + Key2);
                    }
                }
                Log.Fatal("Please check the configuration file. Press any key to exit.");
                Console.ReadKey();
                return;
            }

            //Check CORS addresses
            CORSAddresses = Utils.ParseAddresses(Config.GetValue("ConnectionSettings.AccessControl").ToObject <List <string> >());
            List <string> Addresses = Utils.ParseAddresses(Configurator.Config.GetValue("ConnectionSettings.ServerAddresses").ToObject <List <string> >());

            CORSAddresses = CORSAddresses.Concat(Addresses).ToList();

            //Run inits
            SQLiteConnection Connection = Database.Init();

            WebFiles.Init();
            Redirect.Init();

            //Find all API endpoints
            DiscoverEndpoints();

            //Create Queue and launch listener
            Thread ListenerThread = new Thread(() => Listener.Run());

            ListenerThread.Start();

            //Create performance tab + watchers
            MonitorTab pTab = new MonitorTab("PerfMon");

            RequestWorker.RequestTimeWatcher = pTab.CreateNumWatcher("Request time", ShowMin: true, ShowAverage: true, ShowMax: true);
            Listener.QueueSizeWatcher        = pTab.CreateNumWatcher("Queue size", ShowMax: true);

            //Launch worker threads
            List <Thread> WorkerThreads = new List <Thread>();

            for (int i = 0; i < (int)Config.GetValue("PerformanceSettings.WorkerThreadCount"); i++)
            {
                RequestWorker Worker       = new RequestWorker((SQLiteConnection)Connection.Clone());
                Thread        WorkerThread = new Thread(new ThreadStart(Worker.Run))
                {
                    Name = "RequestWorker" + i
                };
                WorkerThread.Start();
                WorkerThreads.Add(WorkerThread);
            }

            //Launch maintenance thread
            Timer Maintenance = new Timer(new MaintenanceThread {
                Log = Log
            }.Run, null, 0, 3600 * 1000);

            //Wait for an exit command, then exit.
            foreach (Thread Worker in WorkerThreads)
            {
                Worker.Join();
            }
        }