/// <summary> /// Instantiates a PathElement based on the PathElementType /// </summary> /// <param name="elementType">PathElementType</param> /// <returns>ICanvasPathElement</returns> private static ICanvasPathElement CreatePathElement(PathElementType elementType) { ICanvasPathElement result = null; switch (elementType) { case PathElementType.MoveTo: result = new MoveToElement(); break; case PathElementType.Line: result = new LineElement(); break; case PathElementType.HorizontalLine: result = new HorizontalLineElement(); break; case PathElementType.VerticalLine: result = new VerticalLineElement(); break; case PathElementType.QuadraticBezier: result = new QuadraticBezierElement(); break; case PathElementType.SmoothQuadraticBezier: result = new SmoothQuadraticBezierElement(); break; case PathElementType.CubicBezier: result = new CubicBezierElement(); break; case PathElementType.SmoothCubicBezier: result = new SmoothCubicBezierElement(); break; case PathElementType.Arc: result = new ArcElement(); break; case PathElementType.ClosePath: result = new ClosePathElement(); break; } return(result); }
/// <summary> /// Instantiates a PathElement based on the PathElementType /// </summary> /// <param name="elementType">PathElementType</param> /// <param name="capture">Capture object</param> /// <param name="index">Index of the capture</param> /// <param name="isRelative">Indicates whether the coordinates are absolute or relative</param> /// <returns>ICanvasPathElement</returns> internal static ICanvasPathElement CreateAdditionalPathElement(PathElementType elementType, Capture capture, int index, bool isRelative) { // Additional attributes in MoveTo Command must be converted // to Line commands if (elementType == PathElementType.MoveTo) { elementType = PathElementType.Line; } var element = CreatePathElement(elementType); element?.InitializeAdditional(capture, index, isRelative); return(element); }
/// <summary> /// Creates a default Path Element for the given PathElementType /// </summary> /// <param name="elementType">PathElementType</param> /// <returns>ICanvasPathElement</returns> internal static ICanvasPathElement CreateDefaultPathElement(PathElementType elementType) { ICanvasPathElement result; switch (elementType) { case PathElementType.ClosePath: result = new ClosePathElement(); break; default: throw new ArgumentException("Creation of Only Default ClosePathElement is supported.", nameof(elementType)); } return(result); }
/// <summary> /// Get the Regex for extracting attributes of the given PathElementType /// </summary> /// <param name="elementType">PathElementType</param> /// <returns>Regex</returns> internal static Regex GetAttributesRegex(PathElementType elementType) { return(PathElementAttributeRegexes[elementType]); }
/// <summary> /// Get the Regex for the given PathElementType /// </summary> /// <param name="elementType">PathElementType</param> /// <returns>Regex</returns> internal static Regex GetRegex(PathElementType elementType) { return(PathElementRegexes[elementType]); }
static int Compare(PathElementType x, PathElementType y) { return(TypeOrder[x] - TypeOrder[y]); }
public PathElement(int index) { Type = PathElementType.Index; FieldName = ""; Index = index; }
public PathElement(string fieldName) { Type = PathElementType.Member; FieldName = fieldName; Index = -1; }
public static List <PathElement> GetSuggestionList(EMDocument doc, string userPath, PathElementType options) { var list = new List <PathElement>(); var emptyInputPath = false; if (string.IsNullOrWhiteSpace(userPath)) { emptyInputPath = true; userPath = ""; } var langId = LangIdPattern.Match(Path.GetFileName(doc.LocalPath)).Groups["langId"].Value; var m = RootKeywordPattern.Match(userPath); userPath = m.Success ? userPath.Replace(m.Value, GetSourceDir(doc.LocalPath)) : Path.Combine(Path.GetDirectoryName(doc.LocalPath), userPath); DirectoryInfo userDir; try { userDir = new DirectoryInfo(userPath); } catch (Exception e) { if (e is ArgumentNullException || e is SecurityException || e is ArgumentException || e is PathTooLongException) { // ignore and output empty list return(list); } throw; } if (userDir.Exists) { if ((options & (PathElementType.Image | PathElementType.Attachment | PathElementType.Folder)) > 0) { // File system infos. var dirs = userDir.GetDirectories(); if (options.HasFlag(PathElementType.Image)) { var imagesDirs = dirs.Where(d => d.Name.ToLower() == "images").ToArray(); if (imagesDirs.Length > 0) { list.AddRange( imagesDirs[0].GetFiles().Select(f => new PathElement(f.Name, PathElementType.Image))); } } if (options.HasFlag(PathElementType.Attachment)) { var attachmentsDirs = dirs.Where(d => d.Name.ToLower() == "attachments").ToArray(); if (attachmentsDirs.Length > 0) { list.AddRange( attachmentsDirs[0].GetFiles() .Select(f => new PathElement(f.Name, PathElementType.Attachment))); } } if (options.HasFlag(PathElementType.Folder)) { if (emptyInputPath) { list.Add(new PathElement("%ROOT%", PathElementType.Folder)); } list.AddRange( dirs.Where(d => d.Name.ToLower() != "attachments" && d.Name.ToLower() != "images") .Select(d => new PathElement(d.Name, PathElementType.Folder))); } } if ((options & (PathElementType.Bookmark | PathElementType.Excerpt | PathElementType.Variable)) > 0) { var files = userDir.GetFiles(string.Format("*.{0}.udn", langId)); if (files.Length > 0) { var linkedDocument = files[0].FullName.Equals(doc.LocalPath, StringComparison.InvariantCultureIgnoreCase) ? doc : doc.TransformationData.ProcessedDocumentCache.Get(files[0].FullName); if (options.HasFlag(PathElementType.Bookmark) && emptyInputPath) { list.AddRange(linkedDocument.GetBookmarkKeys().Select(n => new PathElement(n, PathElementType.Bookmark))); } if (options.HasFlag(PathElementType.Excerpt)) { list.AddRange(linkedDocument.GetExcerptNames().Select(n => new PathElement(n, PathElementType.Excerpt))); } if (options.HasFlag(PathElementType.Variable)) { list.AddRange(linkedDocument.GetVariableNames().Select(n => new PathElement(n, PathElementType.Variable))); } } } } return(list); }
public PathElement(string text, PathElementType type) { Text = text; Type = type; }
public static List<PathElement> GetSuggestionList(EMDocument doc, string userPath, PathElementType options) { var list = new List<PathElement>(); var emptyInputPath = false; if (string.IsNullOrWhiteSpace(userPath)) { emptyInputPath = true; userPath = ""; } var langId = LangIdPattern.Match(Path.GetFileName(doc.LocalPath)).Groups["langId"].Value; var m = RootKeywordPattern.Match(userPath); userPath = m.Success ? userPath.Replace(m.Value, GetSourceDir(doc.LocalPath)) : Path.Combine(Path.GetDirectoryName(doc.LocalPath), userPath); DirectoryInfo userDir; try { userDir = new DirectoryInfo(userPath); } catch (Exception e) { if (e is ArgumentNullException || e is SecurityException || e is ArgumentException || e is PathTooLongException) { // ignore and output empty list return list; } throw; } if (userDir.Exists) { if ((options & (PathElementType.Image | PathElementType.Attachment | PathElementType.Folder)) > 0) { // File system infos. var dirs = userDir.GetDirectories(); if (options.HasFlag(PathElementType.Image)) { var imagesDirs = dirs.Where(d => d.Name.ToLower() == "images").ToArray(); if (imagesDirs.Length > 0) { list.AddRange( imagesDirs[0].GetFiles().Select(f => new PathElement(f.Name, PathElementType.Image))); } } if (options.HasFlag(PathElementType.Attachment)) { var attachmentsDirs = dirs.Where(d => d.Name.ToLower() == "attachments").ToArray(); if (attachmentsDirs.Length > 0) { list.AddRange( attachmentsDirs[0].GetFiles() .Select(f => new PathElement(f.Name, PathElementType.Attachment))); } } if (options.HasFlag(PathElementType.Folder)) { if (emptyInputPath) { list.Add(new PathElement("%ROOT%", PathElementType.Folder)); } list.AddRange( dirs.Where(d => d.Name.ToLower() != "attachments" && d.Name.ToLower() != "images") .Select(d => new PathElement(d.Name, PathElementType.Folder))); } } if ((options & (PathElementType.Bookmark | PathElementType.Excerpt | PathElementType.Variable)) > 0) { var files = userDir.GetFiles(string.Format("*.{0}.udn", langId)); if (files.Length > 0) { var linkedDocument = files[0].FullName.Equals(doc.LocalPath, StringComparison.InvariantCultureIgnoreCase) ? doc : doc.TransformationData.ProcessedDocumentCache.Get(files[0].FullName); if (options.HasFlag(PathElementType.Bookmark) && emptyInputPath) { list.AddRange(linkedDocument.GetBookmarkKeys().Select(n => new PathElement(n, PathElementType.Bookmark))); } if (options.HasFlag(PathElementType.Excerpt)) { list.AddRange(linkedDocument.GetExcerptNames().Select(n => new PathElement(n, PathElementType.Excerpt))); } if (options.HasFlag(PathElementType.Variable)) { list.AddRange(linkedDocument.GetVariableNames().Select(n => new PathElement(n, PathElementType.Variable))); } } } } return list; }
private static List<PathElement> GetLocalSuggestions(PathElementType type) { return PathCompletionHelper.GetSuggestionList( UDNDocRunningTableMonitor.CurrentUDNDocView.CurrentEMDocument, Path.GetDirectoryName(UDNDocRunningTableMonitor.CurrentUDNDocView.CurrentEMDocument.LocalPath), type); }