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);
     }
 }
示例#2
0
        internal static void StampCookieCount(FileStream cookieFileStream, int count)
        {
            cookieFileStream.Seek(0L, SeekOrigin.Begin);
            BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null);

            binaryFormatter.Serialize(cookieFileStream, count);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
        }
示例#5
0
 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));
        }
示例#7
0
 // 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));
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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());
            }
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
 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);
        }
示例#21
0
        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);
        }
示例#22
0
 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);
 }
示例#23
0
        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);
        }
示例#26
0
        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);
        }
示例#27
0
        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);
        }
示例#28
0
        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);
        }
示例#29
0
        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);
        }
示例#30
0
        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);
        }