예제 #1
0
        public MacroWorker(Macro macro, IStatusDisplay statusDisplay)
        {
            this.macro         = macro;
            this.statusDisplay = statusDisplay;

            backgroundWorker = new BackgroundWorker();
            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.DoWork             += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(this.statusDisplay.WorkProgressChanged);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
        }
예제 #2
0
        public CopyMoveController(CopyMoveModel m, IStatusDisplay statusDisplay)
        {
            this.statusDisplay = statusDisplay;

            model = m;

            backgroundWorker = new BackgroundWorker();
            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.DoWork             += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(statusDisplay.WorkProgressChanged);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
        }
예제 #3
0
        /// <summary>
        /// Master server constructor. Initialises child objects, helpers and listeners
        /// </summary>
        /// <param name="statusDisplay"></param>
        /// <param name="commandInterface"></param>
        private MasterServer(IStatusDisplay statusDisplay, ICommandInterface commandInterface, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats, ILogWriter logWriter)
        {
            if (MasterServer.instance != null)
            {
                throw new InvalidOperationException("Attempted to create a Master Server instance whilst another instance was still active");
            }

            // Assign static references
            MasterServer.instance  = this;
            MasterServer.logWriter = logWriter;

            // Assign instance references
            this.statusDisplay    = statusDisplay;
            this.commandInterface = commandInterface;
            this.cdKeyValidator   = cdKeyValidator;
            this.gameStats        = gameStats;

            // Initialise the command interface if we have one
            if (commandInterface != null)
            {
                commandInterface.OnChange += new EventHandler(DisplayCommandInterface);
            }

            // GeoIP resolver is used to resolve IP addresses to locations
            geoIP = new GeoIP();

            // MD5 database is used to download new MD5 package data to connecting servers
            md5Manager = new MD5Manager();

            // IP ban manager used to ban clients from accessing the server
            banManager = new IPBanManager();

            // Create the Server List object
            serverList = new ServerList(this);

            // Create the web server
            webServer = new WebServer(banManager);

            // Initialise the status display module if we have one
            if (statusDisplay != null)
            {
                logBufferSize = statusDisplay.LogBufferSize;
                logBufferWrap = statusDisplay.LogBufferWrap;

                displayTimer = new Timer(new TimerCallback(this.Display));
                Display(null);
            }

            // Load the GeoIP database, MD5 database and ban list from the files (this happens last because they may take a while)
            geoIP.Load(MasterServer.Settings.GeoIPDataFile);
            md5Manager.Load(MasterServer.Settings.MD5DataFile);
            banManager.Load(MasterServer.Settings.BanListFile);
        }
예제 #4
0
        //controller
        private void buttonSaveAll_Click(object sender, EventArgs e)
        {
            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();
            List <string>  filenames     = this.GetAllFileList(this.chkSubdirs.Checked);

            PauseOtherWorker();

            statusDisplay.WorkStart(filenames.Count);

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    if (File.Exists(filename))
                    {
                        pmd = new PictureMetaData(filename);
                    }
                    else
                    {
                        continue;
                    }
                }


                bool breakForeach = SaveToPicture(pmd, true) == false;

                if (pmd != currentPicture)
                {
                    pmd.Close();
                }

                if (breakForeach)
                {
                    break;
                }

                statusDisplay.WorkNextPart();
            }

            FireDataChanged();

            statusDisplay.WorkFinished();

            RestartOtherWorker();
        }
