public void NothingToReplaceTest()
        {
            List <string> sourceLines = new List <string>();

            sourceLines.Add("1, Try to say Hi");

            SearchReplace sr       = new SearchReplace("Hello", "Bye", null, null);
            List <string> newLines = sr.ReplaceAllLines(sourceLines);

            newLines.FirstOrDefault().ShouldBe("1, Try to say Hi");
        }
 internal WndSearchReplace(SearchReplace mode, PNRichEdit.PNRichEditBox edit):this()
 {
     _Mode = mode;
     _Edit = edit;
 }
        public AppsResult Create()
        {
            var result = new AppsResult();

            try
            {
                string sourceFolder      = @"D:\Work\Brooksoft\AppsJS\AppsJSCLI2\AppsJSCLI2\Templates\TemplateSources\SPA\Default\SelfHosted\DefaultSelfHosted\DefaultSelfHosted";
                string destinationFolder = @"D:\Work\Brooksoft\AppsJS\AppsJSCLI2\AppsJSCLI2\Templates\TemplateDestinations\SPA\Default\SelfHosted\DefaultSelfHosted\DefaultSelfHosted";
                string portNumber        = "45678";

                var searchParams = new SearchParams();

                var searchPortNumbers = new SearchReplace()
                {
                    SearchWord     = "https://localhost:44326/index.html",
                    SearchFileName = "Program.cs",
                    ReplaceWord    = "https://localhost:" + portNumber + "/index.html"
                };

                searchParams.SearchReplaces = new List <SearchReplace>()
                {
                    searchPortNumbers
                };

                var components = new List <ComponentTemplate>();
                components.Add(new ComponentTemplate()
                {
                    ComponentName = "Level1_1",
                    Components    = new List <ComponentTemplate>()
                    {
                        new ComponentTemplate()
                        {
                            ComponentName = "Level2_1",
                            Components    = new List <ComponentTemplate>()
                        },
                        new ComponentTemplate()
                        {
                            ComponentName = "Level2_2",
                            Components    = new List <ComponentTemplate>()
                            {
                                new ComponentTemplate()
                                {
                                    ComponentName = "Level3_1",
                                    Components    = new List <ComponentTemplate>()
                                }
                            }
                        }
                    }
                });
                components.Add(new ComponentTemplate()
                {
                    ComponentName = "Level1_2",
                    Components    = new List <ComponentTemplate>()
                });
                searchParams.ComponentTemplates = components;


                if (Directory.Exists(destinationFolder))
                {
                    Directory.Delete(destinationFolder, true);
                }

                if (Directory.Exists(destinationFolder))
                {
                    Directory.Delete(destinationFolder, true);
                }

                DirectoryCopy(sourceFolder, destinationFolder, true, searchParams, ref result);

                DirectorySearch(destinationFolder, true, searchParams, ref result);

                result.Success = true;
            }
            catch (System.Exception ex)
            {
                result.FailMessages.Add("Test exception: " + ex.Message);
            }

            return(result);
        }
    private void button1_Click(object sender, EventArgs e)
    {
        SearchReplace sr = new SearchReplace(); // Creating your SearchReplace Form

        sr.Show(this);                          // Pass the creating form in as the Owner
    }
Exemple #5
0
        public void LoadFromXML(string xml)
        {
            // current search/replace pattern in case base directory has moved
            List <SearchReplace> paths = new List <SearchReplace>();

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(xml);
            XPathNavigator    nav      = xmldoc.CreateNavigator();
            XPathNodeIterator iterator = nav.Select("/FlickrSync/SyncFolder");

            while (iterator.MoveNext())
            {
                SyncFolder     sf   = new SyncFolder();
                XPathNavigator nav2 = iterator.Current;
                sf.LoadFromXPath(nav2);

                DirectoryInfo dir = new DirectoryInfo(sf.FolderPath);
                if (!dir.Exists && paths.Count > 0)
                {
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (sf.FolderPath.StartsWith(paths[i].oldpath))
                        {
                            // Directory no longer exists, but it seems that we might be able to find its new location,
                            // based on an alternate directory location we got from a previously missing directory
                            string potentialFolderPath = sf.FolderPath.Replace(paths[i].oldpath, paths[i].newpath); // replace prefix as we did last time
                            dir = new DirectoryInfo(potentialFolderPath);
                            // Have we succeeded? silently replace prefix
                            if (dir.Exists)
                            {
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Replaced " + sf.FolderPath + " with " + potentialFolderPath + " based on previous alternate directory location");
                                sf.FolderPath = potentialFolderPath;
                                paths[i].use_count++;
                            }
                        }
                    }
                }
                if (!dir.Exists)
                {
                    if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone)
                    {
                        InformationBoxResult r = InformationBox.Show(
                            "Folder " + sf.FolderPath + " no longer exists. Remove from list of folders to sync?",
                            "Folder not found", InformationBoxButtons.YesNoUser1, new string[] { "Find on disk", String.Empty }, InformationBoxIcon.Exclamation, InformationBoxDefaultButton.Button2);
                        if (r == InformationBoxResult.Yes)
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "marked for removal from configuration");
                            continue;
                        }
                        else if (r == InformationBoxResult.User1)
                        {
                            Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog cofd = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
                            //cofd.InitialDirectory = oldpaths[oldpaths.Length-1];
                            cofd.Multiselect    = false;
                            cofd.IsFolderPicker = true;
                            if (cofd.ShowDialog() == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
                            {
                                string        newfolderpath = cofd.FileName.ToString();
                                SearchReplace p             = new SearchReplace(sf.FolderPath, newfolderpath);
                                paths.Add(p);
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "replaced by " + newfolderpath + " in the configuration");
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, "From now on, we will try replacing " + p.oldpath + " by " + p.newpath);
                                sf.FolderPath = newfolderpath;
                            }
                            else
                            {
                                FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "not replaced after all");
                                continue;
                            }
                        }
                        else
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "does not exists");
                        }
                    }
                }

                SyncFolders.Add(sf);
            }

            foreach (var p in paths)
            {
                if (p.use_count > 0)
                {
                    MessageBox.Show("Replaced Folder prefix " + p.oldpath + " with " + p.newpath + ((p.use_count == 1) ? " once" : " " + p.use_count.ToString() + " times"), "Info", MessageBoxButtons.OK);
                }
            }
            iterator = nav.Select("/FlickrSync/PathInfo");

            while (iterator.MoveNext())
            {
                PathInfo       pi   = new PathInfo();
                XPathNavigator nav2 = iterator.Current;
                pi.LoadFromXPath(nav2);

                DirectoryInfo dir = new DirectoryInfo(pi.Path);
                if (!dir.Exists)
                {
                    if (!pi.ManualAdd)
                    {
                        continue;
                    }

                    if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone)
                    {
                        if (MessageBox.Show("Folder " + pi.Path + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " marked for removal from configuration");
                            continue;
                        }
                        else
                        {
                            FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " no longer exists");
                        }
                    }
                }

                PathInfoList.Add(pi);
            }
        }
 internal WndSearchReplace(SearchReplace mode, PNRichEdit.PNRichEditBox edit) : this()
 {
     _Mode = mode;
     _Edit = edit;
 }