Esempio n. 1
0
 /// <summary>
 /// It is used to check if the current object is equal to another object.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns>It returns true if the objects are equal else false.</returns>
 public override bool Equals(object obj)
 {
     //Check for null and compare run-time types.
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         Node node = (Node)obj;
         if (node.Type == NodeType.NumberNode)
         {
             return(Value == node.Value);
         }
         else if (node.Type == NodeType.PlusNode || node.Type == NodeType.MinusNode || node.Type == NodeType.FactorialNode)
         {
             return(Type.Equals(node.Type) && NodeA.Equals(node.NodeA));
         }
         else if (node.Type == NodeType.EmptyNode)
         {
             return(Type.Equals(node.Type));
         }
         return(Type.Equals(node.Type) && NodeA.Equals(node.NodeA) && NodeB.Equals(node.NodeB));
     }
 }
Esempio n. 2
0
        protected override INode CreateNode(INodeAddress address, NodeType nodeType)
        {
            lock (this)
            {
                string path;

                if (nodeType.Equals(NodeType.File))
                {
                    path = ((AbstractNodeAddressWithRootPart)address).AbsolutePathIncludingRootPart;

                    return(new ZipFile(this, (LayeredNodeAddress)address, GetEntry(path)));
                }
                else if (nodeType.Equals(NodeType.Directory))
                {
                    path = ((AbstractNodeAddressWithRootPart)address).AbsolutePathIncludingRootPart;

                    if (path != FileSystemManager.SeperatorString)
                    {
                        path += "/";
                    }

                    return(new ZipDirectory(this, (LayeredNodeAddress)address, GetEntry(path)));
                }
                else
                {
                    throw new NotSupportedException(nodeType.ToString());
                }
            }
        }
Esempio n. 3
0
        public override IEnumerable <INode> DoGetChildren(NodeType nodeType, Predicate <INode> acceptNode)
        {
            INode node;
            var   files       = new List <IFile>();
            var   directories = new HashSet <string>();

            Refresh();

            var fileSystem = (ZipFileSystem)this.FileSystem;

            foreach (ZLib.ZipEntry zipEntry in fileSystem.zipFile)
            {
                if (zipEntry.Name.StartsWith(this.ZipPath) &&               /* Is descendent */
                    zipEntry.Name.Length != this.ZipPath.Length /* Not self */)
                {
                    var x = zipEntry.Name.IndexOf('/', this.ZipPath.Length + 1);

                    if (x == -1 /* Is direct descendent File */)
                    {
                        node = this.FileSystem.ResolveFile(FileSystemManager.SeperatorChar + zipEntry.Name);

                        if (acceptNode(node))
                        {
                            files.Add((IFile)node);
                        }
                    }
                    else if (x <= zipEntry.Name.Length - 1 /* Is direct descendent dir */)
                    {
                        var s = zipEntry.Name.Substring(0, x);

                        directories.Add(s);
                    }
                }
            }

            if (nodeType.Equals(NodeType.Directory) || nodeType.Equals(NodeType.Any))
            {
                var sortedDirectories = directories.Sorted(StringComparer.InvariantCultureIgnoreCase);

                foreach (var path in sortedDirectories)
                {
                    node = this.FileSystem.ResolveDirectory(FileSystemManager.SeperatorChar + path);

                    if (acceptNode(node))
                    {
                        yield return(node);
                    }
                }
            }

            if (nodeType.Equals(NodeType.File) || nodeType.Equals(NodeType.Any))
            {
                foreach (var file in files)
                {
                    yield return(file);
                }
            }
        }
        private IEnumerable <string> PrivateGetChildNames(NodeType nodeType)
        {
            if (nodeType.Equals(NodeType.File) || nodeType.Equals(NodeType.Any))
            {
                string[] names;

                foreach (string s in this.GetJumpPointNames(NodeType.File))
                {
                    yield return(s);
                }

                try
                {
                    names = Directory.GetFiles(this.directoryInfo.FullName);
                }
                catch (DirectoryNotFoundException)
                {
                    throw new DirectoryNodeNotFoundException(this.Address);
                }

                foreach (string s in names)
                {
                    if (!this.ContainsShortcut(s, NodeType.File))
                    {
                        yield return(Path.GetFileName(s));
                    }
                }
            }

            if (nodeType.Equals(NodeType.Directory) || nodeType.Equals(NodeType.Any))
            {
                string[] names;

                foreach (var s in this.GetJumpPointNames(NodeType.Directory))
                {
                    yield return(s);
                }

                try
                {
                    names = Directory.GetDirectories(this.directoryInfo.FullName);
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    throw new DirectoryNodeNotFoundException(this.Address);
                }

                foreach (var s in names)
                {
                    if (!this.ContainsShortcut(s, NodeType.Directory))
                    {
                        yield return(Path.GetFileName(s));
                    }
                }
            }
        }
