예제 #1
0
        private async Task <InnerUploadFileResponse> InnerUploadFile(String documentHandle)
        {
            IdentityGenerator.New <DocumentDescriptorId>().Returns(new DocumentDescriptorId(1));
            var descriptor = Substitute.For <IBlobDescriptor>();

            descriptor.Hash.Returns(new FileHash("abc"));
            BlobStore.GetDescriptor(Arg.Any <BlobId>()).Returns(descriptor);
            long streamLen = 0;
            HttpResponseMessage response = null;

            using (var stream = new MemoryStream())
            {
                var fileWriter = new BlobWriter(new BlobId("sample_1"), stream, new FileNameWithExtension("a.file"));
                BlobStore.CreateNew(Arg.Any <DocumentFormat>(), Arg.Any <FileNameWithExtension>()).Returns(fileWriter);
                response = await upload_file(TestConfig.PathToDocumentPdf, documentHandle);

                streamLen = stream.Length;
            }


            return(new InnerUploadFileResponse()
            {
                Response = response, StreamLength = streamLen
            });
        }
        private ExerciseSamplesData CreateExerciseSampleData()
        {
            if (double.IsNaN(SamplingInterval))
            {
                throw new InvalidOperationException(Resources.SamplingIntervalMustBeSet);
            }

            ExerciseSamplesData sampleData;

            BlobStore store = GetBlobStore(default(HealthRecordAccessor));
            Blob      blob  = store[string.Empty];

            if (blob == null)
            {
                sampleData = new ExerciseSamplesData(null, string.Empty, "text/csv")
                {
                    SamplingInterval = SamplingInterval
                };
            }
            else
            {
                sampleData = new ExerciseSamplesData(
                    blob.ReadAsString(),
                    blob.ContentEncoding,
                    blob.ContentType)
                {
                    SamplingInterval = SamplingInterval
                };
            }

            return(sampleData);
        }
        public StorageSettings(
            string environment,
            ISettingsBlobStoreSettings settings,
            IExceptionLogger exceptionLogger)
        {
            var blobStore = new BlobStore(settings);

            Task.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        var blob = await blobStore.GetAsync($"{environment.ToLower()}/common.json", true).ConfigureAwait(false);

                        _jsonPropertyService.SetJson(Encoding.UTF8.GetString(blob.Data));
                    }
                    catch (Exception ex)
                    {
                        exceptionLogger.Log(ex);
                    }
                    finally
                    {
                        await Task.Delay(RefreshIntervalSeconds * 1000).ConfigureAwait(false);
                    }
                }
            });
        }
예제 #4
0
 private static ICentralBackupStore CreateBlobStore(string serviceName)
 {
     #warning This blob store is configured to use the Azure Storage Emulator. Replace the connection string with an actual storage account connectionstring for production scenarios.
     //see: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator
     var blobStore = new BlobStore("UseDevelopmentStorage=true", serviceName);
     return(blobStore);
 }
예제 #5
0
        public ReportTab(Designer designer, Report report)
            : base()
        {
            FDesigner = designer;
            FReport   = report;
            FPlugins  = new PluginCollection(FDesigner);
            FUndoRedo = new UndoRedo(this);
            if (!designer.IsPreviewPageDesigner)
            {
                FBlobStore = new BlobStore();
            }

            FTabs                    = new TabStrip();
            FTabs.Height             = 27;
            FTabs.Dock               = DockStyle.Bottom;
            FTabs.TabAlignment       = eTabStripAlignment.Bottom;
            FTabs.TabLayoutType      = eTabLayoutType.FixedWithNavigationBox;
            FTabs.AutoHideSystemBox  = true;
            FTabs.ShowFocusRectangle = false;
            FTabs.CloseButtonVisible = false;

            FTabs.TabItemClose       += new TabStrip.UserActionEventHandler(FTabs_TabItemClose);
            FTabs.TabMoved           += new TabStrip.TabMovedEventHandler(FTabs_TabMoved);
            FTabs.MouseUp            += new MouseEventHandler(FTabs_MouseUp);
            FTabs.SelectedTabChanged += new TabStrip.SelectedTabChangedEventHandler(FTabs_SelectedTabChanged);

            ParentControl.Controls.Add(FTabs);
            ParentControl.Resize += new EventHandler(ParentControl_Resize);

            InitReport();
        }
