Exemplo n.º 1
0
        public ManageTemplate()
        {
            InitializeComponent();

            Localizer.LocalizeControl(this);
            var blank = new TemplateDescription();

            fastGrid.Columns.Add(new FastColumn(blank.Property(p => p.Name), Localizer.GetString("TitleName"))
            {
                ColumnMinWidth           = 50,
                IsHyperlinkStyleColumn   = true,
                ColorHyperlinkTextActive = Color.Blue,
                HyperlinkFontActive      = new Font(Font, FontStyle.Bold),
                HyperlinkActiveCursor    = Cursors.Hand
            });
            fastGrid.Columns.Add(new FastColumn(blank.Property(p => p.IndicatorsCount), Localizer.GetString("TitleIndicators"))
            {
                ColumnMinWidth           = 50,
                IsHyperlinkStyleColumn   = true,
                ColorHyperlinkTextActive = Color.Blue,
                HyperlinkFontActive      = new Font(Font, FontStyle.Bold),
                HyperlinkActiveCursor    = Cursors.Hand
            });
            fastGrid.Columns.Add(new FastColumn(blank.Property(p => p.Close), "-")
            {
                IsHyperlinkStyleColumn = true,
                HyperlinkActiveCursor  = Cursors.Hand,
                ImageList      = imageList,
                ColumnMinWidth = 25,
                ColumnWidth    = 25
            });
            Rebind();
        }
Exemplo n.º 2
0
        public EntityInternal Clone(string name, EntityInternal entity, EntityBuilder entityBuilder)
        {
            entityBuilder.SetName(name);
            if (entity.TemplateAccessor.IsPresent())
            {
                TemplateAccessor accessor = entity.TemplateAccessor.Get();
                if (accessor != null)
                {
                    TemplateDescription templateDescription = accessor.TemplateDescription;
                    entityBuilder.SetTemplate(templateDescription.TemplateClass);
                    if (accessor.HasConfigPath())
                    {
                        entityBuilder.SetConfig(accessor.ConfigPath);
                    }
                    else
                    {
                        YamlNode yamlNode = accessor.YamlNode;
                        if (yamlNode != null)
                        {
                            entityBuilder.SetTemplateYamlNode(yamlNode);
                        }
                    }
                }
            }
            EntityInternal internal2 = entityBuilder.Build(true);

            foreach (Type type in entity.ComponentClasses)
            {
                if (!ReferenceEquals(type, this.newEntityComponentType))
                {
                    internal2.AddComponent(entity.GetComponent(type));
                }
            }
            return(internal2);
        }
Exemplo n.º 3
0
 /// <inheritdoc />
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     return(base.IsSupportingTemplate(templateDescription) &&
            (templateDescription.Id == DefaultSoundId ||
             templateDescription.Id == MusicSoundId ||
             templateDescription.Id == SpatializedSoundId));
 }
        private static void ParseExample(TemplateDescription description, templateExample example, StringBuilder command, bool checkExample = true)
        {
            foreach (templateArgumentInstance argumentInstance in example.Arguments ??
                     Enumerable.Empty <templateArgumentInstance>())
            {
                if (checkExample && description.Arguments?.Any(a => a.name == argumentInstance.name) != true)
                {
                    throw new ArgumentNotFoundException(argumentInstance.name, description.name);
                }

                string value = argumentInstance.value.Contains(' ')
                                   ? $"\"{argumentInstance.value}\""
                                   : argumentInstance.value;
                command.Append(argumentInstance.valueSpecified
                                   ? $" --{argumentInstance.name.ToLowerInvariant()} {value}"
                                   : $" --{argumentInstance.name.ToLowerInvariant()}");
            }

            foreach (templateRelationshipInstance relationshipInstance in example.Relationship ??
                     Enumerable.Empty <templateRelationshipInstance>())
            {
                if (checkExample && description.Relationship?.Any(r => r.name == relationshipInstance.name) != true)
                {
                    throw new RelationshipNotFoundException(relationshipInstance.name, description.name);
                }

                string value = relationshipInstance.value.Contains(' ')
                                   ? $"\"{relationshipInstance.value}\""
                                   : relationshipInstance.value;
                command.Append($" --{relationshipInstance.name.ToLowerInvariant()} {value}");
            }
        }
        public override bool CanResolve(Entity owner, string key, bool fallback = false)
        {
            if (key == EntityKeys.TemplateKey ||
                key == EntityKeys.HiearchyKey ||
                key == EntityKeys.RelatedKey)
            {
                TemplateDescription template = templateRepository.Template(owner.Type);
                return(template != null || ParentTemplateEntity(owner) != null);
            }

            TemplateDescription ownerTemplate = owner.Value <TemplateDescription>();

            if (ownerTemplate != null)
            {
                return(true);
            }

            IEnumerable <ForeachItemContainer> foreachItems = owner.Values <ForeachItemContainer>();

            if (foreachItems.Any(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase)))
            {
                return(true);
            }

            return(owner.Any(e => e.Value <templateFile>() != null) ||
                   IsCheck(owner, key) ||
                   key.StartsWith("is", StringComparison.OrdinalIgnoreCase) && fallback ||
                   (owner.Value <templateFile>() != null &&
                    owner.Value <templateFile>().GetType().GetProperty(key) != null));
        }
