Esempio n. 1
0
 /// <summary>
 /// Syncs file pattern and throws an exception with appropriate code if the sync was not entirely successful.
 /// </summary>
 /// <param name="sdIni">Location of sd.ini file to use when syncing.</param>
 /// <param name="filePattern">Specifies the sync file pattern. For example: "pl-pl...lcl".</param>
 /// <param name="language">Language that is being synced.</param>
 /// <exception cref="IncorrectSDStateException">Thrown when sync for this language could not be completed.</exception>
 protected void SyncFilePattern(string sdIni, string filePattern, string language)
 {
     using (SourceDepot depot = new SourceDepot(sdIni))
     {
         CurrentRetryAttempt = 1;
         SuccessfulSync      = false;
         Console.WriteLine("Syncing language: {0}", language);
         CheckPreconditionThatNoFilesAreOpened(depot, filePattern); //Will throw exception if this precondition fails.
         while (!SuccessfulSync && (CurrentRetryAttempt <= RetryCount))
         {
             try
             {
                 var results = SyncDepot(depot, CurrentRetryAttempt, filePattern);
                 AnalyseSdSyncResults(results, language); //This will throw exception if necessary and pass control outside of the 'while' and 'using' blocks.
             }
             catch (SourceDepotException e)
             {
                 Console.WriteLine("Error connecting to source depot:");
                 Console.WriteLine(e.Message);
                 Console.WriteLine();
             }
             CurrentRetryAttempt++;
         }
         if (!SuccessfulSync)
         {
             Console.WriteLine("Failed to sync {0}. Giving up.", language);
             throw new IncorrectSDStateException("SyncFilePattern")
                   {
                       ProblemCode = ExecutionResult.FailedSync
                   };
         }
     }
 }
Esempio n. 2
0
        public void TestSyncingEditedFile()
        {
            #region Setting the reference file into 'edited' state
            using (SourceDepot store = new SourceDepot(SDIniLocation))
            {
                var cdResults = store.GetChangeList("Test change");
                TestContext.WriteLine("Created changelist: {0}", cdResults);

                TestContext.WriteLine("Editing file...");
                var editResults = store.Edit(FilePattern);
                DumpResults(editResults);

                var context = new SDInterface(new[] { "-core", "pl-pl" });
                var retVal  = context.Execute();
                Assert.AreEqual(ExecutionResult.BadEnlistmentStateFilesOpened, retVal);


                TestContext.WriteLine("Deleting test change list...");
                var revertResults = store.RevertA();
                DumpResults(revertResults);
                var delCdResults = store.DeleteChangeList();
                DumpResults(delCdResults);
            }
            #endregion
        }
