Пример #1
0
        public Item Build([NotNull] IProjectBase project, [NotNull] ITextNode rootTextNode)
        {
            var guid     = StringHelper.GetGuid(project, Guid);
            var database = project.GetDatabase(DatabaseName);

            var item = Factory.Item(database, guid, ItemName, ItemIdOrPath, TemplateIdOrPath).With(rootTextNode);

            if (ItemNameTextNode != TextNode.Empty)
            {
                item.ItemNameProperty.AddSourceTextNode(ItemNameTextNode);
            }

            if (TemplateIdOrPathTextNode != TextNode.Empty)
            {
                item.TemplateIdOrPathProperty.AddSourceTextNode(TemplateIdOrPathTextNode);
            }

            item.IconProperty.SetValue(IconTextNode);

            foreach (var fieldBuilder in Fields)
            {
                var field = fieldBuilder.Build(item);
                item.Fields.Add(field);
            }

            return(item);
        }
        public virtual ISnapshot LoadSnapshot(IProjectBase project, ISourceFile sourceFile, PathMappingContext pathMappingContext)
        {
            var itemName = sourceFile.GetFileNameWithoutExtensions();
            var filePath = pathMappingContext.FilePath;

            if (filePath.StartsWith("~/"))
            {
                filePath = filePath.Mid(1);
            }

            var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath));
            var fileName = Path.GetFileName(filePath);
            var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName);
            var directoryName             = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty);

            var tokens = new Dictionary <string, string>
            {
                ["ItemPath"] = itemName,
                ["FilePathWithoutExtensions"] = filePathWithExtensions,
                ["FilePath"] = filePath,
                ["Database"] = project.Options.DatabaseName,
                ["FileNameWithoutExtensions"] = fileNameWithoutExtensions,
                ["FileName"]         = fileName,
                ["DirectoryName"]    = directoryName,
                ["ProjectDirectory"] = project.ProjectDirectory
            };

            tokens.AddRange(project.Options.Tokens);

            var snapshotParseContext = Factory.SnapshotParseContext(project, tokens);
            var snapshot             = LoadSnapshot(snapshotParseContext, sourceFile);

            return(snapshot);
        }
Пример #3
0
        public virtual IEmitContext With(IProjectEmitter projectEmitter, IProjectBase project)
        {
            ProjectEmitter = projectEmitter;
            Project        = project;

            return(this);
        }
Пример #4
0
        private static IProjectItemUri GetUri([NotNull] IProjectBase project, [NotNull] ISnapshot snapshot)
        {
            // include file extensions in project unique ID for file, so they don't clash with items
            var filePath = "~/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(project.ProjectDirectory, snapshot.SourceFile.AbsoluteFileName)).TrimStart('/');

            return(new ProjectItemUri(project, filePath));
        }
Пример #5
0
        protected ProjectItem([NotNull] IProjectBase project, [NotNull] IProjectItemUri uri)
        {
            Project = project;
            Uri     = uri;

            _snapshots = new LockableList <ISnapshot>(this);
        }
Пример #6
0
        public ProjectItemUri([NotNull] IProjectBase project, [NotNull] string filePath)
        {
            // guids exclude typeOrDatabase, so items have same id across databases
            // - compare uris when database is important
            // - compare guids when database is unimportant

            FileOrDatabaseName = "file";
            Guid = StringHelper.GetGuid(project, filePath);
        }
Пример #7
0
        public void CheckProject(IProjectBase project, IEnumerable <string> checkerNames)
        {
            var context = Factory.CheckerContext(project);
            var treatWarningsAsErrors = Configuration.GetBool(Constants.Configuration.CheckProject.TreatWarningsAsErrors);
            var isMultiThreaded       = Configuration.GetBool(Constants.Configuration.System.MultiThreaded, true);

            var checkers = Checkers.Where(c => checkerNames.Contains(c.Name)).ToArray();

            CheckProject(context, checkers, isMultiThreaded, treatWarningsAsErrors);
        }
Пример #8
0
        public virtual void CheckProject(IProjectBase project)
        {
            var context = Factory.CheckerContext(project);

            var treatWarningsAsErrors = Configuration.GetBool(Constants.Configuration.CheckProject.TreatWarningsAsErrors);
            var isMultiThreaded       = Configuration.GetBool(Constants.Configuration.System.MultiThreaded, true);

            var checkers = GetCheckers(context).ToArray();

            CheckProject(context, checkers, isMultiThreaded, treatWarningsAsErrors);
        }
