Beispiel #1
0
        /// <summary>
        /// Replaces the specified parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public void Replace(ReplaceParameters parameters)
        {
            // Validate:
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.FileCrawlerParameters == null)
            {
                throw new ArgumentException("parameters.FileCrawlerParameters is null");
            }

            if (parameters.FileCrawlerParameters.PathInfoList.Count == 0)
            {
                this.NotifyMessage(null, "Error: No files to crawl.");
                return;
            }

            if (parameters.ReplacePatterns.Count == 0)
            {
                this.NotifyMessage(null, "Error: No replace patterns specified.");
                return;
            }

            // Reset tags:
            AllAvailableSmartTags.Reset();

            // Wrap patterns:
            this.wrappedPatterns = parameters.ReplacePatterns
                                   .Select(p => new ReplacePatternWrapper(p))
                                   .ToList();

            // Process:
            this.crawler = new FileCrawler();
            this.crawler.AddObserver(this);
            this.crawler.Crawl(parameters.FileCrawlerParameters);
            this.crawler.RemoveObserver(this);

            // Clean up:
            this.wrappedPatterns = null;
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Click event of the buttonReplace control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonReplace_Click(object sender, EventArgs e)
        {
            Cursor currentCursor = Cursor.Current;
            try
            {
                // Set wait cursor:
                Cursor.Current = Cursors.WaitCursor;

                // Create replace parameters:
                ReplaceParameters parameters = new ReplaceParameters();
                parameters.FileCrawlerParameters.PathInfoList = this.pathList.ToList();
                parameters.ReplacePatterns = this.patternList.ToList();

                // Process:
                using (ProcessingForm form = new ProcessingForm())
                {
                    form.ReplaceParameters = parameters;
                    form.ShowDialog(this);
                }
            }
            finally
            {
                // Restore original cursor:
                Cursor.Current = currentCursor;
            }
        }
        /// <summary>
        /// Runs the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        public void Run(string[] args)
        {
            // Parse command line args:
            CommandLineArgsParser parser = new CommandLineArgsParser();
            string errorMessage;
            if (!parser.ParseArguments(args, out errorMessage))
            {
                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    System.Console.WriteLine(@"ERROR: " + errorMessage);
                    System.Console.WriteLine();
                }
                parser.PrintHelp();
                return;
            }

            try
            {
                // Read Project File:
                Stream openFileStream = new FileStream(parser.ProjectPath, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof (ReplacerProject));
                XmlReader reader = new XmlTextReader(openFileStream);
                if (!serializer.CanDeserialize(reader))
                {
                    System.Console.WriteLine(@"Invalid Project file");
                    openFileStream.Close();
                    return;
                }

                ReplacerProject project = (ReplacerProject) serializer.Deserialize(reader);
                openFileStream.Close();

                // Setup logging:
                this.logToConsole = parser.LogToConsole;
                if (!string.IsNullOrWhiteSpace(parser.LogFilePath))
                {
                    this.logFile = new StreamWriter(parser.LogFilePath, true, Encoding.UTF8);
                }

                // Process:
                // Create replace parameters:
                ReplaceParameters parameters = new ReplaceParameters
                {
                    FileCrawlerParameters = {PathInfoList = project.FileFolderPaths.ToList()},
                    ReplacePatterns = project.PatternList.ToList()
                };

                // Initialize replacer:
                Business.Engine.Replacer replacer = new Business.Engine.Replacer();
                replacer.AddObserver(this);

                // Start process:
                replacer.Replace(parameters);
            }
            catch (Exception exc)
            {
                if (!this.logToConsole)
                    System.Console.WriteLine(exc);
                this.Log(new LogMessage
                {
                    TimeStamp = DateTime.Now,
                    Message = exc.ToString()
                });
            }
            finally
            {
                if (this.logFile != null)
                    this.logFile.Close();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Replaces the specified parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public void Replace(ReplaceParameters parameters)
        {
            // Validate:
            if (parameters == null)
                throw new ArgumentNullException("parameters");

            if (parameters.FileCrawlerParameters == null)
                throw new ArgumentException("parameters.FileCrawlerParameters is null");

            if (parameters.FileCrawlerParameters.PathInfoList.Count == 0)
            {
                this.NotifyMessage(null, "Error: No files to crawl.");
                return;
            }

            if (parameters.ReplacePatterns.Count == 0)
            {
                this.NotifyMessage(null, "Error: No replace patterns specified.");
                return;
            }

            // Reset tags:
            AllAvailableSmartTags.Reset();

            // Wrap patterns:
            this.wrappedPatterns = parameters.ReplacePatterns
                .Select(p => new ReplacePatternWrapper(p))
                .ToList();

            // Process:
            this.crawler = new FileCrawler();
            this.crawler.AddObserver(this);
            this.crawler.Crawl(parameters.FileCrawlerParameters);
            this.crawler.RemoveObserver(this);

            // Clean up:
            this.wrappedPatterns = null;
        }