示例#1
0
 internal static PackagingResult ExecutePatch(string manifestXml, RepositoryStartSettings settings = null)
 {
     try
     {
         var xml = new XmlDocument();
         xml.LoadXml(manifestXml);
         return(ExecutePatch(xml, settings));
     }
     catch (XmlException ex)
     {
         throw new InvalidPackageException("Invalid manifest xml.", ex);
     }
 }
        internal static PackagingResult ExecutePatch(XmlDocument manifestXml, RepositoryStartSettings settings = null)
        {
            var             phase  = -1;
            var             errors = 0;
            PackagingResult result;

            do
            {
                result  = ExecutePhase(manifestXml, ++phase, settings);
                errors += result.Errors;
            } while (result.NeedRestart);

            result.Errors = errors;
            return(result);
        }
示例#3
0
        public static void InitializeAllTests(TestContext context)
        {
            var pluginsPath = context.TestDeploymentDir;

            pluginsPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(pluginsPath, @"..\..\..\WebSite\bin"));
            if (!System.IO.Directory.Exists(pluginsPath))
            {
                pluginsPath = System.IO.Directory.GetCurrentDirectory();
            }
            var settings = new RepositoryStartSettings
            {
                PluginsPath        = pluginsPath,
                StartLuceneManager = false,
                RestoreIndex       = false
            };
            var repo = Repository.Start(settings);

            //try
            //{
            //    pluginsPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(pluginsPath, @"..\..\..\ContentExplorer\bin"));
            //    SenseNet.ContentRepository.Storage.TypeHandler.LoadAssembliesFrom(pluginsPath);
            //}
            //catch (System.IO.DirectoryNotFoundException)
            //{
            //    pluginsPath = System.IO.Directory.GetCurrentDirectory();
            //    SenseNet.ContentRepository.Storage.TypeHandler.LoadAssembliesFrom(pluginsPath);
            //}

            var populator = new SenseNet.Search.Indexing.DocumentPopulator();

            populator.ClearAndPopulateAll();
            repo.StartLucene();

            //PatchSystemFolder_All(typeof(SystemFolder).Name, "TestSurvey", "BoolTest", "Car_Bug5527", "Car1_AutoNamingTests", "Car2_AutoNamingTests", "File2", "ForMultiPagingSearch", "RepositoryTest_RefTestNode");
            PatchSystemFolder_All("PortalRoot", "RepositoryTest_RefTestNode", "Automobile", "Automobile5", "Automobile6", "DefaultValueTest"
                                  , "FieldSetting_Analyzer", "OuterFieldTestContentType", "ReferredContent", "TypeForIndexingTest", "ValidatedContent"
                                  , "XmlNamespaceCompatibility", "ContentList_for_AllowChildTypes");

            PatchSystemFolder_Add("Site", "WebContent", "File");
            PatchSystemFolder_Add("Car", "Car");
            PatchSystemFolder_Add("ContentLink", "Car", "Page");
            PatchSystemFolder_Add("ContentList", "Car", "Folder", "OuterFieldTestContentType", "Task");
            PatchSystemFolder_Add("Page", "Page", "WebContent", "File");
            PatchSystemFolder_Add("Site", "ContentList");
            PatchSystemFolder_Add("TrashBag", "Folder");
        }