예제 #6
0
        public async Task <string> DownloadToBlobStoreAsync(string blobStoreFolder)
        {
            var dest = System.IO.Path.Combine(blobStoreFolder, Id + ".jpg");

            if (BlobStore.Exists(dest))
            {
                return(dest);
            }
#if SHAMAN
            await this.LoadDetailsAsync(DetailLevel.D);
#else
            await LoadDetailsAsync();
#endif

            using (var stream = await this.LargestImage.OpenStreamAsync())
            {
                DateTime?httpDate = null;
                if (stream is MediaStream ms)
                {
                    httpDate = (await ms.Manager.GetResponseAsync()).Content.Headers.LastModified?.UtcDateTime;
                }
                if (httpDate == null || (this.Date != null && Math.Abs((httpDate.Value - this.Date.Value).TotalDays) >= 2))
                {
                    httpDate = this.Date;
                }
                using (var destStream = BlobStore.OpenWriteNoAutoCommit(dest, httpDate.GetValueOrDefault()))
                {
                    await stream.CopyToAsync(destStream);

                    destStream.Commit();
                }
            }

            return(dest);
        }
        public void should_download_pdf_format()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );
            var format    = new DocumentFormat("pdf");
            var pdfBlobId = new BlobId("pdf");

            var doc = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                new BlobId("file_1"));

            doc.AddFormat(new PipelineId("abc"), format, pdfBlobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore.GetDescriptor(pdfBlobId).Returns(i => new FsBlobDescriptor(pdfBlobId, TestConfig.PathToDocumentPdf));

            // act
            using (var response = Controller.GetFormat(_tenantId, info.Handle, format))
            {
                // assert
                response.EnsureSuccessStatusCode();
                Assert.AreEqual("application/pdf", response.Content.Headers.ContentType.MediaType);
            }
        }
        public void should_download_original_file()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("\"A document.docx\"")
                );

            var format = new DocumentFormat("original");

            var blobId = new BlobId("file_1");
            var doc    = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                blobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore
            .GetDescriptor(blobId)
            .Returns(i => new FsBlobDescriptor(blobId, TestConfig.PathToWordDocument));

            // act
            using (var response = Controller.GetFormat(_tenantId, info.Handle, format))
            {
                // assert
                response.EnsureSuccessStatusCode();
                Assert.AreEqual("\"A document.docx\"", response.Content.Headers.ContentDisposition.FileName);
            }
        }
        private void DocumentDescriptorCleanup(DateTime checkDate)
        {
            var list = RecycleBin.Slots
                       .Where(x => x.DeletedAt < checkDate &&
                              x.Id.StreamId.StartsWith("DocumentDescriptor_"))
                       .Take(200)
                       .ToArray();

            foreach (var slot in list)
            {
                Logger.InfoFormat("Deleting slot {0} because it is in recyclebin and was deleted at {1}", slot.Id.StreamId, slot.DeletedAt);
                var blobIds = (BlobId[])slot.Data["files"];
                foreach (var blobId in blobIds.Distinct())
                {
                    Logger.InfoFormat("....deleting file {0}", blobId);
                    BlobStore.Delete(blobId);
                }

                RecycleBin.Purge(slot.Id);

                Logger.InfoFormat("....deleting stream {0}.{1}", slot.Id.BucketId, slot.Id.StreamId);
                Store.Advanced.DeleteStream(slot.Id.BucketId, slot.Id.StreamId);
                Logger.InfoFormat("Slot {0} deleted", slot.Id.StreamId);
            }
        }
        public void when_file_is_not_found_should_return_404()
        {
            // arrange
            var info = new DocumentHandleInfo(
                new DocumentHandle("doc"),
                new FileNameWithExtension("a.file")
                );
            var format = new DocumentFormat("original");

            var blobId = new BlobId("file_1");
            var doc    = new DocumentDescriptorReadModel(
                1L,
                new DocumentDescriptorId(1),
                blobId);

            SetupDocumentHandle(info, doc.Id);
            SetupDocumentModel(doc);

            BlobStore.GetDescriptor(blobId).Returns(i => null);

            // act
            var response = Controller.GetFormat(_tenantId, info.Handle, format);

            // assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual("File file_1 not found", response.GetError().Message);
        }
        public async Task when_the_snapshot_is_under_table_storage_limits_it_should_save_and_load_to_table_storage()
        {
            var blobStore         = new BlobStore(new BlobSettings());
            var azureBlobStore    = new AzureBlobSnapshotStore(blobStore);
            var azureTableService = new AzureTableService(new AzureTableSettings());
            var sut = new AzureTableSnapshotStore(
                azureBlobStore,
                new AzureSnapshotBuilder(azureBlobStore),
                azureTableService,
                new DomainEntityTypeBuilder()
                );
            var item = new SnapshotContent {
                AggregateRootId = new Guid("b87bc654-3d76-4a46-ab58-c71c16b6a000")
            };

            item.SetToLength(10);
            await sut.SaveSnapshot(item).ConfigureAwait(false);

            var snapshot = await sut.GetSnapshot(item.AggregateRootId).ConfigureAwait(false);

            snapshot.ShouldNotBeNull();
            var cast = snapshot as SnapshotContent;

            cast.ShouldNotBeNull();
            cast.Content.Count.ShouldBe(item.Content.Count);
        }
        public async Task when_the_snapshot_is_over_table_storage_limits_it_should_save_and_load_to_blob_storage()
        {
            var blobStore               = new BlobStore(new BlobSettings());
            var azureBlobStore          = new AzureBlobSnapshotStore(blobStore);
            var azureTableService       = new AzureTableService(new AzureTableSettings());
            var domainEntityTypeBuilder = new DomainEntityTypeBuilder();
            var sut = new AzureTableSnapshotStore(
                azureBlobStore,
                new AzureSnapshotBuilder(azureBlobStore),
                azureTableService,
                domainEntityTypeBuilder
                );
            var item = new SnapshotContent {
                AggregateRootId = new Guid("cc3ea6b8-6396-4c95-be2e-4d90f2c23736")
            };

            // set a new AggregateRootId for this to be tested
            //var snapshot = await sut.GetSnapshot(item.AggregateRootId).ConfigureAwait(false);
            //snapshot.ShouldBeNull();

            item.SetToLength(99999);
            await sut.SaveSnapshot(item).ConfigureAwait(false);

            var snapshot = await sut.GetSnapshot(item.AggregateRootId).ConfigureAwait(false);

            snapshot.ShouldNotBeNull();
            var cast = snapshot as SnapshotContent;

            cast.ShouldNotBeNull();
            cast.Content.Count.ShouldBe(item.Content.Count);
        }
