public MetadataHandler(SystemMediaTransportControls systemMediaTransportControls, ForegroundNotifier notifier, Func <TimeSpan> getPosition, Action <TimeSpan> reportNextEvent, CancellationToken cancellationToken)
        {
            if (null == systemMediaTransportControls)
            {
                throw new ArgumentNullException("systemMediaTransportControls");
            }
            if (null == notifier)
            {
                throw new ArgumentNullException("notifier");
            }
            if (null == getPosition)
            {
                throw new ArgumentNullException("getPosition");
            }
            if (null == reportNextEvent)
            {
                throw new ArgumentNullException("reportNextEvent");
            }

            _systemMediaTransportControls = systemMediaTransportControls;
            _notifier        = notifier;
            _getPosition     = getPosition;
            _reportNextEvent = reportNextEvent;

            _updateTask = new SignalTask(Update, cancellationToken);

            _metadataSink = new ActionMetadataSink(_updateTask.Fire);
        }
Example #2
0
        private void InstallPackage(FileInfo file)
        {
            // in case file disappeared since retrieved
            file.Refresh();
            if (!file.Exists)
            {
                return;
            }

            FridayLog.Info(AutoPackages.FeatureName, $"Install auto package (Skip on conflicts): {file.FullName}");

            using (new SecurityDisabler())
            {
                var context = new SimpleProcessingContext();
                // IItemInstallerEvents type cast is essential
                var items = (IItemInstallerEvents) new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Skip, MergeMode.Undefined));
                context.AddAspect(items);

                // IFileInstallerEvents type cast is essential
                var files = (IFileInstallerEvents) new DefaultFileInstallerEvents(false);
                context.AddAspect(files);

                new Installer().InstallPackage(file.FullName, context);
                new Installer().InstallSecurity(file.FullName, context);

                var previewContext = Installer.CreatePreviewContext();
                var packageReader  = new PackageReader(file.FullName);
                var view           = new MetadataView(previewContext);
                var metadataSink   = new MetadataSink(view);
                metadataSink.Initialize(previewContext);
                packageReader.Populate(metadataSink);

                new Installer().ExecutePostStep(view.PostStep, previewContext);
            }
        }
Example #3
0
        public void Install()
        {
            Context.SetActiveSite("shell");
            using (new SecurityDisabler())
            {
                using (new SyncOperationContext())
                {
                    IProcessingContext context = new SimpleProcessingContext();

                    IItemInstallerEvents events = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Clear));
                    context.AddAspect(events);

                    IFileInstallerEvents events1 = new DefaultFileInstallerEvents(true);
                    context.AddAspect(events1);

                    var inst = new Installer();

                    inst.InstallPackage(FileUtil.MapPath(FileName), context);

                    ISource <PackageEntry> source = new PackageReader(FileUtil.MapPath(FileName));
                    var previewContext            = Installer.CreatePreviewContext();
                    var view = new MetadataView(previewContext);
                    var sink = new MetadataSink(view);
                    sink.Initialize(previewContext);
                    source.Populate(sink);
                    inst.ExecutePostStep(view.PostStep, previewContext);
                }
            }
        }
        protected override void ProcessRecord()
        {
            if (DisableIndexing.IsPresent)
            {
                WriteWarning($"The parameter {nameof(DisableIndexing)} is no longer used. The functionality has been removed from the Sitecore platform.");
            }

            var fileName = Path;

            PerformInstallAction(() =>
            {
                if (!System.IO.Path.IsPathRooted(fileName))
                {
                    var packagePath = FullPackagePath(fileName);
                    WriteVerbose($"Path is not rooted. Updating to {packagePath}.");

                    if (!FileUtil.Exists(packagePath))
                    {
                        packagePath =
                            System.IO.Path.GetFullPath(
                                System.IO.Path.Combine(
                                    CurrentProviderLocation("FileSystem").ProviderPath, fileName));
                        WriteVerbose($"Path could not be found. Updating to {packagePath}.");

                        if (!FileUtil.Exists(packagePath))
                        {
                            WriteVerbose("Path still could not be found. Check that the file actually exists in the Sitecore package directory.");
                        }
                    }

                    fileName = packagePath;
                }

                if (!ShouldProcess(fileName, "Install package"))
                {
                    return;
                }

                using (new Sitecore.Data.BulkUpdateContext())
                {
                    IProcessingContext context     = new SimpleProcessingContext();
                    IItemInstallerEvents instance1 = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode, MergeMode));
                    context.AddAspect(instance1);
                    IFileInstallerEvents instance2 = new DefaultFileInstallerEvents(true);
                    context.AddAspect(instance2);
                    var installer = new Installer();
                    installer.InstallPackage(fileName, context);
                    ISource <PackageEntry> source = new PackageReader(fileName);
                    var previewContext            = Installer.CreatePreviewContext();
                    var view         = new MetadataView(previewContext);
                    var metadataSink = new MetadataSink(view);
                    metadataSink.Initialize(previewContext);
                    source.Populate(metadataSink);
                    installer.ExecutePostStep(view.PostStep, previewContext);
                }
            });
        }
