Exemplo n.º 1
0
 /// <summary>
 /// Run the seed tool, this should check to make sure that it is safe to apply the seed data.
 /// This means that the seed tool should make sure tables are empty before modifying them
 /// or otherwise leave existing data in the database alone.
 /// </summary>
 /// <param name="toolArgs">The tools args.</param>
 public static async Task Seed(this ToolArgs toolArgs)
 {
     //Seed the authorization database, this will automatically manage roles and will add
     //any roles not currently in the database.
     var context = toolArgs.Scope.ServiceProvider.GetRequiredService <AppDbContext>();
     await context.SeedAuthorizationDatabase(Roles.DatabaseRoles());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Run the seed tool, this should check to make sure that it is safe to apply the seed data.
        /// This means that the seed tool should make sure tables are empty before modifying them
        /// or otherwise leave existing data in the database alone.
        /// </summary>
        /// <param name="toolArgs">The tools args.</param>
        public static async Task Seed(this ToolArgs toolArgs)
        {
            //Seed the authorization database, this will automatically manage roles and will add
            //any roles not currently in the database.
            var context = toolArgs.Scope.ServiceProvider.GetRequiredService <AppDbContext>();
            await context.SeedAuthorizationDatabase(Roles.DatabaseRoles());

            //Seed any additional data, it is best to keep this operation safe even if there
            //is data in the database, the easiest way to do this for most tables is to just
            //check to see if there is anything in there already, and if there is, do nothing.
        }
Exemplo n.º 3
0
        public static Task PushMaster(ToolArgs a, EditySettings editySettings)
        {
            if (editySettings.ProjectMode != ProjectMode.OneRepoPerUser)
            {
                throw new InvalidOperationException("The project mode must be OneRepoPerUser to use the pushmaster tool");
            }

            if (a.Args.Count < 1)
            {
                throw new InvalidOperationException("You must include the destination repository that you want to push to.");
            }
            var log       = a.Scope.ServiceProvider.GetRequiredService <ILogger <Repository> >();
            var destRepo  = a.Args[0];
            var masterDir = Path.GetFullPath(Path.Combine(editySettings.ProjectPath, "Master"));

            if (!Directory.Exists(masterDir))
            {
                throw new InvalidOperationException($"Master dir {masterDir} does not exist. No push will occur.");
            }

            var syncDir = Path.GetFullPath(Path.Combine(editySettings.ProjectPath, "Sync"));

            if (!Directory.Exists(syncDir))
            {
                throw new InvalidOperationException($"Sync dir {syncDir} does not exist. No push will occur.");
            }

            var syncRepo = new Repository(syncDir);

            //Change origin to master and pull changes from Master
            log.LogInformation("Pulling from master to sync.");
            ChangeRemote(syncRepo, masterDir);
            var result = Commands.Pull(syncRepo, new Signature("syncbot", "syncbot@syncbot", DateTime.Now), new PullOptions());

            //Change origin to new desitination and push
            ChangeRemote(syncRepo, destRepo);

            //Push to dest
            var remote  = syncRepo.Network.Remotes[origin];
            var options = new PushOptions()
            {
                CredentialsProvider = (url, user, cred) => GetCredentials(a)
            };

            foreach (var branch in syncRepo.Branches.Where(i => !i.IsRemote))
            {
                log.LogInformation($"Pushing branch {branch.CanonicalName} to origin master.");
                syncRepo.Network.Push(remote, branch.CanonicalName, options);
            }

            return(Task.FromResult(0));
        }
Exemplo n.º 4
0
    //从画线和画几何体中提取信息
    public void GetInfo(Tool sender, ToolArgs args)
    {
        Vector3[] pts     = args.vector3s;
        Polygon   polygon = args.polygon;


        if (stat == Stat.line)
        {
            Debug.Log(pts);
        }
        else if (stat == Stat.gon)
        {
            Debug.Log(polygon);
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Add a user as an "admin" this means they get all the roles.
        /// </summary>
        /// <param name="toolArgs">The tools args.</param>
        public static Task AddAdmin(this ToolArgs toolArgs)
        {
            if (toolArgs.Args.Count == 0)
            {
                throw new ToolException("Must add user guids as args to the addadmin tool.");
            }

            var repo = toolArgs.Scope.ServiceProvider.GetRequiredService <IUserEntityRepository>();

            return(repo.AddAdmins(toolArgs.Args.Select(i => new User()
            {
                UserId = Guid.Parse(i),
                Name = $"AddAdmin {i}"
            }), Roles.DatabaseRoles()));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Run the seed tool, this should check to make sure that it is safe to apply the seed data.
        /// This means that the seed tool should make sure tables are empty before modifying them
        /// or otherwise leave existing data in the database alone.
        /// </summary>
        /// <param name="toolArgs">The tools args.</param>
        public static async Task Seed(this ToolArgs toolArgs)
        {
            //Seed the authorization database, this will automatically manage roles and will add
            //any roles not currently in the database.
            var context = toolArgs.Scope.ServiceProvider.GetRequiredService <AppDbContext>();
            await context.SeedAuthorizationDatabase(Roles.DatabaseRoles());

            //Seed any additional data, it is best to keep this operation safe even if there
            //is data in the database, the easiest way to do this for most tables is to just
            //check to see if there is anything in there already, and if there is, do nothing.

            //Here we seed some values if there aren't any yet.
            var valueRepo = toolArgs.Scope.ServiceProvider.GetRequiredService <IValueRepository>();

            if (!await valueRepo.HasValues())
            {
                await valueRepo.AddRange(ValueCreator());
            }
        }
Exemplo n.º 7
0
        private static UsernamePasswordCredentials GetCredentials(ToolArgs a)
        {
            var userPassCredentials = new UsernamePasswordCredentials()
            {
                Username = "",
                Password = ""
            };

            for (var i = 1; i < a.Args.Count; ++i)
            {
                if (a.Args[i] == "-u")
                {
                    userPassCredentials.Username = a.Args[++i];
                }

                if (a.Args[i] == "-p")
                {
                    userPassCredentials.Password = a.Args[++i];
                }
            }

            return(userPassCredentials);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Run the migrate tool.
        /// </summary>
        /// <param name="toolArgs">The tools args.</param>
        public static Task Migrate(this ToolArgs toolArgs)
        {
            var context = toolArgs.Scope.ServiceProvider.GetRequiredService <AppDbContext>();

            return(context.Database.MigrateAsync());
        }
Exemplo n.º 9
0
        public static Task Clone(ToolArgs a, EditySettings editySettings)
        {
            if (a.Args.Count < 1)
            {
                throw new InvalidOperationException("You must include the source repository that you want to clone.");
            }
            var log        = a.Scope.ServiceProvider.GetRequiredService <ILogger <Repository> >();
            var sourceRepo = a.Args[0];
            var masterDir  = Path.GetFullPath(Path.Combine(editySettings.ProjectPath, "Master"));
            var cloneDir   = editySettings.ProjectPath;

            if (editySettings.ProjectMode == ProjectMode.OneRepoPerUser)
            {
                cloneDir = Path.Combine(editySettings.ProjectPath, "Sync");

                if (Directory.Exists(masterDir))
                {
                    throw new InvalidOperationException($"Directory {masterDir} already exists. No clone will take place.");
                }
            }

            cloneDir = Path.GetFullPath(cloneDir);

            //If clone repo exists, do nothing
            if (Directory.Exists(cloneDir) && Directory.EnumerateFileSystemEntries(cloneDir).Any())
            {
                throw new InvalidOperationException($"Directory {cloneDir} already exists and is not empty. No clone will take place.");
            }

            //Clone origin repo
            log.LogInformation($"Cloning {sourceRepo}");
            Repository.Clone(new Uri(sourceRepo).AbsoluteUri, cloneDir, new CloneOptions()
            {
                CredentialsProvider = (url, user, cred) => GetCredentials(a)
            });

            //Create local master repo, if one repo per user
            if (editySettings.ProjectMode == ProjectMode.OneRepoPerUser)
            {
                //Create master repo if it does not exist

                if (!Directory.Exists(masterDir))
                {
                    Directory.CreateDirectory(masterDir);
                    Repository.Init(masterDir, true);
                }

                //Add origin and push from sync to master
                var repo = new Repository(cloneDir);
                ChangeRemote(repo, masterDir);

                var remote  = repo.Network.Remotes[origin];
                var options = new PushOptions();

                foreach (var branch in repo.Branches.Where(i => !i.IsRemote))
                {
                    log.LogInformation($"Pushing branch {branch.CanonicalName} to local master.");
                    repo.Network.Push(remote, branch.CanonicalName, options);
                }
            }

            return(Task.FromResult(0));
        }