コード例 #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 on the 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)
            {
                AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Exception thrown from ReposiotryFolder/FileWatcher", ex, true);
            }
        }
コード例 #2
0
        public void MoveItem(RepositoryItemBase repositoryItem, string targetFolder)
        {
            RepositoryFolderBase RF       = GetItemRepositoryFolder(repositoryItem);
            RepositoryFolderBase targetRF = GetRepositoryFolderByPath(targetFolder);

            if (RF != null && targetRF != null)
            {
                RF.DeleteRepositoryItem(repositoryItem);
                targetRF.AddRepositoryItem(repositoryItem);
            }
            else
            {
                AppReporter.ToLog(eAppReporterLogLevel.ERROR, string.Format("Failed to Move repository item because source or target folders failed to be identified for item '{0}' and target folder '{1}'.", repositoryItem.FilePath, targetFolder));
            }
        }
コード例 #3
0
 // Support backward compatibility - function when we had the list with delimiter
 private ObservableList <OptionalValue> ConvertOptionalValuesStringToList(string valsString)
 {
     try
     {
         List <string> valsList = (new List <string>(valsString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)));
         ObservableList <OptionalValue> valsObservList = new ObservableList <OptionalValue>();
         foreach (string val in valsList)
         {
             valsObservList.Add(new OptionalValue(val));
         }
         return(valsObservList);
     }
     catch
     {
         AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Cannot Convert Optional Values String To List - " + valsString);
         return(new ObservableList <OptionalValue>());
     }
 }