예제 #5
0
        /// <summary>
        /// Start the server instance
        /// </summary>
        /// <param name="statusDisplay">Status display object to use (can be null)</param>
        /// <param name="commandInterface">Command interface to use (can be null)</param>
        /// <param name="cdKeyValidator">CD key validator to use</param>
        /// <param name="connectionLogWriter">LogWriter writer to use</param>
        public static bool Start(IStatusDisplay statusDisplay, ICommandInterface commandInterface)
        {
            if (instance == null)
            {
                IGameStatsLog   gameStats;
                ICDKeyValidator cdKeyValidator;

                if (LoadConfiguredModules(out gameStats, out cdKeyValidator))
                {
                    log.Clear();
                    instance = new MasterServer(statusDisplay, commandInterface, cdKeyValidator, gameStats, logWriter);
                    instance.BeginListening();
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        /// <summary>
        /// Console Main function
        /// </summary>
        public static void ConsoleMain(string[] args)
        {
            IStatusDisplay    statusDisplay    = ModuleManager.GetModule <IStatusDisplay>(typeof(ConsoleStatusDisplay));
            ICommandInterface commandInterface = ModuleManager.GetModule <ICommandInterface>(typeof(ConsoleCommandLine));

            // Process the command-line options (allows settings overrides to be specified on the command line)
            ParseCommandLineVars(Environment.CommandLine);

            if (!Start(statusDisplay, commandInterface))
            {
                // Start was unsuccessful, release interface modules
                ModuleManager.ReleaseModule <IStatusDisplay>();
                ModuleManager.ReleaseModule <ICommandInterface>();
            }
            else
            {
                (commandInterface as ConsoleCommandLine).Run();
            }
        }
예제 #7
0
        /// <summary>
        /// finalize plugin
        /// save its status for later initialization
        /// shutdown the plugin
        /// </summary>
        /// <param name="plugin">the plugin to finalize</param>
        private Task FinalizePlugin(Plugin plugin, IStatusDisplay reporter)
        {
            //delegate method called when the task fails
            var OnPluginStopFail = new Action <Task>(t =>
            {
                var msg = string.Format("Error stopping plugin: {0}", t.Exception.Message);
                this._host.Log(MessageLevel.Warning
                               , msg
                               , plugin);
            });

            return(Task.Factory.StartNew(() =>
            {
                //TODO finish this see above.
                //TODO save plugin status

                //stop plugin
                var stopTask = plugin.Stop(reporter);
                stopTask.ContinueWith(OnPluginStopFail, TaskContinuationOptions.OnlyOnFaulted);
            }));
        }
예제 #8
0
        public Task Finalize(IStatusDisplay reporter)
        {
            if (reporter == null)
            throw new ArgumentNullException("IStatusDisplay can not be null");

              return Task.Factory.StartNew(async () =>
              {
            if (this._plugins.Count == 0)
            {
              reporter.SetStatusMessage("Finalization done", MessageLevel.Info);
              reporter.SetStatusProgress(1000d);
            }else
            {
              for (int i = 0; i < this._plugins.Count; i++)
              {
            var plugin = this._plugins[i];
            await this.FinalizePlugin(plugin, reporter);
              }
            }
              });
        }
예제 #9
0
        /// <summary>
        /// Restart the master server instance
        /// </summary>
        public static void Restart()
        {
            if (instance != null)
            {
                if (service != null)
                {
                    MasterServer.LogMessage("Master server cannot be restarted in service mode, restart the service instead");
                }
                else if (instance.statusDisplay is ConsoleStatusDisplay && instance.commandInterface is ConsoleCommandLine)
                {
                    // Stop the server
                    instance.Shutdown();
                    instance = null;

                    // Release log writer, game stats, and validation modules
                    ReleaseModules();

                    // Clean up garbage
                    Console.WriteLine("Purging garbage...");
                    GC.Collect();

                    // Wait a couple of seconds to let any processes which haven't terminated yet finish closing
                    Console.WriteLine("Restarting master server...");
                    Thread.Sleep(2000);
                    Console.Clear();

                    // Get new status display and input modules
                    IStatusDisplay    statusDisplay    = ModuleManager.GetModule <IStatusDisplay>(typeof(ConsoleStatusDisplay));
                    ICommandInterface commandInterface = ModuleManager.GetModule <ICommandInterface>(typeof(ConsoleCommandLine));

                    // Start a new master server
                    Start(statusDisplay, commandInterface);
                }
            }

            if (shutdownThread != null)
            {
                shutdownThread = null;
            }
        }
예제 #10
0
        public Task Finalize(IStatusDisplay reporter)
        {
            if (reporter == null)
            {
                throw new ArgumentNullException("IStatusDisplay can not be null");
            }

            return(Task.Factory.StartNew(async() =>
            {
                if (this._plugins.Count == 0)
                {
                    reporter.SetStatusMessage("Finalization done", MessageLevel.Info);
                    reporter.SetStatusProgress(1000d);
                }
                else
                {
                    for (int i = 0; i < this._plugins.Count; i++)
                    {
                        var plugin = this._plugins[i];
                        await this.FinalizePlugin(plugin, reporter);
                    }
                }
            }));
        }
예제 #11
0
 public SentencesCSVResultsWriter(string location, IStatusDisplay status)
 {
     _fileName      = Path.Combine(location, "sentences.csv");
     _statusDisplay = status;
 }
예제 #12
0
        private void buttonGetGpsData_Click(object sender, EventArgs e)
        {
            // a picture is need for the offset dialog
            if (this.currentPicture == null)
            {
                return;
            }

            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            // empty log -> exit
            if (log.Count == 0)
            {
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            List <string> filenames = this.GetAllFileList(false);

            statusDisplay.WorkStart(filenames.Count);

            // compute the timespan of all pictures
            DateTime firstPicture           = new DateTime(4000, 1, 1);
            DateTime lastPicture            = new DateTime(1, 1, 1);
            List <PictureMetaData> pictures = new List <PictureMetaData>();

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    pmd = new PictureMetaData(filename);
                }

                if (pmd.ExifOriginalDateTime.HasValue)
                {
                    DateTime time = pmd.ExifOriginalDateTime.Value;

                    if (time > lastPicture)
                    {
                        lastPicture = time;
                    }
                    if (time < firstPicture)
                    {
                        firstPicture = time;
                    }

                    pictures.Add(pmd);
                }
                statusDisplay.WorkNextPart();
            }
            statusDisplay.WorkFinished();

            // ask the user: do it now?
            string text =
                String.Format(
                    "The GPS time is between {0} and {1}.\nThe picture time is between {2} and {3} ({4} and {5}).\n\nContinue?",
                    log.FirstTime,
                    log.LastTime,
                    firstPicture.Add(log.Offset),
                    lastPicture.Add(log.Offset),
                    firstPicture,
                    lastPicture);

            if (MessageBox.Show(text, "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                statusDisplay.WorkStart(pictures.Count);
                foreach (PictureMetaData pmd in pictures)
                {
                    UpdateGpsData(pmd, log);

                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                    statusDisplay.WorkNextPart();
                }

                FireDataChanged();
                statusDisplay.WorkFinished();
            }
            else
            {
                foreach (PictureMetaData pmd in pictures)
                {
                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                }
            }
        }
예제 #13
0
 public SummaryCSVResults(string location, IStatusDisplay status)
 {
     _fileName      = Path.Combine(location, "summary.csv");
     _statusDisplay = status;
 }
예제 #14
0
 public void SetStatusDisplay(IStatusDisplay statusDisplay)
 {
     this.statusDisplay = statusDisplay;
     backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(statusDisplay.WorkProgressChanged);
 }
예제 #15
0
파일: Plugin.cs 프로젝트: Liano/Samaa
 /// <summary>
 /// Uninstall the plugin, typically the plugin has to remove anything related to it when this method is called.
 /// Can be run asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Uninstall(IStatusDisplay reporter);
예제 #16
0
        /// <summary>
        /// Shut down the master server instance
        /// </summary>
        private void Shutdown()
        {
            // End listen thread and close the listen sockets
            EndListening();

            // Web server
            if (webServer != null)
            {
                webServer.Dispose();
                webServer = null;
            }

            // Shut down the server list
            if (serverList != null)
            {
                serverList.Shutdown();
                serverList = null;
            }

            // Ban manager
            if (banManager != null)
            {
                banManager.Dispose();
                banManager = null;
            }

            // MD5 database
            if (md5Manager != null)
            {
                md5Manager.Dispose();
                md5Manager = null;
            }

            // GeoIP resolver
            if (geoIP != null)
            {
                geoIP.Dispose();
                geoIP = null;
            }

            // Display update timer
            if (displayTimer != null)
            {
                displayTimer.Change(Timeout.Infinite, Timeout.Infinite);
                displayTimer.Dispose();
                displayTimer = null;
            }

            // Shut down the status display if we have one
            if (statusDisplay != null)
            {
                statusDisplay.Notify("EXIT");
                ModuleManager.ReleaseModule <IStatusDisplay>();
                statusDisplay = null;
            }

            // Shut down the command interface if we have one
            if (commandInterface != null)
            {
                commandInterface.OnChange -= new EventHandler(DisplayCommandInterface);
                ModuleManager.ReleaseModule <ICommandInterface>();
                commandInterface = null;
            }
        }
예제 #17
0
 public WordsCSVResults(string location, IStatusDisplay status)
 {
     _fileName      = Path.Combine(location, "words.csv");
     _statusDisplay = status;
 }
예제 #18
0
 public CumulativeResultsWriter(string location, IStatusDisplay status)
 {
     _fileName      = Path.Combine(location, "cumulative.csv");
     _statusDisplay = status;
 }
예제 #19
0
        //TODO
        private void btnRename_Click(object sender, EventArgs e)
        {
            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            StopOtherWorker();

            List <string> filenames;

            if (this.chkFilename.Checked)
            {
                filenames = this.GetAllFileList(this.chkSubdirs.Checked);
            }
            else
            {
                filenames = new List <string>();
            }
            List <string> directories;

            if (this.chkDirectory.Checked)
            {
                directories = this.GetAllDirectoryList(this.chkSubdirs.Checked);
            }
            else
            {
                directories = new List <string>();
            }

            statusDisplay.WorkStart(filenames.Count + directories.Count);

            #region renaming files
            Features.Renamer.RenamerEngine renamer = new Features.Renamer.RenamerEngine(this.txtFilename.Text.Contains("%#"), !this.txtFilename.Text.Contains("%##"));

            filenames.Sort();
            foreach (string filename in filenames)
            {
                // get the new name form the metadata
                PictureMetaData pmd     = new PictureMetaData(filename);
                string          newname = FileNameFormater.FormatFilename(pmd, this.txtFilename.Text);
                newname = newname.Replace("%##", "%#");
                pmd.Close();

                if (newname != "")
                {
                    // open a file info
                    FileInfo fi = new FileInfo(filename);
                    newname = fi.DirectoryName + "\\" + newname;

                    // give the new name to the renamer
                    renamer.AddNewRenameItem(fi, newname);
                }

                // next
                statusDisplay.WorkNextPart();
            }

            // and now: do all the dirty working
            renamer.Rename();

            Settings.Default.FilenameFormats.AddIfGrowing(this.txtFilename.Text);
            #endregion

            string goToDir;
            #region renaming directories
            renamer = new Features.Renamer.RenamerEngine(this.txtDirectoryname.Text.Contains("%#"), !this.txtDirectoryname.Text.Contains("%##"));

            directories.Sort();
            foreach (string directory in directories)
            {
                // get the new name form the metadata
                PictureMetaData pmd;
                DirectoryInfo   di           = new DirectoryInfo(directory);
                bool            dontClosePmd = false;
                if (this.currentDirectory == di.FullName && this.currentPicture != null)
                {
                    pmd          = this.currentPicture;
                    dontClosePmd = true;
                }
                else
                {
                    pmd = GetPictureMetaDataFromDirectory(di);
                }

                if (pmd != null)
                {
                    string newname = FileNameFormater.FormatFilename(pmd, this.txtDirectoryname.Text);
                    newname = newname.Replace("%##", "%#");

                    if (!dontClosePmd)
                    {
                        pmd.Close();
                    }

                    if (newname != "")
                    {
                        // give the new name to the renamer
                        renamer.AddNewRenameItem(di, newname);
                    }
                }

                // next
                statusDisplay.WorkNextPart();
            }

            // and now: do all the dirty working
            DirectoryInfo curdi = new DirectoryInfo(this.currentDirectory);
            goToDir = curdi.Parent.FullName + "\\" + renamer.GetNewName(this.currentDirectory);
            renamer.Rename();

            Settings.Default.DirectorynameFormats.AddIfGrowing(this.txtDirectoryname.Text);
            #endregion

            if (this.chkDirectory.Checked)
            {
                if (Directory.Exists((goToDir)))
                {
                    this.FireDirectoryNameChanged(goToDir);
                }
            }
            else
            {
                this.FireDirectoryChanged();
            }

            statusDisplay.WorkFinished();
        }
예제 #20
0
 public Task Initialize(IStatusDisplay reporter)
 {
     throw new NotImplementedException();
 }
예제 #21
0
 private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     this.statusDisplay.WorkFinished();
     this.statusDisplay = null;
 }
예제 #22
0
 /// <summary>
 /// Start execution of the plugin
 /// Can be run asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Start(IStatusDisplay reporter);
예제 #23
0
 /// <summary>
 /// Reset plugin to its default state. Can also be called in case the plugin has execution problems.
 /// Can be run asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Reset(IStatusDisplay reporter);
예제 #24
0
        /// <summary>
        /// finalize plugin
        /// save its status for later initialization
        /// shutdown the plugin
        /// </summary>
        /// <param name="plugin">the plugin to finalize</param>
        private Task FinalizePlugin(Plugin plugin, IStatusDisplay reporter)
        {
            //delegate method called when the task fails
              var OnPluginStopFail = new Action<Task>(t =>
              {
            var msg = string.Format("Error stopping plugin: {0}", t.Exception.Message);
            this._host.Log(MessageLevel.Warning
              , msg
              , plugin);
              });

              return Task.Factory.StartNew(() =>
              {
            //TODO finish this see above.
            //TODO save plugin status

            //stop plugin
            var stopTask = plugin.Stop(reporter);
            stopTask.ContinueWith(OnPluginStopFail, TaskContinuationOptions.OnlyOnFaulted);
              });
        }
예제 #25
0
 public void SetStatusDisplay(IStatusDisplay statusDisplay)
 {
     thumbnails.SetStatusDisplay(statusDisplay);
 }
예제 #26
0
 public Task Initialize(IStatusDisplay reporter)
 {
     throw new NotImplementedException();
 }
예제 #27
0
 /// <summary>
 /// Pause the execution of the plugin, this will not stop plugin from running
 /// this gives the ability to resume run of plugin afterwards.
 /// Can be called asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Pause(IStatusDisplay reporter);
예제 #28
0
파일: Plugin.cs 프로젝트: Liano/Samaa
 /// <summary>
 /// Pause the execution of the plugin, this will not stop plugin from running
 /// this gives the ability to resume run of plugin afterwards.
 /// Can be called asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Pause(IStatusDisplay reporter);
예제 #29
0
 /// <summary>
 /// Uninstall the plugin, typically the plugin has to remove anything related to it when this method is called.
 /// Can be run asyncly
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Uninstall(IStatusDisplay reporter);
예제 #30
0
파일: Plugin.cs 프로젝트: Liano/Samaa
 /// <summary>
 /// Resume plugin execution, this should typically be called after plugin is paused.
 /// Can be called asyncly.
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Resume(IStatusDisplay reporter);
예제 #31
0
        public static bool ExecuteMacro(Macro m, string startDirectory, bool askBeforeExecutionWhenDirectoryIsGivenFromFirstItem, IStatusDisplay statusDisplay, Form Parentform)
        {
            MacroWorker w = new MacroWorker(m, statusDisplay);

            if (w.ForbitExecution())
            {
                MessageBox.Show("Cannot execute the macro. One of the items is not valid.",
                                "Execute PhotoTagStudio Macro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            string dir;

            if (w.ProvidesItsOwnStartDirectories(out dir))
            {
                DirectoryInfo di = new DirectoryInfo(dir);
                if (!di.Exists)
                {
                    MessageBox.Show(String.Format("Cannot execute the macro. The start directory '{0}' does not exist.", di.FullName),
                                    "Execute PhotoTagStudio Macro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false); // directoy not exist -> exit
                }

                if (askBeforeExecutionWhenDirectoryIsGivenFromFirstItem)
                {
                    if (MessageBox.Show(String.Format("Execute the macro on the directory '{0}'?", di.FullName), "Execute PhotoTagStudio Macro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return(false); //answer = no
                    }
                }
            }
            else
            {
                FolderBrowseBox fbb = new FolderBrowseBox("Execute PhotoTagStudio Macro", "Select the folder to execute the macro:", startDirectory);
                fbb.Subdirectories = Settings.Default.MacroUseSubdirectories;
                if (fbb.ShowDialog(Parentform) == DialogResult.Cancel)
                {
                    return(false);
                }

                Settings.Default.MacroUseSubdirectories = fbb.Subdirectories;
                w.SetWorkingset(fbb.Directory, fbb.Subdirectories);
            }

            w.Start();
            return(true);
        }
예제 #32
0
파일: Plugin.cs 프로젝트: Liano/Samaa
 /// <summary>
 /// Stop plugin if it's running, this can be done asyncly.
 /// </summary>
 /// <param name="reporter">Reporter used to report action status</param>
 /// <returns></returns>
 public abstract Task Stop(IStatusDisplay reporter);