示例#1
0
        private void WriteRepoItemProperties(XmlTextWriter xml, RepositoryItemBase ri)
        {
            // Get the properties - need to be ordered so compare/isDirty can work faster
            var properties = ri.GetType().GetMembers().Where(x => x.MemberType == MemberTypes.Property).OrderBy(x => x.Name);

            foreach (MemberInfo mi in properties)
            {
                dynamic v = null;
                IsSerializedForLocalRepositoryAttribute token = Attribute.GetCustomAttribute(mi, typeof(IsSerializedForLocalRepositoryAttribute), false) as IsSerializedForLocalRepositoryAttribute;
                if (token == null)
                {
                    continue;
                }

                //Get tha attr value
                v = ri.GetType().GetProperty(mi.Name).GetValue(ri);
                // Enum might be unknow = not set - so no need to write to xml, like null for object
                if (ri.GetType().GetProperty(mi.Name).PropertyType.IsEnum)
                {
                    string vs = v.ToString();
                    // No need to write enum unknown = null
                    if (vs != "Unknown")
                    {
                        xmlwriteatrr(xml, mi.Name, vs);
                    }
                }
                else
                {
                    if (v != null)
                    {
                        xmlwriteatrr(xml, mi.Name, v.ToString());
                    }
                }
            }
        }
示例#2
0
        private void WriteRepoItemFields(XmlTextWriter xml, RepositoryItemBase ri)
        {
            var Fields = ri.GetType().GetMembers().Where(x => x.MemberType == MemberTypes.Field).OrderBy(x => x.Name);

            foreach (MemberInfo fi in Fields)
            {
                dynamic v = null;
                IsSerializedForLocalRepositoryAttribute token = Attribute.GetCustomAttribute(fi, typeof(IsSerializedForLocalRepositoryAttribute), false) as IsSerializedForLocalRepositoryAttribute;
                if (token == null)
                {
                    continue;
                }

                if (FastLoad)
                {
                    if (IsObseravbleListLazyLoad(fi.Name))
                    {
                        bool b = ((IObservableList)(ri.GetType().GetField(fi.Name).GetValue(ri))).LazyLoad;
                        if (b)
                        {
                            string s = ((IObservableList)(ri.GetType().GetField(fi.Name).GetValue(ri))).StringData;
                            xml.WriteStartElement("Activities");
                            xml.WriteString(s);
                            xml.WriteEndElement();
                            return;
                        }
                    }
                }

                v = ri.GetType().GetField(fi.Name).GetValue(ri);
                if (v != null)
                {
                    if (v is IObservableList)
                    {
                        xmlwriteObservableList(xml, fi.Name, (IObservableList)v);
                    }
                    else
                    {
                        if (v is List <string> )
                        {
                            xmlwriteStringList(xml, fi.Name, (List <string>)v);
                        }
                        else if (v is RepositoryItemBase)
                        {
                            xmlwriteSingleObjectField(xml, fi.Name, v);
                        }
                        else
                        {
                            xml.WriteComment(">>>>>>>>>>>>>>>>> Unknown Field type to serialize - " + fi.Name + " - " + v.ToString());
                        }
                    }
                }
            }
        }
 //TODO: later on get back this function it is more organize, but causing saving problems  -to be fixed later
 private void xmlwriteObject(XmlTextWriter xml, RepositoryItemBase ri)
 {
     xml.WriteStartElement(ri.GetType().ToString());
     WriteRepoItemProperties(xml, ri);
     WriteRepoItemFields(xml, ri);
     xml.WriteEndElement();
 }
