示例#1
0
        public Task <bool> Exists(Uri path)
        {
            var pathInfo = new PathInfo(path);

            this.AssertIsValidWabsUri(pathInfo);

            StorageSimulatorItem result = this.GetItem(pathInfo);

            return(Task.FromResult(result.IsNotNull()));
        }
示例#2
0
        public void Delete(Uri path)
        {
            var pathInfo = new PathInfo(path);

            if (pathInfo.Path.IsNullOrEmpty())
            {
                throw new InvalidOperationException("An attempt was made to delete a container.  Containers can not be deleted via this API.");
            }
            this.AssertIsValidWabsUri(pathInfo);

            StorageSimulatorItem item = this.GetItem(pathInfo, true);

            if (item.IsNotNull() && item.Items.ContainsKey(pathInfo.PathParts[pathInfo.PathParts.Length - 1]))
            {
                item.Items.Remove(pathInfo.PathParts[pathInfo.PathParts.Length - 1]);
            }
        }
示例#3
0
        public Task <IEnumerable <Uri> > List(Uri path, bool recursive)
        {
            var items    = new List <Uri>();
            var queue    = new Queue <StorageSimulatorItem>();
            var pathInfo = new PathInfo(path);

            this.AssertIsValidWabsUri(pathInfo);
            StorageSimulatorItem item = this.GetItem(pathInfo, pathInfo.Path.IsNullOrEmpty());

            if (item.IsNotNull())
            {
                queue.Enqueue(item);
                while (queue.Count > 0)
                {
                    item = queue.Remove();
                    queue.AddRange(item.Items.Values);
                    items.Add(item.Path);
                }
            }
            return(Task.FromResult((IEnumerable <Uri>)items));
        }
示例#4
0
        protected StorageSimulatorItem GetItem(PathInfo pathInfo, bool parent = false)
        {
            StorageSimulatorItem dir = this.Root;

            this.Root.Items.TryGetValue(pathInfo.Container, out dir);

            string[] pathParts = pathInfo.PathParts;
            if (parent)
            {
                if (pathParts.Length > 0)
                {
                    pathParts = pathParts.Take(pathParts.Length - 1).ToArray();
                }
            }

            if (pathParts.Length == 0)
            {
                return(dir);
            }

            int loc = 0;

            while (dir.IsNotNull() && dir.Items.TryGetValue(pathParts[loc], out dir) && loc < pathParts.Length)
            {
                if (loc == pathParts.Length - 1)
                {
                    return(dir);
                }
                if (dir.IsNull())
                {
                    return(null);
                }
                loc++;
            }
            return(null);
        }