コード例 #1
0
        // Skip to download again only when the cloud blob has no changes
        public async Task <string> ExportToTempFileAsync(string serviceName, Version serviceVersion)
        {
            var blob     = this.GetServiceRegistrationBlockBlobReference(serviceName, serviceVersion);
            var filePath = SoaRegistrationAuxModule.GetServiceRegistrationTempFilePath(Path.GetFileNameWithoutExtension(blob.Uri.ToString()));

            Trace.TraceInformation($"Will write Service Registration file to {filePath}");

            // check if the exsiting file's md5 and cloud blob's md5 have the same value
            if (File.Exists(filePath))
            {
                string fileMd5 = await GetMd5AuxAsync(blob);

                string existingFileMd5 = CalculateMd5Hash(File.ReadAllBytes(filePath));
                if (string.Equals(fileMd5, existingFileMd5))
                {
                    return(filePath);
                }
            }

            if (await blob.ExistsAsync())
            {
                await blob.DownloadToFileAsync(filePath, FileMode.Create);

                return(filePath);
            }

            return(string.Empty);
        }
コード例 #2
0
        private CloudBlockBlob GetServiceRegistrationBlockBlobReference(string serviceName, Version serviceVersion)
        {
            var fileName = SoaRegistrationAuxModule.GetRegistrationFileName(serviceName, serviceVersion);

            Trace.TraceInformation($"Getting block blob reference for {fileName}.");
            return(this.blobContainer.GetBlockBlobReference(fileName));
        }
コード例 #3
0
        private async Task <ServiceRegistrationInfo> GetServiceRegistrationInfo(string serviceName, Version serviceVersion)
        {
            var key = SoaRegistrationAuxModule.GetRegistrationName(serviceName, serviceVersion);
            var res = CacheInstance.Get(key);

            if (res == null)
            {
                var svrReg = await this.GetCoreAsync(serviceName, serviceVersion).ConfigureAwait(false);

                if (string.IsNullOrEmpty(svrReg))
                {
                    return(ServiceRegistrationInfo.Empty);
                }

                var svcRegInfo = new ServiceRegistrationInfo(svrReg);
                var newVal     = CacheInstance.AddOrGetExisting(key, svcRegInfo, ExpireIn5Secs) as ServiceRegistrationInfo;
                return(newVal ?? svcRegInfo);
            }

            return((ServiceRegistrationInfo)res);
        }
コード例 #4
0
        public async Task ImportFromFileAsync(string filePath, string serviceName)
        {
            Debug.Assert(filePath != null);
            if (!File.Exists(filePath))
            {
                throw new InvalidOperationException($"File {filePath} for uploading does not exist.");
            }

            string svcName;

            if (string.IsNullOrEmpty(serviceName))
            {
                svcName = Path.GetFileNameWithoutExtension(filePath).ToLowerInvariant();
            }
            else
            {
                svcName = SoaRegistrationAuxModule.GetRegistrationFileName(serviceName, null);
            }

            var blob = this.GetServiceRegistrationBlockBlobReference(svcName, null);
            await blob.UploadFromFileAsync(filePath);
        }
コード例 #5
0
 public string CalculateMd5Hash(byte[] blobData)
 {
     return(SoaRegistrationAuxModule.CalculateMd5Hash(System.Text.Encoding.UTF8.GetString(blobData, 0, blobData.Length)));
 }
コード例 #6
0
 /// <inheritdoc />
 public async Task ImportFromFileAsync(string filePath, string serviceName)
 {
     await SoaRegistrationAuxModule.ImportServiceRegistrationFromFileAuxAsync(this.SetAsync, filePath, serviceName).ConfigureAwait(false);
 }
コード例 #7
0
 public async Task <string> ExportToTempFileAsync(string serviceName, Version serviceVersion)
 {
     return(await SoaRegistrationAuxModule.ExportServiceRegistrationToTempFileAuxAsync(this.GetAsync, serviceName, serviceVersion).ConfigureAwait(false));
 }