Exemple #1
0
        public void CanSaveAndReloadProject()
        {
            doc.LoadXml(NUnitProjectXml.NormalProject);
            doc.Save(xmlfile);
            Assert.IsTrue(File.Exists(xmlfile));

            ProjectDocument doc2 = new ProjectDocument(xmlfile);

            doc2.Load();
            ProjectModel project2 = new ProjectModel(doc2);

            Assert.AreEqual(2, project2.Configs.Count);

            Assert.AreEqual(2, project2.Configs[0].Assemblies.Count);
            Assert.AreEqual("assembly1.dll", project2.Configs[0].Assemblies[0]);
            Assert.AreEqual("assembly2.dll", project2.Configs[0].Assemblies[1]);

            Assert.AreEqual(2, project2.Configs[1].Assemblies.Count);
            Assert.AreEqual("assembly1.dll", project2.Configs[1].Assemblies[0]);
            Assert.AreEqual("assembly2.dll", project2.Configs[1].Assemblies[1]);
        }
        protected void MakeProjectDocument(ClientProjectDocument document)
        {
            PopulateTags(document);
            document.FileContents = UploadFile(document.File);
            ProjectDocument _document = new ProjectDocument(document.ProjectId, document.Title, document.TypeKey, document.Description, document.Tags);

            _document.Save();

            foreach (string tagText in document.Tags)
            {
                Tag tag = new Tag(tagText);
                tag.Save();
                ProjectDocumentTag docTag = new ProjectDocumentTag(_document.Id, tag);
                docTag.Save();
            }

            ProjectDocumentContentTypeCode _contentType = null;

            try
            {
                _contentType = new ProjectDocumentContentTypeCode(document.File.ContentType);
            }
            catch
            {
                _contentType = new ProjectDocumentContentTypeCode()
                {
                    Title  = document.File.ContentType,
                    Key    = document.File.ContentType,
                    Active = true,
                    Order  = 0
                };
                _contentType.Save();
            }
            ProjectDocumentContent content = new ProjectDocumentContent(_document.Id, document.File.FileName, document.FileContents, _contentType.Id);

            content.Save();
        }
Exemple #3
0
 public void SaveMakesProjectNotDirty()
 {
     project.AddConfig("Debug");
     doc.Save(xmlfile);
     Assert.IsFalse(doc.HasUnsavedChanges);
 }
Exemple #4
0
        private static void SetupRelatedProjects()
        {
            string path;

            switch (Args.ProjectType)
            {
            case ProjectType.CloudService:
                path = Paths.CloudProjectFile;
                break;

            case ProjectType.FabricApplication:
                path = Paths.FabricProjectFile;
                break;

            default:
                return;
            }

            if (String.IsNullOrEmpty(Args.RelatedPath))
            {
                throw new InvalidOperationException("Configuration argument 'RelatedPath' is not set.");
            }

            if (String.IsNullOrEmpty(Args.ReferencesPath))
            {
                throw new InvalidOperationException("Configuration argument 'ReferencesPath' is not set.");
            }

            Args.RelatedPath.CreateDirectoryIfNotExists();
            Args.ReferencesPath.CreateDirectoryIfNotExists();

            Console.Write("Converting paths for related projects... ");

            var project = new ProjectDocument(path);

            var references = project.GetProjectReferences();

            if (references.Count == 0)
            {
                throw new InvalidOperationException("It is strange that cloud service or fabric application does not have any referenced projects.");
            }

            var log = new LogPackages();

            foreach (var reference in references)
            {
                SetupRelatedProject(reference, log);
            }

            project.Save();
            Console.WriteLine("OK");

            log.Report();

            Console.Write("Saving local references... ");
            log.SaveReferences(Args.ReferencesPath);
            Console.WriteLine("OK");

            Console.Write("Saving packages summary... ");
            log.SaveSummary(Args.TempPath);
            Console.WriteLine("OK");
        }
Exemple #5
0
        public static void CopySnippetsToVisualStudioProject(string projectDirPath, IEnumerable <SnippetDirectory> snippetDirectories)
        {
            string projectName = Path.GetFileName(projectDirPath);

            string csprojPath = Path.Combine(projectDirPath, $"{projectName}.{ProjectDocument.CSharpProjectExtension}");

            var document = new ProjectDocument(csprojPath);

            document.RemoveSnippetFiles();

#if !DEBUG
            var allSnippets = new List <Snippet>();
#endif

            XElement newItemGroup = document.AddItemGroup();

            foreach (SnippetDirectory snippetDirectory in snippetDirectories)
            {
                string directoryPath = Path.Combine(projectDirPath, snippetDirectory.DirectoryName);

                Directory.CreateDirectory(directoryPath);

                Snippet[] snippets = snippetDirectory.EnumerateSnippets().ToArray();

                foreach (IGrouping <string, Snippet> grouping in snippets
                         .GroupBy(f => Path.GetFileNameWithoutExtension(f.FilePath))
                         .Where(f => f.Count() > 1))
                {
                    throw new Exception($"multiple files with same name '{grouping.Key}'");
                }

                IOUtility.SaveSnippets(snippets, directoryPath);

                document.AddSnippetFiles(snippets.Select(f => f.FilePath), newItemGroup);

#if !DEBUG
                allSnippets.AddRange(snippets);
#endif
            }

            document.Save();

#if !DEBUG
            foreach (Snippet snippet in allSnippets)
            {
                string submenuShortcut = snippet.GetSubmenuShortcut();

                snippet.RemoveShortcutFromTitle();

                snippet.RemoveMetaKeywords();
                snippet.Keywords.Add($"{KnownTags.MetaTagPrefix}Name:{snippet.FileNameWithoutExtension()}");

                if (!string.IsNullOrEmpty(submenuShortcut))
                {
                    snippet.Keywords.Add($"{KnownTags.MetaTagPrefix}SubmenuShortcut:{submenuShortcut}");
                }
            }

            IOUtility.SaveSnippetsToSingleFile(
                allSnippets
                .Where(f => !f.HasTag(KnownTags.ExcludeFromReadme))
                .OrderBy(f => f.Language.ToString())
                .ThenBy(f => f.FileNameWithoutExtension()),
                Path.Combine(projectDirPath, "snippets.xml"));
#endif
        }