Beispiel #1
0
        public CremaHost(CremaSettings settings, [ImportMany] IEnumerable <IRepositoryProvider> repoProviders)
        {
            CremaLog.Debug("crema instance created.");
            this.settings           = settings;
            this.basePath           = settings.BasePath;
            this.repositoryPath     = Path.Combine(settings.BasePath, settings.RepositoryName);
            this.trunkPath          = Path.Combine(this.repositoryPath, trunkString);
            this.tagsPath           = Path.Combine(this.repositoryPath, tagsString);
            this.branchesPath       = Path.Combine(this.repositoryPath, branchesString);
            this.workingPath        = Path.Combine(this.basePath, workingString);
            this.repositoryProvider = repoProviders.First(item => item.Name == this.settings.RepositoryModule);
            this.repositoryProvider.ValidateRepository(this.basePath, this.repositoryPath);

            this.log = new LogService(this.GetType().FullName, this.WorkingPath)
            {
                Name    = "repository",
                Verbose = settings.Verbose
            };
            CremaLog.Debug("crema log service initialized.");
            CremaLog.Debug($"available tags : {string.Join(", ", TagInfoUtility.Names)}");
            if (settings.MultiThreading == true)
            {
                this.dispatcher = new CremaDispatcher(this);
            }
            else
            {
                this.dispatcher = new CremaDispatcher(this, System.Windows.Threading.Dispatcher.CurrentDispatcher);
            }
            this.repositoryDispatcher = new CremaDispatcher(this.repositoryProvider);
            CremaLog.Debug("crema dispatcher initialized.");
        }
Beispiel #2
0
 private void Close(CloseInfo closeInfo)
 {
     this.OnClosing(EventArgs.Empty);
     foreach (var item in this.services.Reverse <ICremaService>())
     {
         item.Close(closeInfo);
     }
     this.services.Clear();
     this.domainContext = null;
     this.dataBases     = null;
     this.userContext   = null;
     foreach (var item in this.plugins)
     {
         item.Release();
     }
     foreach (var item in this.authentications)
     {
         item.InvokeExpiredEvent(Authentication.SystemID);
     }
     this.dispatcher.InvokeAsync(() =>
     {
         this.log?.Dispose();
         this.log = null;
     });
     this.address     = null;
     this.userID      = null;
     this.isConnected = false;
     this.OnClosed(new ClosedEventArgs(closeInfo.Reason, closeInfo.Message));
     CremaLog.Info("Crema closed.");
 }
Beispiel #3
0
        private Guid OpenInternal(string address, string dataBase, string userID, SecureString password)
        {
            this.address     = AddressUtility.GetDisplayAddress(address);
            this.log         = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath);
            this.log.Verbose = this.verbose;
            this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password);
            var user = this.userContext.Users[userID];

            user.SetUserState(UserState.Online);
            this.userID    = userID;
            this.authority = user.Authority;

            this.dataBases     = new DataBaseCollection(this, this.ipAddress, dataBase, serviceInfos[nameof(DataBaseCollectionService)]);
            this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]);
            this.isConnected   = true;
            this.configs       = new CremaConfiguration(this.ConfigPath);
            this.plugins       = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>;
            foreach (var item in this.plugins)
            {
                var authentication = new Authentication(new AuthenticationProvider(user), item.ID);
                this.authentications.Add(authentication);
                item.Initialize(authentication);
            }

            this.OnOpened(EventArgs.Empty);
            this.token = Guid.NewGuid();
            CremaLog.Info($"Crema opened : {address} {userID}");
            return(token);
        }
Beispiel #4
0
        public virtual IEnumerable <Assembly> GetAssemblies()
        {
            var assemblyList = new List <Assembly>();

            if (Assembly.GetEntryAssembly() != null)
            {
                assemblyList.Add(Assembly.GetEntryAssembly());
            }

            var query = from directory in EnumerableUtility.Friends(AssemblyDirectoryPath, this.SelectPath())
                        let catalog = new DirectoryCatalog(directory)
                                      from file in catalog.LoadedFiles
                                      select file;

            foreach (var item in query)
            {
                try
                {
                    var assembly = Assembly.LoadFrom(item);
                    assemblyList.Add(assembly);
                    CremaLog.Debug(assembly.Location);
                }
                catch
                {
                }
            }

            return(assemblyList.Distinct());
        }
