protected override void BeginProcessing()
        {
            source = new ExplicitFileSource { Name = Name };

            if (!String.IsNullOrEmpty(InstallMode))
            {
                var mode = (InstallMode) Enum.Parse(typeof (InstallMode), InstallMode);
                if (mode != Sitecore.Install.Utils.InstallMode.Undefined)
                {
                    source.Converter.Transforms.Add(
                        new InstallerConfigurationTransform(
                            new BehaviourOptions(mode, MergeMode.Undefined)));
                }
            }
        }
Exemplo n.º 2
0
        protected override void BeginProcessing()
        {
            source = new ExplicitFileSource {
                Name = Name
            };

            if (!String.IsNullOrEmpty(InstallMode))
            {
                var mode = (InstallMode)Enum.Parse(typeof(InstallMode), InstallMode);
                if (mode != Sitecore.Install.Utils.InstallMode.Undefined)
                {
                    source.Converter.Transforms.Add(
                        new InstallerConfigurationTransform(
                            new BehaviourOptions(mode, MergeMode.Undefined)));
                }
            }
        }
 protected override void BeginProcessing()
 {
     source = new ExplicitFileSource {Name = Name};
 }
Exemplo n.º 4
0
        public static string GeneratePackage(PackageManifest manifest)
        {
            var packageProject = new PackageProject
            {
                Metadata =
                {
                    PackageName = manifest.PackageName,
                    Author      = manifest.Author,
                    Version     = manifest.Version,
                    Publisher   = manifest.Publisher
                }
            };

            foreach (var fileSource in manifest.Files)
            {
                if (fileSource == null || fileSource.Entries == null || fileSource.Entries.Count == 0)
                {
                    continue;
                }

                var packageFileSource = new ExplicitFileSource
                {
                    Name = "Files"
                };

                packageFileSource.Converter.Transforms.Add(
                    new InstallerConfigurationTransform(
                        new BehaviourOptions(fileSource.InstallMode, fileSource.MergeMode)));

                foreach (var item in fileSource.Entries)
                {
                    var pathMapped = MainUtil.MapPath(item.Path);

                    packageFileSource.Entries.Add(pathMapped);
                }

                if (packageFileSource.Entries.Count > 0)
                {
                    packageProject.Sources.Add(packageFileSource);
                }
            }


            foreach (var itemSource in manifest.Items)
            {
                if (itemSource == null || itemSource.Entries == null || itemSource.Entries.Count == 0)
                {
                    continue;
                }

                List <Item> items             = new List <Item>();
                var         packageItemSource = new ExplicitItemSource
                {
                    Name = itemSource.Name
                };

                packageItemSource.Converter.Transforms.Add(
                    new InstallerConfigurationTransform(
                        new BehaviourOptions(itemSource.InstallMode, itemSource.MergeMode)));

                using (new SecurityDisabler())
                {
                    foreach (var item in itemSource.Entries)
                    {
                        var db = ResolveDatabase(item.Database);

                        var itemUri = db.Items.GetItem(item.Path);
                        if (itemUri != null)
                        {
                            items.Add(itemUri);

                            if (item.IncludeChildren)
                            {
                                var    paths         = Sitecore.StringUtil.Split(itemUri.Paths.Path, '/', true).Where(p => p != null & p != string.Empty).Select(p => "#" + p + "#").ToList();
                                string allChildQuery = string.Format("/{0}//*", Sitecore.StringUtil.Join(paths, "/"));
                                var    children      = db.Items.Database.SelectItems(allChildQuery);

                                if (children != null && children.Length > 0)
                                {
                                    items.AddRange(children);
                                }
                            }
                        }
                    }

                    foreach (var item in items)
                    {
                        packageItemSource.Entries.Add(new ItemReference(item.Uri, false).ToString());
                    }
                }

                if (packageItemSource.Entries.Count > 0)
                {
                    packageProject.Sources.Add(packageItemSource);
                }
            }

            packageProject.SaveProject = true;

            var  location = MainUtil.MapPath($"{ Sitecore.Configuration.Settings.PackagePath}/{ manifest.PackageName}");
            bool exists   = System.IO.Directory.Exists(location);

            if (!exists)
            {
                System.IO.Directory.CreateDirectory(location);
            }

            var packagePath = $"{location}/{manifest.PackageName}.zip";

            try
            {
                using (var writer = new PackageWriter(packagePath))
                {
                    using (new SecurityDisabler())
                    {
                        SiteContext targetSiteContext = SiteContext.GetSite("shell");
                        using (var context = new SiteContextSwitcher(targetSiteContext))
                        {
                            writer.Initialize(Installer.CreateInstallationContext());

                            PackageGenerator.GeneratePackage(packageProject, writer);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Package was not created. Message: {ex.Message}", ex);
            }


            return(packagePath);
        }
Exemplo n.º 5
0
        protected override string BuildPackage()
        {
            var project = new PackageProject();

            var sourceCollection = new SourceCollection <PackageEntry>();

            var itemSource = new ExplicitItemSource
            {
                SkipVersions = false
            };

            sourceCollection.Add(itemSource);

            var list = new List <ID>();

            foreach (var item in Items)
            {
                var i = item;
                if (list.Any(id => id == i.ID))
                {
                    continue;
                }

                list.Add(item.ID);

                var reference = new ItemReference(item.Database.Name, item.Paths.Path, item.ID, LanguageManager.DefaultLanguage, Data.Version.Latest).Reduce();

                itemSource.Entries.Add(reference.ToString());
            }

            var fileSource = new ExplicitFileSource();

            sourceCollection.Add(fileSource);

            foreach (var fileName in Files)
            {
                if (FileUtil.IsFolder(fileName))
                {
                    foreach (var file in Directory.GetFiles(FileUtil.MapPath(fileName), "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new FileInfo(file);
                        if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            continue;
                        }

                        if ((fileInfo.Attributes & FileAttributes.System) == FileAttributes.System)
                        {
                            continue;
                        }

                        fileSource.Entries.Add(file);
                    }
                }
                else
                {
                    fileSource.Entries.Add(fileName);
                }
            }

            project.Sources.Add(sourceCollection);

            project.Name = "Sitecore Package";
            project.Metadata.PackageName = PackageName;
            project.Metadata.Author      = Author;
            project.Metadata.Version     = Version;
            project.Metadata.Publisher   = Publisher;
            project.Metadata.License     = License;
            project.Metadata.Comment     = Comment;
            project.Metadata.Readme      = Readme;
            project.Metadata.PostStep    = PostStep;

            var context          = new SimpleProcessingContext();
            var intermediateFile = GetIntermediateFileName(FileName);

            try
            {
                using (var writer = new PackageWriter(PathUtils.MapPath(intermediateFile)))
                {
                    writer.Initialize(context);
                    PackageGenerator.GeneratePackage(project, writer);
                }

                Commit(intermediateFile, FileName);
            }
            catch
            {
                Cleanup(intermediateFile);
                throw;
            }

            return(FileName);
        }
Exemplo n.º 6
0
        public void GeneratePackage()
        {
            var getReaderProcessor = ReaderTypeProcessor.GetTypeProcessor(this.FileType);

            var items = getReaderProcessor.ReadFile(this.FilePath);

            var packageProject = new PackageProject
            {
                Metadata =
                {
                    PackageName = this.PackageName,
                    Author      = this.Author,
                    Version     = this.Version,
                    Publisher   = this.Publisher
                }
            };

            var packageFileSource = new ExplicitFileSource
            {
                Name = "Custom File Source"
            };

            var packageItemSource = new ExplicitItemSource
            {
                Name = "Custom Item Source"
            };

            var sourceCollection = new SourceCollection <PackageEntry>();

            sourceCollection.Add(packageItemSource);

            foreach (var item in items)
            {
                if (item.ObjectType.ToLower().Equals("item"))
                {
                    var itemUri = Factory.GetDatabase(Settings.GetSetting("SourceDatabase")).Items.GetItem(item.ObjectPath);

                    if (itemUri != null)
                    {
                        if (item.IncludeSubItem.ToLower().Equals("true"))
                        {
                            sourceCollection.Add(new ItemSource()
                            {
                                SkipVersions = true,
                                Database     = itemUri.Uri.DatabaseName,
                                Root         = itemUri.Uri.ItemID.ToString()
                            });
                        }
                        else
                        {
                            packageItemSource.Entries.Add(new ItemReference(itemUri.Uri, false).ToString());
                        }
                    }
                }
                else if (item.ObjectType.ToLower().Equals("file"))
                {
                    var pathMapped = MainUtil.MapPath(item.ObjectPath);

                    packageFileSource.Entries.Add(pathMapped);
                }
            }

            if (packageFileSource.Entries.Count > 0)
            {
                packageProject.Sources.Add(packageFileSource);
            }

            if (packageItemSource.Entries.Count > 0 || sourceCollection.Sources.Count > 0)
            {
                packageProject.Sources.Add(sourceCollection);
            }

            packageProject.SaveProject = true;

            var packageGeneratorFolder = Settings.GetSetting("PackageGeneratorFolder");

            using (var writer = new PackageWriter(MainUtil.MapPath(string.Format("{0}/{1}/{2}.zip", Settings.PackagePath, packageGeneratorFolder, this.PackageName))))
            {
                Context.SetActiveSite("shell");

                writer.Initialize(Installer.CreateInstallationContext());

                PackageGenerator.GeneratePackage(packageProject, writer);

                Context.SetActiveSite("website");
            }
        }
        protected void btnGeneratePackage_OnClick(object sender, EventArgs e)
        {
            var contentExportUtil = new ContentExport();
            var packageProject    = new PackageProject()
            {
                Metadata =
                {
                    PackageName = String.IsNullOrEmpty(txtFileName.Value) ? "Content Export Tool " + DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) : txtFileName.Value,
                    Author      = "Erica Stockwell-Alpert",
                    Version     = txtVersion.Value
                }
            };

            packageProject.Sources.Clear();
            var source = new ExplicitItemSource();

            source.Name = "Items";

            var _core   = Factory.GetDatabase("core");
            var _master = Factory.GetDatabase("master");

            // items
            var coreAppItem  = _core.Items.GetItem("/sitecore/content/Applications/Content Export");
            var coreMenuItem =
                _core.Items.GetItem("/sitecore/content/Documents and settings/All users/Start menu/Right/Content Export");

            var template = _master.Items.GetItem("/sitecore/templates/Modules/Content Export Tool");
            var folder   = _master.Items.GetItem("/sitecore/system/Modules/Content Export Tool ");

            source.Entries.Add(new ItemReference(coreAppItem.Uri, false).ToString());
            source.Entries.Add(new ItemReference(coreMenuItem.Uri, false).ToString());
            source.Entries.Add(new ItemReference(template.Uri, false).ToString());
            source.Entries.Add(new ItemReference(folder.Uri, false).ToString());

            foreach (var child in template.Axes.GetDescendants())
            {
                source.Entries.Add(new ItemReference(child.Uri, false).ToString());
            }

            packageProject.Sources.Add(source);

            // files
            var fileSource = new ExplicitFileSource();

            fileSource.Name = "Files";

            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\ContentExport.aspx"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\ContentExport.aspx.cs"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\ContentExport.aspx.designer.cs"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\jquery-2.2.4.min.js"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\jquery-ui.min.js"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Applications\\ContentExport\\ContentExportScripts.js"));
            fileSource.Entries.Add(
                MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\temp\\IconCache\\Network\\16x16\\download.png"));
            fileSource.Entries.Add(
                MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\temp\\IconCache\\Network\\32x32\\download.png"));
            fileSource.Entries.Add(
                MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\temp\\IconCache\\Network\\24x24\\download.png"));
            fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\BayerCA\\Website\\sitecore\\shell\\Themes\\Standard\\Images\\ProgressIndicator\\sc-spinner32.gif"));

            packageProject.Sources.Add(fileSource);

            packageProject.SaveProject = true;

            var fileName = packageProject.Metadata.PackageName + ".zip";
            var filePath = contentExportUtil.FullPackageProjectPath(fileName);

            using (var writer = new PackageWriter(filePath))
            {
                Sitecore.Context.SetActiveSite("shell");
                writer.Initialize(Installer.CreateInstallationContext());
                PackageGenerator.GeneratePackage(packageProject, writer);
                Sitecore.Context.SetActiveSite("website");

                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", fileName));
                Response.ContentType = "application/zip";

                byte[] data = new WebClient().DownloadData(filePath);
                Response.BinaryWrite(data);
                Response.Flush();
                Response.End();
            }
        }