Ejemplo n.º 1
0
        private CloudBlockBlob GetBlockBlob(StoreLocation location, string snapshot = null)
        {
            DateTime?snapshotDate = null;

            if (snapshot != null)
            {
                snapshotDate = new DateTime(long.Parse(snapshot, CultureInfo.InvariantCulture));
            }

            var container = _blobStorage.GetContainerReference(SafeContainerName(location.Container));
            var offset    = snapshotDate.HasValue ? new DateTimeOffset(snapshotDate.Value, new TimeSpan(0)) : (DateTimeOffset?)null;

            CloudBlockBlob blob;

            if (location.Id.HasValue)
            {
                if (!string.IsNullOrEmpty(location.BasePath))
                {
                    var dir = container.GetDirectoryReference(SafePath.MakeSafeFilePath(location.BasePath));
                    blob = dir.GetBlockBlobReference(location.Id.ToString() + IdExtension, offset);
                }
                else
                {
                    blob = container.GetBlockBlobReference(location.Id.ToString() + IdExtension, offset);
                }
            }
            else
            {
                blob = container.GetBlockBlobReference(SafePath.MakeSafeFilePath(location.BasePath), offset);
            }

            return(blob);
        }
Ejemplo n.º 2
0
        private IAsyncEnumerable <ICloudBlob> ListBlobs(CloudBlobContainer container, string prefix, BlobListingDetails options)
        {
            // Clean up the prefix if required
            prefix = prefix == null ? null : SafePath.MakeSafeFilePath(prefix);

            return(AsyncEnumerableEx.Create <ICloudBlob>(async(y) =>
            {
                BlobContinuationToken token = new BlobContinuationToken();

                try
                {
                    do
                    {
                        var segment = await container.ListBlobsSegmentedAsync(prefix, true, options, null, token, null, null, y.CancellationToken).ConfigureAwait(false);
                        LeoTrace.WriteLine("Listed blob segment for prefix: " + prefix);

                        foreach (var blob in segment.Results.OfType <ICloudBlob>())
                        {
                            await y.YieldReturn(blob).ConfigureAwait(false);
                        }

                        token = segment.ContinuationToken;
                    }while (token != null && !y.CancellationToken.IsCancellationRequested);
                }
                catch (StorageException e)
                {
                    if (e.RequestInformation.HttpStatusCode != 404)
                    {
                        throw e.Wrap(container.Name + "_" + (prefix ?? string.Empty) + "*");
                    }
                }
            }));
        }
Ejemplo n.º 3
0
        private BlockBlobClient GetBlockBlob(StoreLocation location, string snapshot = null)
        {
            var container = _blobStorage.GetBlobContainerClient(SafeContainerName(location.Container));

            BlockBlobClient blob;

            if (location.Id.HasValue)
            {
                if (!string.IsNullOrEmpty(location.BasePath))
                {
                    var path = Path.Combine(SafePath.MakeSafeFilePath(location.BasePath), location.Id.ToString() + IdExtension);
                    blob = container.GetBlockBlobClient(path);
                }
                else
                {
                    blob = container.GetBlockBlobClient(location.Id.ToString() + IdExtension);
                }
            }
            else
            {
                blob = container.GetBlockBlobClient(SafePath.MakeSafeFilePath(location.BasePath));
            }

            return(string.IsNullOrWhiteSpace(snapshot) ? blob : blob.WithSnapshot(snapshot));
        }
Ejemplo n.º 4
0
        private IAsyncEnumerable <BlobItem> ListBlobs(BlobContainerClient container, string prefix, BlobTraits traits, BlobStates states)
        {
            // Clean up the prefix if required
            prefix = prefix == null ? null : SafePath.MakeSafeFilePath(prefix);

            return(container.GetBlobsAsync(traits, states, prefix));
        }
Ejemplo n.º 5
0
        public void Process_Get1MineAfterDrinkingTwice_4Mines15Turns42Profit()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(1,
                                     new Hero(99, 8, 9, 0, 2),
                                     new Hero(01, 1, 0, 0, 0),
                                     new Hero(50, 3, 2, 0, 0),
                                     new Hero(99, 8, 8, 0, 0),
                                     MineOwnership.Parse(".22......"));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(3, 7, 13, MoveDirection.E);

            Assert.AreEqual(exp, act);
        }
Ejemplo n.º 6
0
        public void Process_Get4Mines_4Mines15Turns42Profit()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(0,
                                     new Hero(100, 3, 4, 0, 0),
                                     new Hero(100, 8, 0, 0, 0, true),
                                     new Hero(100, 8, 9, 0, 0, true),
                                     new Hero(100, 1, 9, 0, 0, true),
                                     MineOwnership.Create(map));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(4, 15, 42, MoveDirection.E);

            Assert.AreEqual(exp, act);
        }
Ejemplo n.º 7
0
        public void Process_Get1Mine1Mine4Turns4Profit()
        {
            var map   = MapTest.Map10;
            var state = State.Create(0,
                                     new Hero(23, 0, 0, 0, 0),
                                     new Hero(99, 9, 0, 0, 0),
                                     new Hero(99, 9, 9, 0, 0),
                                     new Hero(99, 0, 9, 0, 0),
                                     MineOwnership.Create(map));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(1, 4, 4, MoveDirection.S);

            Assert.AreEqual(exp, act);
        }