Example #5
0
        public void Install([NotNull] string fileName)
        {
            try
            {
                Context.SetActiveSite("shell");
                using (new SecurityDisabler())
                {
                    using (new ProxyDisabler())
                    {
                        using (new SyncOperationContext())
                        {
                            IProcessingContext context = new SimpleProcessingContext();

                            IItemInstallerEvents itemInstallerEvents = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Clear));
                            context.AddAspect(itemInstallerEvents);

                            IFileInstallerEvents fileInstallerEvents = new DefaultFileInstallerEvents(true);
                            context.AddAspect(fileInstallerEvents);

                            var installer = new Installer();

                            installer.InstallPackage(FileUtil.MapPath(fileName), context);

                            ISource <PackageEntry> source = new PackageReader(FileUtil.MapPath(fileName));
                            var previewContext            = Installer.CreatePreviewContext();
                            var view = new MetadataView(previewContext);
                            var sink = new MetadataSink(view);
                            sink.Initialize(previewContext);
                            source.Populate(sink);
                            installer.ExecutePostStep(view.PostStep, previewContext);
                        }
                    }
                }

                File.WriteAllText(fileName + ".log", @"OK");
            }
            catch (Exception ex)
            {
                File.WriteAllText(fileName + ".log", @"Error" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        private void InstallSitecorePackage([NotNull] string fileName)
        {
            Context.SetActiveSite("shell");
            using (new SecurityDisabler())
            {
                using (new ProxyDisabler())
                {
                    using (new SyncOperationContext())
                    {
                        var context = new SimpleProcessingContext();

                        var defaultItemInstallerEvents = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Clear));
                        context.AddAspect(defaultItemInstallerEvents);

                        var defaultFileInstallerEvents = new DefaultFileInstallerEvents(true);
                        context.AddAspect(defaultFileInstallerEvents);

                        var installer = new Installer();
                        installer.InstallPackage(FileUtil.MapPath(fileName), context);

                        var packageReader = new PackageReader(FileUtil.MapPath(fileName));
                        var previewContext = Installer.CreatePreviewContext();
                        var view = new MetadataView(previewContext);
                        var sink = new MetadataSink(view);

                        sink.Initialize(previewContext);

                        packageReader.Populate(sink);

                        installer.ExecutePostStep(view.PostStep, previewContext);
                    }
                }
            }
        }