示例#4
0
        public static ItemValidationBase CreateNewIssue(RepositoryItemBase rItem)
        {
            ItemValidationBase ITB = new ItemValidationBase();

            ITB.UsageItem = rItem;
            ITB.ItemName  = rItem.ItemName;
            // TODO: remove me and use RepositoryItemBase
            ITB.ItemClass = RepositoryItem.GetShortType(rItem.GetType());
            return(ITB);
        }
 public virtual Type GetTypeOfItemParts(RepositoryItemBase item)
 {
     if (item.GetType() == typeof(Activity))
     {
         return(typeof(eItemParts));
     }
     else if (item.GetType() == typeof(Act))
     {
         return(typeof(Act.eItemParts));
     }
     else if (item.GetType() == typeof(ActivitiesGroup))
     {
         return(typeof(ActivitiesGroup.eItemParts));
     }
     else if (item.GetType() == typeof(VariableBase))
     {
         return(typeof(VariableBase.eItemParts));
     }
     else
     {
         return(null);
     }
 }
 private void CheckChanges(RepositoryItemBase rI, string name, object value)
 {
     if (name != prop)
     {
         Console.WriteLine("Property missing set with OnPropertychanged - " + rI.GetType().FullName + "." + name);
         ErrCounter++;
     }
     if (rI.DirtyStatus != eDirtyStatus.Modified)
     {
         Console.WriteLine("Property changed didn't trigger Dirty Status to modified- " + rI.GetType().FullName + "." + name);
         ErrCounter++;
     }
     // Assert.AreEqual(PI.Name, prop);
     // Assert.AreEqual(eDirtyStatus.Modified, RI.DirtyStatus);
 }
 private static void SetProperties(RepositoryItemBase item, List <Tuple <string, object> > propertiesToSet)
 {
     if (propertiesToSet != null)
     {
         try
         {
             foreach (Tuple <string, object> property in propertiesToSet)
             {
                 item.GetType().GetProperty(property.Item1).SetValue(item, property.Item2);
             }
         }
         catch (Exception ex)
         {
             Reporter.ToLog(eLogLevel.WARN, string.Format("Failed to set the property to the item {0} as part of Paste process", item.ItemName), ex);
         }
     }
 }
        public static void MovePrevVersion(RepositoryItemBase obj, string FileName)
        {
            if (File.Exists(FileName))
            {
                string repoItemTypeFolder = GetSharedRepoItemTypeFolder(obj.GetType());
                string PrevFolder         = Path.Combine(App.UserProfile.Solution.Folder, repoItemTypeFolder, "PrevVersions");
                if (!Directory.Exists(PrevFolder))
                {
                    Directory.CreateDirectory(PrevFolder);
                }
                //TODO: change to usae locale or yyyymmdd...
                string dts      = DateTime.Now.ToString("MM_dd_yyyy_H_mm_ss");
                string repoName = string.Empty;
                if (obj.FileName != null && File.Exists(obj.FileName))
                {
                    repoName = obj.FileName;
                }
                string PrevFileName = repoName.Replace(repoItemTypeFolder, repoItemTypeFolder + @"\PrevVersions") + "." + dts + "." + obj.ObjFileExt;

                if (PrevFileName.Length > 255)
                {
                    PrevFileName = PrevFileName.Substring(0, 250) + new Random().Next(1000).ToString();
                }
                try
                {
                    if (File.Exists(PrevFileName))
                    {
                        File.Delete(PrevFileName);
                    }
                    File.Move(FileName, PrevFileName);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Save Previous File got error " + ex.Message);
                }
            }
        }
        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);
        }
        //[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);
                        }
                    }
                }
            }
        }
