Example #1
0
 public Ctrip.SOA.Infratructure.IOCFactoryModel.RegistMappingContextCollection GetMappingContexts(string fileUrl)
 {
     try
     {
         var returnValue = new RegistMappingContextCollection();
         using (var fs = File.Open(fileUrl, FileMode.Open))
         {
             returnValue = this.GetMappingContexts(fs);
         }
         return returnValue;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        public RegistMappingContextCollection GetMappingContexts(Stream stream)
        {
            RegistMappingContextCollection returnValue = new RegistMappingContextCollection();

            if (stream.CanRead)
            {
                using (StreamReader sr = new StreamReader(stream))
                {
                    var serializer = new JavaScriptSerializer();
                    returnValue = serializer.Deserialize<RegistMappingContextCollection>(sr.ReadToEnd());
                }
            }
            else
            {
                throw new Exception("input stream can't read");
            }
            return returnValue;
        }
Example #3
0
        public RegistMappingContextCollection GetMappingContexts(string fileUrl)
        {
            RegistMappingContextCollection returnValue = new RegistMappingContextCollection();
            try
            {
                var serializer = new JavaScriptSerializer();
                //serializer.WriteObject(fs, returnValue);
                using (Stream sr = File.Open(fileUrl, FileMode.Open))
                {
                    returnValue = this.GetMappingContexts(sr);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returnValue;
        }
Example #4
0
        public RegistMappingContextCollection GetMappingContexts(Stream stream)
        {
            var returnValue = new RegistMappingContextCollection(); 
            try
            {
                var ser = new XmlSerializer(typeof(IOCUnity));
                var config = (IOCUnity)ser.Deserialize(stream);
                var alias = config.TypeAliases.Objects;

                var types = new List<UnityType>();

                foreach (var container in config.Containers.Objects)
                {
                    types.AddRange(container.Types.Objects);
                }

                foreach (var type in types)
                {
                    var newObj = new RegistMappingContext();

                    newObj.PTypeStr = GetFromAlias(alias, type.TypeStr);

                    string cType = type.MapTo;
                    if (string.IsNullOrWhiteSpace(cType))
                    {
                        newObj.CTypeStr = newObj.PTypeStr;
                    }
                    else
                    {
                        newObj.CTypeStr = GetFromAlias(alias, cType);
                    }

                    newObj.InstTypeStr = mapping[type.LifeTime.Type].ToString();

                    returnValue.Contexts.Add(newObj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returnValue;
        }