public void Initialize(CremaHost cremaHost, IEnumerable <IPlugin> plugins)
 {
     foreach (var item in plugins)
     {
         var authentication = new Authentication(new AuthenticationProvider(item), item.ID);
         item.Initialize(authentication);
         this.Add(authentication);
     }
 }
Beispiel #2
0
        public static void UpgradeRepository(IServiceProvider serviceProvider, string basePath, params string[] dataBaseNames)
        {
            var repositoryModule   = GetRepositoryModule(basePath);
            var fileType           = GetFileType(basePath);
            var repositoryProvider = GetRepositoryProvider(serviceProvider, repositoryModule);
            var serializer         = GetSerializer(serviceProvider, fileType);
            var upgradePath        = Path.Combine(basePath, "upgrade");
            var logService         = new LogServiceHost("upgrade", upgradePath, true)
            {
                Verbose = LogLevel.Info,
            };

            var repositoryPath = CremaHost.GetPath(basePath, CremaPath.RepositoryDataBases, false);
            var items          = repositoryProvider.GetRepositories(repositoryPath);

            if (dataBaseNames.Length > 0)
            {
                items = items.Intersect(dataBaseNames).ToArray();
            }

            for (var i = 0; i < items.Length; i++)
            {
                var item               = items[i];
                var tempPath           = Path.Combine(upgradePath, item);
                var repositorySettings = new RepositorySettings()
                {
                    RemotePath     = repositoryPath,
                    RepositoryName = item,
                    BasePath       = tempPath,
                    LogService     = logService,
                };
                try
                {
                    if (UpgradeRepository(repositoryProvider, serializer, repositorySettings) == true)
                    {
                        logService.Info($"[{i + 1}/{items.Length}]{item}: upgraded");
                    }
                    else
                    {
                        logService.Info($"[{i + 1}/{items.Length}]{item}: skip");
                    }
                    DirectoryUtility.Delete(tempPath);
                }
                catch (Exception e)
                {
                    logService.Error(e);
                    logService.Info($"[{i + 1}/{items.Length}]{item}: fail");
                }
            }
        }
Beispiel #3
0
        public static void ValidateRepository(IServiceProvider serviceProvider, string basePath, params string[] dataBaseNames)
        {
            var repositoryModule   = GetRepositoryModule(basePath);
            var fileType           = GetFileType(basePath);
            var repositoryProvider = GetRepositoryProvider(serviceProvider, repositoryModule);
            var serializer         = GetSerializer(serviceProvider, fileType);
            var validationPath     = Path.Combine(basePath, "validation");
            var logService         = new LogServiceHost("validation", validationPath, true)
            {
                Verbose = LogLevel.Info,
            };

            var repositoryPath = CremaHost.GetPath(basePath, CremaPath.RepositoryDataBases, false);
            var items          = repositoryProvider.GetRepositories(repositoryPath);

            if (dataBaseNames.Length > 0)
            {
                items = items.Intersect(dataBaseNames).ToArray();
            }

            for (var i = 0; i < items.Length; i++)
            {
                var item               = items[i];
                var tempPath           = Path.Combine(validationPath, item);
                var repositorySettings = new RepositorySettings()
                {
                    RemotePath     = repositoryPath,
                    RepositoryName = item,
                    BasePath       = tempPath,
                    LogService     = logService,
                };
                var repository = repositoryProvider.CreateInstance(repositorySettings);
                try
                {
                    serializer.Validate(repository.BasePath, typeof(CremaDataSet), ObjectSerializerSettings.Empty);
                    repository.Dispose();
                    DirectoryUtility.Delete(tempPath);
                    logService.Info($"[{i + 1}/{items.Length}]{item}: OK");
                }
                catch (Exception e)
                {
                    logService.Error(e);
                    logService.Info($"[{i + 1}/{items.Length}]{item}: Fail");
                }
            }
        }
Beispiel #4
0
 public RepositoryLocker(CremaHost cremaHost)
 {
     this.cremaHost = cremaHost;
     this.path      = this.cremaHost.GetPath(CremaPath.Repository, CremaString.Lock);
     if (File.Exists(this.path) == true)
     {
         try
         {
             this.stream = new FileStream(this.path, FileMode.Open, FileAccess.Read, FileShare.None);
         }
         catch (Exception e)
         {
             throw new InvalidOperationException("repository is used.", e);
         }
     }
     else
     {
         this.stream = new FileStream(this.path, FileMode.Create, FileAccess.Write, FileShare.None);
     }
 }
 public CremaHostServiceHost(CremaHost cremaHost)
 {
     this.cremaHost = cremaHost;
 }
Beispiel #6
0
 public static void CleanRepository(IServiceProvider serviceProvider, string basePath)
 {
     DirectoryUtility.Delete(CremaHost.GetPath(basePath, CremaPath.Caches, false));
 }