Esempio n. 5
0
 public virtual RMContainer Allocate(NodeType type, FSSchedulerNode node, Priority
                                     priority, ResourceRequest request, Container container)
 {
     lock (this)
     {
         // Update allowed locality level
         NodeType allowed = allowedLocalityLevel[priority];
         if (allowed != null)
         {
             if (allowed.Equals(NodeType.OffSwitch) && (type.Equals(NodeType.NodeLocal) || type
                                                        .Equals(NodeType.RackLocal)))
             {
                 this.ResetAllowedLocalityLevel(priority, type);
             }
             else
             {
                 if (allowed.Equals(NodeType.RackLocal) && type.Equals(NodeType.NodeLocal))
                 {
                     this.ResetAllowedLocalityLevel(priority, type);
                 }
             }
         }
         // Required sanity check - AM can call 'allocate' to update resource
         // request without locking the scheduler, hence we need to check
         if (GetTotalRequiredResources(priority) <= 0)
         {
             return(null);
         }
         // Create RMContainer
         RMContainer rmContainer = new RMContainerImpl(container, GetApplicationAttemptId(
                                                           ), node.GetNodeID(), appSchedulingInfo.GetUser(), rmContext);
         // Add it to allContainers list.
         newlyAllocatedContainers.AddItem(rmContainer);
         liveContainers[container.GetId()] = rmContainer;
         // Update consumption and track allocations
         IList <ResourceRequest> resourceRequestList = appSchedulingInfo.Allocate(type, node
                                                                                  , priority, request, container);
         Resources.AddTo(currentConsumption, container.GetResource());
         // Update resource requests related to "request" and store in RMContainer
         ((RMContainerImpl)rmContainer).SetResourceRequests(resourceRequestList);
         // Inform the container
         rmContainer.Handle(new RMContainerEvent(container.GetId(), RMContainerEventType.Start
                                                 ));
         if (Log.IsDebugEnabled())
         {
             Log.Debug("allocate: applicationAttemptId=" + container.GetId().GetApplicationAttemptId
                           () + " container=" + container.GetId() + " host=" + container.GetNodeId().GetHost
                           () + " type=" + type);
         }
         RMAuditLogger.LogSuccess(GetUser(), RMAuditLogger.AuditConstants.AllocContainer,
                                  "SchedulerApp", GetApplicationId(), container.GetId());
         return(rmContainer);
     }
 }