예제 #13
0
        string WriteFile(string username, Stream traceStream)
        {
            // Log function entrance
            TraceLog.TraceFunction();

            if (username == null)
            {
                username = "******";
            }

            DateTime tod      = DateTime.Now;
            string   filename = String.Format("{0}-{1}.txt",
                                              username,
                                              tod.Ticks);

            // if not in azure, write to the filesystem
            if (HostEnvironment.IsAzure)
            {
                BlobStore.WriteTraceFile(filename, traceStream);
            }
            else
            {
                return(WriteFileToFileSystem(filename, traceStream));
            }

            return(null);
        }
예제 #14
0
        public async Task RetrieveTestData_ToMultilayerNetworkClassifier(string fileName)
        {
            var storagePath = GetStorageDir();

            using (var blobs = new BlobStore(storagePath))
            using (var store = new SampleStore(storagePath))
            {
                await blobs.Setup(true);

                var samples = store.ListSamples();

                var item = samples.Where(s => s.SourceDataUrl != null && s.SourceDataUrl.EndsWith(fileName)).FirstOrDefault();

                var sample = await store.RetrieveSample(item.Uri);

                var pipe = sample.CreatePipeline().OutputResultsTo(blobs);
                
                var classifier = pipe.ToMultilayerNetworkClassifier(x => x.Label).Execute(fileName);

                var classOfFirst = classifier.Classify(sample.SampleData.First());

                var blob = blobs.OpenMultilayerNetworkClassifier<DataItem, string>(fileName, sample.CreateFeatureExtractor());

                Assert.That(classOfFirst.Any());
                Assert.That(classOfFirst.First().Score > 0);
            }
        }
예제 #15
0
 public BlobReferenceIterator(BlobStore blobs, byte[] blobhash, BlobLocation.BlobType blobtype,
                              bool includefiles, bool bottomup)
 {
     Blobs        = blobs;
     ParentHash   = blobhash;
     BottomUp     = bottomup;
     IncludeFiles = includefiles;
     BlobType     = blobtype;
 }
예제 #16
0
        protected async Task DeleteBlobDocuments(IEnumerable <PublishedFundingVersion> publishedFundingVersions)
        {
            LogInformation($"Deleting {publishedFundingVersions.Count()} published funding version blobs");

            foreach (PublishedFundingVersion publishedProviderVersion in publishedFundingVersions)
            {
                await BlobStore.RemovePublishedFundingVersionBlob(publishedProviderVersion);
            }
        }
예제 #17
0
        async Task VerifyPutDeliveresId()
        {
            var fileSystem = TestUtilities.CreateFilesystem();
            var fileStream = fileSystem.FileStream.Create(@"c:\myfile.txt", FileMode.Open);
            var store      = new BlobStore();

            var id = store.Put(fileStream);

            Assert.NotNull(id);
        }