Exemplo n.º 6
0
 public static ICollection <string> TemplateNames(this TemplateDescription templateDescription,
                                                  ITemplateRepository templateRepository)
 {
     return(templateDescription.IncludingBaseTemplates(templateRepository)
            .Select(t => t.name)
            .ToArray());
 }
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     if (templateDescription == null)
     {
         throw new ArgumentNullException(nameof(templateDescription));
     }
     return(templateDescription.Id == TemplateId);
 }
Exemplo n.º 8
0
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     if (templateDescription == null)
     {
         throw new ArgumentNullException(nameof(templateDescription));
     }
     return(SupportedTemplatesToUrl.ContainsKey(templateDescription.Id));
 }
 private void AutoAddComponents(EntityInternal newEntity, TemplateDescription templateDescription)
 {
     foreach (Type type in templateDescription.GetAutoAddedComponentTypes())
     {
         Component component = !typeof(GroupComponent).IsAssignableFrom(type) ? newEntity.CreateNewComponentInstance(type) : GroupRegistry.FindOrCreateGroup(type, newEntity.Id);
         newEntity.AddComponent(component);
     }
 }
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     if (templateDescription == null)
     {
         throw new ArgumentNullException(nameof(templateDescription));
     }
     return(templateDescription is TemplateAssetFactoryDescription);
 }
Exemplo n.º 11
0
        private void CheckCompatibility(TemplateDescription template, Entity dataModel)
        {
            IEnumerable <TemplateDescription> roots       = FindCompatibleRoots();
            TemplateEntity             templateEntity     = TemplateEntity.Decorate(dataModel.Root);
            List <TemplateDescription> dataModelTemplates = GetTemplateHierarchy();

            if (templateEntity.HasTemplate &&
                !roots.Any(dataModelTemplates.Contains))
            {
                throw new TemplateIncompatibleException(template.name, templateEntity.Template.name);
            }

            List <TemplateDescription> GetTemplateHierarchy()
            {
                List <TemplateDescription> result = new List <TemplateDescription>();

                if (!templateEntity.HasTemplate)
                {
                    return(result);
                }

                TemplateDescription current = templateEntity.Template;

                result.Add(current);
                while (!string.IsNullOrEmpty(current?.basedOn))
                {
                    current = repository.Template(current.basedOn);
                    result.Add(current);
                }

                return(result);
            }

            IEnumerable <TemplateDescription> FindCompatibleRoots()
            {
                List <TemplateDescription> unvisited = new List <TemplateDescription>(new [] { template });
                List <TemplateDescription> visited   = new List <TemplateDescription>();
                List <TemplateDescription> result    = new List <TemplateDescription>();

                while (unvisited.Except(visited).Any())
                {
                    TemplateDescription visiting = unvisited.Except(visited).First();
                    visited.Add(visiting);
                    if (visiting.isRoot)
                    {
                        result.Add(visiting);
                    }
                    else
                    {
                        unvisited.AddRange(visiting.Relationship
                                           .Where(relationship => repository.Template(relationship.type) != null)
                                           .Select(relationship => repository.Template(relationship.type)));
                    }
                }

                return(result.Distinct());
            }
        }
