/// <summary> /// Loop over several files and write all tooltips to a tab-separated file. /// </summary> /// <param name="sourcePath">The directory where the text files are stored</param> /// <param name="sourcePattern">Specifies what files to process (e.g. MyObject.txt or *.txt)</param> /// <param name="fileName">The output file</param> static void ImportTooltips(string sourcePath, string fileName) { int tooltipCount = 0; SortedDictionary <int, NAVObject> objects = new SortedDictionary <int, NAVObject>(); try { string[] lines = File.ReadAllLines(fileName, Encoding.GetEncoding("utf-8")); foreach (var line in lines) { string[] col = line.Split(delimiter); try { var obj = new NAVObject() { Type = (ElementType)int.Parse(col[1]), Number = int.Parse(col[2]), FileName = col[0], }; var tooltip = new Tooltip() { ElementType = (ElementType)int.Parse(col[3]), Id = int.Parse(col[5]) }; for (int i = 6; i < col.Length; i += 3) { if (col[i] != "") { tooltip.addText(col[i], col[i + 1]); } } if (!objects.ContainsKey(obj.GetHashCode())) { objects.Add(obj.GetHashCode(), obj); } else { obj = objects[obj.GetHashCode()]; } obj.Tooltips.Add(tooltip); } catch (FormatException) { } } } catch (System.IO.IOException e) { Console.WriteLine(@"Exception while reading {0}: {1}", fileName, e.Message); } string lastFileName = ""; List <ApplicationObject> objectsInFile = new List <ApplicationObject>(); foreach (NAVObject obj in objects.Values) { string objectFilename = sourcePath + Path.DirectorySeparatorChar + obj.FileName; if (objectFilename != lastFileName) { if (lastFileName != "") { SaveNavObjects(lastFileName, objectsInFile); } objectsInFile = ReadNavObjects(objectFilename); lastFileName = objectFilename; Console.WriteLine(@"Processing {0}", objectFilename); } var objInFile = objectsInFile.Find(x => x.Id.ObjectType == obj.Type && x.Id.ObjectNumber == obj.Number); if (objInFile != null) { foreach (Tooltip tooltip in obj.Tooltips) { IEnumerable <IElement> elements = from element in objInFile.GetElements() where element.Id == tooltip.Id && element.ElementTypeInfo.ElementType == tooltip.ElementType select element; try { if (elements.Count() != 0) { string value = tooltip.GetTooltipMLProperty(); if (value != "") { elements.First().SetStringProperty(PropertyType.ToolTipML, tooltip.GetTooltipMLProperty()); } } } catch (ArgumentException e) { Console.WriteLine(@"Exception while setting property in {0} control id {1}", objectFilename, elements.First().Id); Console.WriteLine(e.Message); } tooltipCount++; } } } if (lastFileName != "") { SaveNavObjects(lastFileName, objectsInFile); } Console.WriteLine("{0} object(s) with {1} tooltip(s) processed.", objects.Count(), tooltipCount); }
/// <summary> /// Loop over several files and write all tooltips to a tab-separated file. /// </summary> /// <param name="sourcePath">The directory where the text files are stored</param> /// <param name="sourcePattern">Specifies what files to process (e.g. MyObject.txt or *.txt)</param> /// <param name="fileName">The output file</param> /// <param name="generateTooltips">Generate a tooltip based on CaptionML and SourceExpr properties. </param> static void ExportTooltips(string sourcePath, string sourcePattern, string fileName, bool generateTooltips) { int tooltipCount = 0; SortedDictionary <int, NAVObject> objects = new SortedDictionary <int, NAVObject>(); HashSet <string> duplicates = new HashSet <string>(); string[] files = Directory.GetFiles(sourcePath, sourcePattern, SearchOption.AllDirectories); foreach (string file in files) { List <ApplicationObject> objectsInFile = ReadNavObjects(file); foreach (var objInFile in objectsInFile) { var obj = new NAVObject() { Type = objInFile.Id.ObjectType, Number = objInFile.Id.ObjectNumber, FileName = Path.GetFileName(file) }; obj.Tooltips = GetTooltips(objInFile, generateTooltips); objects.Add(obj.GetHashCode(), obj); } } StringBuilder sb = new StringBuilder(); foreach (var obj in objects.Values) { List <Tooltip> tooltips = obj.Tooltips; foreach (Tooltip tooltip in tooltips) { sb.Append(obj.FileName); sb.Append(delimiter); sb.Append((int)obj.Type); sb.Append(delimiter); sb.Append((int)obj.Number); sb.Append(delimiter); sb.Append((int)tooltip.ElementType); sb.Append(delimiter); sb.Append(tooltip.ElementType); sb.Append(delimiter); sb.Append(tooltip.Id); foreach (var language in tooltip.TooltipML) { sb.Append(delimiter); sb.Append(language.Key); sb.Append(delimiter); sb.Append(language.Value); sb.Append(delimiter); //duplicate? string hash = GetMD5(language.Key, language.Value); if (duplicates.Contains(hash)) { sb.Append("1"); } else { sb.Append("0"); duplicates.Add(hash); } } sb.Append(System.Environment.NewLine); tooltipCount++; } } try { File.WriteAllText(fileName, sb.ToString(), Encoding.GetEncoding("utf-8")); Console.WriteLine("{0} object(s) with {1} tooltip(s) processed.", objects.Count(), tooltipCount); } catch (System.IO.IOException e) { Console.WriteLine(@"Error while writing {0}: {1}", fileName, e.Message); } }