Beispiel #1
0
        public async Task LoadLibrary_Theme()
        {
            var libLoaderMock = new Mock <ILibraryLoader>();

            libLoaderMock.Setup(m => m.LoadThemeFiles(It.IsAny <string>(), It.IsAny <string[]>())).Returns(
                (string n, string[] f) =>
            {
                if (n == "A" && f?.Any() != true)
                {
                    return(new IFile[]
                    {
                        new FileMock(Location.FromPath("file1.txt"), $"{n}_theme_f1"),
                        new FileMock(Location.FromPath("dir\\file2.txt"), $"{n}_theme_f2")
                    }.ToAsyncEnumerable());
                }
                else
                {
                    throw new Exception();
                }
            });

            var fileLoaderMock = new Mock <IFileLoader>();

            fileLoaderMock.Setup(m => m.LoadFolder(It.IsAny <ILocation>(), It.IsAny <string[]>()))
            .Returns((ILocation l, string[] f) => new IFile[]
            {
                new FileMock(Location.FromPath("file1.txt"), "f1"),
                new FileMock(Location.FromPath("file2.txt"), ""),
                new FileMock(Location.FromPath("dir\\file3.txt"), "")
            }.ToAsyncEnumerable());

            var conf = new Configuration();

            conf.ThemesHierarchy.Add("A");

            var loader = new ProjectLoader(fileLoaderMock.Object,
                                           libLoaderMock.Object, new Mock <IPluginsManager>().Object, conf,
                                           new Mock <ILoaderExtension>().Object,
                                           new Mock <ILogger>().Object);

            var res = await loader.Load(new ILocation[] { Location.FromPath("") }).ToListAsync();

            Assert.AreEqual(4, res.Count());
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "file1.txt"));
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "dir::file2.txt"));
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "file2.txt"));
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "dir::file3.txt"));
            Assert.AreEqual("f1", res.First(f => f.Location.ToId() == "file1.txt").AsTextContent());
            Assert.AreEqual("A_theme_f2", res.First(f => f.Location.ToId() == "dir::file2.txt").AsTextContent());
        }