Exemplo n.º 12
0
 public PackageTemplateViewModel(IViewModelServiceProvider serviceProvider, TemplateDescription template, SessionViewModel session = null)
     : base(serviceProvider, template)
 {
     this.session         = session;
     UpdatePackageCommand = new AnonymousTaskCommand(ServiceProvider, UpdatePackage)
     {
         IsEnabled = session != null
     };
 }
Exemplo n.º 13
0
        public override bool IsSupportingTemplate(TemplateDescription templateDescription)
        {
            if (!(templateDescription is TemplateAssetFactoryDescription description))
            {
                return(false);
            }
            var assetType = description.GetAssetType();

            return(base.IsSupportingTemplate(templateDescription) && description.ImportSource && typeof(IAssetWithSource).IsAssignableFrom(assetType));
        }
Exemplo n.º 14
0
 private string GetNameFromTemplate()
 {
     if (this.EntityTemplateAccessor.IsPresent())
     {
         TemplateDescription templateDescription = this.EntityTemplateAccessor.Get().TemplateDescription;
         if (templateDescription != null)
         {
             return(templateDescription.TemplateName);
         }
     }
     return(string.Empty);
 }
Exemplo n.º 15
0
 private void ConfigureTemplates(IContentType node, ContentTypeDescription type)
 {
     type.Templates = new List <TemplateDescription>();
     foreach (var template in node.AllowedTemplates)
     {
         var templateModel = new TemplateDescription();
         templateModel.Alias     = template.Alias;
         templateModel.Name      = template.Name;
         templateModel.IsDefault = template == node.DefaultTemplate ? "true" : "false";
         type.Templates.Add(templateModel);
     }
 }
Exemplo n.º 16
0
        public static ICollection <TemplateDescription> IncludingBaseTemplates(this TemplateDescription templateDescription,
                                                                               ITemplateRepository templateRepository)
        {
            List <TemplateDescription> templates = new List <TemplateDescription>();
            TemplateDescription        template  = templateDescription;

            while (template != null)
            {
                templates.Add(template);
                template = templateRepository.Template(template.basedOn);
            }

            return(templates);
        }
Exemplo n.º 17
0
        public ClassicMapMainWindow(string dbSource, TemplateDescription templateName)
        {
            InitializeComponent();

            MainGrid.DataContext = this;

            _templateName   = templateName;
            ClassicDbSource = "(local)";
            TemplateName    = templateName.Template.Name;
            TemplateType    = templateName.Template.ModuleType.ToString();
            WebDbSource     = dbSource;
            _webDataFactory = new DataFactory(WebDbSource);
            _browserDialog  = new FolderBrowserDialog();
            _transformRules = new LoadTransformRules();
        }
        public void set_description(Template template, string lang, string desc)
        {
            if (template != null)
            {
                TemplateDescription description = new TemplateDescription();
                description.Language = lang;
                description.Value    = desc;
                if (template.DescriptionList == null)
                {
                    template.DescriptionList = new List <TemplateDescription>();
                }

                template.DescriptionList.Add(description);
            }
        }
Exemplo n.º 19
0
 private void ResolveConfigPathByTemplate(Optional <TemplateAccessor> templateAccessor)
 {
     if (templateAccessor.IsPresent())
     {
         TemplateAccessor accessor = templateAccessor.Get();
         if (accessor.HasConfigPath())
         {
             TemplateDescription templateDescription = accessor.TemplateDescription;
             if (templateDescription.IsOverridedConfigPath())
             {
                 accessor.ConfigPath = templateDescription.OverrideConfigPath(accessor.ConfigPath);
             }
         }
     }
 }
