public BindableXmlObject[] GetObjects(Type type)
        {
            ArgumentUtility.CheckNotNull("type", type);

            ArrayList objects = new ArrayList();

            string typeDir = Path.Combine(_rootPath, type.FullName);

            string[] filenames = Directory.GetFiles(typeDir);

            foreach (string filename in filenames)
            {
                Guid id;
                try
                {
                    id = new Guid(new FileInfo(filename).Name);
                }
                catch (FormatException)
                {
                    continue;
                }

                BindableXmlObject obj = GetObject(type, id);
                if (obj != null)
                {
                    objects.Add(obj);
                }
            }

            return((BindableXmlObject[])objects.ToArray(typeof(BindableXmlObject)));
        }
        protected BindableXmlObject CreateObject(Type type, Guid id)
        {
            BindableXmlObject obj = (BindableXmlObject)ObjectFactory.Create(true, type, ParamList.Empty);

            obj._id = id;
            AddToIdentityMap(obj);
            return(obj);
        }
        private void AddToIdentityMap(BindableXmlObject obj)
        {
            if (_identityMap.ContainsKey(obj.ID))
            {
                return;
            }

            _identityMap.Add(obj.ID, obj);
        }
        private BindableXmlObject GetFromIdentityMap(Guid id)
        {
            BindableXmlObject bindableXmlObject = (BindableXmlObject)_identityMap[id];

            if (bindableXmlObject == null)
            {
                return(null);
            }
            return(bindableXmlObject);
        }
        public void SaveObject(BindableXmlObject obj)
        {
            ArgumentUtility.CheckNotNull("obj", obj);


            Type   targetType = GetTargetType(obj);
            string typeDir    = Path.Combine(_rootPath, targetType.FullName);

            if (!Directory.Exists(typeDir))
            {
                Directory.CreateDirectory(typeDir);
            }

            string fileName = Path.Combine(typeDir, obj.ID.ToString());

            Type          concreteType = obj.GetType();
            XmlSerializer serializer   = GetXmlSerializer(concreteType);

            using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                serializer.Serialize(stream, obj);
            }
        }
        public BindableXmlObject GetObject(Type type, Guid id)
        {
            ArgumentUtility.CheckNotNull("type", type);

            if (id == Guid.Empty)
            {
                return(null);
            }

            BindableXmlObject obj = GetFromIdentityMap(id);

            if (obj != null)
            {
                return(obj);
            }


            string typeDir  = Path.Combine(_rootPath, type.FullName);
            string fileName = Path.Combine(typeDir, id.ToString());

            if (!File.Exists(fileName))
            {
                return(null);
            }

            Type          concreteType = GetConcreteType(type);
            XmlSerializer serializer   = GetXmlSerializer(concreteType);

            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                obj = (BindableXmlObject)serializer.Deserialize(stream);
            }
            obj._id = id;
            AddToIdentityMap(obj);
            return(obj);
        }
 private Type GetTargetType(BindableXmlObject obj)
 {
     return(((BindableObjectClass)((IBusinessObject)obj).BusinessObjectClass).TargetType);
 }