예제 #1
0
        public void RunApplication(string[] args)
        {
            SetupCommandLine cmdLine = new SetupCommandLine();

            try
            {
                cmdLine.Parse(args);

                using (PersistenceScope scope = new PersistenceScope(PersistenceContextType.Update))
                {
                    ((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

                    // import authority tokens
                    AuthorityTokenImporter tokenImporter = new AuthorityTokenImporter();
                    IList <AuthorityToken> allTokens     = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);


                    // create the sys admin group, which has all tokens assigned by default
                    string[] tokenStrings = CollectionUtils.Map <AuthorityToken, string, List <string> >(allTokens,
                                                                                                         t => t.Name).ToArray();
                    AuthorityGroupDefinition adminGroupDef = new AuthorityGroupDefinition(cmdLine.SysAdminGroup, cmdLine.SysAdminGroup, false,
                                                                                          tokenStrings);
                    AuthorityGroupImporter groupImporter = new AuthorityGroupImporter();

                    IList <AuthorityGroup> groups =
                        groupImporter.Import(new AuthorityGroupDefinition[] { adminGroupDef }, (IUpdateContext)PersistenceScope.CurrentContext);

                    // find the admin group entity that was just created
                    AuthorityGroup adminGroup = CollectionUtils.SelectFirst(groups,
                                                                            g => g.Name == cmdLine.SysAdminGroup);

                    // create the "sa" user
                    CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

                    // optionally import other default authority groups defined in other plugins
                    if (cmdLine.ImportDefaultAuthorityGroups)
                    {
                        groupImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    }

                    scope.Complete();
                }
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                cmdLine.PrintUsage(Console.Out);
            }
        }
        public ImportAuthorityTokensResponse ImportAuthorityTokens(ImportAuthorityTokensRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.Tokens, "Tokens");

            if (request.Tokens.Count > 0)
            {
                var importer = new AuthorityTokenImporter();
                importer.Import(
                    CollectionUtils.Map(request.Tokens, (AuthorityTokenSummary s) => new AuthorityTokenDefinition(s.Name, s.DefiningAssembly, s.Description, s.FormerIdentities.ToArray())),
                    request.AddToGroups,
                    (IUpdateContext)PersistenceContext);
            }

            return(new ImportAuthorityTokensResponse());
        }
예제 #3
0
        public void RunApplication(string[] args)
        {
            var cmdLine = new SetupCommandLine();

            try
            {
                cmdLine.Parse(args);

                using (var scope = new PersistenceScope(PersistenceContextType.Update))
                {
                    ((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

                    // import authority tokens
                    var tokenImporter = new AuthorityTokenImporter();
                    var allTokens     = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    var tokenStrings  = CollectionUtils.Map <AuthorityToken, string, List <string> >(allTokens, t => t.Name).ToArray();

                    // import built-in groups
                    var builtInAuthorityGroups = new[]
                    {
                        GetSysAdminGroupDefinition(tokenStrings),
                        BuiltInAuthorityGroups.SystemAccounts
                    };

                    var groupImporter = new AuthorityGroupImporter();
                    var groups        = groupImporter.Import(builtInAuthorityGroups, (IUpdateContext)PersistenceScope.CurrentContext);

                    // create the "sa" user
                    var adminGroup = CollectionUtils.SelectFirst(groups, g => g.Name == BuiltInAuthorityGroups.Administrators.Name);
                    CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

                    // optionally import other default authority groups defined in other plugins
                    if (cmdLine.ImportDefaultAuthorityGroups)
                    {
                        groupImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    }

                    scope.Complete();
                }
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                cmdLine.PrintUsage(Console.Out);
            }
        }