Exemplo n.º 20
0
        private async Task <VirtualFile> GetFile(Entity dataModel, templateFile file, bool forced, string basePath,
                                                 TemplateDescription template)
        {
            string path = await resolver.ResolveAsync(file.path ?? string.Empty, dataModel).ConfigureAwait(false);

            string name = await resolver.ResolveAsync(file.name, dataModel).ConfigureAwait(false);

            if (!forced && fileSystem.FileExists(Path.Combine(path, name), basePath))
            {
                throw new FileExistsException(name, template.name);
            }

            VirtualFile destination = fileSystem.GetFile(Path.Combine(path, name), basePath);

            return(destination);
        }
Exemplo n.º 21
0
        public object Decode(ProtocolBuffer protocolBuffer)
        {
            object obj2;
            long   id = (long)this.longCodec.Decode(protocolBuffer);
            TemplateDescription templateInfo = this.templateRegistry.GetTemplateInfo(id);
            string configPath = (string)this.stringCodec.Decode(protocolBuffer);

            try
            {
                obj2 = new TemplateAccessor(templateInfo, configPath);
            }
            catch (Exception exception)
            {
                throw new Exception("templateType = " + templateInfo, exception);
            }
            return(obj2);
        }
Exemplo n.º 22
0
        public override bool IsSupportingTemplate(TemplateDescription templateDescription)
        {
            if (templateDescription == null)
            {
                throw new ArgumentNullException(nameof(templateDescription));
            }
            var assetTemplate = templateDescription as TemplateAssetDescription;

            if (assetTemplate == null)
            {
                return(false);
            }

            var assetType = assetTemplate.GetAssetType();

            return(assetType != null && typeof(HtmlFileAsset).IsAssignableFrom(assetType));
        }
Exemplo n.º 23
0
        public bool IsAcceptable(Type componentType, EntityInternal entity)
        {
            Optional <TemplateAccessor> templateAccessor = entity.TemplateAccessor;

            if (!templateAccessor.IsPresent())
            {
                return(false);
            }
            TemplateDescription templateDescription = templateAccessor.Get().TemplateDescription;

            if (!templateDescription.IsComponentDescriptionPresent(componentType))
            {
                return(false);
            }
            ComponentDescription componentDescription = templateDescription.GetComponentDescription(componentType);

            return(this.IsAcceptable(componentDescription, entity));
        }
Exemplo n.º 24
0
        public TemplateDescriptionViewModel(IViewModelServiceProvider serviceProvider, TemplateDescription template)
            : base(serviceProvider)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }
            Template = template;
            var asmName = Assembly.GetExecutingAssembly().GetName().Name;

            if (!string.IsNullOrEmpty(template.Icon))
            {
                Icon = LoadImage(GetPath(template.Icon));
            }
            if (Icon == null)
            {
                Icon = LoadImage($@"pack://application:,,,/{asmName};component/Resources/Images/default-template-icon.png");
            }
            Screenshots = template.Screenshots.Select(GetPath).Select(LoadImage).NotNull().ToList();
        }
Exemplo n.º 25
0
        public void TestWriteTemplatesToFile()
        {
            List <Template> x = new List <Template>();

            {
                Template t = new Template();
                {
                    t.ID              = "X123";
                    t.Class           = "TEST CLASS";
                    t.Category        = TemplateCategory.Scheduled;
                    t.DescriptionList = new List <TemplateDescription>();
                    {
                        TemplateDescription c = new TemplateDescription();
                        {
                            c.Language = "fra";
                            c.Value    = "Test description fra";
                        }
                        t.DescriptionList.Add(c);
                    }
                    {
                        TemplateDescription c = new TemplateDescription();
                        {
                            c.Language = "eng";
                            c.Value    = "Test description eng";
                        }
                        t.DescriptionList.Add(c);
                    }
                    t.ParameterList = new List <TemplateParameterType>();
                    {
                        t.ParameterList.Add(TemplateParameterType.CarNumber);
                        t.ParameterList.Add(TemplateParameterType.Delay);
                        t.ParameterList.Add(TemplateParameterType.DelayReasonCode);
                        t.ParameterList.Add(TemplateParameterType.StationId);
                        t.ParameterList.Add(TemplateParameterType.Text);
                    }
                }
                x.Add(t);
            }

            TemplateListAccessor.WriteTemplatesToFile(x, @"c:\test.xml");
        }
