Exemple #1
0
        public static void ClassInit(TestContext context)
        {
            var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(context.TestDir));
            var tempDir     = Path.Combine(solutionDir, "crema_repo", "permission_test", typeof(PermissionTest).Name);
            var empty       = DirectoryUtility.Exists(tempDir) == false || DirectoryUtility.IsEmpty(tempDir);

            cremaHost = TestCrema.GetInstance(tempDir);
            cremaHost.Open();

            if (empty == true)
            {
                CremaSimpleGenerator.Generate(cremaHost, 10);
            }

            users.Initialize(cremaHost);
        }
Exemple #2
0
        public DomainServiceHost(ICremaHost cremaHost, int port)
            : base(cremaHost, typeof(DomainService), address, port)
        {
            var binding = CreateBinding();

            this.AddServiceEndpoint(typeof(IDomainService), binding, string.Empty);
            this.Description.Behaviors.Add(new InstanceProviderBehavior());

#if DEBUG
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                this.Description.Behaviors.Add(new ServiceMetadataBehavior());
                this.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
            }
#endif
        }
Exemple #3
0
        public static Authentication Start(this ICremaHost cremaHost)
        {
#if SERVER
            var token          = cremaHost.Open();
            var authentication = cremaHost.Login("admin", Utility.AdminPassword);
            authenticationToToken.Add(authentication, token);
            return(authentication);
#endif
#if CLIENT
            var port           = cremaHostToPort[cremaHost];
            var token          = cremaHost.Open($"localhost:{port}", "admin", Utility.AdminPassword);
            var authentication = cremaHost.GetService(typeof(Authenticator)) as Authenticator;
            authenticationToToken.Add(authentication, token);
            return(authentication);
#endif
        }
        public DescriptorServiceHost(ICremaHost cremaHost, DescriptorService service, int port)
            : base(service, new Uri($"net.tcp://localhost:{port}/DescriptorService"))
        {
            var binding = CremaServiceItemHost.CreateBinding();

            this.service = service;
            this.AddServiceEndpoint(typeof(IDescriptorService), binding, string.Empty);

#if DEBUG
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                this.Description.Behaviors.Add(new ServiceMetadataBehavior());
                this.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
            }
#endif
        }
 public static void ClassInit(TestContext context)
 {
     app = new CremaBootstrapper();
     app.Initialize(context, nameof(ITableCollection_Deleted_DispatcherTest));
     cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost;
     cremaHost.Dispatcher.Invoke(() =>
     {
         authentication = cremaHost.Start();
         dataBase       = cremaHost.DataBases.Random();
         dataBase.Load(authentication);
         dataBase.Enter(authentication);
         dataBase.Initialize(authentication);
         tables = dataBase.TableContext.Tables;
         dataBase.Leave(authentication);
         dataBase.Unload(authentication);
     });
 }
Exemple #6
0
 public ShellView(ICremaHost cremaHost, ConsoleCommandContext commandContext)
 {
     InitializeComponent();
     this.writer = new LogTextWriter()
     {
         TextBox = this.LogBox
     };
     this.cremaHost               = cremaHost;
     this.cremaHost.Opening      += CremaHost_Opening;
     this.cremaHost.Opened       += CremaHost_Opened;
     this.cremaHost.Closed       += CremaHost_Closed;
     this.commandContext          = commandContext;
     this.commandContext.Out      = new ConsoleWriter(this.terminal);
     this.terminal.CommandContext = this.commandContext;
     this.SetPrompt();
     CremaLog.AddRedirection(this.writer, LogLevel.Info);
 }
 public static void ClassInit(TestContext context)
 {
     app = new CremaBootstrapper();
     app.Initialize(context, nameof(ITableTemplate_DispatcherTest));
     cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost;
     cremaHost.Dispatcher.Invoke(() =>
     {
         authentication = cremaHost.Start();
         dataBase       = cremaHost.DataBases.Random();
         dataBase.Load(authentication);
         dataBase.Enter(authentication);
         dataBase.Initialize(authentication);
         template = dataBase.TableContext.Tables.Random(item => item.TemplatedParent == null).Template;
         template.BeginEdit(authentication);
         column = template.AddNew(authentication);
     });
 }
Exemple #8
0
 public static void ClassInit(TestContext context)
 {
     app = new CremaBootstrapper();
     app.Initialize(context, nameof(ITypeMember_DispatcherTest));
     cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost;
     cremaHost.Dispatcher.Invoke(() =>
     {
         authentication = cremaHost.Start();
         dataBase       = cremaHost.DataBases.Random();
         dataBase.Load(authentication);
         dataBase.Enter(authentication);
         dataBase.TypeContext.AddRandomItems(authentication);
         template = dataBase.TypeContext.Types.Random().Template;
         template.BeginEdit(authentication);
         member = template.Random();
     });
 }
        public UserServiceHost(ICremaHost cremaHost, int port, CremaService cremaService)
            : base(cremaHost, typeof(HttpUserService), address, port)
        {
            this.cremaService = cremaService;
            var endpoint = this.AddServiceEndpoint(typeof(IHttpUserService), CreateWebHttpBinding(), string.Empty);

            endpoint.Behaviors.Add(new WebHttpBehavior());
            this.Description.Behaviors.Add(new InstanceProviderBehavior());

#if DEBUG
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                this.Description.Behaviors.Add(new ServiceMetadataBehavior());
                this.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
            }
