Example #1
0
 public RepositoryHost(IRepository repository, CremaDispatcher dispatcher, string path)
 {
     this.repository = repository;
     this.dispatcher = dispatcher;
     this.path       = path;
     this.revision   = this.repository.GetRevision(path);
 }
Example #2
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.");
        }
Example #3
0
 public RuntimeServiceItem(IDataBase dataBase, CremaDispatcher dispatcher, Authentication authentication)
     : base(dataBase)
 {
     this.dispatcher     = dispatcher;
     this.authentication = authentication;
     this.logService     = dataBase.GetService(typeof(ILogService)) as ILogService;
 }
Example #4
0
 protected Domain(DomainInfo domainInfo, CremaDispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
     this.Initialize(domainInfo); ;
     this.Name = domainInfo.DomainID.ToString();
     this.users = new DomainUserCollection(this);
 }
Example #5
0
        public DataBaseCollection(CremaHost cremaHost, string address, string dataBase, ServiceInfo serviceInfo)
        {
            this.cremaHost   = cremaHost;
            this.userContext = cremaHost.UserContext;

            this.serviceDispatcher = new CremaDispatcher(this);
            var metaData = this.serviceDispatcher.Invoke(() =>
            {
                this.service = DataBaseCollectionServiceFactory.CreateServiceClient(address, serviceInfo, this);
                this.service.Open();
                if (this.service is ICommunicationObject service)
                {
                    service.Faulted += Service_Faulted;
                }

                ResultBase <DataBaseCollectionMetaData> result;
                result = dataBase == null
                    ? this.service.Subscribe(cremaHost.AuthenticationToken)
                    : this.service.SubscribeDataBase(cremaHost.AuthenticationToken, dataBase);
                result.Validate();

#if !DEBUG
                this.timer          = new Timer(30000);
                this.timer.Elapsed += Timer_Elapsed;
                this.timer.Start();
#endif
                return(result.Value);
            });

            this.Initialize(metaData);
            this.CremaHost.AddService(this);
        }
Example #6
0
 public TypeDomain(DomainInfo domainInfo, CremaDispatcher dispatcher)
     : base(domainInfo, dispatcher)
 {
     if (domainInfo.ItemType == nameof(NewTypeTemplate))
     {
         this.IsNew = true;
     }
 }
Example #7
0
 protected DataServiceBase(ICremaHost cremaHost, Guid pluginID, string name)
 {
     this.cremaHost          = cremaHost;
     this.pluginID           = pluginID;
     this.name               = name ?? throw new ArgumentNullException(nameof(name));
     this.dispatcher         = new CremaDispatcher(this);
     this.cremaHost.Closing += CremaHost_Closing;
 }
Example #8
0
 public void Dispose(Authentication authentication, bool isCanceled)
 {
     var container = this.Container;
     this.Dispose();
     this.dispatcher = null;
     this.OnDeleted(new DomainDeletedEventArgs(authentication, this, isCanceled));
     container.InvokeDomainDeletedEvent(authentication, this, isCanceled);
 }
Example #9
0
 public CremaEventListenerContext(CremaEventListenerHost[] eventListener)
 {
     this.eventListeners = eventListener.ToDictionary(item => item.EventName);
     this.dispatcher     = new CremaDispatcher(this);
     foreach (var item in eventListener)
     {
         item.Dispatcher = this.dispatcher;
     }
 }
Example #10
0
 public RuntimeService(ICremaHost cremaHost, [ImportMany] IEnumerable <Runtime.Serialization.IDataSerializer> serializers)
 {
     this.cremaHost           = cremaHost;
     this.serializers         = serializers;
     this.dispatcher          = new CremaDispatcher(this);
     this.cremaHost.Opened   += CremaHost_Opened;
     this.cremaHost.Closed   += CremaHost_Closed;
     this.cremaHost.Disposed += (s, e) => this.dispatcher.Dispose();
 }
Example #11
0
        public void Initialize(Authentication authentication)
        {
            this.dispatcher     = new CremaDispatcher(this);
            this.authentication = authentication;

            foreach (var item in this.cremaHost.DataBases)
            {
                var serviceItem = new DataFindServiceItem(item, this.dispatcher, authentication);
                this.items.Add(item.ID, serviceItem);
            }
        }
Example #12
0
 public void Delete(Authentication authentication, bool isCanceled)
 {
     this.dispatcher.VerifyAccess();
     this.CremaHost.DebugMethod(authentication, this, nameof(Delete), this);
     var container = this.Container;
     var result = this.Service.DeleteDomain(this.ID, isCanceled);
     this.Sign(authentication, result);
     this.Dispose();
     this.dispatcher = null;
     this.OnDeleted(new DomainDeletedEventArgs(authentication, this, isCanceled));
     container.InvokeDomainDeletedEvent(authentication, this, isCanceled);
 }