Beispiel #5
0
        public object GetService(System.Type serviceType)
        {
            if (serviceType == typeof(ICremaHost))
            {
                return(this);
            }
            if (serviceType == typeof(IDataBaseCollection))
            {
                return(this.dataBases);
            }
            if (serviceType == typeof(IUserContext))
            {
                return(this.userContext);
            }
            if (serviceType == typeof(IUserCollection))
            {
                return(this.userContext.Users);
            }
            if (serviceType == typeof(IUserCategoryCollection))
            {
                return(this.userContext.Categories);
            }
            if (serviceType == typeof(IDomainContext))
            {
                return(this.domainContext);
            }
            if (serviceType == typeof(IDomainCollection))
            {
                return(this.domainContext.Domains);
            }
            if (serviceType == typeof(IDomainCategoryCollection))
            {
                return(this.domainContext.Categories);
            }
            if (serviceType == typeof(ILogService))
            {
                return(this);
            }
            if (this.IsOpened == true && serviceType == typeof(ICremaConfiguration))
            {
                return(this.configs);
            }

            if (this.container != null)
            {
                try
                {
                    return(this.container.GetService(serviceType));
                }
                catch (Exception e)
                {
                    CremaLog.Error(e);
                    return(null);
                }
            }

            return(null);
        }
Beispiel #6
0
        public Guid Open(string address, string userID, SecureString password)
        {
            if (this.isConnected == true)
            {
                throw new InvalidOperationException(Resources.Exception_AlreadyConnected);
            }

            this.ipAddress    = AddressUtility.GetIPAddress(address);
            this.serviceInfos = GetServiceInfo(address).ToDictionary(item => item.Name);

            this.OnOpening(EventArgs.Empty);
            return(this.dispatcher.Invoke(() =>
            {
                try
                {
                    this.address = AddressUtility.GetDisplayAddress(address);
                    this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath);
                    this.log.Verbose = this.verbose;
                    this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password);
                    var user = this.userContext.Users[userID];
                    user.SetUserState(UserState.Online);
                    this.userID = userID;
                    this.authority = user.Authority;

                    this.dataBases = new DataBaseCollection(this, this.ipAddress, serviceInfos[nameof(DataBaseCollectionService)]);
                    this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]);
                    this.isConnected = true;
                    this.configs = new CremaConfiguration(this.ConfigPath);
                    this.plugins = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>;
                    foreach (var item in this.plugins)
                    {
                        var authentication = new Authentication(new AuthenticationProvider(user), item.ID);
                        this.authentications.Add(authentication);
                        item.Initialize(authentication);
                    }

                    this.OnOpened(EventArgs.Empty);
                    this.token = Guid.NewGuid();
                    CremaLog.Info($"Crema opened : {address} {userID}");
                    return token;
                }
                catch
                {
                    this.userContext?.Close(CloseInfo.Empty);
                    this.userContext = null;
                    this.log?.Dispose();
                    this.log = null;
                    this.address = null;
                    throw;
                }
            }));
        }
Beispiel #7
0
 public void Dispose()
 {
     if (this.dataBases != null)
     {
         throw new InvalidOperationException(Resources.Exception_NotClosed);
     }
     this.repositoryDispatcher.Dispose();
     this.repositoryDispatcher = null;
     this.dispatcher.Dispose();
     this.dispatcher = null;
     this.OnDisposed(EventArgs.Empty);
     CremaLog.Release();
 }
Beispiel #8
0
        public void Dispose()
        {
            this.ValidateDispose();

            if (Environment.ExitCode != 0 && this.IsOpened == true)
            {
                this.Close(CloseInfo.Empty);
            }

            this.dispatcher.Dispose(false);
            this.dispatcher = null;
            this.OnDisposed(EventArgs.Empty);
            CremaLog.Info("Crema disposed.");
        }
Beispiel #9
0
 public async void RemoveService(ICremaService service)
 {
     if (this.services.Contains(service) == false)
     {
         return;
     }
     this.services.Remove(service);
     CremaLog.Debug($"{service.GetType().Name} Released.");
     if (this.services.Any() == false)
     {
         await this.dispatcher.InvokeAsync(() =>
         {
             this.InvokeClose(this.closeInfo);
         });
     }
 }
Beispiel #10
0
 public CremaHost()
 {
     this.dispatcher = new CremaDispatcher(this);
     CremaLog.Debug($"available tags : {string.Join(",", TagInfoUtility.Names)}");
     CremaLog.Debug("Crema created.");
 }
Beispiel #11
0
 public void AddService(ICremaService service)
 {
     this.services.Add(service);
     CremaLog.Debug($"{service.GetType().Name} Initialized.");
 }
Beispiel #12
0
 public CremaBootstrapper()
 {
     this.Initialize();
     this.settings.RepositoryModule = DefaultRepositoryModule;
     CremaLog.Debug("default repository module : {0}", this.settings.RepositoryModule);
 }
Beispiel #13
0
 private void Initialize()
 {
     CremaLog.Debug("Initialize.");
     this.OnInitialize();
     CremaLog.Debug("Initialized.");
 }