Ejemplo n.º 1
0
        public void LoadXrefCollectionValues(object data)
        {
            Type   type     = data.GetType();
            Meta   meta     = data as Meta ?? new Meta(data, ObjectReaderWriter);
            Type   listType = typeof(List <>);
            string dataHash = meta.Hash;

            List <Meta> leftMeta = new List <Meta>();

            TypeXref[] leftXrefs = TypeSchema.Xrefs.Where(xref => xref.Left.Equals(type)).ToArray();
            foreach (TypeXref leftXref in leftXrefs)
            {
                Type  genericRight = listType.MakeGenericType(leftXref.Right);
                IList listInstance = genericRight.Construct <IList>();

                XrefInfo[] xrefs = ObjectReaderWriter.Query <XrefInfo>(xref => xref.LeftHash.Equals(dataHash));
                foreach (XrefInfo xref in xrefs)
                {
                    object value     = ObjectReaderWriter.ReadByHash(Type.GetType(xref.RightType), xref.RightHash);
                    Meta   valueMeta = new Meta(value, ObjectReaderWriter);
                    if (!leftMeta.Contains(valueMeta))
                    {
                        leftMeta.Add(valueMeta);
                        listInstance.Add(value);
                    }
                }
                if (leftXref.RightCollectionProperty.PropertyType.IsArray)
                {
                    Array arr = Array.CreateInstance(leftXref.Right, listInstance.Count);
                    listInstance.CopyTo(arr, 0);
                    leftXref.RightCollectionProperty.SetValue(data, arr);
                }
                else
                {
                    leftXref.RightCollectionProperty.SetValue(data, listInstance);
                }
            }

            List <Meta> rightMeta = new List <Meta>();

            TypeXref[] rightXrefs = TypeSchema.Xrefs.Where(xref => xref.Right.Equals(type)).ToArray();
            foreach (TypeXref rightXref in rightXrefs)
            {
                Type  genericLeft  = listType.MakeGenericType(rightXref.Left);
                IList listInstance = genericLeft.Construct <IList>();

                XrefInfo[] xrefs = ObjectReaderWriter.Query <XrefInfo>(xref => xref.RightHash.Equals(dataHash));
                foreach (XrefInfo xref in xrefs)
                {
                    object value     = ObjectReaderWriter.ReadByHash(Type.GetType(xref.LeftType), xref.LeftHash);
                    Meta   valueMeta = new Meta(value, ObjectReaderWriter);
                    if (!rightMeta.Contains(valueMeta))
                    {
                        rightMeta.Add(valueMeta);
                        listInstance.Add(value);
                    }
                }

                if (rightXref.LeftCollectionProperty.PropertyType.IsArray)
                {
                    Array arr = Array.CreateInstance(rightXref.Left, listInstance.Count);
                    listInstance.CopyTo(arr, 0);
                    rightXref.LeftCollectionProperty.SetValue(data, arr);
                }
                else
                {
                    rightXref.LeftCollectionProperty.SetValue(data, listInstance);
                }
            }
        }
Ejemplo n.º 2
0
        private void SetId(object value)
        {
            Meta meta = new Meta();

            meta.SetId(value, this);
        }
Ejemplo n.º 3
0
        private void SetUuid(object value)
        {
            Meta meta = new Meta();

            Meta.SetUuid(value);
        }
Ejemplo n.º 4
0
 protected virtual string GetIdHash(long id, Type type)
 {
     return(Meta.GetIdHash(id, type));
 }
Ejemplo n.º 5
0
 protected internal static int GetHighestVersionNumber(DirectoryInfo propRoot, PropertyInfo prop, string hash)
 {
     return(Meta.GetHighestVersionNumber(propRoot, prop, hash));
 }
Ejemplo n.º 6
0
 protected virtual string GetIdHash(object value, Type type = null)
 {
     return(Meta.GetIdHash(value, type));
 }
Ejemplo n.º 7
0
 protected string GetUuidHash(string uuid, Type type)
 {
     return(Meta.GetUuidHash(uuid, type));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Deletes the hash.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="type">The type.</param>
        protected void DeleteHash(object data, Type type = null)
        {
            Meta meta = GetMeta(data, type);

            DeleteHash(meta);
        }
Ejemplo n.º 9
0
 protected internal long?GetIdValue(object value)
 {
     return(Meta.GetId(value));
 }
Ejemplo n.º 10
0
 protected internal static PropertyInfo GetKeyProperty(Type type)
 {
     return(Meta.GetKeyProperty(type));
 }