#endif
        }
Exemple #10
0
        public ShellView(IMenuService menuService, ICremaHost cremaHost, ICremaAppHost cremaAppHost)
        {
            InitializeComponent();

            this.menuService  = menuService;
            this.cremaHost    = cremaHost;
            this.cremaAppHost = cremaAppHost;
            foreach (var item in this.menuService.ItemsSource)
            {
                this.SetInputBindings(item);
            }
            this.cremaHost.Opened      += CremaHost_Opened;
            this.cremaHost.Closing     += CremaHost_Closing;
            this.cremaAppHost.Loaded   += CremaAppHost_Loaded;
            this.cremaAppHost.Unloaded += CremaAppHost_Unloaded;

            App.Writer.TextBox = this.logView;
            this.InitializeFromSettings();
        }
        private void InitCremaService()
        {
            var repoPath = DirectoryUtility.Prepare(CremaDbPath, "_repo");

            using (var bootstrap = new CremaBootstrapper())
            {
                bootstrap.CreateRepository(repoPath, "crema", false);
            }

            Service                = new CremaService();
            Service.BasePath       = repoPath;
            Service.MultiThreading = true;
            Service.Port           = 4004;
            Service.HttpPort       = AddressUtility.GetDefaultHttpPort(Service.Port);

            Service.Open();

            CremaHost = Service.GetService <ICremaHost>();
        }
Exemple #12
0
        public static (Authentication, IDataBase) LoginAndEnter(this ICremaHost cremaHost, string databaseName, string userID, string password)
        {
            var authentication = cremaHost.Login(userID, password.ToSecureString());

            return(cremaHost.Dispatcher.Invoke(() =>
            {
                var database = cremaHost.DataBases[databaseName];
                return database.Dispatcher.Invoke(() =>
                {
                    if (!database.IsLoaded)
                    {
                        database.Load(authentication);
                    }

                    database.Enter(authentication);

                    return (authentication, database);
                });
            }));
        }
Exemple #13
0
 public static void ClassInit(TestContext context)
 {
     app = new CremaBootstrapper();
     app.Initialize(context, nameof(ITableContent_Deleted_DispatcherTest));
     cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost;
     cremaHost.Dispatcher.Invoke(() =>
     {
         authentication = cremaHost.Start();
         dataBase       = cremaHost.DataBases.Random();
         dataBase.Load(authentication);
         dataBase.Enter(authentication);
         dataBase.Initialize(authentication);
         content = dataBase.TableContext.Tables.Random(item => item.Parent == null).Content;
         content.BeginEdit(authentication);
         content.EnterEdit(authentication);
         row = content.AddNew(authentication, null);
         dataBase.Leave(authentication);
         dataBase.Unload(authentication);
     });
 }
Exemple #14
0
        public void Open()
        {
            this.OnOpening(EventArgs.Empty);

            this.cremaHost  = this.GetService(typeof(ICremaHost)) as ICremaHost;
            this.logService = this.cremaHost.GetService(typeof(ILogService)) as ILogService;

            this.token              = this.cremaHost.Open();
            this.cremaHost.Opened  += CremaHost_Opened;
            this.cremaHost.Closing += CremaHost_Closing;
            CremaService.Dispatcher.Invoke(() =>
            {
                this.descriptorService     = new DescriptorService(this, this.cremaHost);
                this.descriptorServiceHost = new DescriptorServiceHost(this.cremaHost, this.descriptorService, this.port);
                this.descriptorServiceHost.Open();
                this.logService.Info(Resources.ServiceStart, nameof(DescriptorServiceHost));
            });
            this.StartServices();

            this.OnOpened(EventArgs.Empty);
        }