Example #13
0
        public void Dispose(Authentication authentication, bool isCanceled)
        {
            this.dispatcher.VerifyAccess();
            var container = this.Container;

            this.dispatcher.Dispose();
            this.dispatcher = null;
            this.domainLogger?.Dispose(true);
            this.domainLogger = null;
            this.Dispose();
            this.OnDeleted(new DomainDeletedEventArgs(authentication, this, isCanceled));
            container.InvokeDomainDeletedEvent(authentication, this, isCanceled);
        }
Example #14
0
        public DataBaseEventListenerContext(ICremaHost cremaHost, DataBaseEventListenerHost[] eventListener)
        {
            this.cremaHost = cremaHost;

            this.listenerHosts = eventListener.ToDictionary(item => item.EventName);
            this.dispatcher    = new CremaDispatcher(this);
            foreach (var item in eventListener)
            {
                item.Dispatcher = this.dispatcher;
            }
            this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.DataBases.ItemsLoaded   += DataBases_ItemsLoaded);
            this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.DataBases.ItemsUnloaded += DataBases_ItemsUnloaded);
        }
Example #15
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();
 }
Example #16
0
 void IDomainServiceCallback.OnServiceClosed(SignatureDate signatureDate, CloseInfo closeInfo)
 {
     this.service.Abort();
     this.service = null;
     this.timer?.Dispose();
     this.timer = null;
     this.serviceDispatcher.Dispose();
     this.serviceDispatcher = null;
     this.InvokeAsync(() =>
     {
         this.cremaHost.RemoveService(this);
     }, nameof(IDomainServiceCallback.OnServiceClosed));
 }
Example #17
0
        public UserContext(CremaHost cremaHost, string address, ServiceInfo serviceInfo, string userID, SecureString password)
        {
            this.cremaHost = cremaHost;

            this.serviceDispatcher = new CremaDispatcher(this);
            var metaData = this.serviceDispatcher.Invoke(() =>
            {
                this.service = UserServiceFactory.CreateServiceClient(address, serviceInfo, this);
                this.service.Open();
                if (this.service is ICommunicationObject service)
                {
                    service.Faulted += Service_Faulted;
                }
                var version = AppUtility.ProductVersion;
                try
                {
                    var result = this.service.Subscribe(userID, UserContext.Encrypt(userID, password), $"{version}", $"{Environment.OSVersion.Platform}", $"{CultureInfo.CurrentCulture}");
                    result.Validate();
#if !DEBUG
                    this.timer          = new Timer(30000);
                    this.timer.Elapsed += Timer_Elapsed;
                    this.timer.Start();
#endif
                    return(result.Value);
                }
                catch
                {
                    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        this.service.Close();
                    }
                    else
                    {
                        this.service.Abort();
                    }
                    this.serviceDispatcher.Dispose();
                    this.serviceDispatcher = null;
                    throw;
                }
            });

            this.authenticationToken = metaData.AuthenticationToken;
            this.Initialize(metaData);
            this.Items.MessageReceived  += Users_MessageReceived;
            this.Items.MessageReceived2 += Users_MessageReceived2;
            this.Items.UsersLoggedIn    += Users_UsersLoggedIn;
            this.Items.UsersLoggedOut   += Users_UsersLoggedOut;
            this.Items.UsersKicked      += Users_UsersKicked;
            this.Items.UsersBanChanged  += Users_UsersBanChanged;
            this.cremaHost.AddService(this);
        }
Example #18
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.");
        }
Example #19
0
        public void Delete(Authentication authentication, bool isCanceled)
        {
            this.dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(Delete), base.DomainInfo.ItemPath, base.DomainInfo.ItemType, isCanceled);
            this.ValidateDelete(authentication, isCanceled);
            this.Sign(authentication, true);
            var container = this.Container;

            this.dispatcher.Dispose();
            this.dispatcher = null;
            this.domainLogger?.Dispose(true);
            this.domainLogger = null;
            this.users.Clear();
            this.Dispose();
            this.OnDeleted(new DomainDeletedEventArgs(authentication, this, isCanceled));
            container.InvokeDomainDeletedEvent(authentication, this, isCanceled);
        }
Example #20
0
 public void Dispose(DomainContext domainContext)
 {
     try
     {
         this.dispatcher.VerifyAccess();
         this.dispatcher.Dispose();
         this.dispatcher = null;
         this.domainLogger?.Dispose(false);
         this.domainLogger = null;
         this.Dispose();
     }
     catch (Exception e)
     {
         this.CremaHost.Error(e);
         throw;
     }
 }
Example #21
0
        public void Dispose(bool disposing)
        {
            this.dispatcher.VerifyAccess();

            var container = this.Container;

            this.dispatcher.Dispose();
            this.dispatcher = null;
            this.domainLogger?.Dispose(false);
            this.domainLogger = null;
            this.Dispose();

            if (disposing == false)
            {
                container.InvokeDomainDeletedEvent(Authentication.System, this, false);
            }
        }
