Пример #1
0
            //================================================================================================================= Log

            private void Log(ImportLogLevel level, string format, params object[] parameters)
            {
                if (level > this.LogLevel)
                {
                    return;
                }
                Logger.LogMessage(format, parameters);
            }
Пример #2
0
            internal void Run(string schemaPath, string fsPath, string repositoryPath, ImportLogLevel logLevel)
            {
                //LogFolder = IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                this.LogLevel = logLevel;
                Log(ImportLogLevel.Info, "LogLevel: {0}", logLevel);

                if (schemaPath == null)
                {
                    FSPath         = fsPath;
                    RepositoryPath = repositoryPath;
                }
                else
                {
                    FSPath         = schemaPath;
                    RepositoryPath = ContentRepository.Repository.SchemaFolderPath;
                }

                string ctdPath     = null;
                string aspectsPath = null;

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

                if (ctdPath == null && aspectsPath == null && String.IsNullOrEmpty(fsPath))
                {
                    Log(ImportLogLevel.Info, "No changes");
                    return;
                }

                // 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 SenseNet.ContentRepository.Storage.Security.SystemAccount())
                {
                    //-- Import ContentTypes
                    if (ctdPath != null || aspectsPath != null)
                    {
                        ImportContentTypeDefinitionsAndAspects(ctdPath, aspectsPath);
                        return;
                    }

                    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))
                    {
                        ImportContents(fsPath, repositoryPath, false);
                    }
                    else
                    {
                        Log(ImportLogLevel.Info, "There is no content to import.");
                    }
                }
            }