private void Checkin(object sender, EventArgs e)
        {
            foreach (Change item in itemsToCommit.Items)
            {
                if (item.ChangeType == ChangeType.Added)
                {
                    CmdRunner.ExecuteCommandWithStringResult(
                        string.Format("cm add {0}", item.Name),
                        SampleHelper.GetWorkspace());
                }

                if (item.ChangeType == ChangeType.Deleted)
                {
                    CmdRunner.ExecuteCommandWithStringResult(
                        string.Format("cm rm {0}", item.Name),
                        SampleHelper.GetWorkspace());
                }
            }

            string result = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm ci -c=\"{0}\"", textBox1.Text),
                SampleHelper.GetWorkspace());

            MessageBox.Show(result);

            textBox1.Text = string.Empty;
            Update(sender, e);
        }
        private void RefreshChangesetList(object sender, EventArgs e)
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                "cm find changeset --nototal --format=\"{changesetid}#{date}#{comment}\"",
                SampleHelper.GetWorkspace());

            ArrayList results = SampleHelper.GetListResults(cmdResult, true);

            changesetList.Items.Clear();
            foreach (string item in results)
            {
                Changeset cset = new Changeset(item);
                cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                    string.Format("cm log {0} --csFormat=\"{{items}}\" --itemFormat=\"{{path}}#{{fullstatus}}#{{newline}}\"", cset.Id),
                    SampleHelper.GetWorkspace());

                results = SampleHelper.GetListResults(cmdResult, true);
                foreach (string changedItem in results)
                {
                    cset.Changes.Add(new Item(changedItem));
                }

                changesetList.Items.Add(cset);
            }
        }
        private static void FillBranchesWithRandomItems(int numBranches,
                                                        string repositorySpec,
                                                        bool includeThreadInfo)
        {
            int    minRandomItems = 2;
            int    maxRandomItems = 6;
            string threadInfo     = includeThreadInfo
                ? string.Format("THREAD: {0} ", Thread.CurrentThread.ManagedThreadId)
                : string.Empty;

            Random r = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < numBranches; i++)
            {
                string branch = string.Format("br:/main/task{0}", i);
                CmdRunner.ExecuteCommandWithStringResult(
                    string.Format("cm stb {0}@{1}", branch, repositorySpec),
                    GetWorkspace());

                int items = r.Next(minRandomItems, maxRandomItems);
                Console.WriteLine("{0}Adding {1} random items to {2}",
                                  threadInfo, items, branch);

                for (int j = 0; j < items; j++)
                {
                    string filename = AddRandomItem();
                    CheckinItem(filename, "Added " + filename);
                }
            }
        }
        static void Main(string[] args)
        {
            string server           = "localhost:8084";
            string repository       = SampleHelper.GenerateRepositoryWithData(server);
            string secondRepository = SampleHelper.GenerateEmptyRepository(server);

            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find branch on repositories '{0}' --format={{id}}#{{name}} --nototal", repository),
                Environment.CurrentDirectory);

            ArrayList     results  = SampleHelper.GetListResults(cmdResult, true);
            List <Branch> branches = GetBranchListFromCmdResult(results);

            List <ReplicationResult> resultList = new List <ReplicationResult>();

            foreach (Branch branch in branches)
            {
                resultList.Add(Replicate(branch, repository, secondRepository));
            }

            Console.WriteLine(Environment.NewLine + "Replication complete");
            PrintReplicationResult(resultList);

            Console.ReadLine();

            SampleHelper.RemoveSampleRepository(repository);
            SampleHelper.RemoveSampleRepository(secondRepository);
        }
示例#5
0
        public string GetLatestBranches()
        {
            string command   = string.Format(FindBranchesCommand, Repository, DateFormat);
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(command, Environment.CurrentDirectory, false);

            return(string.Format("Latest branches on repository `{0}`: \r\n {1}", Repository, cmdResult));
        }
 private static void GenerateBranches(string repServer, int numBranches)
 {
     for (int i = 0; i < numBranches; i++)
     {
         string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
             string.Format("cm mkbranch br:/main/task{0}", i),
             GetWorkspace());
     }
 }