Exemple #15
0
        public static UsingDataBase Set(ICremaHost cremaHost, string dataBaseName, Authentication authentication, bool dispatch)
        {
            var dataBase = GetDataBase();

            if (dataBase == null)
            {
                throw new DataBaseNotFoundException(dataBaseName);
            }

            return(Set(dataBase, authentication, dispatch));

            IDataBase GetDataBase()
            {
                if (dispatch == true)
                {
                    return(cremaHost.Dispatcher.Invoke(() => cremaHost.DataBases[dataBaseName]));
                }
                else
                {
                    return(cremaHost.DataBases[dataBaseName]);
                }
            }
        }
        public static void UserCreateTest(this ICremaHost cremaHost, Authentication authentication, Authority authority)
        {
            cremaHost.Dispatcher.Invoke(() =>
            {
                var userContext = cremaHost.GetService(typeof(IUserContext)) as IUserContext;
                if (userContext.Users[authentication.ID].Authority != Authority.Admin)
                {
                    return;
                }

                var category   = userContext.Categories.Random();
                var identifier = RandomUtility.NextIdentifier();

                if (authority == Authority.Admin)
                {
                    var newID   = string.Format("Admin_{0}", identifier);
                    var newName = string.Format("관리자_{0}", identifier);

                    category.AddNewUser(authentication, newID, null, newName, Authority.Admin);
                }
                else if (authority == Authority.Member)
                {
                    var newID   = string.Format("Member_{0}", identifier);
                    var newName = string.Format("구성원_{0}", identifier);

                    category.AddNewUser(authentication, newID, null, newName, Authority.Member);
                }
                else
                {
                    var newID   = string.Format("Guest_{0}", identifier);
                    var newName = string.Format("손님_{0}", identifier);

                    category.AddNewUser(authentication, newID, null, newName, Authority.Guest);
                }
            });
        }
        // public static async Task<bool> ContainsUserAsync(this ICremaHost cremaHost, string userID)
        // {
        //     if (cremaHost.GetService(typeof(IUserContext)) is IUserContext userContext)
        //     {
        //         return await userCollection.ContainsAsync(userID);
        //     }
        //     throw new NotImplementedException();
        // }

        // public static async Task<bool> ContainsUserItemAsync(this ICremaHost cremaHost, string categoryPath)
        // {
        //     if (cremaHost.GetService(typeof(IUserContext)) is IUserContext userContext)
        //     {
        //         return await userContext.Categories.ContainsAsync(categoryPath);
        //     }
        //     throw new NotImplementedException();
        // }

        // public static Task<IDataBase[]> GetDataBasesAsync(this ICremaHost cremaHost)
        // {
        //     if (cremaHost.GetService(typeof(IDataBaseContext)) is IDataBaseContext dataBaseContext)
        //     {
        //         return dataBaseContext.Dispatcher.InvokeAsync(() => dataBaseContext.ToArray());
        //     }
        //     throw new NotImplementedException();
        // }

        // public static Task<IDataBase> GetDataBaseAsync(this ICremaHost cremaHost, string dataBaseName)
        // {
        //     return GetDataBaseAsync(cremaHost, dataBaseName, false);
        // }

        public static Task <IDataBase> GetDataBaseAsync(this ICremaHost cremaHost, string dataBaseName, bool isLoaded)
        {
            if (dataBaseName == null)
            {
                throw new ArgumentNullException(nameof(dataBaseName));
            }
            if (cremaHost.GetService(typeof(IDataBaseContext)) is IDataBaseContext dataBaseContext)
            {
                return(dataBaseContext.Dispatcher.InvokeAsync(() =>
                {
                    if (dataBaseContext.Contains(dataBaseName) == false)
                    {
                        throw new DataBaseNotFoundException(dataBaseName);
                    }
                    var dataBase = dataBaseContext[dataBaseName];
                    if (isLoaded == true && dataBase.IsLoaded == false)
                    {
                        throw new InvalidOperationException("database is not loaded");
                    }
                    return dataBase;
                }));
            }
            throw new NotImplementedException();
        }
Exemple #18
0
        public async Task OpenAsync()
        {
            this.ValidateOpen();
            this.ServiceState = JSSoft.Crema.Services.ServiceState.Opening;
            await this.Dispatcher.InvokeAsync(() =>
            {
                this.OnOpening(EventArgs.Empty);
                this.cremaHost = this.GetService(typeof(ICremaHost)) as ICremaHost;
            });

            this.token = await this.cremaHost.OpenAsync();

            await this.cremaHost.Dispatcher.InvokeAsync(() =>
            {
                this.cremaHost.CloseRequested += CremaHost_CloseRequested;
                this.cremaHost.Closed         += CremaHost_Closed;
            });

            await this.Dispatcher.InvokeAsync(() =>
            {
                this.ServiceState = JSSoft.Crema.Services.ServiceState.Open;
                this.OnOpened(EventArgs.Empty);
            });
        }
 public GetTypeListByTagsMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
Exemple #20
0
 protected UserScriptMethodBase(ICremaHost cremaHost, string name)
     : base(name)
 {
     this.cremaHost = cremaHost;
 }
Exemple #21
0
 protected UserScriptMethodBase(ICremaHost cremaHost)
 {
     this.cremaHost = cremaHost;
 }
Exemple #22
0
 public RunCommand(CremaBootstrapper application, ICremaHost cremaHost)
     : base("run")
 {
     this.application = application;
     this.cremaHost   = cremaHost;
 }
 public GetTypeItemLogInfoMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
 public MessageReceivedEventListenerHost(ICremaHost cremaHost)
     : base(CremaEvents.MessageReceived)
 {
     this.cremaHost = cremaHost;
 }
 public DeleteTypeTemplateMemberMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
Exemple #26
0
 public BeginTypeCreateMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
 public GetTypeTemplatePropertiesMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
Exemple #28
0
 public UnloadDataBaseMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
 public GetTypeInfoByTagsMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }
Exemple #30
0
 public GetTableTemplateColumnPropertiesMethod(ICremaHost cremaHost)
     : base(cremaHost)
 {
 }