예제 #1
0
        public void Start()
        {
            if (String.IsNullOrWhiteSpace(MissionLogFolder))
            {
                Log.WriteInfo("No mission folder specified!");
                return;
            }

            if (!Directory.Exists(MissionLogFolder))
            {
                Log.WriteInfo("Specified mission folder doesn't exist {0}", MissionLogFolder);
                return;
            }

            ClearHistory();

            if (Application.Current != null)
            {
                Log.WriteInfo("Initialize action manager for {0}", server.Name);
                actionManager = (Application.Current as App).ActionManager;
                actionManager.ProcessServerLogStart(server);
            }
            else
            {
                var scriptManager = new ScriptManager();
                scriptManager.LoadScripts();
                scriptManager.Start();
                actionManager = new ActionManager(new ScriptManager());
            }

            server.OnPlayerListChange = (players, srv) =>
            {
                actionManager.ProcessPlayerListChange(srv, players);
            };


            ReadMissionHistory();

            if (tracker != null)
            {
                tracker.Start();
            }
        }
예제 #2
0
        public void LoadScripts()
        {
            string folder = AppDomain.CurrentDomain.GetData("DataDirectory") + scriptsSubFolder;

            if (!Directory.Exists(folder))
            {
                folder = @".\Scripts\";
            }

            var scriptFiles = Directory.GetFiles(folder, "*.cs", SearchOption.AllDirectories);

            config.ScriptConfigs.RemoveAll(script =>
                                           !scriptFiles.Contains(script.FileName) &&
                                           !scriptFiles.Contains(Path.Combine(folder, script.FileName)));

            foreach (var scriptPath in scriptFiles)
            {
                var scriptFileName = Path.GetFileName(scriptPath);
                Util.Try(() => {
                    LoadScript(scriptPath);
                });
            }
            tracker           = new TextFileTracker(folder, "*.cs");
            tracker.OnChanged = (fileName) =>
            {
                Util.Try(() =>
                {
                    Thread.Sleep(1000);
                    LoadScript(fileName);
                });
            };
            tracker.OnFileCreation = (fileName) =>
            {
                Util.Try(() =>
                {
                    Thread.Sleep(1000);
                    LoadScript(fileName);
                });
            };

            tracker.Start();
        }