public void RenameItem(IProviderContext providerContext, string path, string newName)
        {
            if (providerContext == null)
            {
                throw new ArgumentNullException(nameof(providerContext));
            }

            var drive = providerContext.Drive as ICloudDrive;

            if (drive != null)
            {
                var fileSystemInfo = (FileSystemInfoContract)nodeValue.Item;
                fileSystemInfo = drive.RenameItem(fileSystemInfo, newName);
                if (itemMode == Mode.Directory)
                {
                    nodeValue = new ContainerPathValue(fileSystemInfo, fileSystemInfo.Name);
                    return;
                }
                else if (itemMode == Mode.File)
                {
                    nodeValue = new LeafPathValue(fileSystemInfo, fileSystemInfo.Name);
                    return;
                }
            }

            throw new InvalidOperationException();
        }
예제 #2
0
        private ISymbolTable CreateRoleSymbolTable()
        {
            IList <IDeclaredElement> roleDeclaredElements = new List <IDeclaredElement>();
            IList <string>           roles = new List <string>();
            ITreeNode child = FirstChild;

            while (child != null)
            {
                var ruleDeclaration = child as IRuleDeclaration;
                if (ruleDeclaration != null)
                {
                    IExtrasDefinition extras = (ruleDeclaration).Extras;
                    if (extras != null)
                    {
                        ITreeNode extrasChild = extras.FirstChild;
                        while (extrasChild != null)
                        {
                            extrasChild = extrasChild.NextSibling;
                            var extraDefinition = extrasChild as IExtraDefinition;
                            if (extraDefinition != null)
                            {
                                IPathValue pathValue = (extraDefinition).PathValue;
                                if (pathValue != null)
                                {
                                    ITreeNode pathElement = pathValue.FirstChild;
                                    while (pathElement != null)
                                    {
                                        var element = pathElement as IPathElement;
                                        if (element != null)
                                        {
                                            IRoleName roleName = (element).RoleName;
                                            if ((roleName != null) && (!roles.Contains(roleName.GetText())))
                                            {
                                                roles.Add(roleName.GetText());
                                            }
                                        }
                                        pathElement = pathElement.NextSibling;
                                    }
                                }
                            }
                        }
                    }
                }
                child = child.NextSibling;
            }
            foreach (string role in roles)
            {
                IDeclaredElement element = new RoleDeclaredElement(this, role, GetPsiServices());
                roleDeclaredElements.Add(element);
            }
            myRoleSymbolTable = ResolveUtil.CreateSymbolTable(roleDeclaredElements, 0);
            return(myRoleSymbolTable);
        }
예제 #3
0
        public virtual IPathValue NewItem(IProviderContext context, string path, string itemTypeName, object newItemValue)
        {
            if (null == path)
            {
                var err = new ErrorRecord(
                    new ArgumentException("The new item must have a valid item name.  Specify the new item name as part of the -path parameter, or specify the -name parameter.", "Path"),
                    "ScriptProvider.NewItem.MustHaveName",
                    ErrorCategory.InvalidArgument,
                    path);
                context.WriteError(err);
                return(null);
            }

            IPathValue node = null;

            if (null == itemTypeName)
            {
                if (newItemValue is ScriptBlock)
                {
                    itemTypeName = "script";
                }
            }

            switch (itemTypeName.ToLowerInvariant())
            {
            case ("script"):
            {
                if (null == newItemValue || String.IsNullOrWhiteSpace(newItemValue.ToString()))
                {
                    var err = new ErrorRecord(
                        new ArgumentException("Script items must have a value.  Specify the script item value as a string or scriptblock in the -value parameter, or specify the -name parameter.", "Value"),
                        "ScriptProvider.NewItem.ScriptsMustHaveValue",
                        ErrorCategory.InvalidArgument,
                        path
                        );
                    context.WriteError(err);
                    return(null);
                }
                node = NewScript(path, newItemValue);
                break;
            }

            case ("folder"):
            default:
            {
                node = NewFolder(path);
                break;
            }
            }
            return(node);
        }