Example #7
0
        protected override void ProcessRecord()
        {
            var fileName = Path;

            PerformInstallAction(() =>
            {
                if (!System.IO.Path.IsPathRooted(fileName))
                {
                    var packagePath = FullPackagePath(fileName);
                    WriteVerbose($"Path is not rooted. Updating to {packagePath}.");

                    if (!FileUtil.Exists(packagePath))
                    {
                        packagePath =
                            System.IO.Path.GetFullPath(
                                System.IO.Path.Combine(
                                    CurrentProviderLocation("FileSystem").ProviderPath, fileName));
                        WriteVerbose($"Path could not be found. Updating to {packagePath}.");

                        if (!FileUtil.Exists(packagePath))
                        {
                            WriteVerbose("Path still could not be found. Check that the file actually exists in the Sitecore package directory.");
                        }
                    }

                    fileName = packagePath;
                }

                if (ShouldProcess(fileName, "Install package"))
                {
                    var obsoleter    = TypeResolver.Resolve <IObsoleter>();
                    var indexSetting = obsoleter.IndexingEnabled;
                    if (DisableIndexing.IsPresent)
                    {
                        obsoleter.IndexingEnabled = false;
                    }

                    try
                    {
                        IProcessingContext context     = new SimpleProcessingContext();
                        IItemInstallerEvents instance1 = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode, MergeMode));
                        context.AddAspect(instance1);
                        IFileInstallerEvents instance2 = new DefaultFileInstallerEvents(true);
                        context.AddAspect(instance2);
                        var installer = new Installer();
                        installer.InstallPackage(fileName, context);
                        ISource <PackageEntry> source = new PackageReader(fileName);
                        var previewContext            = Installer.CreatePreviewContext();
                        var view         = new MetadataView(previewContext);
                        var metadataSink = new MetadataSink(view);
                        metadataSink.Initialize(previewContext);
                        source.Populate(metadataSink);
                        installer.ExecutePostStep(view.PostStep, previewContext);
                    }
                    finally
                    {
                        if (DisableIndexing.IsPresent)
                        {
                            obsoleter.IndexingEnabled = indexSetting;
                        }
                    }
                }
            });
        }
        protected override void ProcessRecord()
        {
            var fileName = Path;
            PerformInstallAction(() =>
                {
                    if (!System.IO.Path.IsPathRooted(fileName))
                    {
                        var packagePath = FullPackagePath(fileName);
                        WriteVerbose($"Path is not rooted. Updating to {packagePath}.");

                        if (!FileUtil.Exists(packagePath))
                        {
                            packagePath =
                                System.IO.Path.GetFullPath(
                                    System.IO.Path.Combine(
                                        CurrentProviderLocation("FileSystem").ProviderPath, fileName));
                            WriteVerbose($"Path could not be found. Updating to {packagePath}.");

                            if (!FileUtil.Exists(packagePath))
                            {
                                WriteVerbose("Path still could not be found. Check that the file actually exists in the Sitecore package directory.");
                            }
                        }

                        fileName = packagePath;
                    }

                    if (ShouldProcess(fileName, "Install package"))
                    {
                        var indexSetting = Sitecore.Configuration.Settings.Indexing.Enabled;
                        if (DisableIndexing.IsPresent)
                        {
                            Sitecore.Configuration.Settings.Indexing.Enabled = false;
                        }

                        try
                        {
                            IProcessingContext context = new SimpleProcessingContext();
                            IItemInstallerEvents instance1 = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode, MergeMode));
                            context.AddAspect(instance1);
                            IFileInstallerEvents instance2 = new DefaultFileInstallerEvents(true);
                            context.AddAspect(instance2);
                            var installer = new Installer();
                            installer.InstallPackage(fileName, context);
                            ISource<PackageEntry> source = new PackageReader(fileName);
                            var previewContext = Installer.CreatePreviewContext();
                            var view = new MetadataView(previewContext);
                            var metadataSink = new MetadataSink(view);
                            metadataSink.Initialize(previewContext);
                            source.Populate(metadataSink);
                            installer.ExecutePostStep(view.PostStep, previewContext);
                        }
                        finally
                        {
                            if (DisableIndexing.IsPresent)
                            {
                                Sitecore.Configuration.Settings.Indexing.Enabled = indexSetting;
                            }
                        }
                    }
                });
        }
Example #9
0
        private void InstallPackage(FileInfo file)
        {
            // in case file disappeared since retrieved
            file.Refresh();
            if (!file.Exists)
            {
                return;
            }

            var filenameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);

            filenameWithoutExtension = ItemUtil.ProposeValidItemName(filenameWithoutExtension);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(filenameWithoutExtension), "The package should be renamed to something that item can have name of: " + file.Name);

            using (new SecurityDisabler())
            {
                var db          = Factory.GetDatabase("core");
                var historyItem = db.GetItem("/sitecore/system/Packages/Installation history");
                if (historyItem.Children.Any(x => string.Equals(x.Name, filenameWithoutExtension, StringComparison.OrdinalIgnoreCase)))
                {
                    FridayLog.Info(AutoPackages.FeatureName, $"Install auto package skipped (already installed): \"{file.FullName}\"");

                    return;
                }
            }

            // The way how SC creates history item it cumbersome - it has some non-obvious length limitations
            // so add extra logic to work around it.
            var historyFile = new FileInfo(file.FullName + ".history.txt");

            if (historyFile.Exists)
            {
                FridayLog.Info(AutoPackages.FeatureName, $"Install auto package skipped (already installed): \"{file.FullName}\"");

                return;
            }

            File.AppendAllText(historyFile.FullName, DateTime.UtcNow.ToString("o") + "\r\n");

            FridayLog.Info(AutoPackages.FeatureName, $"Install auto package (Skip on conflicts): \"{file.FullName}\"");

            using (new SecurityDisabler())
            {
                var context = new SimpleProcessingContext();
                // IItemInstallerEvents type cast is essential
                var items = (IItemInstallerEvents) new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Undefined));
                context.AddAspect(items);

                // IFileInstallerEvents type cast is essential
                var files = (IFileInstallerEvents) new DefaultFileInstallerEvents(true);
                context.AddAspect(files);

                new Installer().InstallPackage(file.FullName, context);
                new Installer().InstallSecurity(file.FullName, context);

                var previewContext = Installer.CreatePreviewContext();
                var packageReader  = new PackageReader(file.FullName);
                var view           = new MetadataView(previewContext);
                var metadataSink   = new MetadataSink(view);
                metadataSink.Initialize(previewContext);
                packageReader.Populate(metadataSink);

                new Installer().ExecutePostStep(view.PostStep, previewContext);
            }
        }