Esempio n. 1
0
        private void FileWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            try
            {
                // check if it is directory
                if (Directory.Exists(PathHelper.GetLongPath(e.FullPath)))
                {
                    string fn = Path.GetFileName(PathHelper.GetLongPath(e.OldFullPath));
                    RepositoryFolder <T> sf = GetSubFolder(fn);
                    sf.DisplayName        = e.Name;
                    sf.FolderRelativePath = ReplaceLastOccurrence(sf.FolderRelativePath, fn, e.Name);
                    return;
                }

                // this is single repository item
                RepositoryItemBase item = GetItemFromCacheByFileName(e.OldFullPath);
                item.FileName = e.FullPath;
                item.FilePath = e.FullPath;

                // set Folder item cache as it depends ont he file name, so remove the old name and add with new name
                mFolderItemsCache.DeleteItem(e.OldFullPath);
                mFolderItemsCache[e.FullPath] = item;

                RepositoryItemBase item2 = GetItemFromCacheByFileName(e.FullPath);
            }
            catch (Exception ex)
            {
                NewReporter.ToConsole(string.Format("Exception thrown from ReposiotryFolder FileWatcher, Error:'{0}'", ex.Message));
            }
        }
Esempio n. 2
0
 private static void SetObjectAttributes(XmlReader xdr, object obj)
 {
     try
     {
         if (xdr.HasAttributes)
         {
             xdr.MoveToFirstAttribute();
             for (int i = 0; i < xdr.AttributeCount; i++)
             {
                 PropertyInfo propertyInfo = obj.GetType().GetProperty(xdr.Name);
                 if (propertyInfo == null)
                 {
                     if (xdr.Name == "Created" || xdr.Name == "CreatedBy" || xdr.Name == "LastUpdate" || xdr.Name == "LastUpdateBy" || xdr.Name == "Version" || xdr.Name == "ExternalID")
                     {
                         // Ignore common attr on RI which were removed in GingerCoreNET
                     }
                     else
                     {
                         NewReporter.ToLog(eNewLogLevel.WARN, "Property not Found: " + xdr.Name);
                     }
                     xdr.MoveToNextAttribute();
                     continue;
                 }
                 string Value = xdr.Value;
                 // Console.WriteLine("SetObjectAttributes: Property=" + propertyInfo.Name + ", Value=" + Value);
                 if (Value != "Null")
                 {
                     if (propertyInfo.CanWrite)
                     {
                         SetObjAttrValue(obj, propertyInfo, Value);
                     }
                     else
                     {
                         // this is for case like Activity.PercentAutomation - we had it serialzed but set was removed, we can ignore
                         // Ignore
                     }
                 }
                 xdr.MoveToNextAttribute();
             }
         }
         xdr.MoveToNextAttribute();
     }
     catch (Exception ex)
     {
         NewReporter.ToLog(eNewLogLevel.WARN, "Error when setting Property: " + xdr.Name);
         throw ex;
     }
 }
Esempio n. 3
0
        public static RepositoryItemBase DeserializeFromText(string xml, RepositoryItemBase targetObj = null, string filePath = "")
        {
            string encoding = "utf-8"; // make it static or remove string creation
            //check if we need ms or maybe text reader + do using to release mem
            var ms   = new MemoryStream(Encoding.GetEncoding(encoding).GetBytes(xml));
            var xdrs = new XmlReaderSettings()
            {
                IgnoreComments   = true,
                IgnoreWhitespace = true,
                CloseInput       = true
            };
            XmlReader xdr = XmlReader.Create(ms, xdrs);

            xdr.Read();
            xdr.Read();
            object RootObj;

            if (xdr.Name == cGingerRepositoryItem)
            {
                // New style with header
                xdr.Read();  // Now we are in the header

                RepositoryItemHeader RIH = new RepositoryItemHeader();
                xdr.MoveToFirstAttribute();
                for (int i = 0; i < xdr.AttributeCount; i++)
                {
                    SetRepositoryItemHeaderAttr(RIH, xdr.Name, xdr.Value);
                    xdr.MoveToNextAttribute();
                }

                // After we are done reading the RI header attrs we moved to the main object
                xdr.Read();

                RootObj = xmlReadObject(null, xdr, targetObj);
                ((RepositoryItemBase)RootObj).RepositoryItemHeader = RIH;
            }
            else
            {
                //Item saved by old Serialzier so calling it to load the XML
                NewReporter.ToConsole(string.Format("New Serialzier is calling Old Serialzier for loading the file: '{0}'", filePath));//add support to write it to log
                return((RepositoryItemBase)OnNewRepositorySerializerEvent(NewRepositorySerilizerEventArgs.eEventType.LoadWithOldSerilizerRequired, filePath, xml, targetObj));
            }

            return((RepositoryItemBase)RootObj);
        }
