Ejemplo n.º 1
0
        protected override T PerformInsert <T>(T ValueToInsert)// where T : PersistentBase
        {
            Type type = ValueToInsert.GetType();

            string TableName = type.GetCustomAttribute <PersistentTableName>().TableName;
            string query     = "INSERT INTO [" + TableName + "](";
            string values    = " Values (";
            bool   first     = true;

            int           i          = 1;
            SQLiteCommand tmpCommand = new SQLiteCommand();

            foreach (PropertyInfo PI in type.GetProperties())
            {
                if (!PI.PropertyType.IsArray && PI.Name.ToLower() != "id" && PI.GetCustomAttribute(typeof(NonPersistent)) == null)
                {
                    if (!first)
                    {
                        query  += ", ";
                        values += ",";
                    }
                    first   = false;
                    query  += "[" + PI.Name + "]";
                    values += "@" + i.ToString();
                    tmpCommand.Parameters.AddWithValue("@" + i++.ToString(), PI.GetValue(ValueToInsert));
                }
            }
            query  += ") ";
            values += "); select last_insert_rowid()";
            tmpCommand.CommandText = query + values;
            tmpCommand.Connection  = Connection; //Set sql connection here
            ValueToInsert.Id       = (int)(long)tmpCommand.ExecuteScalar();
            return(ValueToInsert);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is used to set the DirtyStatus to NoChange to item and it's child items
        /// </summary>
        public void SetDirtyStatusToNoChange()
        {
            DirtyStatus = eDirtyStatus.NoChange;

            // Properties
            foreach (PropertyInfo PI in this.GetType().GetProperties())
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        continue;
                    }
                    foreach (object o in obj)
                    {
                        if (o is RepositoryItemBase)
                        {
                            ((RepositoryItemBase)o).SetDirtyStatusToNoChange();
                        }
                    }
                }
            }

            // Fields
            foreach (FieldInfo FI in this.GetType().GetFields())
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    foreach (object o in obj)
                    {
                        if (o is RepositoryItemBase)
                        {
                            ((RepositoryItemBase)o).SetDirtyStatusToNoChange();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 //метод для установки Childs и ChildType
 public virtual void SetNodes()
 {
     foreach (PropertyInfo PI in GetType().GetProperties())
     {
         //атрибут текущего объекта (false - без родителей)
         ChildsAttribute ChildsAttribute =
             PI.GetCustomAttribute <ChildsAttribute>(false);
         if (ChildsAttribute != null)
         {
             Childs    = PI.GetValue(this);
             ChildType = ChildsAttribute.ChildType;
             break;
         }
     }
 }
Ejemplo n.º 4
0
        private void UpdateRepoItemGuids(RepositoryItemBase item, List <GuidMapper> guidMappingList)
        {
            foreach (FieldInfo PI in item.GetType().GetFields())
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                // we drill down to ObservableList
                if (typeof(IObservableList).IsAssignableFrom(PI.FieldType))
                {
                    IObservableList obj = (IObservableList)PI.GetValue(item);
                    if (obj == null)
                    {
                        return;
                    }
                    List <object> items = ((IObservableList)obj).ListItems;

                    if ((items != null) && (items.Count > 0) && (items[0].GetType().IsSubclassOf(typeof(RepositoryItemBase))))
                    {
                        foreach (RepositoryItemBase ri in items.Cast <RepositoryItemBase>())
                        {
                            GuidMapper mapping = new GuidMapper();
                            mapping.Original = ri.Guid;
                            ri.Guid          = Guid.NewGuid();
                            mapping.newGuid  = ri.Guid;

                            guidMappingList.Add(mapping);

                            UpdateRepoItemGuids(ri, guidMappingList);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void CheckPropertyChangedTriggered()
        {
            // Scan all RIs for each prop marked with [IsSerializedForLocalRepositoryAttribute] try to change and verify prop changed triggered

            //Arrange

            // Get all Repository items
            IEnumerable <Type> list = GetRepoItems();

            ErrCounter = 0;

            //Act
            foreach (Type type in list)
            {
                Console.WriteLine("CheckPropertyChangedTriggered for type: " + type.FullName);
                if (type.IsAbstract)
                {
                    continue;
                }
                RepositoryItemBase RI = (RepositoryItemBase)Activator.CreateInstance(type);
                RI.PropertyChanged += RIPropertyChanged;
                RI.StartDirtyTracking();

                // Properties
                foreach (PropertyInfo PI in RI.GetType().GetProperties())
                {
                    var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + PI.Name);
                    object newValue = GetNewValue(PI.PropertyType, PI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        PI.SetValue(RI, newValue);
                        CheckChanges(RI, PI.Name, newValue);
                    }
                }


                // Fields
                foreach (FieldInfo FI in RI.GetType().GetFields())
                {
                    var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + FI.Name);
                    object newValue = GetNewValue(FI.FieldType, FI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        FI.SetValue(RI, newValue);
                        CheckChanges(RI, FI.Name, newValue);
                    }
                }
            }
            //Assert
            Assert.AreEqual(0, ErrCounter);
        }
Ejemplo n.º 6
0
        //[Ignore]
        //[TestMethod]  [Timeout(60000)]
        //public void NewRepositorySerializer_ReadOldXML()
        //{
        //    // Using new SR2 to load and write old XML but load old object, save with the style


        //    //Arrange
        //    //GingerCore.Repository.RepositorySerializerInitilizer OldSR = new GingerCore.Repository.RepositorySerializerInitilizer();


        //    //GingerCore.Repository.RepositorySerializerInitilizer.InitClassTypesDictionary();
        //    NewRepositorySerializer RS2 = new NewRepositorySerializer();

        //    string fileName = Common.getGingerUnitTesterDocumentsFolder() + @"Repository\BigFlow1.Ginger.BusinessFlow.xml";

        //    //Act
        //    string txt = System.IO.File.ReadAllText(fileName);
        //    BusinessFlow BF = (BusinessFlow)NewRepositorySerializer.DeserializeFromText(txt);

        //    //load with new
        //    // BusinessFlow BF = (BusinessFlow)RS2.DeserializeFromFile(fileName);
        //    //Serialize to new style
        //    //string s = RS2.SerializeToString(BF);
        //    // cretae from new style SR2
        //    BusinessFlow BF2 = (BusinessFlow)RS2.DeserializeFromText(typeof(BusinessFlow), txt, filePath: fileName);

        //    //to test the compare change something in b like below
        //    // BF2.Activities[5].Description = "aaa";
        //    // BF2.Activities.Remove(BF2.Activities[10]);

        //    //Assert

        //    // System.IO.File.WriteAllText(@"c:\temp\BF1.xml", s);
        //   // Assert.AreEqual(78, BF.Activities.Count);
        //    //Assert.AreEqual(78, BF2.Activities.Count);

        //    CompareRepoItem(BF, BF2);
        //}

        private void CompareRepoItem(RepositoryItemBase a, RepositoryItemBase b)
        {
            var props = a.GetType().GetProperties();

            foreach (PropertyInfo PI in props)
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token != null)
                {
                    Console.WriteLine("compare: " + a.ToString() + " " + PI.Name);

                    object aProp = PI.GetValue(a);
                    object bProp = b.GetType().GetProperty(PI.Name).GetValue(b);

                    if (aProp == null && bProp == null)
                    {
                        continue;
                    }


                    if (aProp.ToString() != bProp.ToString())
                    {
                        throw new Exception("Items no match tostring: " + a.ItemName + " attr: " + PI.Name + " a=" + aProp.ToString() + " b=" + bProp.ToString());
                    }

                    //if (aProp != bProp)
                    //{
                    //    throw new Exception("Items no match: " + a.ItemName + " attr: " + PI.Name + " a=" + aProp.ToString() + " b=" + bProp.ToString());
                    //}
                }
            }

            var fields = a.GetType().GetFields();

            foreach (FieldInfo FI in fields)
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token != null)
                {
                    Console.WriteLine("compare: " + a.ToString() + " " + FI.Name);

                    object aFiled = FI.GetValue(a);
                    object bField = b.GetType().GetField(FI.Name).GetValue(b);

                    if (aFiled == null && bField == null)
                    {
                        continue;
                    }

                    if (aFiled.ToString() != bField.ToString())
                    {
                        throw new Exception("Items no match tostring: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                    }

                    //if (aFiled != bField)
                    //{
                    //    throw new Exception("Items no match: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                    //}

                    if (aFiled is IObservableList)
                    {
                        if (((IObservableList)aFiled).Count != ((IObservableList)bField).Count)
                        {
                            throw new Exception("Items in list count do not match: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                        }
                        var aList = ((IObservableList)aFiled).GetEnumerator();
                        var bList = ((IObservableList)bField).GetEnumerator();



                        while (aList.MoveNext())
                        {
                            bList.MoveNext();
                            RepositoryItemBase o1 = (RepositoryItemBase)aList.Current;
                            RepositoryItemBase o2 = (RepositoryItemBase)bList.Current;
                            CompareRepoItem(o1, o2);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void StartDirtyTracking()
        {
            if (DirtyStatus != eDirtyStatus.NoTracked)
            {
                // Nothing to do
                return;
            }

            DirtyTrackingFields = new List <string>();
            DirtyStatus         = eDirtyStatus.NoChange;
            //first track self item changes
            PropertyChanged += ItmePropertyChanged;

            // now track all children which are marked with isSerizalized...
            // throw err if item is serialized but dindn't impl IsDirty

            // Properties
            foreach (PropertyInfo PI in this.GetType().GetProperties())
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                DirtyTrackingFields.Add(PI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            }

            // Fields
            foreach (FieldInfo FI in this.GetType().GetFields())
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                DirtyTrackingFields.Add(FI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            }
        }
Ejemplo n.º 8
0
        public void StartDirtyTracking()
        {
            if (DirtyStatus != eDirtyStatus.NoTracked)
            {
                // Nothing to do
                return;
            }

            DirtyTrackingFields = new ConcurrentBag <string>();
            DirtyStatus         = eDirtyStatus.NoChange;
            //first track self item changes
            PropertyChanged += ItmePropertyChanged;

            // now track all children which are marked with isSerizalized...
            // throw err if item is serialized but dindn't impl IsDirty

            // Properties
            Parallel.ForEach(this.GetType().GetProperties(), PI =>
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    return;
                }

                DirtyTrackingFields.Add(PI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    //skip list if it is LazyLoad and was not loaded yet
                    var lazyLoadtoken = PI.GetCustomAttribute(typeof(IsLazyLoadAttribute));
                    if (lazyLoadtoken != null)
                    {
                        string lazyStatusProp = PI.Name + nameof(IObservableList.LazyLoad);
                        if (this.GetType().GetProperty(lazyStatusProp) != null)
                        {
                            if (bool.Parse(this.GetType().GetProperty(PI.Name + nameof(IObservableList.LazyLoad)).GetValue(this).ToString()) == true)
                            {
                                return;//skip doing dirty tracking for observableList which is LazyLoad and not loaded yet
                            }
                        }
                        else
                        {
                            Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to check if to start DirtyTracking for Lazy Load ObservabelList called '{0}' because the property '{1}' is missing", PI.Name, lazyStatusProp));
                        }
                    }

                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            });

            // Fields
            Parallel.ForEach(this.GetType().GetFields(), FI =>
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    return;
                }

                DirtyTrackingFields.Add(FI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            });
        }