Пример #1
0
        public static IDominoWrapper CreateNodeFromPath(DominoAssembly futureParent, string path)
        {
            var parentPath   = Workspace.Find(futureParent);
            var relPath      = Workspace.MakeRelativePath(parentPath, path);
            var deserialized = Workspace.Load <IDominoProvider>(path);

            return(deserialized switch
            {
                FieldParameters _ => new FieldNode(relPath, futureParent),
                StructureParameters _ => new StructureNode(relPath, futureParent),
                SpiralParameters _ => new SpiralNode(relPath, futureParent),
                CircleParameters _ => new CircleNode(relPath, futureParent),
                _ => throw new ArgumentException("Path is not loadable"),
            });
Пример #2
0
        public static IDominoWrapper CreateNodeFromPath(DominoAssembly futureParent, string path)
        {
            var parentPath   = Workspace.Find(futureParent);
            var relPath      = Workspace.MakeRelativePath(parentPath, path);
            var deserialized = Workspace.Load <IDominoProvider>(path);

            switch (deserialized)
            {
            case FieldParameters p:
                return(new FieldNode(relPath, futureParent));

            case StructureParameters p:
                return(new StructureNode(relPath, futureParent));

            case SpiralParameters p:
                return(new SpiralNode(relPath, futureParent));

            case CircleParameters p:
                return(new CircleNode(relPath, futureParent));

            default:
                throw new ArgumentException("Path is not loadable");
            }
        }
Пример #3
0
        public static string AbsolutePathFromReference(ref string relativePath, IWorkspaceLoadable reference)
        {
            if (relativePath.Contains("\\"))
            {
                relativePath = relativePath.Replace("\\", "/");
            }

            bool   resolved         = false;
            bool   createResolution = false;
            string absolutePath     = "";
            string oldrelpath       = relativePath;

            var referenceTuple = Instance.openedFiles.Where(x => x.Item2 == reference).FirstOrDefault();

            if (Path.IsPathRooted(relativePath) && File.Exists(relativePath))
            {
                // The relative path that was passed is in fact already absolute; return the path if the file exists.
                absolutePath = relativePath;
                resolved     = true;
                // If there is a reference, the path should not be absolute.
                if (reference != null && referenceTuple != null)
                {
                    relativePath = Workspace.MakeRelativePath(referenceTuple.Item1, relativePath);
                    Debug.WriteLine($"Updated Path {oldrelpath} because it was absolute when it should have been relative. New Path {relativePath}");
                }
            }
            else if (reference != null)
            {
                string basepath = "";
                if (referenceTuple != null)
                {
                    basepath = referenceTuple.Item1;
                }
                else if (!String.IsNullOrEmpty(Instance.FileInWork))
                {
                    basepath = Instance.FileInWork;
                }
                if (basepath != "")
                {
                    // try primitive resolution
                    string directoryofreference = Path.GetDirectoryName(basepath);
                    if (relativePath != null)
                    {
                        absolutePath = Path.GetFullPath(Path.Combine(directoryofreference, relativePath));
                        resolved     = true;
                    }
                    if (relativePath == null || !File.Exists(absolutePath))
                    {
                        resolved = false;
                    }
                    var resolution = FindResolution(relativePath, reference);
                    // if the resolution was already computed, return that instead.
                    if (resolution != null)
                    {
                        if (!string.IsNullOrEmpty(resolution.AbsolutePath) && File.Exists(resolution.AbsolutePath))
                        {
                            if (!Path.IsPathRooted(resolution.AbsolutePath))
                            {
                                relativePath = resolution.AbsolutePath;
                            }
                            else
                            {
                                relativePath = Workspace.MakeRelativePath(basepath, resolution.AbsolutePath);
                            }
                            if (oldrelpath != relativePath)
                            {
                                Debug.WriteLine($"Updated Path {oldrelpath}. New Path {relativePath}");
                            }


                            resolution.isResolved = true;
                            return(resolution.AbsolutePath);
                        }
                        else if (resolution.isResolved)
                        {
                            // resolution is marked as resolved, but file doesn't exist
                            resolution.isResolved = false;
                        }
                        if (resolved)
                        {
                            // primitive search was successful. Update the PathResolution
                            // this should only be called if a file was moved to its original filename while the program was running
                            resolution.AbsolutePath = absolutePath;
                            resolution.isResolved   = resolved;
                        }
                    }
                    else
                    {
                        // no resolution exists yet - create a new one
                        createResolution = true;
                    }
                    if (createResolution)
                    {
                        Instance.resolvedPaths.Add(new PathResolution()
                        {
                            AbsolutePath = absolutePath, isResolved = resolved, reference = reference, RelativePath = relativePath, ParentPath = basepath
                        });
                    }
                }
            }

            else
            {
                throw new IOException("When not providing a reference, the path must be absolute");
            }
            if (!resolved)
            {
                throw new FileNotFoundException("File not found, update failed", absolutePath);
            }
            return(absolutePath);
        }