Esempio n. 1
0
 public static object DeserializeSafe(Stream s)
 {
     return(TypedBinaryFormatter.DeserializeObject(s, DxBinarySerializationUtil.GetTypeBinder()));
 }
Esempio n. 2
0
        private object DeserializeObject(object sourceValue, Type destinationType)
        {
            Exception ex = null;

            byte[] array;
            string text;

            if (!this.CanConvert(sourceValue, destinationType, out array, out text, out ex))
            {
                throw ex;
            }
            ExTraceGlobals.SerializationTracer.TraceFunction <object, string>((long)this.GetHashCode(), "SerializationTypeConverter.DeserializeObject(); SerializationData.Length = {0}; ToStringValue = '{1}'", (array == null) ? "<null>" : array.Length, text);
            object obj = null;

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(array))
                {
                    AppDomain.CurrentDomain.AssemblyResolve += SerializationTypeConverter.AssemblyHandler;
                    try
                    {
                        int tickCount = Environment.TickCount;
                        if (SerializationTypeConverter.IsRunningInRPSServerSide.Value)
                        {
                            if (SerializationTypeBinder.Instance == null)
                            {
                                throw new InvalidCastException("SerializationTypeBinder initialization failed.");
                            }
                            obj = TypedBinaryFormatter.DeserializeObject(memoryStream, SerializationTypeBinder.Instance);
                        }
                        else
                        {
                            BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null, new string[]
                            {
                                "System.Management.Automation.PSObject",
                                "System.DelegateSerializationHolder"
                            });
                            obj = binaryFormatter.Deserialize(memoryStream);
                        }
                        ExTraceGlobals.SerializationTracer.TraceDebug <string, int>((long)this.GetHashCode(), "DeserializeObject of type {0} succeeded in {1} ms.", (obj != null) ? obj.GetType().Name : "null", Environment.TickCount - tickCount);
                        IDeserializationCallback deserializationCallback = obj as IDeserializationCallback;
                        if (deserializationCallback != null)
                        {
                            deserializationCallback.OnDeserialization(sourceValue);
                        }
                    }
                    finally
                    {
                        AppDomain.CurrentDomain.AssemblyResolve -= SerializationTypeConverter.AssemblyHandler;
                    }
                }
            }
            catch (SerializationException ex2)
            {
                ExTraceGlobals.SerializationTracer.TraceDebug <SerializationException>((long)this.GetHashCode(), "Deserialization Failed. Error = {0}", ex2);
                if (ValueConvertor.TryConvertValueFromString(text, destinationType, null, out obj, out ex))
                {
                    ExTraceGlobals.SerializationTracer.TraceDebug <SerializationException>((long)this.GetHashCode(), "String Conversion Succeeded.", ex2);
                }
                else
                {
                    ex = new InvalidCastException(string.Format("Deserialization fails due to one SerializationException: {0}", ex2.ToString()), ex2);
                }
            }
            catch (DataSourceTransientException ex3)
            {
                ex = new InvalidCastException(string.Format("Deserialization fails due to an DataSourceTransientException: {0}", ex3.ToString()), ex3);
            }
            if (ex is InvalidCastException)
            {
                throw ex;
            }
            return(obj);
        }
Esempio n. 3
0
 // Token: 0x06001155 RID: 4437 RVA: 0x000655E0 File Offset: 0x000637E0
 private void Initialize()
 {
     try
     {
         this.logger.TraceDebug(this, "Entering NormalizationCache.Initialize normalizationCacheFolderPath='{0}', versionedCacheFolderName='{1}'", new object[]
         {
             this.normalizationCacheFolderPath,
             this.versionedCacheFolderName
         });
         string text = Path.Combine(this.normalizationCacheFolderPath, this.versionedCacheFolderName);
         Directory.CreateDirectory(text);
         string path = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", new object[]
         {
             this.fileNamePrefix,
             this.culture.Name
         });
         this.filePath = Path.Combine(text, path);
         this.logger.TraceDebug(this, "NormalizationCache.Initialize filePath='{0}'", new object[]
         {
             this.filePath
         });
         if (this.CheckCacheFile())
         {
             using (Stream stream = File.Open(this.filePath, FileMode.Open, FileAccess.Read))
             {
                 Type[] expectedTypes = new Type[]
                 {
                     Type.GetType("System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib], [System.Boolean, mscorlib]]"),
                     Type.GetType("System.Collections.Generic.GenericEqualityComparer`1[[System.String, mscorlib]]"),
                     typeof(Dictionary <string, bool>)
                 };
                 this.cache             = (Dictionary <string, bool>)TypedBinaryFormatter.DeserializeObject(stream, expectedTypes, null, true);
                 this.initialCacheCount = this.cache.Count;
             }
             this.logger.TraceDebug(this, "NormalizationCache.Initialize - Loaded cache from filePath='{0}', initial cache count = '{1}'", new object[]
             {
                 this.filePath,
                 this.initialCacheCount
             });
         }
         else
         {
             this.logger.TraceDebug(this, "NormalizationCache.Initialize - Cache does not exist or could not be downloaded, filePath='{0}'", new object[]
             {
                 this.filePath
             });
         }
     }
     catch (Exception ex)
     {
         this.logger.TraceDebug(this, "NormalizationCache.Initialize - Unable to load cache from filePath='{0}', exception='{1}'", new object[]
         {
             this.filePath,
             ex
         });
         UmGlobals.ExEvent.LogEvent(UMEventLogConstants.Tuple_LoadNormalizationCacheFailed, null, new object[]
         {
             this.logger.TenantId,
             this.filePath,
             this.culture,
             CommonUtil.ToEventLogString(ex)
         });
         if (!this.IsExpectedException(ex))
         {
             throw;
         }
     }
     if (this.cache == null)
     {
         this.logger.TraceDebug(this, "NormalizationCache.Initialize - Creating empty cache", new object[0]);
         this.cache             = new Dictionary <string, bool>(1000);
         this.initialCacheCount = 0;
     }
 }