Beispiel #2
0
        private void LoadProject(string fileName)
        {
            project = ProjectLoader.Load(fileName);

            textBoxProjectPath.Text = project.ProjectPath;
            textBoxOutputPath.Text  = project.OutputPath;
            comboBoxObfuscationProfile.SelectedValue = project.Obfuscation.PluginName;
            comboBoxSigningProfile.SelectedValue     = project.Signing.PluginName;

            RefreshProject();

            document.DocumentFileName   = fileName;
            document.IsDocumentModified = false;
        }
 public Project OpenProjectSilent(string path)
 {
     try
     {
         String physical = PathHelper.GetPhysicalPathName(path);
         return(ProjectLoader.Load(physical));
     }
     catch (Exception exception)
     {
         string msg = TextHelper.GetString("Info.CouldNotOpenProject");
         ErrorManager.ShowInfo(msg + " " + exception.Message);
         return(null);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates a new project based on the specified template directory.
        /// </summary>
        public Project CreateProject(string templateDirectory, string projectLocation, string projectName)
        {
            isRunning = true;
            if (!projectTypesSet)
            {
                SetInitialProjectHash();
            }
            this.projectName = projectName;
            projectId        = Regex.Replace(Project.RemoveDiacritics(projectName), "[^a-z0-9]", "", RegexOptions.IgnoreCase);

            string projectTemplate = FindProjectTemplate(templateDirectory);
            string projectPath     = Path.Combine(projectLocation, projectName + Path.GetExtension(projectTemplate));

            projectPath = PathHelper.GetPhysicalPathName(projectPath);
            // notify & let a plugin handle project creation
            Hashtable para = new Hashtable();

            para["template"] = projectTemplate;
            para["location"] = projectLocation;
            para["project"]  = projectPath;
            para["id"]       = projectId;
            DataEvent de = new DataEvent(EventType.Command, ProjectManagerEvents.CreateProject, para);

            EventManager.DispatchEvent(this, de);
            if (!de.Handled)
            {
                arguments = PluginBase.MainForm.CustomArguments.ToArray();

                Directory.CreateDirectory(projectLocation);
                // manually copy important files
                CopyFile(projectTemplate, projectPath);
                CopyProjectFiles(templateDirectory, projectLocation, true);
            }
            isRunning = false;
            if (File.Exists(projectPath))
            {
                projectPath = PathHelper.GetPhysicalPathName(projectPath);
                de          = new DataEvent(EventType.Command, ProjectManagerEvents.ProjectCreated, para);
                EventManager.DispatchEvent(this, de);
                return(ProjectLoader.Load(projectPath));
            }
            else
            {
                return(null);
            }
        }
Beispiel #5
0
        private void BtnLoadProjectClick(object sender, EventArgs e)
        {
            var projectTask = ProjectLoader.Load(ToggleFormState);

            projectTask.ContinueWith(
                antecedent =>
            {
                Project = antecedent.Result;

                DialogResult = DialogResult.OK;
                Close();
            },
                CancellationToken.None,
                TaskContinuationOptions.OnlyOnRanToCompletion,
                TaskScheduler.FromCurrentSynchronizationContext());

            projectTask.ContinueWith(
                antecedent =>
            {
                DialogResult = MessageBox.Show(
                    "An error occured while reading the project file, continue with an empty project?",
                    "Error retriving the project details",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button2);

                if (DialogResult == DialogResult.OK)
                {
                    var result = ProjectSaver.Save();

                    DialogResult = result.Item1;
                    Project      = result.Item2;
                }

                if (DialogResult == DialogResult.OK && Project != null)
                {
                    Close();
                }
            },
                CancellationToken.None,
                TaskContinuationOptions.OnlyOnCanceled,
                TaskScheduler.FromCurrentSynchronizationContext());
        }
        protected override void OnSetup()
        {
            var parser = new ScriptParser();

            parser.AddRule("catalog", txt => new CatalogBlock(txt));
            parser.AddRule("options", txt => new OptionsBlock(txt));
            parser.AddRule("need", txt => new NeedBlock(txt));
            parser.AddRule("ignore", txt => new IgnoreScriptBlock(txt));
            parser.AddRule("pre", txt => new SqlCommandBlock("pre", txt, SqlScriptPhase.Pre));
            parser.AddRule("main", txt => new SqlCommandBlock("main", txt, SqlScriptPhase.Main));
            parser.AddRule("post", txt => new SqlCommandBlock("post", txt, SqlScriptPhase.Post));

            parser.SetFallbackRule((kw, txt) => new UnexpectedBlock(kw, txt));

            var loader = new ProjectLoader(@".\TestFiles\ProjectA", parser);

            loader.Load();
            Given.Configuration = loader.Configuration;
            Given.Scripts       = loader.AllScripts;
        }
Beispiel #7
0
        public async Task Load_MultipleLocationsTest()
        {
            var files = new Dictionary <string, IFile[]>();

            files.Add("C:\\site", new IFile[]
            {
                new FileMock("index.md", "abc"),
                new FileMock("1.txt", "")
            });

            files.Add("C:\\site1", new IFile[]
            {
                new FileMock(@"page2\index.md", "xyz"),
                new FileMock(@"page2\2.txt", "")
            });

            var fileLoaderMock = new Mock <IFileLoader>();

            fileLoaderMock.Setup(m => m.LoadFolder(It.IsAny <ILocation>(), It.IsAny <string[]>()))
            .Returns((ILocation l, string[]  f) => files[l.ToPath()].ToAsyncEnumerable());

            var loader = new ProjectLoader(fileLoaderMock.Object,
                                           new Mock <ILibraryLoader>().Object,
                                           new Mock <IPluginsManager>().Object,
                                           new Configuration(),
                                           new Mock <ILoaderExtension>().Object,
                                           new Mock <ILogger>().Object);

            var res = await loader.Load(new ILocation[]
            {
                Location.FromPath("C:\\site"),
                Location.FromPath("C:\\site1")
            }).ToListAsync();

            Assert.AreEqual(4, res.Count());
            Assert.IsNotNull(res.FirstOrDefault(f => f.Location.ToId() == "index.md"));
            Assert.IsNotNull(res.FirstOrDefault(f => f.Location.ToId() == "1.txt"));
            Assert.IsNotNull(res.FirstOrDefault(f => f.Location.ToId() == "page2::index.md"));
            Assert.IsNotNull(res.FirstOrDefault(f => f.Location.ToId() == "page2::2.txt"));
        }
Beispiel #8
0
        public async Task Load_MultipleLocationsConflictTest()
        {
            var fileLoaderMock = new Mock <IFileLoader>();

            fileLoaderMock.Setup(m => m.LoadFolder(It.IsAny <ILocation>(), It.IsAny <string[]>()))
            .Returns((ILocation l, string[] f) => new IFile[]
            {
                new FileMock(@"index.md", ""),
            }.ToAsyncEnumerable());

            var loader = new ProjectLoader(fileLoaderMock.Object,
                                           new Mock <ILibraryLoader>().Object,
                                           new Mock <IPluginsManager>().Object,
                                           new Configuration(),
                                           new Mock <ILoaderExtension>().Object,
                                           new Mock <ILogger>().Object);

            await AssertException.ThrowsOfTypeAsync <DuplicateFileException>(async() =>
            {
                await loader.Load(new ILocation[] { Location.FromPath("C:\\site"), Location.FromPath("C:\\site1") }).ToListAsync();
            });
        }
Beispiel #9
0
        public async Task LoadLibrary_Components()
        {
            var libLoaderMock = new Mock <ILibraryLoader>();

            libLoaderMock.Setup(m => m.LoadComponentFiles(It.IsAny <string>(), It.IsAny <string[]>())).Returns(
                (string n, string[] f) =>
            {
                if (n == "A" && f?.Any() != true)
                {
                    return(new IFile[]
                    {
                        new FileMock(Location.FromPath("file2.txt"), "a"),
                        new FileMock(Location.FromPath("dir\\file3.txt"), "b")
                    }.ToAsyncEnumerable());
                }
                else
                {
                    throw new Exception();
                }
            });

            var loader = new ProjectLoader(new Mock <IFileLoader>().Object,
                                           libLoaderMock.Object,
                                           new Mock <IPluginsManager>().Object,
                                           new Configuration()
            {
                Components = new string[] { "A" }.ToList()
            },
                                           new Mock <ILoaderExtension>().Object,
                                           new Mock <ILogger>().Object);

            var res = await loader.Load(new ILocation[0]).ToListAsync();

            Assert.AreEqual(2, res.Count());
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "file2.txt"));
            Assert.IsNotNull(res.First(f => f.Location.ToId() == "dir::file3.txt"));
            Assert.AreEqual("a", res.First(f => f.Location.ToId() == "file2.txt").AsTextContent());
            Assert.AreEqual("b", res.First(f => f.Location.ToId() == "dir::file3.txt").AsTextContent());
        }
        protected override void Creating()
        {
            var parser = new ScriptParser();

            parser.AddRule("catalog", txt => new CatalogBlock(txt));
            parser.AddRule("options", txt => new OptionsBlock(txt));
            parser.AddRule("need", txt => new NeedBlock(txt));
            parser.AddRule("ignore", txt => new IgnoreScriptBlock(txt));
            parser.AddRule("pre", txt => new SqlCommandBlock("pre", txt, SqlScriptPhase.Pre));
            parser.AddRule("main", txt => new SqlCommandBlock("main", txt, SqlScriptPhase.Main));
            parser.AddRule("post", txt => new SqlCommandBlock("post", txt, SqlScriptPhase.Post));
            parser.SetFallbackRule((kw, txt) => new UnexpectedBlock(kw, txt));

            var loader = new ProjectLoader(Given.Path, parser, null, Then.Logger);

            loader.Load();
            var config = Given.Config ?? ScriptDeployerConfig.Default;

            var project = new Project(loader.Configuration, loader.AllScripts);

            Then.Deployer = new SqlServerDeployer(config, project, Then.Manager, Then.Logger);
        }
Beispiel #11
0
        public async Task Load_ExcludePluginFilesTest()
        {
            var fs = new System.IO.Abstractions.TestingHelpers.MockFileSystem();

            fs.AddFile("C:\\site\\index.md", new System.IO.Abstractions.TestingHelpers.MockFileData(""));
            fs.AddFile("C:\\site\\_plugins\\abc\\plugin.dll", new System.IO.Abstractions.TestingHelpers.MockFileData(""));

            var loader = new ProjectLoader(
                new LocalFileSystemFileLoader(fs, new Mock <ILogger>().Object),
                new Mock <ILibraryLoader>().Object,
                new Mock <IPluginsManager>().Object,
                new Configuration(),
                new Mock <ILoaderExtension>().Object,
                new Mock <ILogger>().Object);

            var res = await loader.Load(new ILocation[]
            {
                Location.FromPath("C:\\site"),
            }).ToListAsync();

            Assert.AreEqual(1, res.Count());
            Assert.IsNotNull(res.FirstOrDefault(f => f.Location.ToId() == "index.md"));
        }
Beispiel #12
0
 static void Main(String[] args)
 {
     ProjectLoader loader     = new ProjectLoader();
     ProjectDef    projectDef = loader.Load("samples/Test.json");
 }