ObjectExists() публичный Метод

Checks if an object exists. If the model did not read all of the objects during its last update, it may make a service call if the object is not found in its data.
public ObjectExists ( string objectName ) : bool
objectName string
Результат bool
Пример #1
0
        /// <summary>
        /// PowerShell uses this to check if items exist.
        /// </summary>
        protected override bool ItemExists(string path)
        {
            var gcsPath = GcsPath.Parse(path);

            switch (gcsPath.Type)
            {
            case GcsPath.GcsPathType.Drive:
                return(true);

            case GcsPath.GcsPathType.Bucket:
                var bucketCache = BucketCache.Value;
                if (bucketCache.ContainsKey(gcsPath.Bucket))
                {
                    return(true);
                }
                try
                {
                    var bucket = Service.Buckets.Get(gcsPath.Bucket).Execute();
                    bucketCache[bucket.Name] = bucket;
                    return(true);
                }
                catch
                {
                    return(false);
                }

            case GcsPath.GcsPathType.Object:
                BucketModel model        = GetBucketModel(gcsPath.Bucket);
                bool        objectExists = model.ObjectExists(gcsPath.ObjectPath);
                return(objectExists);

            default:
                throw new InvalidOperationException($"Unknown Path Type {gcsPath.Type}");
            }
        }
        /// <summary>
        /// PowerShell uses this to check if items exist.
        /// </summary>
        protected override bool ItemExists(string path)
        {
            var gcsPath = GcsPath.Parse(path);

            switch (gcsPath.Type)
            {
            case GcsPath.GcsPathType.Drive:
                return(true);

            case GcsPath.GcsPathType.Bucket:
                Dictionary <string, Bucket> bucketDict = null;
                // If the bucket cache is not initialized, then don't bother initializing it
                // because that will cause a long wait time and we may not even know whether
                // the user needs to use all the other buckets right away. Also, we should not
                // refresh the whole cache right at this instance (which is why we call
                // GetValueWithoutUpdate) for the same reason.
                bucketDict = BucketCache.GetLastValueWithoutUpdate();
                if (bucketDict != null && bucketDict.ContainsKey(gcsPath.Bucket))
                {
                    return(true);
                }

                try
                {
                    var bucket = Service.Buckets.Get(gcsPath.Bucket).Execute();
                    if (bucketDict != null)
                    {
                        bucketDict[bucket.Name] = bucket;
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }

            case GcsPath.GcsPathType.Object:
                BucketModel model        = GetBucketModel(gcsPath.Bucket);
                bool        objectExists = model.ObjectExists(gcsPath.ObjectPath);
                return(objectExists);

            default:
                throw new InvalidOperationException($"Unknown Path Type {gcsPath.Type}");
            }
        }