Esempio n. 4
0
        private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("FileWatcher change detected: " + e.FullPath + " , " + e.ChangeType);
            try
            {
                m.WaitOne();
                {
                    if (e.ChangeType == WatcherChangeTypes.Deleted)
                    {
                        if ((from x in mSubFoldersCache where x.FolderName == e.Name select x).SingleOrDefault() != null)
                        {
                            HandleDirecortyChange(e);
                        }
                        else
                        {
                            HandleFileChange(e);
                        }
                    }
                    else
                    {
                        if (Directory.Exists(PathHelper.GetLongPath(e.FullPath)))
                        {
                            HandleDirecortyChange(e);
                        }
                        else
                        {
                            HandleFileChange(e);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NewReporter.ToConsole(string.Format("Exception thrown from ReposiotryFolder FileWatcher, Error:'{0}'", ex.Message));
            }

            finally
            {
                m.ReleaseMutex();
            }
            Console.WriteLine("FileWatcher change handled: " + e.FullPath + " , " + e.ChangeType);
        }
Esempio n. 5
0
        private static object xmlReadObject(Object Parent, XmlReader xdr, RepositoryItemBase targetObj = null)
        {
            string className = xdr.Name;

            //bool conversion = false;
            //  if (className == "GingerCore.Platforms.ApplicationPlatform") className = "GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib";


            try
            {
                int level = xdr.Depth;

                object obj;

                if (targetObj == null)
                {
                    obj = CreateObject(className);
                }
                else
                {
                    obj = targetObj;
                }

                SetObjectSerialziedAttrDefaultValue(obj);
                SetObjectAttributes(xdr, obj);

                xdr.Read();
                // Set lists attrs
                // read all object sub elements like lists - obj members
                while (xdr.Depth == level + 1)
                {
                    // Check if it one obj attr or list
                    string    attrName = xdr.Name;
                    FieldInfo FI       = obj.GetType().GetField(attrName);
                    // PropertyInfo FI = obj.GetType().GetProperty(attrName);
                    // string bt = FI.FieldType.Name;

                    // We check if it is list by arg count - List<string> will have string etc...
                    // another option is check the nake to start with List, Observ...
                    //or find a better way
                    // meanwhile it is working
                    if (FI.FieldType.GenericTypeArguments.Count() > 0)
                    {
                        SetObjectListAttrs(xdr, obj);
                    }
                    else
                    {
                        // Read the attr name/move next
                        xdr.ReadStartElement();
                        // read the actual object we need to put on the attr
                        object item = xmlReadObject(obj, xdr);
                        // Set the attr val with the object
                        FI.SetValue(obj, item);

                        // Create UT for below and then remove the next if
                        xdr.ReadEndElement();
                    }

                    //Keep it here
                    if (xdr.NodeType == XmlNodeType.EndElement)
                    {
                        xdr.ReadEndElement();
                    }
                }

                //if (conversion)
                //{
                //    //for converting old actions keep the ID
                //    if (obj is DriverAction)
                //    {
                //        DriverAction DA = ((DriverAction)obj);
                //        DA.OldClassName = OldClassName;


                //        //temp moved from here to conversion class or function
                //        if (DA.OldClassName == "GingerCore.Actions.ActGotoURL")
                //        {
                //            DA.ID = "GotoURL";
                //            DA.InputValues[0].Param = "URL"; //convert param name 'Value' to 'URL'
                //        }

                //        if (DA.OldClassName == "GingerCore.Actions.ActTextBox")
                //        {
                //            DA.ID = "UIElementAction";
                //            string LocateBy = "ByID";
                //            string LocateValue = "UserName";  // temp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                //            string Action = "SetValue";
                //            string Value = (from x in DA.InputValues where x.Param == "Value" select x.Value).FirstOrDefault();
                //            DA.InputValues.Clear();
                //            DA.InputValues.Add(new ActInputValue() { Param = "LocateBy", Value = LocateBy });
                //            DA.InputValues.Add(new ActInputValue() { Param = "LocateValue", Value = LocateValue });
                //            DA.InputValues.Add(new ActInputValue() { Param = "Action", Value = Action });
                //            DA.InputValues.Add(new ActInputValue() { Param = "Value", Value = Value });

                //        }

                //    }
                //}


                return(obj);
            }
            catch (Exception ex)
            {
                NewReporter.ToConsole("Error:Cannot create instance of: " + className + ", for attribute: " + xdr.Name + " - " + ex.Message);
                throw new Exception("Error:Cannot create instance of: " + className + ", for attribute: " + xdr.Name + " - " + ex.Message);
            }
        }