示例#4
0
        static void Main(string[] args)
        {
            var startSettings = new RepositoryStartSettings
            {
                Console            = Console.Out,
                StartLuceneManager = true
            };

            using (Repository.Start(startSettings))
            {
                using (var traceOperation = Logger.TraceOperation("SyncPortal2AD", string.Empty, AdLog.AdSyncLogCategory))
                {
                    ADProvider.RetryAllFailedActions();

                    traceOperation.IsSuccessful = true;
                }
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            var startSettings = new RepositoryStartSettings
            {
                Console            = Console.Out,
                StartLuceneManager = true
            };

            using (var repo = Repository.Start(startSettings))
            {
                using (var traceOperation = Logger.TraceOperation("SyncAD2Portal", string.Empty, AdLog.AdSyncLogCategory))
                {
                    SyncAD2Portal directoryServices = new SyncAD2Portal();
                    directoryServices.SyncFromAD();

                    traceOperation.IsSuccessful = true;
                }
            }
        }
示例#6
0
        public static void InitializeAllTests(TestContext context)
        {
            var pluginsPath = context.TestDeploymentDir;
            pluginsPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(pluginsPath, @"..\..\..\WebSite\bin"));
            if(!System.IO.Directory.Exists(pluginsPath))
                pluginsPath = System.IO.Directory.GetCurrentDirectory();
            var settings = new RepositoryStartSettings
            {
                PluginsPath = pluginsPath,
                StartLuceneManager = false,
                RestoreIndex = false
            };
            var repo = Repository.Start(settings);

            //try
            //{
            //    pluginsPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(pluginsPath, @"..\..\..\ContentExplorer\bin"));
            //    SenseNet.ContentRepository.Storage.TypeHandler.LoadAssembliesFrom(pluginsPath);
            //}
            //catch (System.IO.DirectoryNotFoundException)
            //{
            //    pluginsPath = System.IO.Directory.GetCurrentDirectory();
            //    SenseNet.ContentRepository.Storage.TypeHandler.LoadAssembliesFrom(pluginsPath);
            //}

            var populator = new SenseNet.Search.Indexing.DocumentPopulator();
            populator.ClearAndPopulateAll();
            repo.StartLucene();

            //PatchSystemFolder_All(typeof(SystemFolder).Name, "TestSurvey", "BoolTest", "Car_Bug5527", "Car1_AutoNamingTests", "Car2_AutoNamingTests", "File2", "ForMultiPagingSearch", "RepositoryTest_RefTestNode");
            PatchSystemFolder_All("PortalRoot", "RepositoryTest_RefTestNode", "Automobile", "Automobile5", "Automobile6", "DefaultValueTest"
                , "FieldSetting_Analyzer", "OuterFieldTestContentType", "ReferredContent", "TypeForIndexingTest", "ValidatedContent"
                , "XmlNamespaceCompatibility", "ContentList_for_AllowChildTypes");

            PatchSystemFolder_Add("Site", "WebContent", "File");
            PatchSystemFolder_Add("Car", "Car");
            PatchSystemFolder_Add("ContentLink", "Car", "Page");
            PatchSystemFolder_Add("ContentList", "Car", "Folder", "OuterFieldTestContentType", "Task");
            PatchSystemFolder_Add("Page", "Page", "WebContent", "File");
            PatchSystemFolder_Add("Site", "ContentList");
            PatchSystemFolder_Add("TrashBag", "Folder");
        }
示例#7
0
        protected virtual void Application_Start(object sender, EventArgs e, HttpApplication application)
        {
            using (var op = SnTrace.Repository.StartOperation("Application_Start. Process: {0}, AppDomain: {1}, ",
                                                              System.Diagnostics.Process.GetCurrentProcess().Id, AppDomain.CurrentDomain.Id))
            {
                var runOnceMarkerPath = application.Server.MapPath("/" + RunOnceGuid);
                var firstRun          = File.Exists(runOnceMarkerPath);
                var startConfig       = new RepositoryStartSettings {
                    StartIndexingEngine = !firstRun, IsWebContext = true
                };

                Repository.Start(startConfig);

                RepositoryVersionInfo.CheckComponentVersions();

                StorageContext.L2Cache = new L2CacheImpl();

                RegisterRoutes(RouteTable.Routes, application);
                RepositoryPathProvider.Register();

                op.Successful = true;
            }
        }