예제 #4
0
        //----------------------------------------------------------------------------
        //              Generate Path
        //----------------------------------------------------------------------------

        #region GeneratePath

        /// <summary>
        /// Generic A* pathfinding, hex distance as heuristic
        /// </summary>
        public MapPath GeneratePath(IHexagon hex_a, IHexagon hex_b)
        {
            SortedSet <IPathValue> openSet = new SortedSet <IPathValue>();

            PathValueDict = new Dictionary <IHexagon, IPathValue>();

            Start       = hex_a;
            Destination = hex_b;

            IPathValue firstPath = GetPathValue(hex_a);

            firstPath.SetFirstPathDistance();

            openSet.Add(firstPath);
            while (openSet.Count != 0)
            {
                IPathValue currentPath = openSet.Min;
                openSet.Remove(currentPath);

                IHexagon currentHex = currentPath.Hex;


                if (currentHex.MyHexMap.CoOrds == hex_b.MyHexMap.CoOrds)
                {
                    return(currentPath.ReconstructPath());
                }


                foreach (IHexagon neighbour in currentHex.MyHexMap.Neighbours)
                {
                    if (!neighbour.MyHexMap.IsOccupied())
                    {
                        IPathValue neighbourPath = GetPathValue(neighbour);
                        int        newGScore     = currentPath.Score_g + neighbour.MyHexMap.MovementCost;
                        if (newGScore < neighbourPath.Score_g)
                        {
                            if (openSet.Contains(neighbourPath))
                            {
                                openSet.Remove(neighbourPath);
                            }

                            neighbourPath.UpdateValues(newGScore, currentPath);
                            openSet.Add(neighbourPath);
                        }
                    }
                }
            }
            return(null);
        }
        public CloudPathNode(FileSystemInfoContract fileSystemInfo)
        {
            var directoryInfo = fileSystemInfo as DirectoryInfoContract;
            if (directoryInfo != null) {
                itemMode = Mode.Directory;
                nodeValue = new ContainerPathValue(directoryInfo, directoryInfo.Name);
                return;
            }

            var fileInfo = fileSystemInfo as FileInfoContract;
            if (fileInfo != null) {
                itemMode = Mode.File;
                nodeValue = new LeafPathValue(fileInfo, fileInfo.Name);
                return;
            }

            throw new InvalidOperationException();
        }