Esempio n. 3
0
        public void SyncTestFile()
        {
            SDIniLocation = Environment.ExpandEnvironmentVariables(@"%SRCROOT%\..\sd.ini");
            var SDRootDirectory = Environment.GetEnvironmentVariable("SRCROOT");
            var language        = "pl-pl";

            FilePattern = string.Format(@"{0}\intl\word\{1}\main_dll\bibform.xml.lcl", SDRootDirectory, language);
            using (SourceDepot store = new SourceDepot(SDIniLocation))
            {
                DumpResults = r =>
                {
                    TestContext.WriteLine(r.ResultType.ToString());
                    foreach (SDCommandOutput x in r.Outputs)
                    {
                        TestContext.WriteLine(x.Message);
                    }
                };
                TestContext.WriteLine("Reverting...");
                var revertResults = store.Revert(FilePattern);
                DumpResults(revertResults);
                TestContext.WriteLine("Forced syncing...");
                var results = store.ForceSync(FilePattern);
                DumpResults(results);
                TestContext.WriteLine("Reference file {0} is now hot-synced.", FilePattern);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This method tries to execute sd label -o bld14_xxxx_1000
        /// where xxxx is the <see cref="CheckPoint"/> number.
        /// <para/>It outputs the following:<para/>
        /// <example>
        /// # A Source Depot Label Specification.
        /// #
        /// #  Label:       The label name.
        /// #  Update:      The date this specification was last modified.
        /// #  Access:      The date of the last 'labelsync' on this label.
        /// #  Owner:       The user who created this label.
        /// #  Description: A short description of the label (optional).
        /// #  Options:     Label update options: locked or unlocked.
        /// #  View:        Lines to select depot files for the label.
        /// #
        /// # Use 'sd help label' to see more about label views.
        ///
        /// Label:  bld14_4229_1000
        ///
        /// Update: 2009/07/02 23:15:05
        ///
        /// Access: 2009/07/08 08:52:54
        ///
        /// Owner:  REDMOND\y-arnold
        ///
        /// Description:
        ///         Office14 Build 4229.1000
        ///        ovintegrate=-l bld14_4229_1000 -d 3107333 -s 3107337 -e 3135268 -u ""
        ///        Status: complete
        ///
        /// Options:        locked
        ///
        /// View:
        ///         //depot/dev14lab3/...
        ///        -//depot/dev14lab3/otools/inc/otools/hotsync.txt
        /// </example>
        ///
        /// <para/>From the output it retrieves the first line of view description to find dev14lab{x} branch name.
        /// <para/>If branch name is found, it attempts to sync the file pattern on branch using this file pattern:
        /// <para/>sd sync -b {2} {0}\intl_...{1}\...lct@{3}
        /// <para/> where {2} is branch name,
        /// <para/>       {3} is label name calculated from checkpoint number.
        /// <para/>       {0} is SD root directory
        /// <para/>       {1} is language name (ll-cc).
        /// </summary>
        /// <param name="iniLocation">Where source depot ini file is located.</param>
        /// <exception cref="IncorrectSDStateException">Thrown when branch information could not be found.</exception>
        private void FindBranchInformation(string iniLocation)
        {
            using (var depot = new SourceDepot(iniLocation))
            {
                LabelName = string.Format("bld14_{0}_1000", CheckpointNumber);
                var results = depot.LabelDescription(LabelName);
                var output  = results.GetMessages();

                #region State machine that scans the label description
                var machine = LabelStateMachine.ExpectingViewLine;

                foreach (var line in output)
                {
                    switch (machine)
                    {
                    case LabelStateMachine.ExpectingViewLine:
                        if (Regex.IsMatch(line, "^View:"))
                        {
                            machine = LabelStateMachine.LineWithBranch;
                        }
                        break;

                    case LabelStateMachine.LineWithBranch:
                        var match = Regex.Match(line, "//depot/(?<branch>.+)/[.]{3}", RegexOptions.ExplicitCapture);
                        if (match.Success)
                        {
                            BranchName = match.Groups["branch"].Value;
                        }
                        else
                        {
                            throw new IncorrectSDStateException("No branch available")
                                  {
                                      ProblemCode = ExecutionResult.FailedSyncLabelNotPresent
                                  };
                        }
                        machine = LabelStateMachine.IgnoreRemainingLines;
                        break;

                    case LabelStateMachine.IgnoreRemainingLines: break;     //Do nothing.
                    }
                }

                if (machine != LabelStateMachine.IgnoreRemainingLines)
                {
                    throw new IncorrectSDStateException("Branch information not found")
                          {
                              ProblemCode = ExecutionResult.FailedSyncLabelNotPresent
                          };
                }
                if (string.IsNullOrEmpty(BranchName))
                {
                    throw new IncorrectSDStateException("Branch information not located")
                          {
                              ProblemCode = ExecutionResult.FailedSyncLabelNotPresent
                          };
                }
                #endregion
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Uses normal sync or forced sync (depending on retry attempt) to the appropriate depot.
        /// </summary>
        /// <param name="depot">Depot to synchronize</param>
        /// <param name="retryNumber">Number of the current retry. If it is 1, normal sync is used. If it is greater than 1, uses forced sync.</param>
        /// <param name="filePattern">Pattern of files to sync.</param>
        /// <param name="branchName">Branch on which to synchronize the files.</param>
        /// <returns>Command results.</returns>
        protected static SourceDepotCommandResult SyncDepotToBranch(SourceDepot depot, string branchName, int retryNumber, string filePattern)
        {
            Console.WriteLine("Attempt {0}...", retryNumber);

            SourceDepotCommandResult results = null;

            if (retryNumber == 1)
            {
                results = depot.Sync(filePattern, branchName);
            }
            else
            {
                results = depot.ForceSync(filePattern, branchName);
            }
            return(results);
        }
Esempio n. 6
0
        /// <summary>
        /// Checks a precondition that there are no open files in the specified file pattern.
        /// </summary>
        /// <param name="depot">Source depot where pattern is to be searched for open files.</param>
        /// <param name="filePattern">Pattern of files we want to ensure that are not opened.</param>
        /// <exception cref="FilesOpenedException">Thrown when files are actually opened in the specified pattern.</exception>
        /// <exception cref="IncorrectSDStateException">Thrown when network connectivity is lost.</exception>
        protected void CheckPreconditionThatNoFilesAreOpened(SourceDepot depot, string filePattern)
        {
            bool okToExit = false; //When set to true, the inner loop can break and we can return to the caller.

            Enumerable.Range(1, 3) //3 retries maximum
            .ToList().ForEach((retry) =>
            {
                try
                {
                    if (!okToExit)
                    {
                        if (retry != 1)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Retrying({0})...", retry);
                            Thread.Sleep(2000);
                        }

                        var opened = depot.Opened(filePattern);
                        if (opened.ResultType == SourceDepotCommandResultType.Infos)
                        {
                            if (opened.GetMessages().Count != 0)
                            {
                                Console.WriteLine("Error: Some files are opened in this file pattern: {0}", filePattern);
                                Console.WriteLine("This tool requires that all files in enlistment be unmodified.");
                                throw new FilesOpenedException();
                            }
                        }
                        okToExit = true; //Successful operation
                    }
                }
                catch (SourceDepotException e) //Thrown when network connectivity is lost
                {
                    Console.WriteLine("Error connecting to source depot:");
                    Console.WriteLine(e.Message);
                }
            });

            if (!okToExit) //Unable to successfully connect to source depot
            {
                throw new IncorrectSDStateException {
                          ProblemCode = ExecutionResult.BadEnlistmentStateConnectionFailed
                };
            }
        }