/// <summary> /// Called by the shell if the _strSolutionUserOptionsKey section declared in LoadUserOptions() as /// being written by this package has been found in the suo file /// </summary> public int ReadUserOptions(IStream pOptionsStream, 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 OnAfterOpenSolution 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 hashSpiraUserData = new Hashtable(); if (pStream.Length > 0) { BinaryFormatter formatter = new BinaryFormatter(); hashSpiraUserData = formatter.Deserialize(pStream) as Hashtable; if (hashSpiraUserData.ContainsKey("spiraLogin")) { SpiraContext.Login = (string)hashSpiraUserData["spiraLogin"]; } if (hashSpiraUserData.ContainsKey("spiraPassword")) { SpiraContext.Password = (string)hashSpiraUserData["spiraPassword"]; } } return(VSConstants.S_OK); }
public int ReadUserOptions(IStream pOptionsStream, string pszKey) { if (pszKey == SettingsKey) { try { using (var pStream = new DataStreamFromComStream(pOptionsStream)) if (pStream != null && pStream.CanRead) { using (var ms = new MemoryStream()) { byte[] data = new byte[pStream.Length]; pStream.Read(data, 0, data.Length); ms.Write(data, 0, data.Length); ms.Seek(0, SeekOrigin.Begin); var strValue = Encoding.ASCII.GetString(data); var msSqlConnectionSettings = JsonConvert.DeserializeObject <MsSqlDatabaseConnectionSettings>(strValue); if (msSqlConnectionSettings != null) { SettingsStore.SetInstance(msSqlConnectionSettings); } } } } catch (Exception ex) { // TODO: log exception } } return(VSConstants.S_OK); }
/// <summary> /// Called by the shell to let the package write user options under the specified key. /// </summary> public int WriteUserOptions(IStream pOptionsStream, 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"); //Add the Spira settings to the hashtable Hashtable hashSpiraUserData = new Hashtable(); if (!String.IsNullOrEmpty(SpiraContext.Login) && !String.IsNullOrEmpty(SpiraContext.Password)) { hashSpiraUserData["spiraLogin"] = SpiraContext.Login; hashSpiraUserData["spiraPassword"] = SpiraContext.Password; // 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, hashSpiraUserData); } return(VSConstants.S_OK); }
public int WriteUserOptions(IStream pOptionsStream, string pszKey) { if (pszKey == SettingsKey) { try { using (var pStream = new DataStreamFromComStream(pOptionsStream)) if (pStream != null && pStream.CanWrite) { using (var ms = new MemoryStream()) { var strValue = JsonConvert.SerializeObject(SettingsStore.Instance.MsSqlDatabaseConnectionSettings); var data = Encoding.ASCII.GetBytes(strValue); pStream.Write(data, 0, data.Length); pStream.Flush(); } } } catch (Exception ex) { // TODO: log exception } } return(VSConstants.S_OK); }
public void Write_DoesNotThrowCountZeroOrLess(int bufferSize, int index, int count) { // The mock should never be called in outlier cases var comStreamMock = new Mock <Ole32.IStream>(MockBehavior.Strict); var dataStream = new DataStreamFromComStream(comStreamMock.Object); dataStream.Write(new byte[bufferSize], index, count); }
public void Write_ThrowsInvalidCount(int bufferSize, int index, int count) { // The mock should never be called in outlier cases var comStreamMock = new Mock <Ole32.IStream>(MockBehavior.Strict); var dataStream = new DataStreamFromComStream(comStreamMock.Object); Assert.Throws <IOException>(() => dataStream.Write(new byte[bufferSize], index, count)); }
public void Save(Microsoft.VisualStudio.OLE.Interop.IStream pOptionsStream) { DataStreamFromComStream pStream = new DataStreamFromComStream(pOptionsStream); BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new AllowAllAssemblyVersionsDeserializationBinder(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;//!!! while develop !!! formatter.Serialize(pStream, new CPPropsDeSerializator()); }
public void SetPropsStream(Microsoft.VisualStudio.OLE.Interop.IStream _propsStream) { DataStreamFromComStream pStream = new DataStreamFromComStream(_propsStream); if (propsStream != null) { propsStream = null; } propsStream = new MemoryStream(); pStream.CopyTo(propsStream); }
private int _WriteUserOptions(IStream pOptionsStream, string pszKey) { if (pszKey != persistenceKey) { throw new InvalidOperationException("SuperBookmarks: WriteUserOptions was called for unknown key " + pszKey); } var info = this.BookmarksManager.GetSerializableInfo(); var stream = new DataStreamFromComStream(pOptionsStream); info.SerializeTo(stream, prettyPrint: false); return(VSConstants.S_OK); }
public int WriteUserOptions(IStream pOptionsStream, string pszKey) { try { using (var stream = new DataStreamFromComStream(pOptionsStream)) { using (var weiter = new StreamWriter(stream, Encoding.UTF8)) { weiter.Write(JsonConvert.SerializeObject(mData)); } } } catch { } return(VSConstants.S_OK); }
public int ReadUserOptions(IStream pOptionsStream, string pszKey) { try { using (var stream = new DataStreamFromComStream(pOptionsStream)) { using (var reader = new StreamReader(stream, Encoding.UTF8, false)) { var str = reader.ReadToEnd(); mData = JsonConvert.DeserializeObject <Data>(str); foreach (var p in typeof(UserOptions).GetProperties().Where(x => x.MemberType == System.Reflection.MemberTypes.Property)) { RaisePropertyChanged(p.Name); } } } } catch { } return(VSConstants.S_OK); }
private int _ReadUserOptions(IStream pOptionsStream, string pszKey) { if (pszKey != persistenceKey) { throw new InvalidOperationException("SuperBookmarks: ReadUserOptions was called for unknown key " + pszKey); } var stream = new DataStreamFromComStream(pOptionsStream); SerializableBookmarksInfo info; try { info = SerializableBookmarksInfo.DeserializeFrom(stream); } catch { Helpers.ShowErrorMessage("Sorry, I couldn't parse the bookmarks information from the .suo file", showHeader: false); return(VSConstants.S_OK); } this.BookmarksManager.RecreateBookmarksFromSerializedInfo(info); Helpers.WriteToStatusBar($"Restored {Helpers.Quantifier(info.TotalBookmarksCount, "bookmark")} for {Helpers.Quantifier(info.TotalFilesCount, "file")} from .suo file"); return(VSConstants.S_OK); }