示例#8
0
        protected virtual void Application_Start(object sender, EventArgs e, HttpApplication application)
        {
            using (var op = SnTrace.Repository.StartOperation("Application_Start. Process: {0}, AppDomain: {1}, ",
                                                              System.Diagnostics.Process.GetCurrentProcess().Id, AppDomain.CurrentDomain.Id))
            {
                var runOnceMarkerPath = application.Server.MapPath("/" + RunOnceGuid);
                var firstRun          = File.Exists(runOnceMarkerPath);
                var startConfig       = new RepositoryStartSettings {
                    StartLuceneManager = !firstRun, IsWebContext = true
                };

                RepositoryInstance.WaitForWriterLockFileIsReleased(RepositoryInstance.WaitForLockFileType.OnStart);

                Repository.Start(startConfig);

                StorageContext.L2Cache = new L2CacheImpl();

                RegisterRoutes(RouteTable.Routes, application);
                RepositoryPathProvider.Register();

                op.Successful = true;
            }
        }
示例#9
0
        internal static void Run(string ctdPath, string asmPath, string fsPath, string repositoryPath, bool validate)
        {
            if (String.IsNullOrEmpty(ctdPath) && String.IsNullOrEmpty(fsPath))
            {
                LogWriteLine("No changes");
                return;
            }

            var startSettings = new RepositoryStartSettings
            {
                Console            = Console.Out,
                StartLuceneManager = StorageContext.Search.IsOuterEngineEnabled,
                PluginsPath        = asmPath
            };

            using (Repository.Start(startSettings))
            {
                var installationMode = false;
                try
                {
                    installationMode = IsInstallationMode();
                }
                catch (Exception e)
                {
                    PrintException(e, null);
                    return;
                }

                //-- Install ContentTypes
                if (String.IsNullOrEmpty(ctdPath))
                {
                    LogWriteLine("ContentTypeDefinitions are not changed");
                }
                else
                {
                    if (installationMode)
                    {
                        StorageContext.Search.DisableOuterEngine();
                        LogWriteLine("Indexing is temporarily switched off." + CR);
                    }

                    InstallContentTypeDefinitions(ctdPath);

                    if (installationMode)
                    {
                        StorageContext.Search.EnableOuterEngine();
                        CreateInitialIndex();
                        LogWriteLine("Indexing is switched on." + CR);
                    }
                }

                //-- Create missing index documents
                SaveInitialIndexDocuments();

                //-- Import Contents
                if (!String.IsNullOrEmpty(fsPath))
                {
                    ImportContents(fsPath, repositoryPath, validate);
                }
                else
                {
                    LogWriteLine("Contents are not changed");
                }
            }
        }
示例#10
0
 internal PatchExecutionContext(RepositoryStartSettings settings, Action <PatchExecutionLogRecord> logCallback)
 {
     Settings    = settings;
     LogCallback = logCallback ?? DefaultLogCallback;
 }