예제 #6
0
        //----------------------------------------------------------------------------
        //              Hexes in Range
        //----------------------------------------------------------------------------

        /// <summary>
        /// This is an almost direct copy of above, but it sets the heuristic distance to
        /// to the start location <para/>
        ///
        /// So in practice it is Dijkstra's out until range
        /// </summary>
        public HashSet <IHexagon> GetHexesInRange(IHexagon start, int range)
        {
            SortedSet <IPathValue> openSet      = new SortedSet <IPathValue>();
            HashSet <IHexagon>     hexesInRange = new HashSet <IHexagon>();

            PathValueDict = new Dictionary <IHexagon, IPathValue>();

            Destination = start;
            Start       = start;

            IPathValue firstPath = GetPathValue(start);

            firstPath.SetFirstPathDistance();

            openSet.Add(firstPath);
            while (openSet.Count != 0)
            {
                IPathValue currentPath = openSet.Min;
                openSet.Remove(currentPath);

                IHexagon currentHex = currentPath.Hex;
                hexesInRange.Add(currentHex);

                foreach (IHexagon neighbour in currentHex.MyHexMap.Neighbours)
                {
                    if (!neighbour.MyHexMap.IsOccupied())
                    {
                        IPathValue neighbourPath = GetPathValue(neighbour);
                        int        newGScore     = currentPath.Score_g + neighbour.MyHexMap.MovementCost;
                        if (newGScore < neighbourPath.Score_g && newGScore <= range)
                        {
                            if (openSet.Contains(neighbourPath))
                            {
                                openSet.Remove(neighbourPath);
                            }

                            neighbourPath.UpdateValues(newGScore, currentPath);
                            openSet.Add(neighbourPath);
                        }
                    }
                }
            }
            return(hexesInRange);
        }
        public CloudPathNode(FileSystemInfoContract fileSystemInfo)
        {
            var directoryInfo = fileSystemInfo as DirectoryInfoContract;

            if (directoryInfo != null)
            {
                itemMode  = Mode.Directory;
                nodeValue = new ContainerPathValue(directoryInfo, directoryInfo.Name);
                return;
            }

            var fileInfo = fileSystemInfo as FileInfoContract;

            if (fileInfo != null)
            {
                itemMode  = Mode.File;
                nodeValue = new LeafPathValue(fileInfo, fileInfo.Name);
                return;
            }

            throw new InvalidOperationException();
        }
        public IPathValue MoveItem(IProviderContext providerContext, string path, string movePath, IPathValue destinationContainer)
        {
            if (providerContext == null)
            {
                throw new ArgumentNullException(nameof(providerContext));
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (destinationContainer == null)
            {
                throw new ArgumentNullException(nameof(destinationContainer));
            }

            var drive = providerContext.Drive as ICloudDrive;

            if (drive != null)
            {
                var moveItem = new CloudPathNode(drive.MoveItem((FileSystemInfoContract)nodeValue.Item, movePath, (DirectoryInfoContract)destinationContainer.Item));
                var destinationContainerNode = providerContext.ResolvePath(((DirectoryInfoContract)destinationContainer.Item).Id.Value) as CloudPathNode;
                destinationContainerNode.children.Add(moveItem);
                moveItem.SetParent(destinationContainerNode);
                parent.children.Remove(this);
                SetParent(null);
                return(moveItem.nodeValue);
            }

            throw new InvalidOperationException();
        }
예제 #9
0
 /// <summary>
 /// If a shorter path to a hex is found <para/>
 /// You should update the path to it (previous), and the new cost to this node (score_g)
 /// </summary>
 /// <param name="score_g"></param>
 /// <param name="previous"></param>
 public void UpdateValues(int score_g, IPathValue previous)
 {
     Score_g  = score_g;
     Previous = (PathValue)previous;
 }
        public void RenameItem(IProviderContext providerContext, string path, string newName)
        {
            if (providerContext == null)
                throw new ArgumentNullException(nameof(providerContext));

            var drive = providerContext.Drive as ICloudDrive;
            if (drive != null) {
                var fileSystemInfo = (FileSystemInfoContract)nodeValue.Item;
                fileSystemInfo = drive.RenameItem(fileSystemInfo, newName);
                if (itemMode == Mode.Directory) {
                    nodeValue = new ContainerPathValue(fileSystemInfo, fileSystemInfo.Name);
                    return;
                } else if (itemMode == Mode.File) {
                    nodeValue = new LeafPathValue(fileSystemInfo, fileSystemInfo.Name);
                    return;
                }
            }

            throw new InvalidOperationException();
        }
        public IPathValue MoveItem(IProviderContext providerContext, string path, string movePath, IPathValue destinationContainer)
        {
            if (providerContext == null)
                throw new ArgumentNullException(nameof(providerContext));
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException(nameof(path));
            if (destinationContainer == null)
                throw new ArgumentNullException(nameof(destinationContainer));

            var drive = providerContext.Drive as ICloudDrive;
            if (drive != null) {
                var moveItem = new CloudPathNode(drive.MoveItem((FileSystemInfoContract)nodeValue.Item, movePath, (DirectoryInfoContract)destinationContainer.Item));
                var destinationContainerNode = providerContext.ResolvePath(((DirectoryInfoContract)destinationContainer.Item).Id.Value) as CloudPathNode;
                destinationContainerNode.children.Add(moveItem);
                moveItem.SetParent(destinationContainerNode);
                parent.children.Remove(this);
                SetParent(null);
                return moveItem.nodeValue;
            }

            throw new InvalidOperationException();
        }