Exemplo n.º 26
0
        public async Task UpdatePackageTemplate(TemplateDescription template)
        {
            var loggerResult = new LoggerResult();

            var workProgress = new WorkProgressViewModel(ServiceProvider, loggerResult)
            {
                Title           = "Updating package...",
                KeepOpen        = KeepOpen.OnWarningsOrErrors,
                IsIndeterminate = true,
                IsCancellable   = false
            };

            workProgress.RegisterProgressStatus(loggerResult, true);

            var parameters = new PackageTemplateGeneratorParameters
            {
                Name            = Package.Meta.Name,
                OutputDirectory = Package.FullPath.GetFullDirectory(),
                Description     = template,
                Package         = Package,
                Logger          = loggerResult,
            };

            var generator = TemplateManager.FindTemplateGenerator(parameters);

            if (generator == null)
            {
                await ServiceProvider.Get <IDialogService>().MessageBox(Tr._p("Message", "Unable to retrieve template generator for the selected template. Aborting."), MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            // Errors might occur when generating the template. For the moment we consider them non-fatal and allow to open the project anyway.
            await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, workProgress);

            RefreshProjects();

            await workProgress.NotifyWorkFinished(false, loggerResult.HasErrors);

            Package.IsDirty = true;
        }
Exemplo n.º 27
0
        private bool TryResolveRelationship(Entity owner, string key, IType type, out Entity result)
        {
            templateRelationship[] relationships = owner.Template().Relationship;
            templateRelationship   relationship  =
                relationships?.FirstOrDefault(r => r.name.Equals(key, StringComparison.OrdinalIgnoreCase))
                ?? relationships?.FirstOrDefault(
                    r => r.name.Equals(key.Singular(), StringComparison.OrdinalIgnoreCase));
            TemplateDescription relationshipDescription =
                relationship != null?templateRepository.Template(relationship.type) : null;

            if (relationshipDescription != null)
            {
                IEnumerable <string> names = type.Attributes
                                             .Where(a => a.Name.Equals(relationship.name,
                                                                       StringComparison.OrdinalIgnoreCase))
                                             .SelectMany(a => a.Values);
                result = relationship.GetRelationship(relationshipDescription, owner, names.ToArray());
                return(true);
            }

            result = null;
            return(false);
        }
Exemplo n.º 28
0
        public static UDirectory GetTemplateDataDirectory(TemplateDescription template)
        {
            var installDir = DirectoryHelper.GetInstallationDirectory("Xenko");

            if (DirectoryHelper.IsRootDevDirectory(installDir))
            {
                var templateRoot = template.TemplateDirectory;
                while (templateRoot.GetDirectoryName() != "Templates")
                {
                    templateRoot = templateRoot.GetParent();
                    // Should not happen, but let's fail gracefully
                    if (templateRoot == UDirectory.Empty)
                    {
                        return(template.TemplateDirectory);
                    }
                }

                var relativePath = template.TemplateDirectory.MakeRelative(templateRoot);
                var devDataPath  = UPath.Combine(@"sources\data\XenkoPackage\Templates", relativePath);
                var fullPath     = UPath.Combine(installDir, devDataPath);
                return(fullPath);
            }
            return(template.TemplateDirectory);
        }
 /// <inheritdoc />
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     return(base.IsSupportingTemplate(templateDescription) && templateDescription.Id == Id);
 }
Exemplo n.º 30
0
 public override bool IsSupportingTemplate(TemplateDescription templateDescription)
 {
     return(true);
 }