示例#11
0
        internal static ExecutionContext Create(string packagePath, string targetPath, string[] networkTargets, string sandboxPath, Manifest manifest, int currentPhase, int countOfPhases, string[] parameters, TextWriter console, RepositoryStartSettings settings)
        {
            var packageParameters = parameters?.Select(PackageParameter.Parse).ToArray() ?? new PackageParameter[0];

            return(new ExecutionContext(packagePath, targetPath, networkTargets, sandboxPath, manifest, currentPhase, countOfPhases, packageParameters, console)
            {
                Test = false,
                RepositoryStartSettings = settings
            });
        }
        internal static PackagingResult ExecutePhase(XmlDocument manifestXml, int phase, RepositoryStartSettings settings = null)
        {
            var manifest = Manifest.Parse(manifestXml, phase, true, new PackageParameter[0]);

            // Fill context with indexing folder, repo start settings, providers and other
            // parameters necessary for on-the-fly steps to run.
            var executionContext = ExecutionContext.Create("packagePath", "targetPath",
                                                           new string[0], "sandboxPath", manifest, phase, manifest.CountOfPhases,
                                                           null, null, settings);

            PackagingResult result;

            try
            {
                result = ExecuteCurrentPhase(manifest, executionContext);
            }
            finally
            {
                if (Repository.Started())
                {
                    SnTrace.System.Write("PackageManager: stopping repository ... ");
                    Repository.Shutdown();
                }
            }

            RepositoryVersionInfo.Reset();

            return(result);
        }
        internal static Dictionary <Version, PackagingResult> ExecuteAssemblyPatches(SnComponentInfo assemblyComponent,
                                                                                     RepositoryStartSettings settings = null)
        {
            var patchResults = new Dictionary <Version, PackagingResult>();

            // If there is no installed component for this id, skip patching.
            var installedComponent = RepositoryVersionInfo.Instance.Components.FirstOrDefault(c => c.ComponentId == assemblyComponent.ComponentId);

            if (installedComponent == null)
            {
                return(patchResults);
            }

            // check which db version is supported by the assembly
            if (assemblyComponent.SupportedVersion == null ||
                assemblyComponent.SupportedVersion <= installedComponent.Version)
            {
                return(patchResults);
            }

            // Supported version in the assembly is higher than
            // the physical version: there should be a patch.
            if (!(assemblyComponent.Patches?.Any() ?? false))
            {
                throw new InvalidOperationException($"Missing patch for component {installedComponent.ComponentId}. " +
                                                    $"Installed version is {installedComponent.Version}. " +
                                                    $"The assembly requires at least version {assemblyComponent.SupportedVersion}.");
            }

            foreach (var patch in assemblyComponent.Patches)
            {
                // this variable is refreshed in every cycle
                if (installedComponent == null)
                {
                    break;
                }

                if (patch.MinVersion > patch.MaxVersion ||
                    patch.MaxVersion > patch.Version)
                {
                    // the patch version numbers are the responsibility of the developer of the component
                    SnLog.WriteWarning(
                        $"Patch {patch.Version} for component {assemblyComponent.ComponentId} cannot be executed because it contains invalid version numbers.",
                        properties: new Dictionary <string, object>
                    {
                        { "MinVersion", patch.MinVersion },
                        { "MaxVersion", patch.MaxVersion }
                    });

                    continue;
                }

                if (!string.IsNullOrEmpty(patch.Contents) && patch.Execute != null)
                {
                    // ambigous patch definition
                    SnLog.WriteWarning(
                        $"Patch {patch.Version} for component {assemblyComponent.ComponentId} cannot be executed because it contains multiple patch definitions.");

                    continue;
                }

                // check if the patch is relevant for the currently installed component version
                if (patch.MinVersion > installedComponent.Version ||
                    patch.MinVersionIsExclusive && patch.MinVersion == installedComponent.Version ||
                    patch.MaxVersion < installedComponent.Version ||
                    patch.MaxVersionIsExclusive && patch.MaxVersion == installedComponent.Version)
                {
                    continue;
                }

                PackagingResult patchResult;

                try
                {
                    if (patch.Contents?.StartsWith("<?xml", StringComparison.InvariantCultureIgnoreCase) ?? false)
                    {
                        // execute manifest patch
                        patchResult = ExecutePatch(patch.Contents, settings);
                    }
                    else if (patch.Execute != null)
                    {
                        // execute code patch
                        patch.Execute(new PatchContext
                        {
                            Settings = settings
                        });

                        // save the new package info manually based on the patch version number
                        Storage.SavePackageAsync(new Package
                        {
                            ComponentId      = assemblyComponent.ComponentId,
                            ComponentVersion = patch.Version,
                            ExecutionResult  = ExecutionResult.Successful,
                            PackageType      = PackageType.Patch
                        }, CancellationToken.None).GetAwaiter().GetResult();

                        patchResult = new PackagingResult
                        {
                            NeedRestart = false,
                            Successful  = true,
                            Terminated  = false,
                            Errors      = 0
                        };
                    }
                    else
                    {
                        //TODO: handle other patch formats (resource or filesystem path)

                        // unknown patch format
                        patchResult = new PackagingResult
                        {
                            NeedRestart = false,
                            Successful  = false,
                            Terminated  = false,
                            Errors      = 0
                        };
                    }
                }
                catch (Exception ex)
                {
                    SnLog.WriteException(ex,
                                         $"Error during patch execution for component {assemblyComponent.ComponentId}. Patch target version: {patch.Version}.");

                    throw;
                }

                patchResults[patch.Version] = patchResult;

                // reload
                installedComponent = RepositoryVersionInfo.Instance.Components.FirstOrDefault(c =>
                                                                                              c.ComponentId == assemblyComponent.ComponentId);
            }

            return(patchResults);
        }