Пример #9
0
        public Database([NotNull] IFactory factory, [NotNull] IProjectBase project, [NotNull] string databaseName, [ItemNotNull, NotNull] IEnumerable <string> languageNames)
        {
            Factory      = factory;
            Project      = project;
            DatabaseName = databaseName;

            foreach (var languageName in languageNames)
            {
                _languages[languageName] = Factory.Language(languageName);
            }
        }
        public void ConstructorTest()
        {
            Start();
            Project = Services.ProjectService.LoadProjectFromConfiguration();

            var fileName   = Path.Combine(ProjectDirectory, "items\\yaml\\ribbon.content.yaml");
            var sourceFile = new SourceFile(Services.Configuration, Services.FileSystem, fileName);

            Assert.AreEqual(fileName, sourceFile.AbsoluteFileName);
            Assert.AreNotEqual(DateTime.MinValue, sourceFile.LastWriteTimeUtc);
            Assert.AreEqual("~/items/yaml/ribbon", sourceFile.ProjectFileName);
        }
Пример #11
0
        /// <summary>
        /// Заполнить список прав на проект.
        /// </summary>
        /// <param name="document">Документ.</param>
        /// <param name="projectBase">Проект.</param>
        /// <param name="grantRightsToProject">True, если выдавать права участникам проектов. Иначе - false.</param>
        /// <param name="result">Список прав в виде реципиент-тип прав.</param>
        public virtual void AddRecipientRightsForProject(IOfficialDocument document, IProjectBase projectBase, bool grantRightsToProject, List <RecipientRights> result)
        {
            if (projectBase == null)
            {
                return;
            }

            if (!Projects.Is(projectBase))
            {
                return;
            }

            var project  = Projects.As(projectBase);
            var readType = Constants.Module.AccessRightsReadTypeName;
            var editType = Constants.Module.AccessRightsEditTypeName;

            if (Docflow.PublicFunctions.OfficialDocument.IsProjectDocument(document))
            {
                result.Add(Structures.Module.RecipientRights.Create(project.Manager, editType));
            }

            if (grantRightsToProject == true)
            {
                if (project.Administrator != null)
                {
                    result.Add(Structures.Module.RecipientRights.Create(project.Administrator, editType));
                }

                if (project.InternalCustomer != null)
                {
                    result.Add(Structures.Module.RecipientRights.Create(project.InternalCustomer, readType));
                }

                foreach (var teamMember in project.TeamMembers)
                {
                    result.Add(teamMember.Group == Sungero.Projects.ProjectTeamMembers.Group.Management
                     ? Structures.Module.RecipientRights.Create(teamMember.Member, editType)
                     : Structures.Module.RecipientRights.Create(teamMember.Member, readType));
                }
            }

            if (project.LeadingProject != null)
            {
                this.AddRecipientRightsForProject(document, project.LeadingProject, grantRightsToProject, result);
            }
        }
Пример #12
0
        // [NotNull]
        // private static readonly MD5 Md5Hash = MD5.Create();

        public static Guid GetGuid([NotNull] IProjectBase project, [NotNull] string id)
        {
            Guid guid;

            if (Guid.TryParse(id, out guid))
            {
                return(guid);
            }

            if (id.StartsWith("{") && id.EndsWith("}"))
            {
                return(ToGuid(id));
            }

            // calculate guid from id and project id case-insensitively
            return(ToGuid((project.ProjectUniqueId + "/" + id).ToUpperInvariant()));
        }
        public PathMappingContext Parse([NotNull] IProjectBase project, [NotNull] ISourceFile sourceFile)
        {
            ItemName = sourceFile.GetFileNameWithoutExtensions();
            Database = project.GetDatabase(project.Options.DatabaseName);

            var projectFileName = "/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(project.ProjectDirectory, sourceFile.AbsoluteFileName)).TrimStart('/');

            if (PathMapper.TryGetWebsiteFileName(projectFileName, out var filePath))
            {
                FilePath = filePath;
                IsMapped = true;
            }

            if (PathMapper.TryGetWebsiteItemPath(projectFileName, out var databaseName, out var itemPath, out var isImport, out var uploadMedia))
            {
                Database    = project.GetDatabase(databaseName);
                ItemPath    = itemPath;
                UploadMedia = uploadMedia;
                IsMapped    = true;
            }

            return(this);
        }