예제 #18
0
파일: Repo.cs 프로젝트: dt-bet/Smarkets2
 public string GetJson(string id)
 {
     if (BlobStore.Exists(System.IO.Path.Combine(ss, id)))
     {
         return(BlobStore.ReadAllText(System.IO.Path.Combine(ss, id)));
     }
     else
     {
         return(null);
     }
 }
예제 #19
0
            public async Task Can_Remove_Container_From_Blob_Storage()
            {
                //Arrange
                var store = new BlobStore(_mockConnection.Object, _mockSerialiser.Object, _mockCalculator.Object);

                //Act
                await store.RemoveAllAsync(Guid.NewGuid());

                //Assert
                _mockConnection.Verify(x => x.RemoveObjectAsync(It.IsAny <Guid>()), Times.Once);
            }
예제 #20
0
            public void Can_Be_Constructed()
            {
                //Arrange

                //Act
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Assert
                Assert.That(store, Is.Not.Null);
            }
예제 #21
0
        async Task VerifyDataCanBeRead()
        {
            var fileSystem = TestUtilities.CreateFilesystem();
            var fileStream = fileSystem.FileStream.Create(@"c:\myfile.txt", FileMode.Open);
            var store      = new BlobStore();

            var id     = store.Put(fileStream);
            var stream = store.GetBlob(id);

            Assert.Equal(stream, fileStream);
        }
예제 #22
0
 public void ClearUndo()
 {
     foreach (UndoRedoInfo info in FUndo)
     {
         info.Dispose();
     }
     FUndo.Clear();
     if (BlobStore != null)
     {
         BlobStore.Clear();
     }
 }
예제 #23
0
            public void Null_Stream_Will_Throw_Argument_Null_Exception_4_Arguments()
            {
                //Arrange
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Act
                async Task TestDelegate() => await store.AddAsync <object>(null, Guid.NewGuid(), FileName, FolderName);

                //Assert
                Assert.That(TestDelegate, Throws.ArgumentNullException.With.Property("ParamName").EqualTo("data"));
            }
예제 #24
0
            public void Empty_Transaction_Id_Will_Throw_Argument_Exception_4_Arguments()
            {
                //Arrange
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Act
                async Task TestDelegate() => await store.AddAsync(_mockMemoryStream, Guid.Empty, FileName, FolderName);

                //Assert
                Assert.That(TestDelegate, Throws.ArgumentException.With.Message.EqualTo("id cannot be Empty"));
            }
예제 #25
0
            public void Empty_File_Name_Will_Throw_Argument_Exception_3_Arguments()
            {
                //Arrange
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Act
                async Task TestDelegate() => await store.GetAsync <object>(Guid.NewGuid(), "", FolderName);

                //Assert
                Assert.That(TestDelegate, Throws.ArgumentException.With.Message.EqualTo("key cannot be Null or Empty"));
            }
예제 #26
0
            public void Null_Folder_Name_Will_Throw_Argument_Exception()
            {
                //Arrange
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Act
                async Task TestDelegate() => await store.RemoveAsync(Guid.NewGuid(), FileName, null);

                //Assert
                Assert.That(TestDelegate, Throws.ArgumentException.With.Message.EqualTo("objectName cannot be Null or Empty"));
            }
예제 #27
0
            public void Empty_Transaction_Id_Will_Throw_Argument_Exception()
            {
                //Arrange
                var store = new BlobStore(Mock.Of <IStorageConnection <CloudBlobContainer, Guid> >(),
                                          Mock.Of <IJsonSerialiser>(), Mock.Of <IBlobSizeCalculator>());

                //Act
                async Task TestDelegate() => await store.RemoveAllAsync(Guid.Empty);

                //Assert
                Assert.That(TestDelegate, Throws.ArgumentException.With.Message.EqualTo("transactionId cannot be Empty"));
            }
