Beispiel #1
0
        protected string GetFileName([NotNull] NewItemWizardPipeline pipeline, [NotNull] ProjectItem projectItem)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));

            return("/" + projectItem.Path.Replace("\\", "/"));
        }
        private string Expand([NotNull] NewItemWizardPipeline pipeline, [NotNull] string value)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(value, nameof(value));

            return(pipeline.Tokens.Aggregate(value, (current, token) => current.Replace(token.Key, token.Value)));
        }
Beispiel #3
0
        protected string GetTypeName([NotNull] NewItemWizardPipeline pipeline, [NotNull] ProjectItem projectItem)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));

            var result = pipeline.Tokens["$rootnamespace$"] + "." + pipeline.Tokens["$safeitemrootname$"] + ", " + projectItem.Project.OutputFileName;

            return(result);
        }
        protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));
            Debug.ArgumentNotNull(itemUri, nameof(itemUri));

            var modelName = GetTypeName(pipeline, projectItem);

            ItemModifier.Edit(itemUri, new FieldId(new Guid("{EE9E23D2-181D-4172-A929-0E0B8D10313C}")), modelName);
        }
Beispiel #5
0
        protected virtual void Handle([NotNull] NewItemWizardPipeline pipeline, [NotNull] DatabaseName databaseName, [NotNull] ProjectItem projectItem, [NotNull] string itemPath, [NotNull] ProcessedEventHandler callback)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(databaseName, nameof(databaseName));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));
            Debug.ArgumentNotNull(itemPath, nameof(itemPath));
            Debug.ArgumentNotNull(callback, nameof(callback));

            var projectFile = (ProjectFileItem)projectItem;

            var site = projectItem.Project.Site;

            if (site == null)
            {
                return;
            }

            var databaseUri = new DatabaseUri(site, databaseName);

            var name = Path.GetFileNameWithoutExtension(projectItem.Path);

            GetItemsCompleted <ItemPath> completed = delegate(IEnumerable <ItemPath> items)
            {
                if (!items.Any())
                {
                    callback(this, new ProcessedEventArgs(Resources.PathBasedFileItemHandler_Create_failed, Resources.PathBasedFileItemHandler_Create_Path_was_not_created));
                    return;
                }

                // create item
                var parentUri   = items.First().ItemUri;
                var templateuri = new ItemUri(databaseUri, TemplateId);

                var itemUri = site.DataService.AddFromTemplate(parentUri, templateuri, name);

                UpdateFields(pipeline, projectItem, itemUri);

                // done
                projectFile.Items.Add(itemUri);

                callback(this, new ProcessedEventArgs(Resources.PathBasedFileItemHandler_Create_created, Path.GetDirectoryName(itemPath) + @"/" + name));

                Notifications.RaiseItemAdded(this, new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Version.Latest), parentUri);

                if (AppHost.CurrentContentTree != null)
                {
                    AppHost.CurrentContentTree.Locate(itemUri);
                }
            };

            site.DataService.CreateItemPath(databaseUri, (Path.GetDirectoryName(itemPath) ?? string.Empty).Replace('\\', '/'), completed);
        }
Beispiel #6
0
        protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));
            Debug.ArgumentNotNull(itemUri, nameof(itemUri));

            var modelName = GetTypeName(pipeline, projectItem);

            var fieldValues = new List <Tuple <FieldId, string> >();

            fieldValues.Add(new Tuple <FieldId, string>(new FieldId(new Guid("{1A0AE537-291C-4CC8-B53F-7CA307A0FEF5}")), modelName));
            fieldValues.Add(new Tuple <FieldId, string>(new FieldId(new Guid("{298F7E71-8AEB-488B-BC93-CE6F2B09E130}")), "Index"));

            ItemModifier.Edit(itemUri, fieldValues);
        }
        protected override void UpdateFields(NewItemWizardPipeline pipeline, ProjectItem projectItem, ItemUri itemUri)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));
            Debug.ArgumentNotNull(projectItem, nameof(projectItem));
            Debug.ArgumentNotNull(itemUri, nameof(itemUri));

            var fileName = GetFileName(pipeline, projectItem);

            var pathFieldId = IdManager.GetFieldId("/sitecore/templates/System/Layout/Layout/Data/Path");

            var fieldValues = new List <Tuple <FieldId, string> >
            {
                new Tuple <FieldId, string>(pathFieldId, fileName),
            };

            ItemModifier.Edit(itemUri, fieldValues);

            projectItem.Project.LinkItemAndFile(itemUri, fileName);
        }
