public void Save(TenantInfo tenantInfo) { try { using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(this.SyncMailboxPrincipal, CultureInfo.InvariantCulture, "Client=UnifiedPolicy;Action=CommitChanges;Interactive=False")) { using (UserConfiguration mailboxConfiguration = UserConfigurationHelper.GetMailboxConfiguration(mailboxSession, "TenantInfoConfigurations", UserConfigurationTypes.Stream, true)) { using (Stream stream = mailboxConfiguration.GetStream()) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(stream, tenantInfo); } mailboxConfiguration.Save(); } } } catch (StoragePermanentException innerException) { throw new SyncAgentPermanentException("TenantInfoProvider.Save failed with StoragePermanentException", innerException); } catch (StorageTransientException innerException2) { throw new SyncAgentTransientException("TenantInfoProvider.Save failed with StorageTransientException", innerException2); } catch (IOException innerException3) { throw new SyncAgentTransientException("TenantInfoProvider.Save failed with IOException", innerException3); } }
internal static void StampCookieCount(FileStream cookieFileStream, int count) { cookieFileStream.Seek(0L, SeekOrigin.Begin); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(cookieFileStream, count); }
internal static void ReadPreCookies(FileStream fs, long offset, int pageSize, LinkedList <CacheFileCookie> cookieList, int capacity) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); CacheFileCookieSerializer.SetOffsetAndPageSize(fs, binaryFormatter, offset, ref pageSize); for (int i = 0; i < pageSize; i++) { long position = fs.Position; if (position == fs.Length) { return; } CacheFileCookie cacheFileCookie = (CacheFileCookie)binaryFormatter.Deserialize(fs); cacheFileCookie.NextCookieOffset = fs.Position; cookieList.AddFirst(cacheFileCookie); if (cookieList.Count > capacity) { cookieList.RemoveLast(); } if (cacheFileCookie.PreCookieOffset < 0L) { return; } fs.Seek(cacheFileCookie.PreCookieOffset, SeekOrigin.Begin); } }
public static LocalizedString SafeDeserialize(byte[] bytes) { if (bytes == null) { return(default(LocalizedString)); } BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(new SafeLocalizedStringSerializer.ValidatingBinder()); object obj; using (MemoryStream memoryStream = new MemoryStream(bytes)) { try { obj = binaryFormatter.Deserialize(memoryStream); } catch (BlockedTypeException ex) { SafeLocalizedStringSerializer.CreateWatson(ex); return(ex.LocalizedString); } } if (!(obj is LocalizedString)) { return(new LocalizedString((obj == null) ? "null" : obj.ToString())); } return((LocalizedString)obj); }
public static object GetSerializationData(PSObject psObject) { ExTraceGlobals.SerializationTracer.TraceFunction <PSObject>(0L, "SerializationTypeConvertor.GetSerializationData({0})", psObject); byte[] result = null; try { using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(memoryStream, psObject.BaseObject); result = memoryStream.ToArray(); } } catch (Exception arg) { ExTraceGlobals.SerializationTracer.TraceDebug <Exception>(0L, "Serialization Failed. Error = {0}", arg); if (psObject != null && psObject.BaseObject != null) { ExWatson.AddExtraData("Object Type: " + psObject.BaseObject.GetType().ToString()); ExWatson.AddExtraData("Object String: " + psObject.BaseObject.ToString()); ExWatson.AddExtraData("Handler StackTrace: " + Environment.StackTrace); } throw; } return(result); }
public static object SafeBinaryFormatterDeserializeWithAllowList(Stream stream, IEnumerable <Type> allowList, SafeSerialization.TypeEncounteredDelegate typeEncounteredCallback = null) { SafeSerialization.ValidatingBinder binder = new SafeSerialization.ValidatingBinder(new SafeSerialization.AllowList(allowList), typeEncounteredCallback); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(binder); return(binaryFormatter.Deserialize(stream)); }
// Token: 0x06001153 RID: 4435 RVA: 0x000653E0 File Offset: 0x000635E0 public void UpdateDiskCache() { this.logger.TraceDebug(this, "Entering NormalizationCache.UpdateDiskCache filePath='{0}', cache.Count='{1}'", new object[] { this.filePath, this.cache.Count }); try { if (this.ShouldUpdateDiskCache()) { using (Stream stream = File.Open(this.filePath, FileMode.Create, FileAccess.Write)) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(stream, this.cache); } this.logger.TraceDebug(this, "NormalizationCache.UpdateDiskCache - Saved cache to filePath='{0}'", new object[] { this.filePath }); this.shouldUploadCache = true; } this.cache.Clear(); this.cache = null; string[] directories = Directory.GetDirectories(this.normalizationCacheFolderPath); foreach (string text in directories) { string fileName = Path.GetFileName(text); if (string.Compare(fileName, this.versionedCacheFolderName, StringComparison.OrdinalIgnoreCase) != 0) { this.logger.TraceDebug(this, "Deleting normalization cache directory '{0}'", new object[] { text }); Directory.Delete(text, true); } } } catch (Exception ex) { this.logger.TraceDebug(this, "NormalizationCache.UpdateDiskCache - Unable to update disk cache filePath='{0}', exception='{1}'", new object[] { this.filePath, ex }); UmGlobals.ExEvent.LogEvent(UMEventLogConstants.Tuple_SaveNormalizationCacheFailed, null, new object[] { this.logger.TenantId, this.filePath, this.culture, CommonUtil.ToEventLogString(ex) }); if (!this.IsExpectedException(ex)) { throw; } } }
// Token: 0x06000058 RID: 88 RVA: 0x0000464C File Offset: 0x0000284C private static object Deserialize(Stream serializationStream, SerializationBinder binder) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(binder, new string[] { "System.DelegateSerializationHolder" }); return(binaryFormatter.Deserialize(serializationStream)); }
internal bool Save(bool onlyMetaData) { bool result; using (UserConfiguration userConfiguration = this.OpenMessage(true)) { if (userConfiguration == null) { TopNConfiguration.Tracer.TraceError <TopNConfiguration>((long)this.GetHashCode(), "{0}: Save() failed because FAI could not be opened or created.", this); result = false; } else { IDictionary dictionary = userConfiguration.GetDictionary(); dictionary["Version"] = this.version; dictionary["LastScanTime"] = this.lastScanTime; if (!this.IsMailboxExtendedPropertySupported()) { dictionary["ScanRequested"] = this.scanRequested; } if (onlyMetaData) { result = this.SaveMessage(userConfiguration); } else { using (Stream stream = userConfiguration.GetStream()) { IFormatter formatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); Exception ex = null; try { formatter.Serialize(stream, this.wordFrequency); } catch (ArgumentNullException ex2) { ex = ex2; } catch (SerializationException ex3) { ex = ex3; } if (ex != null) { TopNConfiguration.Tracer.TraceError <TopNConfiguration, Exception>((long)this.GetHashCode(), "{0}: Failed to serialize word frequency data. Exception: {1}", this, ex); return(false); } } result = this.SaveMessage(userConfiguration); } } } return(result); }
public static T ObjectFromBytes <T>(byte[] data) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); T result; using (MemoryStream memoryStream = new MemoryStream(data, false)) { result = (T)((object)binaryFormatter.Deserialize(memoryStream)); } return(result); }
public static DarTaskResult GetResultObject(byte[] data) { ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); DarTaskResult darTaskResult = DarTaskResult.ObjectFromBytes <DarTaskResult>(data); if (darTaskResult.LocalizedError != null) { throw new DataSourceOperationException(new LocalizedString(darTaskResult.LocalizedError)); } return(darTaskResult); }
internal void Write(EventBookmark bookmark) { this.OpenKeyIfRequired(); MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(memoryStream, bookmark); if (this.m_regKey != null) { this.m_regKey.SetValue(Bookmarker.valueName, memoryStream.GetBuffer()); } }
public override byte[] GetBytes() { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); Stream stream = new MemoryStream(); binaryFormatter.Serialize(stream, this.RegistryKeyPath); binaryFormatter.Serialize(stream, this.Name); byte[] array = new byte[stream.Length]; stream.Read(array, 0, (int)stream.Length); stream.Close(); return(array); }
public static byte[] ObjectToBytes <T>(T obj) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); byte[] buffer; using (MemoryStream memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, obj); buffer = memoryStream.GetBuffer(); } return(buffer); }
public object Clone() { object result; using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(memoryStream, this); memoryStream.Position = 0L; result = binaryFormatter.Deserialize(memoryStream); } return(result); }
public byte[] ToBytes() { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); byte[] result; using (MemoryStream memoryStream = new MemoryStream(2048)) { binaryFormatter.Serialize(memoryStream, this); byte[] array = memoryStream.ToArray(); result = array; } return(result); }
internal static void WriteCookieToFile(FileStream cookieFileStream, CacheFileCookie cookie, CacheFileCookie preCookie) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); if (cookieFileStream.Length == 0L) { binaryFormatter.Serialize(cookieFileStream, 0); } cookie.PreCookieOffset = preCookie.CookieOffset; cookie.CookieOffset = cookieFileStream.Position; binaryFormatter.Serialize(cookieFileStream, cookie); cookieFileStream.SetLength(cookieFileStream.Position); }
private byte[] SerializeObjectBinary(object value) { if (value == null) { return(null); } BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(this.HelperStream, value); byte[] array = new byte[this.HelperStream.Length]; Array.Copy(this.HelperStream.GetBuffer(), array, array.Length); this.ResetHelperStream(); return(array); }
public static byte[] Serialize(object data) { if (data == null) { return(null); } byte[] result; using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(memoryStream, data); result = memoryStream.ToArray(); } return(result); }
internal static object DeserializeFromBinary(byte[] input) { if (input == null || input.Length == 0) { return(null); } BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); object result; using (MemoryStream memoryStream = new MemoryStream(input)) { result = binaryFormatter.Deserialize(memoryStream); } return(result); }
public string ToBase64() { string result; using (MemoryStream memoryStream = new MemoryStream()) { using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(gzipStream, this); } result = Convert.ToBase64String(memoryStream.ToArray()); } return(result); }
private static byte[] SerializeObject(object inputObject) { if (inputObject != null) { byte[] result = null; using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); binaryFormatter.Serialize(memoryStream, inputObject); result = memoryStream.ToArray(); } return(result); } return(null); }
public static object BytesToObject(byte[] mBinaryData) { if (mBinaryData == null || mBinaryData.Length == 0) { return(null); } BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); object result; using (MemoryStream memoryStream = new MemoryStream(mBinaryData, false)) { result = binaryFormatter.Deserialize(memoryStream); } return(result); }
internal static byte[] SerializeToBinary(object input) { if (input == null) { return(null); } BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); byte[] result; using (MemoryStream memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, input); result = memoryStream.ToArray(); } return(result); }
public TenantInfo Load() { TenantInfo result; try { using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(this.SyncMailboxPrincipal, CultureInfo.InvariantCulture, "Client=UnifiedPolicy;Action=CommitChanges;Interactive=False")) { using (UserConfiguration mailboxConfiguration = UserConfigurationHelper.GetMailboxConfiguration(mailboxSession, "TenantInfoConfigurations", UserConfigurationTypes.Stream, false)) { if (mailboxConfiguration == null) { result = null; } else { using (Stream stream = mailboxConfiguration.GetStream()) { if (stream == null || stream.Length == 0L) { result = null; } else { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); TenantInfo tenantInfo = (TenantInfo)binaryFormatter.Deserialize(stream); result = tenantInfo; } } } } } } catch (StoragePermanentException innerException) { throw new SyncAgentPermanentException("TenantInfoProvider.Load failed with StoragePermanentException", innerException); } catch (StorageTransientException innerException2) { throw new SyncAgentTransientException("TenantInfoProvider.Load failed with StorageTransientException", innerException2); } catch (IOException innerException3) { throw new SyncAgentTransientException("TenantInfoProvider.Load failed with IOException", innerException3); } return(result); }
public static object DeSerialize(byte[] data) { object result = null; if (data != null) { using (MemoryStream memoryStream = new MemoryStream(data)) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null, new string[] { "System.DelegateSerializationHolder" }); result = binaryFormatter.Deserialize(memoryStream); } } return(result); }
internal EventBookmark Read() { this.OpenKeyIfRequired(); EventBookmark result = null; if (this.m_regKey != null) { byte[] array = (byte[])this.m_regKey.GetValue(Bookmarker.valueName); if (array != null) { MemoryStream serializationStream = new MemoryStream(array); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); result = (EventBookmark)binaryFormatter.Deserialize(serializationStream); } } return(result); }
public static ImageInfo FromBase64(string base64) { if (base64 == null) { throw new ArgumentNullException("base64"); } ImageInfo result; using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(base64))) { using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); result = (ImageInfo)binaryFormatter.Deserialize(gzipStream); } } return(result); }
private static bool IsSafeBinaryFormatterStreamCommon(SafeSerialization.ValidatingBinder binder, Stream serializationStream) { long position = serializationStream.Position; BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(binder); try { binaryFormatter.Deserialize(serializationStream); } catch (SafeSerialization.BlockedTypeException) { return(false); } finally { serializationStream.Seek(position, SeekOrigin.Begin); } return(true); }
internal static LinkedList <CacheFileCookie> ReadCookieList(FileStream fs, long offset, int pageSize) { LinkedList <CacheFileCookie> linkedList = new LinkedList <CacheFileCookie>(); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); CacheFileCookieSerializer.SetOffsetAndPageSize(fs, binaryFormatter, offset, ref pageSize); for (int i = 0; i < pageSize; i++) { long position = fs.Position; if (position == fs.Length) { break; } CacheFileCookie cacheFileCookie = (CacheFileCookie)binaryFormatter.Deserialize(fs); cacheFileCookie.NextCookieOffset = fs.Position; linkedList.AddLast(cacheFileCookie); } return(linkedList); }