示例#14
0
 public PatchManager(RepositoryStartSettings settings, Action <PatchExecutionLogRecord> logCallback)
 {
     _context = new PatchExecutionContext(settings, logCallback);
 }
示例#15
0
        internal void Run(string schemaPath, string asmPath, string fsPath, string repositoryPath, bool validate)
        {
            string ctdPath     = null;
            string aspectsPath = null;

            if (schemaPath != null)
            {
                ctdPath     = Directory.GetDirectories(schemaPath, "ContentTypes").FirstOrDefault();
                aspectsPath = Directory.GetDirectories(schemaPath, "Aspects").FirstOrDefault();
            }

            if (ctdPath == null && aspectsPath == null && String.IsNullOrEmpty(fsPath) && String.IsNullOrEmpty(SourceFile))
            {
                LogWriteLine("No changes");
                return;
            }

            var startSettings = new RepositoryStartSettings
            {
                Console            = Console.Out,
                StartLuceneManager = StorageContext.Search.IsOuterEngineEnabled,
                PluginsPath        = asmPath
            };

            using (Repository.Start(startSettings))
            {
                var installationMode = false;
                try
                {
                    installationMode = IsInstallationMode();
                }
                catch (Exception e)
                {
                    PrintException(e, null);
                    return;
                }

                ApplicationInfo.CreateInitialSenseNetVersion("Sense/Net ECM", "Unofficial", new Version(6, 3, 1),
                                                             "This edition can only be used for development and testing purposes.");

                // Elevation: there can be folders where even admins
                // do not have any permissions. This is why we need to
                // use system account for the whole import process.
                using (new SystemAccount())
                {
                    //-- Install ContentTypes
                    if (ctdPath == null && aspectsPath == null)
                    {
                        LogWriteLine("Schema is not changed");
                    }
                    else
                    {
                        if (installationMode)
                        {
                            StorageContext.Search.DisableOuterEngine();
                            LogWriteLine("Indexing is temporarily switched off." + CR);
                        }

                        InstallContentTypeDefinitionsAndAspects(ctdPath, aspectsPath);

                        if (installationMode)
                        {
                            StorageContext.Search.EnableOuterEngine();
                            CreateInitialIndex();
                            LogWriteLine("Indexing is switched on." + CR);
                        }
                    }

                    //-- Create missing index documents
                    var firstImport = SaveInitialIndexDocuments();
                    if (firstImport)
                    {
                        var admin     = Node.Load <User>(User.Administrator.Id);
                        var admins    = Node.Load <Group>(Group.Administrators.Id);
                        var operators = Node.Load <Group>(RepositoryConfiguration.OperatorsGroupPath);

                        admins.AddMember(admin);
                        admins.Save();

                        operators.AddMember(admins);
                        operators.Save();
                    }

                    //-- Import Contents
                    if (!String.IsNullOrEmpty(fsPath) || !String.IsNullOrEmpty(SourceFile))
                    {
                        ImportContents(fsPath, repositoryPath, validate, false);
                    }
                    else
                    {
                        LogWriteLine("Contents are not changed");
                    }
                }
            }
        }