コード例 #4
0
        public static string GetTermResValue(eTermResKey termResourceKey, string prefixString = "", string suffixString = "", bool setToUpperCase = false)
        {
            object termResValue = null;

            try
            {
                termResValue = GingerTerminology.GetTerminologyValue(termResourceKey);
            }
            catch (Exception ex)
            {
                termResValue = null;
                AppReporter.ToLog(eAppReporterLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
            }

            if (termResValue != null)
            {
                string strValue = "";
                if (!string.IsNullOrEmpty(prefixString))
                {
                    strValue = prefixString;
                }
                if (!string.IsNullOrEmpty(strValue))
                {
                    strValue = strValue + " " + termResValue.ToString();
                }
                else
                {
                    strValue = termResValue.ToString();
                }
                if (!string.IsNullOrEmpty(suffixString))
                {
                    strValue = strValue + " " + suffixString;
                }
                if (setToUpperCase)
                {
                    strValue = strValue.ToUpper();
                }
                return(strValue);
            }
            else
            {
                return(string.Empty);  //key not found
            }
        }
コード例 #5
0
        private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            AppReporter.ToConsole("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)
            {
                AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Exception thrown from ReposiotryFolder/FileWatcher", ex, true);
            }

            finally
            {
                m.ReleaseMutex();
            }
            AppReporter.ToConsole("FileWatcher change handled: " + e.FullPath + " , " + e.ChangeType);
        }
コード例 #6
0
        /// <summary>
        /// Move existing shared repository item to PrevVersion folder. And remove it from cache
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void MoveSharedRepositoryItemToPrevVersion(RepositoryItemBase repositoryItem)
        {
            if (repositoryItem.FileName != null && File.Exists(repositoryItem.FileName))
            {
                RepositoryFolderBase repostitoryFolder = GetItemRepositoryFolder(repositoryItem);

                string targetPath = Path.Combine(repostitoryFolder.FolderFullPath, "PrevVerions");
                if (!Directory.Exists(targetPath))
                {
                    //We do not want to file watcher track PrevVersions Folder. So creating it explicity using Create directory
                    Directory.CreateDirectory(targetPath);
                }

                string dts = DateTime.Now.ToString("yyyyMMddHHmm");

                string targetFileName = Path.GetFileName(repositoryItem.FileName) + "." + dts + "." + repositoryItem.ObjFileExt;

                targetFileName = Path.Combine(targetPath, targetFileName);

                if (targetFileName.Length > 255)
                {
                    targetFileName = targetFileName.Substring(0, 250) + new Random().Next(1000).ToString();
                }

                try
                {
                    if (File.Exists(targetFileName))
                    {
                        File.Delete(targetFileName);
                    }
                    //We want to delete the item and remove it from cache. So first we copy it to destination and then delete using Repository Folder.
                    File.Copy(repositoryItem.FileName, targetFileName);
                    repostitoryFolder.DeleteRepositoryItem(repositoryItem);
                }
                catch (IOException ex)
                {
                    AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Shared Repository moving item to PrevVersion", ex);
                }
            }
        }
コード例 #7
0
        // Generic handling for any RI type
        // This is recursive function which run in parallel for extreme speed, be careful!
        private ObservableList <T> LoadFolderFiles <T>(string Folder = null)
        {
            // for each file we check if in cache return from cache else load from file system and cache the item

            string FullPath = SolutionRepository.GetFolderFullPath(Folder);

            if (FullPath == null || !Directory.Exists(PathHelper.GetLongPath(FullPath)))
            {
                AppReporter.ToLog(eAppReporterLogLevel.ERROR, "RepositoryFolder/LoadFolderFiles- Invalid folder: " + Folder);
                return(null);
            }

            // TODO: move from here to better place
            string ContainingFolder = Folder.Replace(SolutionRepository.SolutionFolder, SolutionRepository.cSolutionRootFolderSign);

            ConcurrentBag <T> list = new ConcurrentBag <T>(); // Thread safe list

            string[] fileEntries = FileSystem.GetDirectoryFiles(FullPath, mSolutionRepositoryItemInfo.Pattern);

            Parallel.ForEach(fileEntries, FileName =>
            {
                try
                {
                    // Check if item exist in cache if yes use it, no need to load from file, yay!
                    T item = (T)mFolderItemsCache[FileName];
                    if (item == null)
                    {
                        item = LoadItemfromFile <T>(FileName, ContainingFolder);
                        AddItemtoCache(FileName, item);
                    }
                    list.Add(item);
                }
                catch (Exception ex)
                {
                    AppReporter.ToLog(eAppReporterLogLevel.ERROR, string.Format("RepositoryFolder/LoadFolderFiles- Failed to load the Repository Item XML which in file: '{0}'.", FileName), ex);
                }
            });

            return(new ObservableList <T>(list)); //TODO: order by name .OrderBy(x => ((RepositoryItem)x).FilePath)); ??
        }
コード例 #8
0
        public static void GetListOfUsedVariables(object item, ref List <string> usedVariables)
        {
            var properties = item.GetType().GetMembers().Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field);

            foreach (MemberInfo mi in properties)
            {
                if (Amdocs.Ginger.Common.GeneralLib.General.IsFieldToAvoidInVeFieldSearch(mi.Name))
                {
                    continue;
                }

                //Get the attr value
                PropertyInfo PI    = item.GetType().GetProperty(mi.Name);
                object       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 (Exception ex)
                {
                    AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Exception during GetListOfUsedVariables", ex, true);
                    value = null;
                }

                if (value is IObservableList)
                {
                    foreach (object o in (IObservableList)value)
                    {
                        GetListOfUsedVariables(o, ref usedVariables);
                    }
                }
                else
                {
                    if (value != null)
                    {
                        try
                        {
                            if (PI.CanWrite)
                            {
                                //TODO: Use nameof !!!!!
                                if (mi.Name == "StoreToValue" && mi.DeclaringType.Name == "ActReturnValue" && value.ToString().IndexOf("{DS Name") == -1)
                                {
                                    //check that it is not GUID of global model Param
                                    Guid dummyGuid = new Guid();
                                    if (!Guid.TryParse(value.ToString(), out dummyGuid))
                                    {
                                        if (value.ToString() != string.Empty)
                                        {
                                            if (usedVariables.Contains(value.ToString()) == false)
                                            {
                                                usedVariables.Add(value.ToString());
                                            }
                                        }
                                    }
                                }
                                else if (mi.Name == "FlowControlAction" && value.ToString() == "SetVariableValue") //get used variable in flow control with set variable action type.
                                {
                                    string[]  vals  = ((string)item.GetType().GetRuntimeProperty("ValueCalculated").GetValue(item)).Split(new[] { '=' });
                                    const int count = 2;
                                    if (vals.Count() == count && !usedVariables.Contains(vals[0]))
                                    {
                                        usedVariables.Add(vals[0]);
                                    }
                                }
                                else if (mi.Name == "VariableName" && mi.DeclaringType.Name == "VariableDependency" && usedVariables != null)
                                {
                                    if (!usedVariables.Contains(value))
                                    {
                                        usedVariables.Add((string)value);
                                    }
                                }
                                else
                                {
                                    string   stringValue  = value.ToString();
                                    string[] splitedValue = stringValue.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (splitedValue.Length > 0)
                                    {
                                        for (int indx = 0; indx < splitedValue.Length; indx++)
                                        {
                                            string val = splitedValue[indx];
                                            if (val.Contains("Var Name=") == true)
                                            {
                                                val = val.Replace("Var Name=", "");
                                                if (usedVariables.Contains(val) == false)
                                                {
                                                    usedVariables.Add(val);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            // TODO: FIXME!!! no empty exception
                        }
                    }
                }
            }
        }
コード例 #9
0
        public static void UpdateVariableNameChangeInItem(object item, string prevVarName, string newVarName, ref bool namechange)
        {
            var properties = item.GetType().GetMembers().Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field);

            foreach (MemberInfo mi in properties)
            {
                if (Amdocs.Ginger.Common.GeneralLib.General.IsFieldToAvoidInVeFieldSearch(mi.Name))
                {
                    continue;
                }

                //Get the attr value
                PropertyInfo PI    = item.GetType().GetProperty(mi.Name);
                dynamic      value = null;
                try
                {
                    if (mi.MemberType == MemberTypes.Property)
                    {
                        if (PI.CanWrite)
                        {
                            value = PI.GetValue(item);
                        }
                    }
                    else if (mi.MemberType == MemberTypes.Field)
                    {
                        value = item.GetType().GetField(mi.Name).GetValue(item);
                    }
                }
                catch (Exception ex)
                {
                    AppReporter.ToLog(eAppReporterLogLevel.ERROR, "Exception during UpdateVariableNameChangeInItem", ex, true);
                }

                if (value is IObservableList)
                {
                    List <dynamic> list = new List <dynamic>();
                    foreach (object o in value)
                    {
                        UpdateVariableNameChangeInItem(o, prevVarName, newVarName, ref namechange);
                    }
                }
                else
                {
                    if (value != null)
                    {
                        if (mi.Name == "VariableName")
                        {
                            if (value == prevVarName)
                            {
                                PI.SetValue(item, newVarName);
                            }
                            namechange = true;
                        }
                        else if (mi.Name == "StoreToValue")
                        {
                            if (value == prevVarName)
                            {
                                PI.SetValue(item, newVarName);
                            }
                            else if (value.IndexOf("{Var Name=" + prevVarName + "}") > 0)
                            {
                                PI.SetValue(item, value.Replace("{Var Name=" + prevVarName + "}", "{Var Name=" + newVarName + "}"));
                            }
                            namechange = true;
                        }
                        else
                        {
                            try
                            {
                                if (PI.CanWrite)
                                {
                                    string stringValue        = value.ToString();
                                    string variablePlaceHoler = "{Var Name=xx}";
                                    if (stringValue.Contains(variablePlaceHoler.Replace("xx", prevVarName)))
                                    {
                                        PI.SetValue(item, stringValue.Replace(variablePlaceHoler.Replace("xx", prevVarName), variablePlaceHoler.Replace("xx", newVarName)));
                                        namechange = true;
                                    }
                                }
                            }
                            catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
                        }
                    }
                }
            }
        }