Пример #14
0
 public ProjectIndexes([NotNull] IProjectBase project)
 {
     Project = project;
 }
Пример #15
0
 public ContentFile([NotNull] IProjectBase project, [NotNull] ISnapshot snapshot, [NotNull] string filePath) : base(project, snapshot, filePath)
 {
 }
Пример #16
0
 public File([NotNull] IProjectBase project, [NotNull] ISnapshot snapshot, [NotNull] string filePath) : base(project, GetUri(project, snapshot))
 {
     AddSnapshot(snapshot);
     FilePath = filePath;
 }
Пример #17
0
        public void Generate(IBuildContext context, ITextTemplatingEngine textTemplatingEngine, IProjectBase project)
        {
            var extension   = '.' + context.Configuration.GetString(Constants.Configuration.GenerateCode.Extension, ".*").TrimStart('.');
            var pathMatcher = Factory.PathMatcher(context.Configuration.GetString(Constants.Configuration.GenerateCode.Include), context.Configuration.GetString(Constants.Configuration.GenerateCode.Exclude));

            foreach (var fileName in FileSystem.GetFiles(context.ProjectDirectory, "*" + extension, SearchOption.AllDirectories))
            {
                if (!pathMatcher.IsMatch(fileName))
                {
                    continue;
                }

                context.Trace.TraceInformation(Msg.G1008, Texts.Generating_code, PathHelper.UnmapPath(context.ProjectDirectory, fileName));

                try
                {
                    var targetFileName = fileName.Left(fileName.Length - extension.Length);
                    var template       = FileSystem.ReadAllText(fileName);

                    var output = textTemplatingEngine.Generate(template, project);

                    if (string.IsNullOrEmpty(output))
                    {
                        FileSystem.DeleteFile(targetFileName);
                        continue;
                    }

                    if (output.IndexOf("<pagebreak", StringComparison.Ordinal) < 0)
                    {
                        FileSystem.WriteAllText(targetFileName, output);
                        continue;
                    }

                    SplitOutputIntoFiles(output, fileName);
                }
                catch (TemplateParsingException ex)
                {
                    foreach (var parserError in ex.ParserErrors)
                    {
                        context.Trace.TraceError(Msg.G1007, parserError.Message, fileName, new TextSpan(parserError.Location.LineIndex, parserError.Location.CharacterIndex, parserError.Length));
                    }
                }
                catch (TemplateCompilationException ex)
                {
                    foreach (var compilationError in ex.CompilationErrors)
                    {
                        context.Trace.TraceError(Msg.G1007, compilationError, fileName, TextSpan.Empty);
                    }
                }
                catch (Exception ex)
                {
                    context.Trace.TraceError(Msg.G1007, ex.Message, fileName, TextSpan.Empty);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Получить права участников проекта.
        /// </summary>
        /// <param name="queueItem">Элемент очереди.</param>
        /// <param name="document">Документ.</param>
        /// <param name="project">Проект.</param>
        /// <returns>Список прав в виде реципиент-тип прав.</returns>
        internal List <Structures.Module.RecipientRights> GetProjectRecipientRights(IProjectDocumentRightsQueueItem queueItem,
                                                                                    IOfficialDocument document, IProjectBase project)
        {
            var result = new List <Structures.Module.RecipientRights>();

            // Выдать права на сам документ.
            this.AddRecipientRightsForProject(document, project, document.DocumentKind.GrantRightsToProject.Value, result);
            this.GrantRightsOnDocumentToLeadingProgect(document, result);

            return(result);
        }
        protected virtual void Compare([NotNull] IBuildContext context, [NotNull] IProjectBase project1, [NotNull] IProjectBase project2)
        {
            foreach (var i in project1.ProjectItems.OrderBy(p => p.QualifiedName))
            {
                var projectItem1 = i;
                Header = projectItem1.QualifiedName;

                var projectItem2 = project2.Indexes.FindQualifiedItem <IProjectItem>(projectItem1.Uri);
                if (projectItem2 == null)
                {
                    var file          = projectItem1 as Projects.Files.File;
                    var qualifiedName = file != null ? file.FilePath : projectItem1.QualifiedName;

                    context.Trace.WriteLine($"+ {qualifiedName} [{projectItem1.GetType().Name}]");
                    continue;
                }

                // if either project items are imported, treat them as if not existing
                var databaseProjectItem1 = projectItem1 as DatabaseProjectItem;
                if (databaseProjectItem1 != null && databaseProjectItem1.IsImport)
                {
                    projectItem1 = null;
                }

                var databaseProjectItem2 = projectItem2 as DatabaseProjectItem;
                if (databaseProjectItem2 != null && databaseProjectItem2.IsImport)
                {
                    projectItem2 = null;
                }

                if (projectItem1 == null && projectItem2 == null)
                {
                    continue;
                }

                // compare items
                var item1 = projectItem1 as Item;
                var item2 = projectItem2 as Item;
                if (item1 != null || item2 != null)
                {
                    if (item1 == null)
                    {
                        WriteHeader(context);
                        context.Trace.WriteLine($"- {projectItem2.QualifiedName} [Item]");
                        context.Trace.WriteLine($"+ {projectItem1.QualifiedName} [Item]");
                        continue;
                    }

                    if (item2 == null)
                    {
                        WriteHeader(context);
                        context.Trace.WriteLine($"- {projectItem2.QualifiedName} [Item]");
                        context.Trace.WriteLine($"+ {projectItem1.QualifiedName} [Item]");
                        continue;
                    }

                    Compare(context, item1, item2);

                    continue;
                }

                // compare templates
                var template1 = projectItem1 as Template;
                var template2 = projectItem2 as Template;
                if (template1 != null || template2 != null)
                {
                    if (template1 == null)
                    {
                        context.Trace.WriteLine($"- {projectItem2.QualifiedName} [Template]");
                        continue;
                    }

                    if (template2 == null)
                    {
                        context.Trace.WriteLine($"+ {projectItem1.QualifiedName} [Template]");
                        continue;
                    }

                    Compare(context, template1, template2);
                }

                var file1 = projectItem1 as Projects.Files.File;
                var file2 = projectItem2 as Projects.Files.File;
                if (file1 != null || file2 != null)
                {
                    if (file1 == null)
                    {
                        context.Trace.WriteLine($"- {file2.FilePath} [File]");
                        continue;
                    }

                    if (file2 == null)
                    {
                        context.Trace.WriteLine($"+ {file1.FilePath} [File]");
                    }
                }
            }

            foreach (var projectItem2 in project2.ProjectItems.OrderBy(p => p.QualifiedName))
            {
                var databaseProjectItem2 = projectItem2 as DatabaseProjectItem;
                if (databaseProjectItem2 != null && databaseProjectItem2.IsImport)
                {
                    continue;
                }

                Header = projectItem2.QualifiedName;

                var projectItem1 = project1.Indexes.FindQualifiedItem <IProjectItem>(projectItem2.Uri);
                if (projectItem1 == null)
                {
                    var file          = projectItem2 as Projects.Files.File;
                    var qualifiedName = file != null ? file.FilePath : projectItem2.QualifiedName;

                    context.Trace.WriteLine($"- {qualifiedName} [{projectItem2.GetType().Name}]");
                }
            }
        }
 public SnapshotParseContext([NotNull] IProjectBase project, [NotNull] IDictionary <string, string> tokens)
 {
     Project = project;
     Tokens  = tokens;
 }
Пример #21
0
 protected virtual void Emit([NotNull] IEmitContext context, [NotNull] IProjectBase project, [NotNull, ItemNotNull] List <IEmitter> emitters, [NotNull, ItemNotNull] ICollection <Tuple <IProjectItem, Exception> > retries)
 {
     EmitProjectItems(context, project.ProjectItems, emitters, retries);
 }
Пример #22
0
        public ICheckerContext With(IProjectBase project)
        {
            Project = project;

            return(this);
        }
 public SerializationFile([NotNull] IProjectBase project, [NotNull] ISnapshot snapshot, [NotNull] string filePath) : base(project, snapshot, filePath)
 {
 }
 public LayoutCompileContext([NotNull] IProjectBase project, [NotNull] IDatabase database, [NotNull] ITextSnapshot snapshot)
 {
     Project  = project;
     Database = database;
     Snapshot = snapshot;
 }