예제 #28
0
        /// <summary>
        /// Reads the image from the <see cref="Blob"/>
        /// as a stream.
        /// </summary>
        ///
        /// <remarks>
        /// An application must explicitly request that the blob information is returned
        /// when querying for an personal image. It can do this by asking for the BlobPayload section
        /// in the Sections property of the <see cref="HealthRecordView"/> class (filter.View).
        /// </remarks>
        ///
        /// <returns>
        /// A Stream containing the image bytes. It is the caller's
        /// responsibility to close this stream.
        /// May return null if the blob payload is not requested or the personal
        /// image has no data...
        /// </returns>
        ///
        public Stream ReadImage()
        {
            BlobStore store = GetBlobStore(default(HealthRecordAccessor));
            Blob      blob  = store[string.Empty];

            if (blob == null)
            {
                return(null);
            }

            return(blob.GetReaderStream());
        }
        public async Task TestUploadBackupFolderAsync()
        {
            if (!CanOperate())
            {
                Assert.Inconclusive("Can't run at this machine!");
            }

            //setup
            const string content       = "content";
            const string testTxt       = "test.txt";
            const string subFolderName = "Sub";

            var    partitionId     = Guid.Parse("{92DA7CA2-CE18-497C-84DB-428B8C476994}");
            string partitionFolder = partitionId.ToString("n");

            //prepare a folder and a file in the local store:
            Directory.CreateDirectory(Local);
            File.WriteAllText(Path.Combine(Local, testTxt), content);

            string subFolder = Path.Combine(Local, subFolderName);

            Directory.CreateDirectory(subFolder);
            File.WriteAllText(Path.Combine(subFolder, testTxt), content);

            BlobStore store = new BlobStore("UseDevelopmentStorage=true", ContainerName);
            await store.InitializeAsync();

            //act
            var result = await store.UploadBackupFolderAsync(BackupOption.Full, partitionId, Local, CancellationToken.None);

            //asserts
            Assert.IsInstanceOfType(result, typeof(BackupMetadata));
            Assert.AreEqual(partitionId, result.OriginalServicePartitionId);
            Assert.AreNotEqual(Guid.Empty, result.BackupId);

            var container = store.BlobClient.GetContainerReference(ContainerName);

            Assert.IsTrue(container.ExistsAsync().ConfigureAwait(false).GetAwaiter().GetResult());

            var rootFolder = container.GetDirectoryReference(BlobStore.RootFolder);

            var list = rootFolder.ListBlobsSegmentedAsync(true, BlobListingDetails.All, 10, new BlobContinuationToken(), null, null)
                       .ConfigureAwait(false)
                       .GetAwaiter()
                       .GetResult()
                       .Results
                       .ToList();

            Assert.AreEqual(2, list.Count(file => file.Uri.AbsoluteUri.EndsWith(testTxt)));
            Assert.AreEqual(1, list.Count(file => file.Uri.AbsoluteUri.EndsWith($"{subFolderName}/{testTxt}")));
            Assert.AreEqual(1, list.Count(file => file.Uri.AbsoluteUri.EndsWith(FileStore.ServiceFabricBackupRestoreMetadataFileName)));
        }
예제 #30
0
    protected virtual void TearDown()
    {
        if (Root != null)
        {
            GameObject.DestroyImmediate(Root);
            Root = null;
        }

        Child = null;

        BlobStore.Dispose();
        World.Dispose();
    }
예제 #31
0
        public async Task <IActionResult> ScanPdf417(string blobRef, [FromQuery] bool?raw = false, [FromQuery] bool?veh = false, [FromQuery] bool?drv = false)
        {
            var res = this.Response;
            var req = this.Request;

            try
            {
                // always start off not caching whatever we send back
                res.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0";
                res.Headers["Pragma"]        = "no-cache"; // HTTP 1.0.
                res.Headers["Content-Type"]  = "application/json";

                if (!BlobStore.Exists(blobRef))
                {
                    return(NotFound($"Invalid, non-existent or expired blob reference specified: '{blobRef}'"));
                }

                var blobData = BlobStore.Get(blobRef);

                var client = new System.Net.Http.HttpClient();

                using (var content = new System.Net.Http.ByteArrayContent(blobData.Data))
                {
                    var barcodeServiceUrl = this.config["AppSettings:BarcodeService.URL"].TrimEnd('/');
                    var postUrl           = $"{barcodeServiceUrl}/scan/pdf417?raw={raw}&veh={veh}&drv={drv}";

                    var response = await client.PostAsync(postUrl, content);

                    var responseText = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var json = JsonConvert.DeserializeObject(responseText);

                        return(Ok(ApiResponse.Payload(json)));
                    }
                    else
                    {
                        SessionLog.Error("Barcode failed. postUrl = {0}; contentLength: {1}; responseText={2}", postUrl ?? "(null)", blobData?.Data?.Length ?? -1, responseText ?? "(null)");

                        //return StatusCode((int)response.StatusCode, responseText);
                        //return new ContentResult() { Content = responseText, StatusCode = (int)response.StatusCode, ContentType = "text/plain" };
                        return(BadRequest(responseText));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(ApiResponse.Exception(ex)));
            }
        }