Ejemplo n.º 1
0
        /// <summary>
        /// Discards selected changes from the selected project.
        /// </summary>
        public void Discard(string[] files)
        {
            if (CheckProjects())
            {
                return;
            }

            ClientUI.ShowProgress("Discarding...");

            try
            {
                var diffs  = CurrentProject.BuildDiff();
                var diff   = diffs.Where(file => files.Any(x => x == file.FileName)).ToList();
                var commit = Commit.FromDiff(diff.ToArray());

                CurrentProject.Discard(commit.Files,
                                       x =>
                {
                    ClientUI.SetProgress("Discarding " + diff.Count + " change(s). " + x);
                });
            }
            catch (Exception ex)
            {
                ClientUI.ShowMessage("Error when discarding, no changes were discared, message: <br>" + ex.Message, true);
            }

            ClientUI.HideProgress();

            ClientUI.ShowProgress("Discarding done! Loading...");
            CurrentProject.Refresh(delegate
            {
                UpdateView();
                ClientUI.HideProgress();
            });
        }
Ejemplo n.º 2
0
        // private
        private void UpdateView()
        {
            Javascript.Run("selectProject('" + CurrentProject.ProjectName + "', false);");

            var diff    = CurrentProject.BuildDiff();
            var filesJs = diff.Aggregate("", (current, file) => current + ("addFileChange('" + file.FileName + "', " + (int)file.DiffType) + ");");

            Javascript.Run(filesJs);
            Javascript.Run("setChangeCount('" + CurrentProject.ProjectName + "', " + diff.Length + ");");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pueshes selected changes from the selected project.
        /// </summary>
        public void Push(string[] files)
        {
            if (CheckProjects())
            {
                return;
            }

            if (files.Length == 0)
            {
                ClientUI.ShowMessage("No file changes selected, select some.");
                return;
            }

            try
            {
                ClientUI.ShowProgress("Building commit...");

                var diffs = CurrentProject.BuildDiff();
                var diff  = diffs.Where(file => files.Any(x => x == file.FileName)).ToList();

                if (diff.Count == 0)
                {
                    ClientUI.ShowMessage("No file changes selected, select some.");
                    return;
                }

                var commit   = Commit.FromDiff(diff.ToArray());
                var datafile = commit.Build(CurrentProject.RootDir, CurrentProject.RootDir + ".mysync\\commit.zip",
                                            x =>
                {
                    ClientUI.SetProgress("Building commit... " + x);
                });
                ClientUI.SetProgress("Pushing " + diff.Count + " change(s).");
                CurrentProject.Push(commit, datafile,
                                    x =>
                {
                    ClientUI.SetProgress("Pushing " + diff.Count + " change(s). " + x);
                });
                ClientUI.HideProgress();

                ClientUI.ShowProgress("Push done! Loading...");
                CurrentProject.Refresh(delegate
                {
                    UpdateView();
                    ClientUI.HideProgress();
                });
            }
            catch (Exception ex)
            {
                ClientUI.HideProgress();
                ClientUI.ShowMessage("Error when pushing, no changes were pushed, message: <br>" + ex.Message, true);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Selects project by name, also refreshes the files changes.
        /// </summary>
        /// <param name="projectName">The project name.</param>
        /// <param name="callback">Is this javascript callback?</param>
        /// <param name="refresh">Refresh the project?</param>
        public void Select(string projectName, bool callback = false, bool refresh = true)
        {
            try
            {
                ClientUI.ShowProgress("Loading...");

                // select
                CurrentProject = AllProjects.FirstOrDefault(project => project.ProjectName == projectName);

                if (CurrentProject == null)
                {
                    ClientUI.ShowMessage("Failed to select project '" + projectName + "', invalid project name!", true);
                    return;
                }

                if (!callback)
                {
                    Javascript.Run("selectProject('" + projectName + "', false);");
                }

                if (refresh)
                {
                    CurrentProject.Refresh(delegate
                    {
                        var diff    = CurrentProject.BuildDiff();
                        var filesJs = diff.Aggregate("", (current, file) => current + ("addFileChange('" + file.FileName + "', " + (int)file.DiffType) + ");");

                        Javascript.Run(filesJs);
                        Javascript.Run("setChangeCount('" + CurrentProject.ProjectName + "', " + diff.Length + ");");
                        ClientUI.HideProgress();
                    });
                }
            }
            catch
            {
                if (refresh)
                {
                    ClientUI.HideProgress();
                }

                ClientUI.ShowMessage("Failed to select project '" + projectName + "'!", true);
            }
        }