示例#11
0
        public void FindItemsByReflection(RepositoryItemBase OriginItemObject, RepositoryItemBase item, ObservableList <FoundItem> foundItemsList, string textToFind, SearchConfig searchConfig, RepositoryItemBase parentItemToSave, string itemParent, string foundField)
        {
            var properties = item.GetType().GetMembers().Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field);

            foreach (MemberInfo mi in properties)
            {
                try
                {
                    if (mi.Name == nameof(ActInputValue.ValueForDriver) || mi.Name == /*nameof(RepositoryItemBase.mBackupDic)*/ "mBackupDic" || mi.Name == nameof(RepositoryItemBase.FileName) || mi.Name == nameof(RepositoryItemBase.Guid) ||
                        mi.Name == nameof(RepositoryItemBase.ObjFolderName) || mi.Name == nameof(RepositoryItemBase.ObjFileExt) || mi.Name == "ScreenShots" ||
                        mi.Name == nameof(RepositoryItemBase.ContainingFolder) || mi.Name == nameof(RepositoryItemBase.ContainingFolderFullPath) || mi.Name == nameof(RepositoryItemBase.Guid) || mi.Name == nameof(RepositoryItemBase.ParentGuid) || mi.Name == "Created" || mi.Name == "Version" || mi.Name == "CreatedBy" || mi.Name == "LastUpdate" || mi.Name == "LastUpdateBy")
                    {
                        continue;
                    }


                    //Get the attr value
                    PropertyInfo PI = item.GetType().GetProperty(mi.Name);
                    if (mi.MemberType == MemberTypes.Property)
                    {
                        var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                        if (token == null)
                        {
                            continue;
                        }
                    }
                    else if (mi.MemberType == MemberTypes.Field)
                    {
                        var token = item.GetType().GetField(mi.Name).GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                        if (token == null)
                        {
                            continue;
                        }
                    }
                    if (PI != null && (PI.PropertyType == typeof(DateTime) || PI.PropertyType == typeof(Guid)))
                    {
                        continue;
                    }

                    dynamic value = null;
                    try
                    {
                        if (mi.MemberType == MemberTypes.Property)
                        {
                            value = PI.GetValue(item);
                        }
                        else if (mi.MemberType == MemberTypes.Field)
                        {
                            value = item.GetType().GetField(mi.Name).GetValue(item);
                        }
                    }
                    catch
                    {
                        continue;
                    }

                    if (value == null)
                    {
                        continue;
                    }

                    if (value is IObservableList)
                    {
                        string foundListField = string.Empty;

                        if (string.IsNullOrEmpty(foundField))
                        {
                            foundListField = mi.Name;
                        }
                        else
                        {
                            foundListField = foundField + @"\" + mi.Name;
                        }

                        int index = 0;
                        foreach (RepositoryItemBase o in value)
                        {
                            index++;
                            string paramNameString = string.Empty;
                            if (o is RepositoryItemBase)
                            {
                                paramNameString = ((RepositoryItemBase)o).ItemName;
                            }
                            else
                            {
                                paramNameString = o.ToString();
                            }

                            string foundListFieldValue = string.Format(@"{0}[{1}]\{2}", foundListField, index, paramNameString);

                            FindItemsByReflection(OriginItemObject, o, foundItemsList, textToFind, searchConfig, parentItemToSave, itemParent, foundListFieldValue);
                        }
                    }
                    else if (value is RepositoryItemBase)//!RegularTypeList.Contains(value.GetType().Name) && value.GetType().BaseType.Name != nameof(Enum) && value.GetType().Name != "Bitmap" && value.GetType().Name != nameof(Guid) && value.GetType().Name !=  nameof(RepositoryItemKey))
                    {
                        //TODO taking care of List which is not iobservableList

                        if (string.IsNullOrEmpty(foundField))
                        {
                            foundField = @"\" + mi.Name;
                        }
                        else
                        {
                            foundField = foundField + @"\" + mi.Name;
                        }
                        FindItemsByReflection(OriginItemObject, value, foundItemsList, textToFind, searchConfig, parentItemToSave, itemParent, foundField);
                    }
                    else
                    {
                        if (value != null)
                        {
                            try
                            {
                                string stringValue        = value.ToString();
                                string matchedStringValue = string.Empty;
                                if (searchConfig.MatchCase == false)
                                {
                                    matchedStringValue = stringValue.ToUpper();
                                    textToFind         = textToFind.ToUpper();
                                }
                                else
                                {
                                    matchedStringValue = stringValue;
                                }

                                if ((searchConfig.MatchAllWord == true && matchedStringValue == textToFind) || (searchConfig.MatchAllWord == false && matchedStringValue.Contains(textToFind)) /* || new Regex(textToFind).Match(stringValue).Success == true*/) //Comment out until fixing Regex search
                                {
                                    string finalFoundFieldPath = string.Empty;
                                    if (string.IsNullOrEmpty(foundField))
                                    {
                                        finalFoundFieldPath = mi.Name;
                                    }
                                    else
                                    {
                                        finalFoundFieldPath = foundField + @"\" + mi.Name;
                                    }

                                    FoundItem foundItem = foundItemsList.Where(x => x.FieldName == mi.Name && x.FieldValue == stringValue && x.ItemObject == item).FirstOrDefault();
                                    if (foundItem == null)
                                    {
                                        List <string> OptionalValuseToReplaceList = new List <string>();
                                        if (PI.PropertyType.BaseType == typeof(Enum))
                                        {
                                            Array enumValues = Enum.GetValues(PI.PropertyType);
                                            for (int i = 0; i < enumValues.Length; i++)
                                            {
                                                object enumValue = enumValues.GetValue(i);
                                                OptionalValuseToReplaceList.Add(enumValue.ToString());
                                            }
                                        }
                                        else if (PI.PropertyType == typeof(bool))
                                        {
                                            OptionalValuseToReplaceList.Add("True");
                                            OptionalValuseToReplaceList.Add("False");
                                        }

                                        foundItemsList.Add(new FoundItem()
                                        {
                                            OriginObject = OriginItemObject, ItemObject = item, ParentItemToSave = parentItemToSave, FieldName = mi.Name, FieldValue = stringValue, ItemParent = itemParent, FoundField = finalFoundFieldPath, OptionalValuesToRepalce = OptionalValuseToReplaceList
                                        });
                                    }

                                    else
                                    {
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }