Ejemplo n.º 1
0
        public void AddFilesToStorageTest()
        {
            string projectFile = Path.GetTempFileName();
            string storageFile = projectFile + ".storage";
            if (File.Exists(storageFile))
            {
                File.Delete(storageFile);
            }

            SccProviderStorage target = new SccProviderStorage(projectFile);

            IList<string> files = new List<string>();
            files.Add(projectFile);
            files.Add("dummy.txt");
            target.AddFilesToStorage(files);
            // Test that project file is now controlled
            Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(projectFile), "Failed to add the project file");
            // Test the storage file was written
            Assert.IsTrue(File.Exists(storageFile), "Storage file was not created");

            // Cleanup the files written by the test
            File.SetAttributes(projectFile, FileAttributes.Normal);
            File.Delete(projectFile);
            File.Delete(storageFile);
        }
Ejemplo n.º 2
0
        public void CheckinCheckoutFileTest()
        {
            string projectFile = Path.GetTempFileName();
            SccProviderStorage target = new SccProviderStorage(projectFile);

            target.CheckinFile(projectFile);
            // Test the file is readonly
            Assert.AreEqual(File.GetAttributes(projectFile) & FileAttributes.ReadOnly, FileAttributes.ReadOnly, "Checkin failed");

            // Cleanup the files written by the test
            File.SetAttributes(projectFile, FileAttributes.Normal);
            File.Delete(projectFile);
        }
        /// <summary>
        /// One of the most important methods in a source control provider, is called by projects that are under source control when they are first opened to register project settings
        /// </summary>
        public int RegisterSccProject([InAttribute] IVsSccProject2 pscp2Project, [InAttribute] string pszSccProjectName, [InAttribute] string pszSccAuxPath, [InAttribute] string pszSccLocalPath, [InAttribute] string pszProvider)
        {
            if (pszProvider.CompareTo(_sccProvider.ProviderName)!=0)
            {
                // If the provider name controlling this project is not our provider, the user may be adding to a 
                // solution controlled by this provider an existing project controlled by some other provider.
                // We'll deny the registration with scc in such case.
                return VSConstants.E_FAIL;
            }

            if (pscp2Project == null)
            {
                // Manual registration with source control of the solution, from OnAfterOpenSolution
                Debug.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Solution {0} is registering with source control - {1}, {2}, {3}, {4}", _sccProvider.GetSolutionFileName(), pszSccProjectName, pszSccAuxPath, pszSccLocalPath, pszProvider));

                IVsHierarchy solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
                string solutionFile = _sccProvider.GetSolutionFileName();
                SccProviderStorage storage = new SccProviderStorage(solutionFile);
                _controlledProjects[solHier] = storage;
            }
            else
            {
                Debug.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Project {0} is registering with source control - {1}, {2}, {3}, {4}", _sccProvider.GetProjectFileName(pscp2Project), pszSccProjectName, pszSccAuxPath, pszSccLocalPath, pszProvider));

                // Add the project to the list of controlled projects
                IVsHierarchy hierProject = (IVsHierarchy)pscp2Project;
                SccProviderStorage storage = new SccProviderStorage(_sccProvider.GetProjectFileName(pscp2Project));
                _controlledProjects[hierProject] = storage;
            }

            return VSConstants.S_OK;
        }
        /// <summary>
        /// Adds the specified projects and solution to source control
        /// </summary>
        public void AddProjectsToSourceControl(ref Hashtable hashUncontrolledProjects, bool addSolutionToSourceControl)
        {
            // A real source control provider will ask the user for a location where the projects will be controlled
            // From the user input it should create up to 4 strings that will pass them to the projects to persist, 
            // so next time the project is open from disk, it will callback source control package, and the package
            // could use the 4 binding strings to identify the correct database location of the project files.
            foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys)
            {
                IVsSccProject2 sccProject2 = (IVsSccProject2)pHier;
                sccProject2.SetSccLocation("<Project Location In Database>", "<Source Control Database>", "<Local Binding Root of Project>", _sccProvider.ProviderName);

                // Add the newly controlled projects now to the list of controlled projects in this solution
                _controlledProjects[pHier] = null;
            }

            // Also, if the solution was selected to be added to scc, write in the solution properties the controlled status
            if (addSolutionToSourceControl)
            {
                IVsHierarchy solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
                _controlledProjects[solHier] = null;
                _sccProvider.SolutionHasDirtyProps = true;
            }

            // Now save all the modified files
            IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution));
            sol.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, null, 0);

            // Add now the solution and project files to the source control database
            // which in our case means creating a text file containing the list of controlled files
            foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys)
            {
                IVsSccProject2 sccProject2 = (IVsSccProject2)pHier;
                IList<string> files = _sccProvider.GetProjectFiles(sccProject2);
                SccProviderStorage storage = new SccProviderStorage(_sccProvider.GetProjectFileName(sccProject2));
                storage.AddFilesToStorage(files);
                _controlledProjects[pHier] = storage;
            }

            // If adding solution to source control, create a storage for the solution, too
            if (addSolutionToSourceControl)
            {
                IVsHierarchy solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
                IList<string> files = new List<string>();
                string solutionFile = _sccProvider.GetSolutionFileName();
                files.Add(solutionFile);
                SccProviderStorage storage = new SccProviderStorage(solutionFile);
                storage.AddFilesToStorage(files);
                _controlledProjects[solHier] = storage;
            }

            // For all the projects added to source control, refresh their source control glyphs
            IList<VSITEMSELECTION> nodes = new List<VSITEMSELECTION>();
            foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys)
            {
                VSITEMSELECTION vsItem;
                vsItem.itemid = VSConstants.VSITEMID_ROOT;
                vsItem.pHier = pHier;
                nodes.Add(vsItem);
            }

            // Also, add the solution if necessary to the list of glyphs to refresh
            if (addSolutionToSourceControl)
            {
                VSITEMSELECTION vsItem;
                vsItem.itemid = VSConstants.VSITEMID_ROOT;
                vsItem.pHier = null;
                nodes.Add(vsItem);
            }

            _sccProvider.RefreshNodesGlyphs(nodes);
        }