Example #22
0
 public UserContext(CremaHost cremaHost)
 {
     this.cremaHost = cremaHost;
     this.cremaHost.Debug(Resources.Message_UserContextInitialize);
     this.userFilePath = GenerateUsersFilePath(cremaHost.RepositoryPath);
     this.repository   = new RepositoryHost(cremaHost.Repository, cremaHost.RepositoryDispatcher, this.userFilePath);
     this.dispatcher   = new CremaDispatcher(this);
     this.dispatcher.Invoke(() =>
     {
         this.Items.MessageReceived += Users_MessageReceived;
         this.Items.UsersLoggedIn   += Users_UsersLoggedIn;
         this.Items.UsersLoggedOut  += Users_UsersLoggedOut;
         this.Items.UsersKicked     += Users_UsersKicked;
         this.Items.UsersBanChanged += Users_UsersBanChanged;
     });
     this.cremaHost.Debug(Resources.Message_UserContextIsCreated);
 }
Example #23
0
 private void Service_Faulted(object sender, EventArgs e)
 {
     this.serviceDispatcher.Invoke(() =>
     {
         try
         {
             this.service.Abort();
             this.service = null;
         }
         catch
         {
         }
         this.timer?.Dispose();
         this.timer = null;
         this.serviceDispatcher.Dispose();
         this.serviceDispatcher = null;
     });
     this.InvokeAsync(() =>
     {
         this.cremaHost.RemoveService(this, new CloseInfo(CloseReason.Faulted, "서버와의 연결이 끊어졌습니다."));
     }, nameof(Service_Faulted));
 }
Example #24
0
 private void Service_Faulted(object sender, EventArgs e)
 {
     this.serviceDispatcher.Invoke(() =>
     {
         try
         {
             this.service.Abort();
             this.service = null;
         }
         catch
         {
         }
         this.timer?.Dispose();
         this.timer = null;
         this.serviceDispatcher.Dispose();
         this.serviceDispatcher = null;
     });
     this.InvokeAsync(() =>
     {
         this.cremaHost.RemoveService(this);
     }, nameof(Service_Faulted));
 }
Example #25
0
        public DomainContext(CremaHost cremaHost, string address, ServiceInfo serviceInfo)
        {
            this.cremaHost   = cremaHost;
            this.userContext = cremaHost.UserContext;

            this.serviceDispatcher = new CremaDispatcher(this);
            var metaData = this.serviceDispatcher.Invoke(() =>
            {
                var binding = CremaHost.CreateBinding(serviceInfo);

                var endPointAddress = new EndpointAddress($"net.tcp://{address}:{serviceInfo.Port}/DomainService");
                var instanceContext = new InstanceContext(this);
                if (Environment.OSVersion.Platform != PlatformID.Unix)
                {
                    instanceContext.SynchronizationContext = System.Threading.SynchronizationContext.Current;
                }

                this.service = new DomainServiceClient(instanceContext, binding, endPointAddress);
                this.service.Open();
                if (this.service is ICommunicationObject service)
                {
                    service.Faulted += Service_Faulted;
                }
                var result = this.service.Subscribe(this.cremaHost.AuthenticationToken);
                result.Validate();
#if !DEBUG
                this.timer          = new Timer(30000);
                this.timer.Elapsed += Timer_Elapsed;
                this.timer.Start();
#endif
                return(result.Value);
            });

            this.Initialize(metaData);
            this.cremaHost.DataBases.ItemsCreated += DataBases_ItemsCreated;
            this.cremaHost.DataBases.ItemsRenamed += DataBases_ItemsRenamed;
            this.cremaHost.DataBases.ItemsDeleted += DataBases_ItemDeleted;
            this.cremaHost.AddService(this);
        }
Example #26
0
 public void Close(CloseInfo closeInfo)
 {
     this.serviceDispatcher?.Invoke(() =>
     {
         this.timer?.Dispose();
         this.timer = null;
         if (this.service != null)
         {
             try
             {
                 if (closeInfo.Reason != CloseReason.NoResponding)
                 {
                     this.service.Unsubscribe();
                     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                     {
                         this.service.Close();
                     }
                     else
                     {
                         this.service.Abort();
                     }
                 }
                 else
                 {
                     this.service.Abort();
                 }
             }
             catch
             {
                 this.service.Abort();
             }
             this.service = null;
         }
         this.serviceDispatcher.Dispose();
         this.serviceDispatcher = null;
     });
 }
Example #27
0
 static CremaService()
 {
     dispatcher = new CremaDispatcher(typeof(CremaServiceItemHost));
 }
Example #28
0
 public CremaHost()
 {
     this.dispatcher = new CremaDispatcher(this);
     CremaLog.Debug($"available tags : {string.Join(",", TagInfoUtility.Names)}");
     CremaLog.Debug("Crema created.");
 }
Example #29
0
 public TableContentDomain(DomainInfo domainInfo, CremaDispatcher dispatcher)
     : base(domainInfo, dispatcher)
 {
 }
Example #30
0
 protected abstract T CreateItem(IDataBase dataBase, CremaDispatcher Dispatcher, Authentication authentication);