Пример #1
0
        // IVsPersistSolutionProps::WriteUserOptions
        public int WriteUserOptions([In] IStream pOptionsStream, [In] string pszKey)
        {
            // This function gets called by the shell to let the package write user options under the specified key.
            // The key was declared in SaveUserOptions(), when the shell started saving the suo file.
            Debug.Assert(pszKey.CompareTo(_strSolutionUserOptionsKey) == 0, "The shell called to read an key that doesn't belong to this package");

            Hashtable hashProjectsUserData = new Hashtable();

            if ((SccService != null) && (SccService.ScmProvider != null))
            {
                hashProjectsUserData["Connect_State"]     = SccService.ScmProvider.Connected ? "Connected" : null;
                hashProjectsUserData["Connect_Port"]      = SccService.ScmProvider.Connection.Port;
                hashProjectsUserData["Connect_User"]      = SccService.ScmProvider.Connection.User;
                hashProjectsUserData["Connect_Workspace"] = SccService.ScmProvider.Connection.Workspace;
            }
            // The easiest way to read/write the data of interest is by using a binary formatter class
            // This way, we can write a map of information about projects with one call
            // (each element in the map needs to be serializable though)
            // The alternative is to write binary data in any byte format you'd like using pOptionsStream.Write
            DataStreamFromComStream pStream   = new DataStreamFromComStream(pOptionsStream);
            BinaryFormatter         formatter = new BinaryFormatter();

            formatter.Serialize(pStream, hashProjectsUserData);

            return(VSConstants.S_OK);
        }
Пример #2
0
        // IVsPersistSolutionProps::ReadUserOptions
        public int ReadUserOptions([In] IStream pOptionsStream, [In] string pszKey)
        {
            // This function is called by the shell if the _strSolutionUserOptionsKey section declared
            // in LoadUserOptions() as being written by this package has been found in the suo file.
            // Note this can be during opening a new solution, or may be during merging of 2 solutions.
            // A good source control provider may need to persist this data until OnIVsSccProject2ution or OnAfterMergeSolution is called

            // The easiest way to read/write the data of interest is by using a binary formatter class
            DataStreamFromComStream pStream = new DataStreamFromComStream(pOptionsStream);
            Hashtable hashProjectsUserData  = new Hashtable();

            if (pStream.Length > 0)
            {
                BinaryFormatter formatter = new BinaryFormatter();
                hashProjectsUserData = formatter.Deserialize(pStream) as Hashtable;
            }

            string port      = null;
            string user      = null;
            string workspace = null;

            if (hashProjectsUserData != null && (hashProjectsUserData.ContainsKey("Connect_State") && (hashProjectsUserData["Connect_State"] != null)))
            {
                if (hashProjectsUserData.ContainsKey("Connect_Port"))
                {
                    port = hashProjectsUserData["Connect_Port"] as string;
                }
                if (hashProjectsUserData.ContainsKey("Connect_User"))
                {
                    user = hashProjectsUserData["Connect_User"] as string;
                }
                if (hashProjectsUserData.ContainsKey("Connect_Workspace"))
                {
                    workspace = hashProjectsUserData["Connect_Workspace"] as string;
                }
                if (string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation))
                {
                    SccService.LoadingControlledSolutionLocation = port;
                }
            }

            ConnectToScm(port, user, workspace);

            return(VSConstants.S_OK);
        }