Esempio n. 6
0
 /// <summary>Return the level at which we are allowed to schedule containers.</summary>
 /// <remarks>
 /// Return the level at which we are allowed to schedule containers.
 /// Given the thresholds indicating how much time passed before relaxing
 /// scheduling constraints.
 /// </remarks>
 public virtual NodeType GetAllowedLocalityLevelByTime(Priority priority, long nodeLocalityDelayMs
                                                       , long rackLocalityDelayMs, long currentTimeMs)
 {
     lock (this)
     {
         // if not being used, can schedule anywhere
         if (nodeLocalityDelayMs < 0 || rackLocalityDelayMs < 0)
         {
             return(NodeType.OffSwitch);
         }
         // default level is NODE_LOCAL
         if (!allowedLocalityLevel.Contains(priority))
         {
             allowedLocalityLevel[priority] = NodeType.NodeLocal;
             return(NodeType.NodeLocal);
         }
         NodeType allowed = allowedLocalityLevel[priority];
         // if level is already most liberal, we're done
         if (allowed.Equals(NodeType.OffSwitch))
         {
             return(NodeType.OffSwitch);
         }
         // check waiting time
         long waitTime = currentTimeMs;
         if (lastScheduledContainer.Contains(priority))
         {
             waitTime -= lastScheduledContainer[priority];
         }
         else
         {
             waitTime -= GetStartTime();
         }
         long thresholdTime = allowed.Equals(NodeType.NodeLocal) ? nodeLocalityDelayMs : rackLocalityDelayMs;
         if (waitTime > thresholdTime)
         {
             if (allowed.Equals(NodeType.NodeLocal))
             {
                 allowedLocalityLevel[priority] = NodeType.RackLocal;
                 ResetSchedulingOpportunities(priority, currentTimeMs);
             }
             else
             {
                 if (allowed.Equals(NodeType.RackLocal))
                 {
                     allowedLocalityLevel[priority] = NodeType.OffSwitch;
                     ResetSchedulingOpportunities(priority, currentTimeMs);
                 }
             }
         }
         return(allowedLocalityLevel[priority]);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Return the level at which we are allowed to schedule containers, given the
 /// current size of the cluster and thresholds indicating how many nodes to
 /// fail at (as a fraction of cluster size) before relaxing scheduling
 /// constraints.
 /// </summary>
 public virtual NodeType GetAllowedLocalityLevel(Priority priority, int numNodes,
                                                 double nodeLocalityThreshold, double rackLocalityThreshold)
 {
     lock (this)
     {
         // upper limit on threshold
         if (nodeLocalityThreshold > 1.0)
         {
             nodeLocalityThreshold = 1.0;
         }
         if (rackLocalityThreshold > 1.0)
         {
             rackLocalityThreshold = 1.0;
         }
         // If delay scheduling is not being used, can schedule anywhere
         if (nodeLocalityThreshold < 0.0 || rackLocalityThreshold < 0.0)
         {
             return(NodeType.OffSwitch);
         }
         // Default level is NODE_LOCAL
         if (!allowedLocalityLevel.Contains(priority))
         {
             allowedLocalityLevel[priority] = NodeType.NodeLocal;
             return(NodeType.NodeLocal);
         }
         NodeType allowed = allowedLocalityLevel[priority];
         // If level is already most liberal, we're done
         if (allowed.Equals(NodeType.OffSwitch))
         {
             return(NodeType.OffSwitch);
         }
         double threshold = allowed.Equals(NodeType.NodeLocal) ? nodeLocalityThreshold : rackLocalityThreshold;
         // Relax locality constraints once we've surpassed threshold.
         if (GetSchedulingOpportunities(priority) > (numNodes * threshold))
         {
             if (allowed.Equals(NodeType.NodeLocal))
             {
                 allowedLocalityLevel[priority] = NodeType.RackLocal;
                 ResetSchedulingOpportunities(priority);
             }
             else
             {
                 if (allowed.Equals(NodeType.RackLocal))
                 {
                     allowedLocalityLevel[priority] = NodeType.OffSwitch;
                     ResetSchedulingOpportunities(priority);
                 }
             }
         }
         return(allowedLocalityLevel[priority]);
     }
 }
Esempio n. 8
0
    public void OnValidate()
    {
        if (dialogueNodeType.Equals(NodeType.branch))
        {
            // If the branch node has text, remove it.
            if (!dialogueText.Equals(""))
            {
                dialogueText = "";
            }

            // If the number of child nodes is greater than four, we have a problem.
            if (childNodes.Count > 4)
            {
                dialogueNodeType = NodeType.error;
                return;
            }
            else
            {
                // If the children do not have the proper condition (none), we have a problem.
                foreach (DialogueBranchCondition dbc in childNodes)
                {
                    if (!dbc.condition.Equals(DialogueBranchCondition.Condition.none))
                    {
                        dialogueNodeType = NodeType.error;
                        return;
                    }
                }
            }
        }
        else if (dialogueNodeType.Equals(NodeType.single))
        {
            // If the children use the same condition more than once, we have a problem.
            List <DialogueBranchCondition.Condition> conditions = new List <DialogueBranchCondition.Condition>();

            foreach (DialogueBranchCondition dbc in childNodes)
            {
                if (!conditions.Contains(dbc.condition))
                {
                    conditions.Add(dbc.condition);
                }
                else
                {
                    dialogueNodeType = NodeType.error;
                    return;
                }
            }
        }

        // Check to make sure there are no invalid IDs in the child nodes.
        ((DialogueTree)graph).ValidateNode(this);
    }
Esempio n. 9
0
        /// <summary>
        /// Creates the node.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="nodeType">Type of the node.</param>
        /// <returns></returns>
        protected override INode CreateNode(INodeAddress address, NodeType nodeType)
        {
            lock (this)
            {
                if (nodeType.Equals(NodeType.File))
                    return new PgpFile(this, address, ParentLayer);

                throw new NodeTypeNotSupportedException(nodeType);
            }
        }
Esempio n. 10
0
        public Node(Point point, NodeType n, String name, int localPort, int mPort, int ccrcPort, int nccPort = 0)
        {
            nodeType = n;
            if (n.Equals(NodeType.CLIENT))
            {
                this.Name          = name;
                this.LocalPort     = localPort;
                this.Position      = point;
                this.ManagmentPort = mPort;
                this.CcRcPort      = ccrcPort;
                this.NccPort       = nccPort;
                String           parameters = name + " " + this.LocalPort + " " + this.ManagmentPort + " " + this.NccPort;
                ProcessStartInfo startInfo  = new ProcessStartInfo("ClientNode.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                startInfo.Arguments   = parameters;

                this.ProcessHandle = Process.Start(startInfo);
                Thread.Sleep(100);
                Program.SwitchToThisWindow(Process.GetCurrentProcess().MainWindowHandle, true);
            }
            else if (n.Equals(NodeType.NETWORK))
            {
                this.Name          = name;
                this.LocalPort     = localPort;
                this.Position      = point;
                this.ManagmentPort = mPort;
                this.CcRcPort      = ccrcPort;
                String           parameters = name + " " + this.LocalPort + " " + this.ManagmentPort + " " + this.CcRcPort;
                ProcessStartInfo startInfo  = new ProcessStartInfo("NetNode.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                startInfo.Arguments   = parameters;

                this.ProcessHandle = Process.Start(startInfo);
                Thread.Sleep(50);
                Program.SwitchToThisWindow(Process.GetCurrentProcess().MainWindowHandle, true);
            }
            //Thread.Sleep(100);
            //System.Diagnostics.Process me = System.Diagnostics.Process.GetCurrentProcess();
            //Program.SwitchToThisWindow(me.MainWindowHandle, true);
        }
Esempio n. 11
0
        public void Reset()
        {
            F = G = H = 0;

            parent = null;

            state = NodeState.None;

            if (type.Equals(NodeType.Route))
            {
                type = NodeType.Movable;
            }
        }
        public virtual INode Filter(ref INodeResolver resolver, ref INodeAddress address, ref NodeType nodeType, out bool canCache)
        {
            string value;

            canCache = false;

            if (this.QueryKey == null)
            {
                value = "true";
            }
            else
            {
                try
                {
                    if (address.QueryValues[QueryKey] == null)
                    {
                        return(null);
                    }

                    value = (string)address.QueryValues[this.QueryKey];
                }
                catch (KeyNotFoundException)
                {
                    value = null;
                }
            }

            if (nodeType.Equals(NodeType.File) && value != null && value.ToLower() == "true")
            {
                canCache = true;

                var innerNodeType = nodeType.InnerType;

                if (innerNodeType == null)
                {
                    innerNodeType = NodeType.File;
                }

                var query = StringUriUtils.BuildQuery
                            (
                    address.QueryValues,
                    QueryFilter
                            );

                var uri = address.AbsolutePath + "?" + query;

                return(new ShadowFile((IFile)resolver.Resolve(uri, innerNodeType), address));
            }

            return(null);
        }
		public virtual INode Filter(ref INodeResolver resolver, ref INodeAddress address, ref NodeType nodeType, out bool canCache)
		{
			string value;

			canCache = false;
			
			if (this.QueryKey == null)
			{
				value = "true";
			}
			else
			{
				try
				{
					if (address.QueryValues[QueryKey] == null)
					{
						return null;
					}

					value = (string)address.QueryValues[this.QueryKey];
				}
				catch (KeyNotFoundException)
				{
					value = null;
				}
			}

			if (nodeType.Equals(NodeType.File) && value != null && value.ToLower() == "true")
			{
				canCache = true;

				var innerNodeType = nodeType.InnerType;

				if (innerNodeType == null)
				{
					innerNodeType = NodeType.File;
				}

				var query = StringUriUtils.BuildQuery
				(
					address.QueryValues,
					QueryFilter
				);

				var uri = address.AbsolutePath + "?" + query;

				return new ShadowFile((IFile)resolver.Resolve(uri, innerNodeType), address);
			}				
			
			return null;
		}
        public override IEnumerable <INode> DoGetChildren(NodeType nodeType, Predicate <INode> acceptNode)
        {
            bool localRefreshNodes;

            lock (this.SyncLock)
            {
                localRefreshNodes = this.refreshNodes;

                this.refreshNodes = false;
            }

            localRefreshNodes = true;

            /**
             * TODO: If refreshNodes is true then we have to manually refresh
             * all children that aren't listed in the current listing but are
             * still in the node cache.
             *
             * Do this by attaching to cache events (thru a weak event handler) and
             * keeping a list of all cached (and thus resolved) nodes that are children
             * of this node.
             */

            //lock (this.SyncLock)
            {
                string[] items;

                foreach (var jumpPoint in GetJumpPoints(NodeType.Directory))
                {
                    yield return(jumpPoint);
                }

                if ((nodeType.Equals(NodeType.Directory)) || nodeType.Equals(NodeType.Any))
                {
                    try
                    {
                        if (Environment.OSVersion.Platform == PlatformID.Unix)
                        {
                            // Hack for mono which does not return symbolic links as directories anymore

                            items = Directory.GetFileSystemEntries(this.directoryInfo.FullName);
                        }
                        else
                        {
                            items = Directory.GetDirectories(this.directoryInfo.FullName);
                        }
                    }
                    catch (System.IO.IOException)
                    {
                        throw new DirectoryNodeNotFoundException(this.Address);
                    }

                    foreach (var name in items)
                    {
                        if (Environment.OSVersion.Platform == PlatformID.Unix)
                        {
                            if (Native.GetInstance().GetSymbolicLinkTarget(name) != null)
                            {
                                if (Native.GetInstance().GetSymbolicLinkTargetType(name) != NodeType.Directory)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (!Directory.Exists(name))
                                {
                                    continue;
                                }
                            }
                        }

                        var dir = (IDirectory)this.FileSystem.Resolve(this.Address.ResolveAddress(Path.GetFileName(name)), NodeType.Directory);

                        if (localRefreshNodes && !String.Equals((string)dir.Attributes["DriveType"], "Removable", StringComparison.CurrentCultureIgnoreCase))
                        {
                            dir.Refresh();
                        }

                        if (!ContainsShortcut(dir.Name, NodeType.Directory))
                        {
                            if (acceptNode(dir))
                            {
                                yield return(dir);
                            }
                        }
                    }
                }

                foreach (INode jumpPoint in GetJumpPoints(NodeType.File))
                {
                    yield return(jumpPoint);
                }

                if ((nodeType.Equals(NodeType.File)) || nodeType.Equals(NodeType.Any))
                {
                    try
                    {
                        if (Environment.OSVersion.Platform == PlatformID.Unix)
                        {
                            items = Directory.GetFileSystemEntries(this.directoryInfo.FullName);
                        }
                        else
                        {
                            items = Directory.GetFiles(this.directoryInfo.FullName);
                        }
                    }
                    catch (System.IO.DirectoryNotFoundException)
                    {
                        throw new DirectoryNodeNotFoundException(this.Address);
                    }

                    foreach (string name in items)
                    {
                        if (Environment.OSVersion.Platform == PlatformID.Unix)
                        {
                            if (Native.GetInstance().GetSymbolicLinkTarget(name) != null)
                            {
                                if (Native.GetInstance().GetSymbolicLinkTargetType(name) != NodeType.File)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (!File.Exists(name))
                                {
                                    continue;
                                }
                            }
                        }

                        var file = (IFile)this.FileSystem.Resolve(this.Address.ResolveAddress(Path.GetFileName(name)), NodeType.File);

                        if (localRefreshNodes)
                        {
                            file.Refresh();
                        }

                        if (!ContainsShortcut(file.Name, NodeType.File))
                        {
                            if (acceptNode(file))
                            {
                                yield return(file);
                            }
                        }
                    }
                }

                localRefreshNodes = false;
            }
        }
		public override IEnumerable<INode> DoGetChildren(NodeType nodeType, Predicate<INode> acceptNode)
		{
			var listedAllChildren = false;
			IDictionary<string, INode> newChildren;
			Pair<DirectoryRefreshMask, int> refreshInfo;
			
			foreach (INode node in this.GetJumpPoints(nodeType, acceptNode))
			{
				yield return node;
			}
						
			var shouldLoadFromNetwork = false;
						
			lock (this.SyncLock)
			{
				refreshInfo = this.directoryRefreshInfo;

				if ((refreshInfo.Left & DirectoryRefreshMask.Children) != 0)
				{
					shouldLoadFromNetwork = true;
				}

				if (this.children == null)
				{
					this.children = new SortedDictionary<string, INode>(StringComparer.CurrentCultureIgnoreCase);
				}
			}

			if (shouldLoadFromNetwork)
			{
				string regex = null;
				var skipAcceptNode = false; ;
				var toRemove = new List<string>();

				var newAttributes = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase);

				if (NetworkDirectory.threadLocalNewChildren == null)
				{
					NetworkDirectory.threadLocalNewChildren = new SortedDictionary<string, INode>(StringComparer.CurrentCultureIgnoreCase);
				}
				else
				{
					NetworkDirectory.threadLocalNewChildren.Clear();
				}

				newChildren = NetworkDirectory.threadLocalNewChildren;

				try
				{
					if (RegexBasedNodePredicateHelper.IsRegexBasedNodePredicate(acceptNode)
						/* Only load based on REGEX if not refreshing AllChildren */
						&& refreshInfo.Left != DirectoryRefreshMask.AllChildren)
					{
						regex = RegexBasedNodePredicateHelper.GetRegexFromRegexBasedNodePredicate(acceptNode).ToString();

						if (RegexBasedNodePredicateHelper.PredicateNameBasedOnly(acceptNode))
						{
							skipAcceptNode = true;
						}
					}

					using (var freeClientContext = ((NetworkFileSystem)this.FileSystem).GetFreeClientContext())
					{
						var networkclient = freeClientContext.NetworkFileSystemClient;

						IEnumerator<NetworkFileSystemEntry> enumerator;

						var enumerable = networkclient.ListAttributes(this.Address.RemoteUri, regex);

						using (enumerator = enumerable.GetEnumerator())
						{
							while (true)
							{
								try
								{
									if (!enumerator.MoveNext())
									{
										break;
									}
								}
								catch (DirectoryNodeNotFoundException)
								{
									lock (this.SyncLock)
									{
										foreach (var node in this.children.Values)
										{
											((NetworkNodeAndFileAttributes)node.Attributes).Clear();
											((NetworkNodeAndFileAttributes)node.Attributes).SetValue<bool>("exists", false);
										}

										this.children.Clear();
									}

									throw;
								}

								var entry = enumerator.Current;

								INode child = null;

								if (entry.NodeType == NodeType.Directory)
								{
									child = this.ResolveDirectory(entry.Name);
								}
								else
								{
									child = this.ResolveFile(entry.Name);
								}

								var attributes = (NetworkNodeAndFileAttributes)child.Attributes;

								newAttributes.Clear();

								foreach (var attribute in entry.ReadAttributes())
								{
									newAttributes[attribute.Key] = attribute.Value;
								}

								try
								{
									lock (attributes.SyncLock)
									{
										toRemove.Clear();

										foreach (var attribute in newAttributes)
										{
											attributes.SetValue<object>(attribute.Key, attribute.Value);
										}

										foreach (var name in attributes.Names)
										{
											if (!newAttributes.ContainsKey(name))
											{
												toRemove.Add(name);
											}
										}

										foreach (var name in toRemove)
										{
											attributes.SetValue<object>(name, null);
										}

										attributes.SetValue<bool>("exists", true);
									}

									newChildren.Add(child.Name, child);
								}
								catch (Exception)
								{
									Debugger.Break();
								}

								if ((nodeType.Equals(NodeType.Any) || child.NodeType.Equals(nodeType))
									&& (skipAcceptNode || acceptNode(child)))
								{
									yield return child;
								}
							}
						}

						if (regex == null)
						{
							listedAllChildren = true;
						}
					}
				}
				finally
				{
					lock (this.SyncLock)
					{
						if (listedAllChildren)
						{
							toRemove.Clear();

							foreach (var node in this.children.Values)
							{
								if (!newChildren.ContainsKey(node.Name))
								{
									((NetworkNodeAndFileAttributes)node.Attributes).Clear();
									((NetworkNodeAndFileAttributes)node.Attributes).SetValue<bool>("exists", false);

									toRemove.Add(node.Name);									
								}
							}

							foreach (var name in toRemove)
							{
								this.children.Remove(name);
							}

							if (this.directoryRefreshInfo.Right == refreshInfo.Right)
							{
								this.directoryRefreshInfo.Left = DirectoryRefreshMask.None;
							}
						}

						foreach (var node in newChildren.Values)
						{
							this.children[node.Name] = node;
						}
					}

					toRemove.Clear();
				}
					
				yield break;
			}
			else
			{
				var retvals = new List<INode>();

				// Copy the children because we want to yield outside the lock

				lock (this.SyncLock)
				{
					foreach (var pair in this.children)
					{
						if ((nodeType.Equals(NodeType.Any) || pair.Value.NodeType.Equals(nodeType)) && acceptNode(pair.Value))
						{
							retvals.Add(pair.Value);
						}
					}
				}

				foreach (var node in retvals)
				{
					yield return node;
				}
			}
		}
		public override IEnumerable<INode> DoGetChildren(NodeType nodeType, Predicate<INode> acceptNode)
		{
			INode node;
			var files = new List<IFile>();
			var directories = new HashSet<string>();

			Refresh();

			var fileSystem = (ZipFileSystem)this.FileSystem;

			foreach (ZLib.ZipEntry zipEntry in fileSystem.zipFile)
			{
				if (zipEntry.Name.StartsWith(this.ZipPath)  /* Is descendent */
					&& zipEntry.Name.Length != this.ZipPath.Length /* Not self */)
				{
					var x = zipEntry.Name.IndexOf('/', this.ZipPath.Length + 1);

					if (x == -1 /* Is direct descendent File */)
					{
						node = this.FileSystem.ResolveFile(FileSystemManager.SeperatorChar + zipEntry.Name);

						if (acceptNode(node))
						{
							files.Add((IFile)node);
						}
					}
					else if (x <= zipEntry.Name.Length - 1 /* Is direct descendent dir */)
					{
						var s = zipEntry.Name.Substring(0, x);
                            
						directories.Add(s);
					}
				}
			}

			if (nodeType.Equals(NodeType.Directory) || nodeType.Equals(NodeType.Any))
			{
				var sortedDirectories = directories.Sorted(StringComparer.InvariantCultureIgnoreCase);

				foreach (var path in sortedDirectories)
				{
					node = this.FileSystem.ResolveDirectory(FileSystemManager.SeperatorChar + path);

					if (acceptNode(node))
					{
						yield return node;
					}
				}
			}
			
			if (nodeType.Equals(NodeType.File) || nodeType.Equals(NodeType.Any))
			{
				foreach (var file in files)
				{
					yield return file;
				}
			}
		}
Esempio n. 17
0
        public bool Equals(DestinyPresentationNodeDefinition input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     DisplayProperties == input.DisplayProperties ||
                     (DisplayProperties != null && DisplayProperties.Equals(input.DisplayProperties))
                     ) &&
                 (
                     OriginalIcon == input.OriginalIcon ||
                     (OriginalIcon != null && OriginalIcon.Equals(input.OriginalIcon))
                 ) &&
                 (
                     RootViewIcon == input.RootViewIcon ||
                     (RootViewIcon != null && RootViewIcon.Equals(input.RootViewIcon))
                 ) &&
                 (
                     NodeType == input.NodeType ||
                     (NodeType != null && NodeType.Equals(input.NodeType))
                 ) &&
                 (
                     Scope == input.Scope ||
                     (Scope != null && Scope.Equals(input.Scope))
                 ) &&
                 (
                     ObjectiveHash == input.ObjectiveHash ||
                     (ObjectiveHash.Equals(input.ObjectiveHash))
                 ) &&
                 (
                     CompletionRecordHash == input.CompletionRecordHash ||
                     (CompletionRecordHash.Equals(input.CompletionRecordHash))
                 ) &&
                 (
                     Children == input.Children ||
                     (Children != null && Children.Equals(input.Children))
                 ) &&
                 (
                     DisplayStyle == input.DisplayStyle ||
                     (DisplayStyle != null && DisplayStyle.Equals(input.DisplayStyle))
                 ) &&
                 (
                     ScreenStyle == input.ScreenStyle ||
                     (ScreenStyle != null && ScreenStyle.Equals(input.ScreenStyle))
                 ) &&
                 (
                     Requirements == input.Requirements ||
                     (Requirements != null && Requirements.Equals(input.Requirements))
                 ) &&
                 (
                     DisableChildSubscreenNavigation == input.DisableChildSubscreenNavigation ||
                     (DisableChildSubscreenNavigation != null && DisableChildSubscreenNavigation.Equals(input.DisableChildSubscreenNavigation))
                 ) &&
                 (
                     MaxCategoryRecordScore == input.MaxCategoryRecordScore ||
                     (MaxCategoryRecordScore.Equals(input.MaxCategoryRecordScore))
                 ) &&
                 (
                     PresentationNodeType == input.PresentationNodeType ||
                     (PresentationNodeType != null && PresentationNodeType.Equals(input.PresentationNodeType))
                 ) &&
                 (
                     TraitIds == input.TraitIds ||
                     (TraitIds != null && TraitIds.SequenceEqual(input.TraitIds))
                 ) &&
                 (
                     TraitHashes == input.TraitHashes ||
                     (TraitHashes != null && TraitHashes.SequenceEqual(input.TraitHashes))
                 ) &&
                 (
                     ParentNodeHashes == input.ParentNodeHashes ||
                     (ParentNodeHashes != null && ParentNodeHashes.SequenceEqual(input.ParentNodeHashes))
                 ) &&
                 (
                     Hash == input.Hash ||
                     (Hash.Equals(input.Hash))
                 ) &&
                 (
                     Index == input.Index ||
                     (Index.Equals(input.Index))
                 ) &&
                 (
                     Redacted == input.Redacted ||
                     (Redacted != null && Redacted.Equals(input.Redacted))
                 ));
        }
		private IEnumerable<string> PrivateGetChildNames(NodeType nodeType)
		{
			if (nodeType.Equals(NodeType.File) || nodeType.Equals(NodeType.Any))
			{
				string[] names;

				foreach (string s in this.GetJumpPointNames(NodeType.File))
				{
					yield return s;
				}

				try
				{
					names = Directory.GetFiles(this.directoryInfo.FullName);
				}
				catch (DirectoryNotFoundException)
				{
					throw new DirectoryNodeNotFoundException(this.Address);
				}

				foreach (string s in names)
				{
					if (!this.ContainsShortcut(s, NodeType.File))
					{
						yield return Path.GetFileName(s);
					}
				}
			}

			if (nodeType.Equals(NodeType.Directory) || nodeType.Equals(NodeType.Any))
			{
				string[] names;

				foreach (var s in this.GetJumpPointNames(NodeType.Directory))
				{
					yield return s;
				}

				try
				{
					names = Directory.GetDirectories(this.directoryInfo.FullName);
				}
				catch (System.IO.DirectoryNotFoundException)
				{
					throw new DirectoryNodeNotFoundException(this.Address);
				}

				foreach (var s in names)
				{
					if (!this.ContainsShortcut(s, NodeType.Directory))
					{
						yield return Path.GetFileName(s);
					}
				}
			}
		}
		protected override INode CreateNode(INodeAddress address, NodeType nodeType)
		{
			lock (this)
			{
				string path;

				if (nodeType.Equals(NodeType.File))
				{
					path = ((AbstractNodeAddressWithRootPart)address).AbsolutePathIncludingRootPart;

					return new ZipFile(this, (LayeredNodeAddress)address, GetEntry(path));
				}
				else if (nodeType.Equals(NodeType.Directory))
				{
					path = ((AbstractNodeAddressWithRootPart)address).AbsolutePathIncludingRootPart;

					if (path != FileSystemManager.SeperatorString)
					{
						path += "/";
					}

					return new ZipDirectory(this, (LayeredNodeAddress)address, GetEntry(path));
				}
				else
				{
					throw new NotSupportedException(nodeType.ToString());
				}
			}
		}
        public override IEnumerable <INode> DoGetChildren(NodeType nodeType, Predicate <INode> acceptNode)
        {
            var listedAllChildren = false;
            IDictionary <string, INode>      newChildren;
            Pair <DirectoryRefreshMask, int> refreshInfo;

            foreach (INode node in this.GetJumpPoints(nodeType, acceptNode))
            {
                yield return(node);
            }

            var shouldLoadFromNetwork = false;

            lock (this.SyncLock)
            {
                refreshInfo = this.directoryRefreshInfo;

                if ((refreshInfo.Left & DirectoryRefreshMask.Children) != 0)
                {
                    shouldLoadFromNetwork = true;
                }

                if (this.children == null)
                {
                    this.children = new SortedDictionary <string, INode>(StringComparer.CurrentCultureIgnoreCase);
                }
            }

            if (shouldLoadFromNetwork)
            {
                string regex          = null;
                var    skipAcceptNode = false;;
                var    toRemove       = new List <string>();

                var newAttributes = new Dictionary <string, object>(StringComparer.CurrentCultureIgnoreCase);

                if (NetworkDirectory.threadLocalNewChildren == null)
                {
                    NetworkDirectory.threadLocalNewChildren = new SortedDictionary <string, INode>(StringComparer.CurrentCultureIgnoreCase);
                }
                else
                {
                    NetworkDirectory.threadLocalNewChildren.Clear();
                }

                newChildren = NetworkDirectory.threadLocalNewChildren;

                try
                {
                    if (RegexBasedNodePredicateHelper.IsRegexBasedNodePredicate(acceptNode)
                        /* Only load based on REGEX if not refreshing AllChildren */
                        && refreshInfo.Left != DirectoryRefreshMask.AllChildren)
                    {
                        regex = RegexBasedNodePredicateHelper.GetRegexFromRegexBasedNodePredicate(acceptNode).ToString();

                        if (RegexBasedNodePredicateHelper.PredicateNameBasedOnly(acceptNode))
                        {
                            skipAcceptNode = true;
                        }
                    }

                    using (var freeClientContext = ((NetworkFileSystem)this.FileSystem).GetFreeClientContext())
                    {
                        var networkclient = freeClientContext.NetworkFileSystemClient;

                        IEnumerator <NetworkFileSystemEntry> enumerator;

                        var enumerable = networkclient.ListAttributes(this.Address.RemoteUri, regex);

                        using (enumerator = enumerable.GetEnumerator())
                        {
                            while (true)
                            {
                                try
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        break;
                                    }
                                }
                                catch (DirectoryNodeNotFoundException)
                                {
                                    lock (this.SyncLock)
                                    {
                                        foreach (var node in this.children.Values)
                                        {
                                            ((NetworkNodeAndFileAttributes)node.Attributes).Clear();
                                            ((NetworkNodeAndFileAttributes)node.Attributes).SetValue <bool>("exists", false);
                                        }

                                        this.children.Clear();
                                    }

                                    throw;
                                }

                                var entry = enumerator.Current;

                                INode child = null;

                                if (entry.NodeType == NodeType.Directory)
                                {
                                    child = this.ResolveDirectory(entry.Name);
                                }
                                else
                                {
                                    child = this.ResolveFile(entry.Name);
                                }

                                var attributes = (NetworkNodeAndFileAttributes)child.Attributes;

                                newAttributes.Clear();

                                foreach (var attribute in entry.ReadAttributes())
                                {
                                    newAttributes[attribute.Key] = attribute.Value;
                                }

                                try
                                {
                                    lock (attributes.SyncLock)
                                    {
                                        toRemove.Clear();

                                        foreach (var attribute in newAttributes)
                                        {
                                            attributes.SetValue <object>(attribute.Key, attribute.Value);
                                        }

                                        foreach (var name in attributes.Names)
                                        {
                                            if (!newAttributes.ContainsKey(name))
                                            {
                                                toRemove.Add(name);
                                            }
                                        }

                                        foreach (var name in toRemove)
                                        {
                                            attributes.SetValue <object>(name, null);
                                        }

                                        attributes.SetValue <bool>("exists", true);
                                    }

                                    newChildren.Add(child.Name, child);
                                }
                                catch (Exception)
                                {
                                    Debugger.Break();
                                }

                                if ((nodeType.Equals(NodeType.Any) || child.NodeType.Equals(nodeType)) &&
                                    (skipAcceptNode || acceptNode(child)))
                                {
                                    yield return(child);
                                }
                            }
                        }

                        if (regex == null)
                        {
                            listedAllChildren = true;
                        }
                    }
                }
                finally
                {
                    lock (this.SyncLock)
                    {
                        if (listedAllChildren)
                        {
                            toRemove.Clear();

                            foreach (var node in this.children.Values)
                            {
                                if (!newChildren.ContainsKey(node.Name))
                                {
                                    ((NetworkNodeAndFileAttributes)node.Attributes).Clear();
                                    ((NetworkNodeAndFileAttributes)node.Attributes).SetValue <bool>("exists", false);

                                    toRemove.Add(node.Name);
                                }
                            }

                            foreach (var name in toRemove)
                            {
                                this.children.Remove(name);
                            }

                            if (this.directoryRefreshInfo.Right == refreshInfo.Right)
                            {
                                this.directoryRefreshInfo.Left = DirectoryRefreshMask.None;
                            }
                        }

                        foreach (var node in newChildren.Values)
                        {
                            this.children[node.Name] = node;
                        }
                    }

                    toRemove.Clear();
                }

                yield break;
            }
            else
            {
                var retvals = new List <INode>();

                // Copy the children because we want to yield outside the lock

                lock (this.SyncLock)
                {
                    foreach (var pair in this.children)
                    {
                        if ((nodeType.Equals(NodeType.Any) || pair.Value.NodeType.Equals(nodeType)) && acceptNode(pair.Value))
                        {
                            retvals.Add(pair.Value);
                        }
                    }
                }

                foreach (var node in retvals)
                {
                    yield return(node);
                }
            }
        }
		public override IEnumerable<INode> DoGetChildren(NodeType nodeType, Predicate<INode> acceptNode)
		{
			bool localRefreshNodes;

			lock (this.SyncLock)
			{
				localRefreshNodes = this.refreshNodes;

				this.refreshNodes = false;
			}

			localRefreshNodes = true;

			/**
			 * TODO: If refreshNodes is true then we have to manually refresh 
			 * all children that aren't listed in the current listing but are
			 * still in the node cache.
			 * 
			 * Do this by attaching to cache events (thru a weak event handler) and 
			 * keeping a list of all cached (and thus resolved) nodes that are children
			 * of this node.
			 */

			//lock (this.SyncLock)
			{
				string[] items;

				foreach (var jumpPoint in GetJumpPoints(NodeType.Directory))
				{
					yield return jumpPoint;
				}

				if ((nodeType.Equals(NodeType.Directory)) || nodeType.Equals(NodeType.Any))
				{
					try
					{
						if (Environment.OSVersion.Platform == PlatformID.Unix)
						{
							// Hack for mono which does not return symbolic links as directories anymore

							items = Directory.GetFileSystemEntries(this.directoryInfo.FullName);
						}
						else
						{
							items = Directory.GetDirectories(this.directoryInfo.FullName);
						}
					}
					catch (System.IO.IOException)
					{
						throw new DirectoryNodeNotFoundException(this.Address);
					}

					foreach (var name in items)
					{
						if (Environment.OSVersion.Platform == PlatformID.Unix)
						{
							if (Native.GetInstance().GetSymbolicLinkTarget(name) != null)
							{
								if (Native.GetInstance().GetSymbolicLinkTargetType(name) != NodeType.Directory)
								{
									continue;
								}
							}
							else
							{
								if (!Directory.Exists(name))
								{
									continue;
								}
							}
						}

						var dir = (IDirectory)this.FileSystem.Resolve(this.Address.ResolveAddress(Path.GetFileName(name)), NodeType.Directory);

						if (localRefreshNodes && !String.Equals((string)dir.Attributes["DriveType"], "Removable", StringComparison.CurrentCultureIgnoreCase))
						{							
							dir.Refresh();
						}

						if (!ContainsShortcut(dir.Name, NodeType.Directory))
						{
							if (acceptNode(dir))
							{
								yield return dir;
							}
						}
					}
				}

				foreach (INode jumpPoint in GetJumpPoints(NodeType.File))
				{
					yield return jumpPoint;
				}

				if ((nodeType.Equals(NodeType.File)) || nodeType.Equals(NodeType.Any))
				{
					try
					{
						if (Environment.OSVersion.Platform == PlatformID.Unix)
						{
							items = Directory.GetFileSystemEntries(this.directoryInfo.FullName);
						}
						else
						{
							items = Directory.GetFiles(this.directoryInfo.FullName);
						}
					}
					catch (System.IO.DirectoryNotFoundException)
					{
						throw new DirectoryNodeNotFoundException(this.Address);
					}

					foreach (string name in items)
					{
						if (Environment.OSVersion.Platform == PlatformID.Unix)
						{
							if (Native.GetInstance().GetSymbolicLinkTarget(name) != null)
							{
								if (Native.GetInstance().GetSymbolicLinkTargetType(name) != NodeType.File)
								{
									continue;
								}
							}
							else
							{
								if (!File.Exists(name))
								{
									continue;
								}
							}
						}

                        var file = (IFile)this.FileSystem.Resolve(this.Address.ResolveAddress(Path.GetFileName(name)), NodeType.File);
						
						if (localRefreshNodes)
						{
							file.Refresh();
						}

						if (!ContainsShortcut(file.Name, NodeType.File))
						{
							if (acceptNode(file))
							{
								yield return file;
							}
						}
					}
				}

				localRefreshNodes = false;
			}
		}