示例#7
0
        internal IList FilterBranches(IList branches, string initialdate)
        {
            string cmd = mCmExec +
                         " find \"changeset where date >= '" + initialdate +
                         "'\" --format={branch} --nototal on repository '" +
                         mSrcServer + "'";

            string cmdres = CmdRunner.ExecuteCommandWithStringResult(cmd, mWkpath);

            StringReader reader = new StringReader(cmdres);

            ArrayList filtered = new ArrayList();

            // there will be many csets on some branches, only take on
            // branch for each

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Trim() == string.Empty)
                {
                    continue;
                }

                line = line.Trim();

                if (!filtered.Contains(line))
                {
                    filtered.Add(line);
                }
            }

            filtered.Sort();

            ArrayList result = new ArrayList();

            foreach (string branchname in filtered)
            {
                // find it on the original list... (it has the id list)
                foreach (Branch br in branches)
                {
                    if (br.Name == branchname)
                    {
                        if (!result.Contains(br))
                        {
                            result.Add(br);
                        }
                        break;
                    }
                }
            }

            result.Sort(new BranchComparer());

            return(result);
        }
        public static void CheckinItem(string fileName, string comment)
        {
            string addResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm add {0}", fileName),
                GetWorkspace());

            string commitResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm ci -c=\"{0}\"", comment),
                GetWorkspace());
        }
        List <Branch> GetBranchesFromRepo(string repository)
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find branch on repositories '{0}' --format={{id}}#{{name}} --nototal", repository),
                Environment.CurrentDirectory);

            ArrayList results = SampleHelper.GetListResults(cmdResult, true);

            return(GetBranchListFromCmdResult(results));
        }
        private static void PrintCmVersion()
        {
            string cmVersion =
                CmdRunner.ExecuteCommandWithStringResult(
                    "cm version",
                    Environment.CurrentDirectory);

            Console.WriteLine(string.Format("The cm version is: {0}", cmVersion));
            Console.WriteLine();
        }
        private static void PrintCmBranches()
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                "cm find branches on repository 'default' --nototal",
                Environment.CurrentDirectory);

            Console.WriteLine("Branches on default repository:");
            PrintResult(cmdResult);
            Console.WriteLine();
        }
        private static void PrintCmRevisionsOnMainBranch()
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                "cm find revision where branch='main' " +
                " --format=\"{item}#{branch}#{changeset}\" on repository 'default' --nototal",
                Environment.CurrentDirectory);

            Console.WriteLine("Revisions on main branch:");
            PrintResult(cmdResult);
            Console.WriteLine();
        }
        private static ReplicationResult Replicate(Branch branch, string repository,
                                                   string secondRepository)
        {
            Console.WriteLine("Replicating branch {0}", branch.Name);

            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm replicate \"br:{0}@{1}\" \"rep:{2}\"",
                              branch.Name, repository, secondRepository),
                Environment.CurrentDirectory);

            return(new ReplicationResult(SampleHelper.GetListResults(cmdResult, true), branch));
        }
        private static void CreateWorkspaceAndSwitchToMain(string repositorySpec,
                                                           string repServer)
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm mkwk {0} .", repositorySpec),
                GetWorkspace());

            Console.WriteLine(string.Format("Workspace created at {0}",
                                            GetWorkspace()));

            cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm stb br:/main@{0}@{1}", repositorySpec,
                              repServer), GetWorkspace());
        }
        public static void RemoveSampleRepository(string repository)
        {
            Console.WriteLine("Removing sample repository {0}. Please confirm: [y/N]", repository);
            string line = Console.ReadLine();

            if (line != "y")
            {
                return;
            }

            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm rmrep {0}", repository),
                Environment.CurrentDirectory);
        }
