Exemplo n.º 1
0
        public void SaveSessionFirstTime()
        {
            // set the value
            using (ISessionState sessionState = sessionStorage.LoadSession("testId"))
            {
                Assert.IsNotNull(sessionState);

                sessionState.SetValue("testvalue", "test");
            }

            // now read it from the session storage
            using (ISessionState sessionState = sessionStorage.LoadSession("testId"))
            {
                Assert.AreEqual("test", sessionState.GetValue <string>("testvalue"));
            }
        }
        public RevisionControlHistoryData FetchHistory()
        {
            // load the previously fetched history from the persistent storage
            using (ISessionState sessionState = sessionStorage.LoadSession(
                       String.Format(
                           CultureInfo.InvariantCulture,
                           "SubversionHistoryFacility_{0}",
                           facilityId)))
            {
                RevisionControlHistoryData lastFetchedHistory
                    = sessionState.GetValue <RevisionControlHistoryData>(SessionKeyLastFetchedHistory);

                // find the last revision that was fetched
                string lastRevisionFetched = null;

                if (lastFetchedHistory != null)
                {
                    lastRevisionFetched = lastFetchedHistory.LastRevision;
                }

                // svn log d:\svn\mobilkom.nl-bhwr\trunk\src -v --xml --non-interactive >D:\BuildArea\builds\mobilkom.nl-bhwr\svn-log.xml
                // -r 1729:HEAD

                using (Process process = new Process())
                {
                    StringBuilder argumentsBuilder = new StringBuilder();
                    argumentsBuilder.AppendFormat(
                        CultureInfo.InvariantCulture,
                        @"log ""{0}"" --xml --non-interactive",
                        svnRootPath);

                    // add revisions range, if we have history data fetched previously
                    if (lastRevisionFetched != null)
                    {
                        int lastRevisionFetchedInt = Int32.Parse(lastRevisionFetched, CultureInfo.InvariantCulture);
                        argumentsBuilder.AppendFormat(
                            CultureInfo.InvariantCulture,
                            " -r {0}:HEAD",
                            lastRevisionFetchedInt + 1);
                    }

                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.FileName  = svnToolPath;
                    process.StartInfo.Arguments = argumentsBuilder.ToString();
                    process.Start();

                    process.WaitForExit();

                    // merge the two histories
                    RevisionControlHistoryData historyData = LoadHistory(process.StandardOutput.BaseStream);
                    if (lastFetchedHistory != null)
                    {
                        historyData.Merge(lastFetchedHistory);
                    }

                    // save the new history to the session state
                    sessionState.SetValue(SessionKeyLastFetchedHistory, historyData);

                    return(historyData);
                }
            }
        }