public object LoadObject(byte[] data, string storageName)
        {
            using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
            {
                try
                {
                    // Uncompress if need it
                    if (UseCompression)
                    {
                        data = SafeUnzip(data, storageName);
                    }

                    // Deserialize  object
                    var dataObject = m_objectReadDelegate(new MemoryStream(data));

                    if (dataObject == null)
                    {
                        throw new TisException("Null was returned while deserialize {0}", storageName);
                    }

                    return(dataObject);
                }
                catch (Exception e)
                {
                    Log.WriteError("Failed to deserialize data from {0}. Caught exception {1}", storageName, e);
                    throw;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Load configuration object from specified configuration file
        /// </summary>
        /// <param name="configFileName">Configuration file name</param>
        /// <param name="sectionName">Configuration section name</param>
        /// <returns>
        /// Configuration object
        /// </returns>
        protected object LoadSection(string configFileName, string sectionName)
        {
            System.Configuration.Configuration config = OpenExeConfiguration(configFileName, false);

            if (config == null)
            {
                Log.Write(Log.Severity.INFO,
                          System.Reflection.MethodInfo.GetCurrentMethod(),
                          " No local configuration file found. Default station options will be used.");

                return(null);
            }

            CustomSection currentSection;

            using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
            {
                currentSection = (CustomSection)config.Sections[sectionName];
            }

            if (currentSection == null)
            {
                Log.Write(Log.Severity.INFO,
                          System.Reflection.MethodInfo.GetCurrentMethod(),
                          " No relevant section in the local configuration file found. Default station options will be used.");

                return(null);
            }

            object configObject = currentSection.Data;

            return(configObject);
        }
예제 #3
0
        //<summary>
        //Deserializes the data from the reader.
        //</summary>
        //<param name="reader">The XmlReader containing the serialized data.</param>
        private void DeserializeData(XmlReader reader)
        {
            m_typeName = reader.GetAttribute("Type");

            Type dataType = Type.GetType(this.m_typeName);

            reader.Read();

            reader.MoveToContent();

            DataContractSerializer serializer = new DataContractSerializer(dataType);

            using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
            {
                this.Data = serializer.ReadObject(reader);
            }
        }
예제 #4
0
        protected override void DeserializeSection(System.Xml.XmlReader reader)
        {
            if (!reader.Read() || (reader.NodeType != XmlNodeType.Element))
            {
                ConfigurationErrorsException exc = new ConfigurationErrorsException(
                    "Configuration reader expected to find an element", reader);

                Log.Write(Log.Severity.ERROR,
                          System.Reflection.MethodInfo.GetCurrentMethod(),
                          exc.Message);

                throw exc;
            }
            using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
            {
                this.DeserializeElement(reader, false);
            }
        }
예제 #5
0
        /// <summary>
        /// Renames the section.
        /// </summary>
        /// <param name="configFileName">Name of the configuration file.</param>
        /// <param name="existingSectionName">Name of the existing section.</param>
        /// <param name="newSectionName">New name of the section.</param>
        public virtual void RenameSection(string configFileName, string existingSectionName, string newSectionName)
        {
            System.Configuration.Configuration config = OpenExeConfiguration(configFileName, false);

            if (config == null)
            {
                Log.Write(Log.Severity.WARNING,
                          System.Reflection.MethodInfo.GetCurrentMethod(),
                          "Cannot load <{0}> configuration. ", configFileName);

                return;
            }
            try
            {
                using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
                {
                    CustomSection currentSection = (CustomSection)config.Sections[existingSectionName];

                    if (currentSection == null)
                    {
                        Log.Write(Log.Severity.INFO,
                                  System.Reflection.MethodInfo.GetCurrentMethod(),
                                  " No relevant section in the local configuration file found. Default station options will be used.");

                        return;
                    }
                    else
                    {
                        config.Sections.Remove(existingSectionName);

                        config.Sections.Add(newSectionName, currentSection);
                    }
                }
            }
            catch (ConfigurationException exc)
            {
                Log.WriteException(exc);
            }
        }
예제 #6
0
        /// <summary>
        /// do the soap deserialization from the string
        /// </summary>
        /// <param name="strData">the string of data from the serialization operation</param>
        /// <returns>the object after the deserialization</returns>
        private object DoSoapDeserialization(string strData)
        {
            object       oObject   = null;
            MemoryStream memStream = null;

            if (!StringUtil.IsStringInitialized(m_innerXML))
            {
                return(oObject);
            }

            using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
            {
                try
                {
                    SoapFormatter soapFormatter = new SoapFormatter();

                    byte[] buf = Encoding.ASCII.GetBytes(m_innerXML);
                    memStream = new MemoryStream(buf);

                    oObject = soapFormatter.Deserialize(memStream);
                }
                catch (SerializationException e)
                {
                    // write error to Log File.
                    Log.WriteError("ConfigSectionImpl.DoXmlDeserialization failed to do Xml Deserialization in config section , Details :  {0}", e.Message);
                    //				throw new TiS.TisCommon.TisException(
                    //					e,
                    //					"ConfigSectionImpl.DoXmlDeserialization failed to do Xml Deserialization in config section , Details :  {0}", e.Message);
                }
                finally
                {
                    memStream.Close();
                }
            }

            return(oObject);
        }
        private MethodInfo[] FilterOutTypeMethods(
            MethodInfo[] TypePublicMethods,
            IAssemblyQueryFilter oQueryFilter)
        {
            bool bFilterByParamsCount = oQueryFilter != null && oQueryFilter.MethodParamsCount > -1;

            Type [] TypeArray = null;

            bool bFilterByParamsType = oQueryFilter != null &&
                                       oQueryFilter.MethodTypeOfParams != null;

            if (bFilterByParamsType)
            {
                TypeArray = GetTypesByName(oQueryFilter.MethodTypeOfParams);
            }

            Type oReturnType = null;

            bool bFilterByReturnType = oQueryFilter != null &&
                                       oQueryFilter.MethodReturnType != null;

            if (bFilterByReturnType)
            {
                oReturnType = GetTypeByName(oQueryFilter.MethodReturnType, m_oAssembly);

                bFilterByReturnType = oReturnType != null;
            }

            ArrayList oFilteredMethods = new ArrayList();

            oFilteredMethods.AddRange(TypePublicMethods);

            if (bFilterByParamsCount || bFilterByParamsType || bFilterByReturnType)
            {
                using (AssemblyVersionIgnorer versionResolver = new AssemblyVersionIgnorer())
                {
                    foreach (MethodInfo oMethodInfo in TypePublicMethods)
                    {
                        bool bShouldBeFilteredOut = bFilterByParamsCount &&
                                                    oQueryFilter.MethodParamsCount != oMethodInfo.GetParameters().Length;

                        if (!bShouldBeFilteredOut && bFilterByParamsType)
                        {
                            bShouldBeFilteredOut =
                                m_TypeToExplore.GetMethod(
                                    oMethodInfo.Name,
                                    BindingFlags.ExactBinding |
                                    BindingFlags.IgnoreCase |
                                    BindingFlags.Public |
                                    BindingFlags.Instance |
                                    BindingFlags.Static,
                                    null,
                                    TypeArray,
                                    new ParameterModifier[0]) == null;
                        }

                        if (!bShouldBeFilteredOut && bFilterByReturnType)
                        {
                            bShouldBeFilteredOut = oMethodInfo.ReturnType != oReturnType;
                        }

                        if (bShouldBeFilteredOut)
                        {
                            oFilteredMethods.Remove(oMethodInfo);
                        }
                    }
                }
            }

            return((MethodInfo [])oFilteredMethods.ToArray(typeof(MethodInfo)));
        }