Ejemplo n.º 5
0
        public void RenameFileInStorageTest()
        {
            string projectFile = Path.GetTempFileName();
            string storageFile = projectFile + ".storage";
            string newStorageFile = "dummy.txt.storage";
            if (File.Exists(storageFile))
            {
                File.Delete(storageFile);
            }
            if (File.Exists(newStorageFile))
            {
                File.Delete(newStorageFile);
            }

            SccProviderStorage target = new SccProviderStorage(projectFile);

            IList<string> files = new List<string>();
            files.Add(projectFile);
            target.AddFilesToStorage(files);
            target.RenameFileInStorage(projectFile, "dummy.txt");
            // Test that project file is now uncontrolled
            Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(projectFile), "GetFileStatus failed for old name");
            // Test that dummy file is now controlled (and checked in since it's missing from disk)
            Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus("Dummy.txt"), "GetFileStatus failed for new name");

            // Cleanup the files written by the test
            File.SetAttributes(projectFile, FileAttributes.Normal);
            File.Delete(projectFile);
            File.Delete(newStorageFile);
        }
Ejemplo n.º 6
0
        public void ReadStorageFileTest()
        {
            string projectFile = Path.GetTempFileName();
            string storageFile = projectFile + ".storage";
            if (File.Exists(storageFile))
            {
                File.Delete(storageFile);
            }

            StreamWriter objWriter = new StreamWriter(storageFile, false, System.Text.Encoding.Unicode);
            objWriter.Write("dummy.txt\r\n");
            objWriter.Close();
            objWriter.Dispose();

            SccProviderStorage target = new SccProviderStorage(projectFile);
            // Test that dummy file is now controlled (and checked in since it's missing from disk)
            Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus("Dummy.txt"), "GetFileStatus failed for new name");

            // Cleanup the files written by the test
            File.SetAttributes(projectFile, FileAttributes.Normal);
            File.Delete(projectFile);
            File.Delete(storageFile);
        }
Ejemplo n.º 7
0
        public void GetFileStatusTest()
        {
            string projectFile = Path.GetTempFileName();
            string storageFile = projectFile + ".storage";
            if (File.Exists(storageFile))
            {
                File.Delete(storageFile);
            }

            SccProviderStorage target = new SccProviderStorage(projectFile);

            IList<string> files = new List<string>();
            files.Add(projectFile);
            target.AddFilesToStorage(files);
            // Test that project file is now controlled
            Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(projectFile), "GetFileStatus failed for project file");
            // Checkout the file and test status again
            target.CheckoutFile(projectFile);
            Assert.AreEqual(SourceControlStatus.scsCheckedOut, target.GetFileStatus(projectFile), "GetFileStatus failed for project file");
            // Test that a dummy file is uncontrolled
            Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus("Dummy.txt"), "GetFileStatus failed for uncontrolled file");

            // Cleanup the files written by the test
            File.Delete(projectFile);
            File.Delete(storageFile);
        }
Ejemplo n.º 8
0
 public void ConstructorTest()
 {
     SccProviderStorage target = new SccProviderStorage("Dummy.txt");
     Assert.IsNotNull(target, "SccProviderStorage cannot be created");
 }