Beispiel #8
0
 protected virtual void UpdateFields([NotNull] NewItemWizardPipeline pipeline, [NotNull] ProjectItem projectItem, [NotNull] ItemUri itemUri)
 {
     Debug.ArgumentNotNull(pipeline, nameof(pipeline));
     Debug.ArgumentNotNull(projectItem, nameof(projectItem));
     Debug.ArgumentNotNull(itemUri, nameof(itemUri));
 }
Beispiel #9
0
        protected override void Process(NewItemWizardPipeline pipeline)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));

            string fileType;

            if (!pipeline.Tokens.TryGetValue("$filetype$", out fileType))
            {
                return;
            }

            if (fileType != FileType)
            {
                return;
            }

            pipeline.Abort();

            var project = ProjectManager.GetProject(pipeline.Item) ?? GetProject(pipeline);

            if (project == null)
            {
                return;
            }

            var site = project.Site;

            if (site == null)
            {
                return;
            }

            var itemPath = string.Empty;

            if (pipeline.DatabaseName == null)
            {
                var d = new NewItemWizardDialog();
                d.Initialize(site, TemplateName);

                if (AppHost.Shell.ShowDialog(d) != true)
                {
                    return;
                }

                var itemUri = d.ItemUri;
                if (itemUri == null || itemUri == ItemUri.Empty)
                {
                    return;
                }

                pipeline.DatabaseName = itemUri.DatabaseName;

                itemPath = d.SelectedPath ?? string.Empty;
                if (!string.IsNullOrEmpty(itemPath))
                {
                    itemPath += "/" + Path.GetFileNameWithoutExtension(pipeline.Item.Name);
                }
            }

            var fileName    = project.GetProjectItemFileName(pipeline.Item);
            var projectItem = ProjectFileItem.Load(project, fileName);

            project.Add(projectItem);

            var busy = true;

            Handle(pipeline, pipeline.DatabaseName, projectItem, itemPath, (sender, args) => busy = false);

            AppHost.DoEvents(ref busy);

            pipeline.ProjectItem = projectItem;
        }
        protected override void Process(NewItemWizardPipeline pipeline)
        {
            Debug.ArgumentNotNull(pipeline, nameof(pipeline));

            var template = pipeline.Template.Replace(@"xmlns=""http://schemas.microsoft.com/developer/vstemplate/2005""", string.Empty);

            var doc = XDocument.Parse(template);

            var itemElements = doc.XPathSelectElements(@"/VSTemplate/SitecoreItems/Item").ToList();

            if (!itemElements.Any())
            {
                itemElements = doc.XPathSelectElements(@"/VSTemplate/WizardData/SitecoreItems/Item").ToList();
            }

            if (!itemElements.Any())
            {
                return;
            }

            var project = ProjectManager.GetProject(pipeline.Item) ?? GetProject(pipeline);

            if (project == null)
            {
                return;
            }

            var site = project.Site;

            if (site == null)
            {
                return;
            }

            foreach (var element in itemElements)
            {
                var databaseName = Expand(pipeline, element.GetAttributeValue("DatabaseName"));
                var path         = Expand(pipeline, element.GetAttributeValue("Path"));
                var name         = Expand(pipeline, element.GetAttributeValue("Name"));
                var templateName = Expand(pipeline, element.GetAttributeValue("TemplateName"));

                var fields = new StringBuilder();
                var first  = true;

                foreach (var field in element.Elements())
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        fields.Append('|');
                    }

                    fields.Append(Expand(pipeline, field.GetAttributeValue("Name")));
                    fields.Append('|');
                    fields.Append(Expand(pipeline, field.GetAttributeValue("Value")));
                }

                ExecuteCompleted completed = delegate(string response, ExecuteResult result)
                {
                    if (!DataService.HandleExecute(response, result))
                    {
                        return;
                    }

                    var parts = response.Split('|');
                    if (parts.Length != 2)
                    {
                        return;
                    }

                    Guid itemId;
                    if (!Guid.TryParse(parts[0], out itemId))
                    {
                        return;
                    }

                    Guid parentId;
                    if (!Guid.TryParse(parts[1], out parentId))
                    {
                        return;
                    }

                    var databaseUri = new DatabaseUri(site, new DatabaseName(databaseName));
                    var itemUri     = new ItemUri(databaseUri, new ItemId(itemId));
                    var parentUri   = new ItemUri(itemUri.DatabaseUri, new ItemId(parentId));

                    var fileName    = project.GetProjectItemFileName(pipeline.Item);
                    var projectItem = ProjectFileItem.Load(project, fileName);
                    project.Add(projectItem);
                    projectItem.Items.Add(itemUri);

                    project.Save();

                    Notifications.RaiseItemAdded(this, new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Data.Version.Latest), parentUri);
                };

                site.DataService.ExecuteAsync("Items.CreateItem", completed, databaseName, path, name, templateName, fields.ToString());
            }
        }