示例#16
0
        static List <string> GetResolvedBranches(Config config)
        {
            string cmdOutput = CmdRunner.ExecuteCommandWithStringResult(
                string.Format(
                    "cm find \"branch where (name like '{0}%' or name like '{1}%') "
                    + "and attribute='status' and attrvalue='RESOLVED' on repository '{2}'\" "
                    + "--format={{name}} --nototal ",
                    config.PlasticBranchPrefix,
                    config.PlasticBranchPrefix.ToUpperInvariant(),
                    config.PlasticRepo),
                Environment.CurrentDirectory);

            return(new List <string>(cmdOutput.Split(
                                         new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
        }
        private List <Change> GetChanges()
        {
            List <Change> changes   = new List <Change>();
            string        cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm status --all --machinereadable"),
                SampleHelper.GetWorkspace());

            ArrayList results = SampleHelper.GetListResults(cmdResult, true);

            for (int i = 1; i < results.Count; i++)
            {
                changes.Add(new Change((string)results[i]));
            }

            return(changes);
        }
        private void ReloadSavedGames()
        {
            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find changeset on repositories '{0}' --format={{comment}} --nototal",
                              textBox1.Text),
                Environment.CurrentDirectory);

            ArrayList results = SampleHelper.GetListResults(cmdResult, true);

            listBox1.Items.Clear();
            results.RemoveAt(0);
            foreach (string item in results)
            {
                listBox1.Items.Add(new SavedGame(item));
            }
        }
        private static void SomeCommandsInShell()
        {
            string repos = CmdRunner.ExecuteCommandWithStringResult(
                "cm lrep",
                Environment.CurrentDirectory, true);

            string output;
            string error;

            CmdRunner.ExecuteCommandWithResult(
                "cm rmwk .",
                Environment.CurrentDirectory, out output, out error, true);

            Console.WriteLine("The Plastic server has the following repositories: ");
            PrintResult(repos);
            Console.WriteLine(String.Format("The workspace was deleted. Output: {0}. Error: {1} ",
                                            output, error));
        }
        private bool HasChangesInBranch(Branch branch)
        {
            string srcResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find changeset where branch = 'br:{0}' on repositories '{1}' --format={{id}} --nototal",
                              branch.Name, mSampleRep),
                Environment.CurrentDirectory);

            ArrayList srcResults = SampleHelper.GetListResults(srcResult, true);

            string dstResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find changeset where branch = 'br:{0}' on repositories '{1}' --format={{id}} --nototal",
                              branch.Name, mSecondRep),
                Environment.CurrentDirectory);

            ArrayList dstResults = SampleHelper.GetListResults(dstResult, true);

            return(srcResults.Count != dstResults.Count);
        }
        static void Main(string[] args)
        {
            string server    = "localhost:8084";
            string sampleRep = SampleHelper.GenerateRepositoryWithData(server);

            string cmVersion = CmdRunner.ExecuteCommandWithStringResult("cm version",
                                                                        Environment.CurrentDirectory);

            Console.WriteLine(string.Format("The cm version is: {0}", cmVersion));

            string repoList = CmdRunner.ExecuteCommandWithStringResult(string.Format("cm lrep {0}", server),
                                                                       Environment.CurrentDirectory);

            Console.WriteLine(string.Format("{0}", repoList));

            Console.ReadLine();

            SampleHelper.RemoveSampleRepository(server);
        }
        private void CheckinUpdates(object sender, EventArgs e)
        {
            List <Change> mChanges = GetChanges();

            if (mChanges.Count == 0)
            {
                return;
            }

            StringBuilder builder = new StringBuilder();

            foreach (var item in mChanges)
            {
                builder.Append(string.Format("{0} {1}\n",
                                             item.ChangeType, item.Name));
            }

            foreach (var item in mChanges)
            {
                if (item.ChangeType == ChangeType.Added)
                {
                    CmdRunner.ExecuteCommandWithStringResult(
                        string.Format("cm add {0}", item.Name),
                        SampleHelper.GetWorkspace());
                }

                if (item.ChangeType == ChangeType.Deleted)
                {
                    CmdRunner.ExecuteCommandWithStringResult(
                        string.Format("cm rm {0}", item.Name),
                        SampleHelper.GetWorkspace());
                }
            }

            CmdRunner.ExecuteCommandWithStringResult("cm ci ",
                                                     SampleHelper.GetWorkspace());

            mTrayIcon.ShowBalloonTip(3, string.Format("{0} new changes saved", mChanges.Count),
                                     string.Format("The following changes have been checked in.\n{0}",
                                                   builder.ToString()),
                                     ToolTipIcon.Info);
        }
        public static string GenerateEmptyRepository(string repServer)
        {
            string repositorySpec = repositoryName
                                    + Guid.NewGuid().ToString().Substring(0, 7);

            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm mkrep {0}@{1}", repositorySpec, repServer),
                Environment.CurrentDirectory);

            if (cmdResult.IndexOf("Error") == 0)
            {
                throw new Exception(cmdResult);
            }

            Console.WriteLine("Created repository: {0}", repositorySpec);

            CreateWorkspaceAndSwitchToMain(repositorySpec, repServer);

            return(repositorySpec);
        }
        private static void EditRandomItem(Random random)
        {
            string[] files = Directory.GetFiles(GetWorkspace());
            if (files.Length == 0)
            {
                return;
            }

            int    index     = random.Next(files.Length);
            string addResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm co {0}", files[index]),
                GetWorkspace());

            using (StreamWriter sw = new StreamWriter(files[index]))
            {
                sw.WriteLine("Testing " + Guid.NewGuid());
            }

            Console.WriteLine("Edited {0}", files[index]);
        }
示例#25
0
        internal IList GetBranches()
        {
            ArrayList result = new ArrayList();

            try
            {
                string cmdres = CmdRunner.ExecuteCommandWithStringResult(
                    mCmExec + " find branch --format={name}#{id} --nototal " +
                    string.Format("on repository '{0}'", mSrcServer), mWkpath);

                StringReader reader = new StringReader(cmdres);

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Trim() == string.Empty)
                    {
                        continue;
                    }

                    // output will be like /main/SCM5754#2625
                    string[] values = line.Split('#');

                    Branch br = new Branch(values[0], values[1]);
                    result.Add(br);
                }

                result.Sort(new BranchComparer());
            }
            catch (Exception e)
            {
                Console.WriteLine("Error listing branches: " + e.Message);
                mLog.ErrorFormat("Error listing branches:{0} at {1}{2}",
                                 e.Message, Environment.NewLine, e.StackTrace);
                return(null);
            }

            return(result);
        }
        static void Main(string[] args)
        {
            string server     = "localhost:8084";
            string repository = SampleHelper.GenerateRepositoryWithData(server);

            Console.WriteLine("Created repository: {0}", repository);

            string cmdResult = CmdRunner.ExecuteCommandWithStringResult(
                string.Format("cm find branch on repositories '{0}' --format={{id}}#{{name}} --nototal", repository),
                Environment.CurrentDirectory);

            ArrayList     results  = SampleHelper.GetListResults(cmdResult, true);
            List <Branch> branches = GetBranchListFromCmdResult(results);

            foreach (Branch branch in branches)
            {
                Console.WriteLine(branch);
            }

            Console.ReadLine();

            SampleHelper.RemoveSampleRepository(repository);
        }
 private static string ExecuteCommandForOutput(string command)
 {
     return(CmdRunner.ExecuteCommandWithStringResult(command, WorkingDirectory));
 }