Example #1
0
        public static T Deserialize <T>(Stream stream) where T : class
        {
            T result;

            try
            {
                if (DxSerializationUtil.UseBinarySerialize)
                {
                    result = (T)((object)DxBinarySerializationUtil.Deserialize(stream));
                }
                else
                {
                    DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T), null, int.MaxValue, false, false, null, new DxSerializationUtil.SharedTypeResolver());
                    result = (T)((object)dataContractSerializer.ReadObject(stream));
                }
            }
            catch (Exception ex)
            {
                EventLogger.LogErr("Deserialize<T> err: {0}", new object[]
                {
                    ex
                });
                throw new DxStoreSerializeException(ex.Message, ex);
            }
            return(result);
        }
Example #2
0
        public static MemoryStream Serialize <T>(T obj) where T : class
        {
            MemoryStream result;

            try
            {
                MemoryStream memoryStream = new MemoryStream();
                if (DxSerializationUtil.UseBinarySerialize)
                {
                    DxBinarySerializationUtil.Serialize(memoryStream, obj);
                }
                else
                {
                    DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T), null, int.MaxValue, false, false, null, new DxSerializationUtil.SharedTypeResolver());
                    dataContractSerializer.WriteObject(memoryStream, obj);
                }
                result = memoryStream;
            }
            catch (Exception ex)
            {
                EventLogger.LogErr("Serialize<T> err: {0}", new object[]
                {
                    ex
                });
                throw new DxStoreSerializeException(ex.Message, ex);
            }
            return(result);
        }
Example #3
0
            public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
            {
                Type type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);

                if (type == null)
                {
                    if (typeNamespace.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
                    {
                        return(null);
                    }
                    try
                    {
                        string typeName2 = typeName + ", " + typeNamespace;
                        type = Type.GetType(typeName2);
                    }
                    catch (Exception ex)
                    {
                        EventLogger.LogErr("ResolveName err: {0}", new object[]
                        {
                            ex
                        });
                    }
                }
                return(type);
            }
        private static bool IgnoreCertValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
        {
            bool flag = false;

            if (!HttpConfiguration.invalidCertLogged)
            {
                lock (HttpConfiguration.lockObj)
                {
                    if (!HttpConfiguration.invalidCertLogged)
                    {
                        flag = true;
                        HttpConfiguration.invalidCertLogged = true;
                    }
                }
            }
            if (flag)
            {
                EventLogger.LogErr("IgnoreCertValidate ignored {0}", new object[]
                {
                    cert
                });
            }
            return(true);
        }
Example #5
0
        private void ListenerCallback(IAsyncResult asyncContext)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.ListenForAnotherRequest));
            Exception arg = null;

            try
            {
                HttpListenerContext httpListenerContext = this.listener.EndGetContext(asyncContext);
                HttpListenerRequest request             = httpListenerContext.Request;
                using (HttpListenerResponse response = httpListenerContext.Response)
                {
                    using (Stream inputStream = request.InputStream)
                    {
                        int          num          = (int)request.ContentLength64;
                        MemoryStream memoryStream = new MemoryStream(num);
                        inputStream.CopyTo(memoryStream);
                        memoryStream.Position = 0L;
                        HttpRequest httpRequest = DxSerializationUtil.TryDeserialize <HttpRequest>(memoryStream, out arg);
                        if (httpRequest != null)
                        {
                            ExTraceGlobals.InstanceTracer.TraceDebug <string, int>(0L, "Listener got {0} of size {1}", httpRequest.GetType().FullName, num);
                            HttpReply httpReply = null;
                            try
                            {
                                httpReply = this.msgHandler(httpRequest);
                            }
                            catch (Exception ex)
                            {
                                ExTraceGlobals.InstanceTracer.TraceError <Exception>(0L, "Listener handler threw {0}", ex);
                                httpReply = new HttpReply.ExceptionReply(ex);
                            }
                            if (httpReply == null)
                            {
                                response.ContentLength64 = 0L;
                                response.Close();
                                return;
                            }
                            using (MemoryStream memoryStream2 = DxSerializationUtil.Serialize <HttpReply>(httpReply))
                            {
                                response.ContentLength64 = memoryStream2.Length;
                                memoryStream2.Position   = 0L;
                                using (Stream outputStream = response.OutputStream)
                                {
                                    memoryStream2.CopyTo(outputStream);
                                }
                                ExTraceGlobals.InstanceTracer.TraceDebug <string, long>(0L, "Listener returns {0} of size {1}", httpReply.GetType().FullName, memoryStream2.Length);
                                response.Close();
                                return;
                            }
                        }
                        response.StatusCode      = 400;
                        response.ContentLength64 = 0L;
                        response.Close();
                        EventLogger.LogErr("msg unhandled: {0}", new object[]
                        {
                            (httpRequest == null) ? "UnknownMsg" : httpRequest.GetType().FullName
                        });
                    }
                }
            }
            catch (Exception ex2)
            {
                arg = ex2;
                ExTraceGlobals.InstanceTracer.TraceError <Exception>(0L, "Listener caught {0}", arg);
            }
        }
Example #6
0
 private static void LogErr(string formatString, params object[] args)
 {
     EventLogger.LogErr(formatString, args);
 }