Пример #1
0
        private void LogError(Exception ex, string message)
        {
            //ConfigurationManager.ConnectionStrings["CineStorageConStr"].ConnectionString
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr"));

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data");

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob logBlob = container.GetBlockBlobReference(String.Format(this.LogFile, DateTime.UtcNow.ToString("dd MMM yyyy")));
            try
            {
                using (StreamReader sr = new StreamReader(logBlob.OpenRead()))
                {
                    using (StreamWriter sw = new StreamWriter(logBlob.OpenWrite()))
                    {
                        sw.Write(sr.ReadToEnd());

                        if (ex != null)
                        {
                            sw.Write(System.Environment.NewLine);

                            sw.WriteLine(ex.Message);
                            sw.WriteLine(ex.StackTrace);

                            sw.Write(System.Environment.NewLine);

                            if (ex.InnerException != null)
                            {
                                sw.Write(System.Environment.NewLine);

                                sw.WriteLine(ex.InnerException.Message);
                                sw.WriteLine(ex.InnerException.StackTrace);

                                sw.Write(System.Environment.NewLine);
                            }
                        }

                        if (message != null)
                        {
                            sw.Write(System.Environment.NewLine);

                            sw.WriteLine(message);

                            sw.Write(System.Environment.NewLine);
                        }
                    }
                }
            }
            catch { }
        }
 public bool Connect(string blobNamePrefix, string containerName, string storageConnectionString)
 {
     try
     {
         _ContainerReference = SetUpContainer(storageConnectionString, containerName);
         _ContainerReference.CreateIfNotExists();
         
         _Blob = _ContainerReference.GetBlockBlobReference(blobNamePrefix + DateTime.UtcNow.Ticks);
         _StreamWriter = _Blob.OpenWrite();
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Пример #3
0
        public void BlockBlobWriteStreamOneByteTest()
        {
            byte buffer = 127;

            MD5 hasher = MD5.Create();
            CloudBlobContainer container = GetRandomContainerReference();

            container.ServiceClient.ParallelOperationThreadCount = 2;
            try
            {
                container.Create();

                CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
                blob.StreamWriteSizeInBytes = 16 * 1024;
                using (MemoryStream wholeBlob = new MemoryStream())
                {
                    BlobRequestOptions options = new BlobRequestOptions()
                    {
                        StoreBlobContentMD5 = true,
                    };
                    using (Stream blobStream = blob.OpenWrite(null, options))
                    {
                        for (int i = 0; i < 1 * 1024 * 1024; i++)
                        {
                            blobStream.WriteByte(buffer);
                            wholeBlob.WriteByte(buffer);
                            Assert.AreEqual(wholeBlob.Position, blobStream.Position);
                        }
                    }

                    wholeBlob.Seek(0, SeekOrigin.Begin);
                    string md5 = Convert.ToBase64String(hasher.ComputeHash(wholeBlob));
                    blob.FetchAttributes();
                    Assert.AreEqual(md5, blob.Properties.ContentMD5);

                    using (MemoryStream downloadedBlob = new MemoryStream())
                    {
                        blob.DownloadToStream(downloadedBlob);
                        TestHelper.AssertStreamsAreEqual(wholeBlob, downloadedBlob);
                    }
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
Пример #4
0
        public void BlockBlobWriteStreamSeekTest()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
                using (Stream blobStream = blob.OpenWrite())
                {
                    TestHelper.ExpectedException <NotSupportedException>(
                        () => blobStream.Seek(1, SeekOrigin.Begin),
                        "Block blob write stream should not be seekable");
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
Пример #5
0
        public void BlobWriteStreamOpenAndClose()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1");
                using (Stream blobStream = blockBlob.OpenWrite())
                {
                }

                CloudBlockBlob blockBlob2 = container.GetBlockBlobReference("blob1");
                blockBlob2.FetchAttributes();
                Assert.AreEqual(0, blockBlob2.Properties.Length);
                Assert.AreEqual(BlobType.BlockBlob, blockBlob2.Properties.BlobType);

                CloudPageBlob pageBlob = container.GetPageBlobReference("blob2");
                TestHelper.ExpectedException(
                    () => pageBlob.OpenWrite(null),
                    "Opening a page blob stream with no size should fail on a blob that does not exist",
                    HttpStatusCode.NotFound);
                using (Stream blobStream = pageBlob.OpenWrite(1024))
                {
                }
                using (Stream blobStream = pageBlob.OpenWrite(null))
                {
                }

                CloudPageBlob pageBlob2 = container.GetPageBlobReference("blob2");
                pageBlob2.FetchAttributes();
                Assert.AreEqual(1024, pageBlob2.Properties.Length);
                Assert.AreEqual(BlobType.PageBlob, pageBlob2.Properties.BlobType);
            }
            finally
            {
                container.Delete();
            }
        }
Пример #6
0
            public Stream CreateFile() {
                // as opposed to the File System implementation, if nothing is done on the stream
                // the file will be emptied, because Azure doesn't implement FileMode.Truncate
                _blob.DeleteIfExists();
                _blob = _blob.Container.GetBlockBlobReference(_blob.Uri.ToString());
                _blob.OpenWrite().Dispose(); // force file creation

                return OpenWrite();
            }
Пример #7
0
        /// <summary>
        /// Test blob writing, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private void BlobWriteExpectLeaseSuccess(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
        {
            testBlob.SetMetadata(testAccessCondition, null /* options */);
            testBlob.SetProperties(testAccessCondition, null /* options */);
            UploadText(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */);
            testBlob.StartCopy(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */);

            while (testBlob.CopyState.Status == CopyStatus.Pending)
            {
                Thread.Sleep(1000);
                testBlob.FetchAttributes();
            }

            Stream stream = testBlob.OpenWrite(testAccessCondition, null /* options */);
            stream.WriteByte(0);
            stream.Flush();

            testBlob.Delete(DeleteSnapshotsOption.None, testAccessCondition, null /* options */);
        }
Пример #8
0
        /// <summary>
        /// Test blob creation, expecting lease failure.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The failing access condition to use.</param>
        /// <param name="expectedErrorCode">The expected error code.</param>
        /// <param name="description">The reason why these calls should fail.</param>
        private void BlobCreateExpectLeaseFailure(CloudBlockBlob testBlob, CloudBlockBlob sourceBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            TestHelper.ExpectedException(
                () => UploadText(testBlob, "No Dice", Encoding.UTF8, testAccessCondition, null /* options */),
                description + " (Upload Text)",
                expectedStatusCode,
                expectedErrorCode);
            TestHelper.ExpectedException(
                () => testBlob.StartCopy(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */),
                description + " (Copy From)",
                expectedStatusCode,
                expectedErrorCode);

            Stream stream = testBlob.OpenWrite(testAccessCondition, null /* options */);
            TestHelper.ExpectedException(
                () =>
                {
                    stream.WriteByte(0);
                    stream.Flush();
                },
                description + " (Write Stream)",
                expectedStatusCode,
                expectedErrorCode);
        }
Пример #9
0
        public void BlockBlobWriteStreamBasicTestAPM()
        {
            byte[] buffer = GetRandomBuffer(1024 * 1024);

            MD5             hasher     = MD5.Create();
            CloudBlobClient blobClient = GenerateCloudBlobClient();

            blobClient.ParallelOperationThreadCount = 4;
            string             name      = GetRandomContainerName();
            CloudBlobContainer container = blobClient.GetContainerReference(name);

            try
            {
                container.Create();

                CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
                blob.StreamWriteSizeInBytes = buffer.Length;
                using (MemoryStream wholeBlob = new MemoryStream())
                {
                    BlobRequestOptions options = new BlobRequestOptions()
                    {
                        StoreBlobContentMD5 = true,
                    };
                    using (Stream blobStream = blob.OpenWrite(null, options))
                    {
                        IAsyncResult[] results = new IAsyncResult[blobClient.ParallelOperationThreadCount * 2];
                        for (int i = 0; i < results.Length; i++)
                        {
                            results[i] = blobStream.BeginWrite(buffer, 0, buffer.Length, null, null);
                            wholeBlob.Write(buffer, 0, buffer.Length);
                            Assert.AreEqual(wholeBlob.Position, blobStream.Position);
                        }
                        for (int i = 0; i < blobClient.ParallelOperationThreadCount; i++)
                        {
                            Assert.IsTrue(results[i].IsCompleted);
                        }
                        for (int i = blobClient.ParallelOperationThreadCount; i < results.Length; i++)
                        {
                            Assert.IsFalse(results[i].IsCompleted);
                        }
                        for (int i = 0; i < results.Length; i++)
                        {
                            blobStream.EndWrite(results[i]);
                        }
                    }

                    wholeBlob.Seek(0, SeekOrigin.Begin);
                    string md5 = Convert.ToBase64String(hasher.ComputeHash(wholeBlob));
                    blob.FetchAttributes();
                    Assert.AreEqual(md5, blob.Properties.ContentMD5);

                    using (MemoryStream downloadedBlob = new MemoryStream())
                    {
                        blob.DownloadToStream(downloadedBlob);
                        TestHelper.AssertStreamsAreEqual(wholeBlob, downloadedBlob);
                    }
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
Пример #10
0
        private async static Task<bool> scaleImage(Stream blobInput, CloudBlockBlob blobOutput, ImageSizes imageSize, string contentType)
        {
            bool retVal = true; //Assume success

            try
            {
                using (Stream output = blobOutput.OpenWrite())
                {
                    if (doScaling(blobInput, output, imageSize))
                    {
                        blobOutput.Properties.ContentType = contentType;
                    }
                    else
                        retVal = false;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error while scaling image: " + ex.Message);
                retVal = false;
            }

            return retVal;
        }
Пример #11
0
        public void UseTransactionalMD5GetTestAPM()
        {
            BlobRequestOptions optionsWithNoMD5 = new BlobRequestOptions()
            {
                UseTransactionalMD5 = false,
            };
            BlobRequestOptions optionsWithMD5 = new BlobRequestOptions()
            {
                UseTransactionalMD5 = true,
            };

            byte[] buffer = GetRandomBuffer(3 * 1024 * 1024);
            MD5    hasher = MD5.Create();
            string md5    = Convert.ToBase64String(hasher.ComputeHash(buffer));

            string           lastCheckMD5          = null;
            int              checkCount            = 0;
            OperationContext opContextWithMD5Check = new OperationContext();

            opContextWithMD5Check.ResponseReceived += (_, args) =>
            {
                if (args.Response.ContentLength >= buffer.Length)
                {
                    lastCheckMD5 = args.Response.Headers[HttpResponseHeader.ContentMd5];
                    checkCount++;
                }
            };

            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    IAsyncResult   result;
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1");
                    using (Stream blobStream = blockBlob.OpenWrite())
                    {
                        blobStream.Write(buffer, 0, buffer.Length);
                        blobStream.Write(buffer, 0, buffer.Length);
                    }

                    checkCount = 0;
                    using (Stream stream = new MemoryStream())
                    {
                        result = blockBlob.BeginDownloadToStream(stream, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                 ar => waitHandle.Set(),
                                                                 null);
                        waitHandle.WaitOne();
                        blockBlob.EndDownloadRangeToStream(result);
                        Assert.IsNotNull(lastCheckMD5);

                        result = blockBlob.BeginDownloadToStream(stream, null, optionsWithMD5, opContextWithMD5Check,
                                                                 ar => waitHandle.Set(),
                                                                 null);
                        waitHandle.WaitOne();
                        blockBlob.EndDownloadRangeToStream(result);
                        Assert.IsNotNull(lastCheckMD5);

                        result = blockBlob.BeginDownloadRangeToStream(stream, buffer.Length, buffer.Length, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                      ar => waitHandle.Set(),
                                                                      null);
                        waitHandle.WaitOne();
                        blockBlob.EndDownloadRangeToStream(result);
                        Assert.IsNull(lastCheckMD5);

                        result = blockBlob.BeginDownloadRangeToStream(stream, buffer.Length, buffer.Length, null, optionsWithMD5, opContextWithMD5Check,
                                                                      ar => waitHandle.Set(),
                                                                      null);
                        waitHandle.WaitOne();
                        blockBlob.EndDownloadRangeToStream(result);
                        Assert.AreEqual(md5, lastCheckMD5);

                        result = blockBlob.BeginDownloadRangeToStream(stream, 1024, 4 * 1024 * 1024 + 1, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                      ar => waitHandle.Set(),
                                                                      null);
                        waitHandle.WaitOne();
                        blockBlob.EndDownloadRangeToStream(result);
                        Assert.IsNull(lastCheckMD5);

                        result = blockBlob.BeginDownloadRangeToStream(stream, 1024, 4 * 1024 * 1024 + 1, null, optionsWithMD5, opContextWithMD5Check,
                                                                      ar => waitHandle.Set(),
                                                                      null);
                        waitHandle.WaitOne();
                        StorageException storageEx = TestHelper.ExpectedException <StorageException>(
                            () => blockBlob.EndDownloadRangeToStream(result),
                            "Downloading more than 4MB with transactional MD5 should not be supported");
                        Assert.IsInstanceOfType(storageEx.InnerException, typeof(ArgumentOutOfRangeException));
                    }
                    Assert.AreEqual(5, checkCount);

                    CloudPageBlob pageBlob = container.GetPageBlobReference("blob2");
                    using (Stream blobStream = pageBlob.OpenWrite(buffer.Length * 2))
                    {
                        blobStream.Write(buffer, 0, buffer.Length);
                        blobStream.Write(buffer, 0, buffer.Length);
                    }

                    checkCount = 0;
                    using (Stream stream = new MemoryStream())
                    {
                        result = pageBlob.BeginDownloadToStream(stream, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                ar => waitHandle.Set(),
                                                                null);
                        waitHandle.WaitOne();
                        pageBlob.EndDownloadRangeToStream(result);
                        Assert.IsNull(lastCheckMD5);

                        result = pageBlob.BeginDownloadToStream(stream, null, optionsWithMD5, opContextWithMD5Check,
                                                                ar => waitHandle.Set(),
                                                                null);
                        waitHandle.WaitOne();
                        StorageException storageEx = TestHelper.ExpectedException <StorageException>(
                            () => pageBlob.EndDownloadRangeToStream(result),
                            "Page blob will not have MD5 set by default; with UseTransactional, download should fail");

                        result = pageBlob.BeginDownloadRangeToStream(stream, buffer.Length, buffer.Length, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                     ar => waitHandle.Set(),
                                                                     null);
                        waitHandle.WaitOne();
                        pageBlob.EndDownloadRangeToStream(result);
                        Assert.IsNull(lastCheckMD5);

                        result = pageBlob.BeginDownloadRangeToStream(stream, buffer.Length, buffer.Length, null, optionsWithMD5, opContextWithMD5Check,
                                                                     ar => waitHandle.Set(),
                                                                     null);
                        waitHandle.WaitOne();
                        pageBlob.EndDownloadRangeToStream(result);
                        Assert.AreEqual(md5, lastCheckMD5);

                        result = pageBlob.BeginDownloadRangeToStream(stream, 1024, 4 * 1024 * 1024 + 1, null, optionsWithNoMD5, opContextWithMD5Check,
                                                                     ar => waitHandle.Set(),
                                                                     null);
                        waitHandle.WaitOne();
                        pageBlob.EndDownloadRangeToStream(result);
                        Assert.IsNull(lastCheckMD5);

                        result = pageBlob.BeginDownloadRangeToStream(stream, 1024, 4 * 1024 * 1024 + 1, null, optionsWithMD5, opContextWithMD5Check,
                                                                     ar => waitHandle.Set(),
                                                                     null);
                        waitHandle.WaitOne();
                        storageEx = TestHelper.ExpectedException <StorageException>(
                            () => pageBlob.EndDownloadRangeToStream(result),
                            "Downloading more than 4MB with transactional MD5 should not be supported");
                        Assert.IsInstanceOfType(storageEx.InnerException, typeof(ArgumentOutOfRangeException));
                    }
                    Assert.AreEqual(5, checkCount);
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
Пример #12
0
        public void UseTransactionalMD5PutTest()
        {
            BlobRequestOptions optionsWithNoMD5 = new BlobRequestOptions()
            {
                UseTransactionalMD5 = false,
            };
            BlobRequestOptions optionsWithMD5 = new BlobRequestOptions()
            {
                UseTransactionalMD5 = true,
            };

            byte[] buffer = GetRandomBuffer(1024);
            MD5    hasher = MD5.Create();
            string md5    = Convert.ToBase64String(hasher.ComputeHash(buffer));

            string           lastCheckMD5          = null;
            int              checkCount            = 0;
            OperationContext opContextWithMD5Check = new OperationContext();

            opContextWithMD5Check.SendingRequest += (_, args) =>
            {
                if (args.Request.ContentLength >= buffer.Length)
                {
                    lastCheckMD5 = args.Request.Headers[HttpRequestHeader.ContentMd5];
                    checkCount++;
                }
            };

            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1");
                List <string>  blockIds  = GetBlockIdList(3);
                checkCount = 0;
                using (Stream blockData = new MemoryStream(buffer))
                {
                    blockBlob.PutBlock(blockIds[0], blockData, null, null, optionsWithNoMD5, opContextWithMD5Check);
                    Assert.IsNull(lastCheckMD5);

                    blockData.Seek(0, SeekOrigin.Begin);
                    blockBlob.PutBlock(blockIds[1], blockData, null, null, optionsWithMD5, opContextWithMD5Check);
                    Assert.AreEqual(md5, lastCheckMD5);

                    blockData.Seek(0, SeekOrigin.Begin);
                    blockBlob.PutBlock(blockIds[2], blockData, md5, null, optionsWithNoMD5, opContextWithMD5Check);
                    Assert.AreEqual(md5, lastCheckMD5);
                }
                Assert.AreEqual(3, checkCount);

                CloudPageBlob pageBlob = container.GetPageBlobReference("blob2");
                pageBlob.Create(buffer.Length);
                checkCount = 0;
                using (Stream pageData = new MemoryStream(buffer))
                {
                    pageBlob.WritePages(pageData, 0, null, null, optionsWithNoMD5, opContextWithMD5Check);
                    Assert.IsNull(lastCheckMD5);

                    pageData.Seek(0, SeekOrigin.Begin);
                    pageBlob.WritePages(pageData, 0, null, null, optionsWithMD5, opContextWithMD5Check);
                    Assert.AreEqual(md5, lastCheckMD5);

                    pageData.Seek(0, SeekOrigin.Begin);
                    pageBlob.WritePages(pageData, 0, md5, null, optionsWithNoMD5, opContextWithMD5Check);
                    Assert.AreEqual(md5, lastCheckMD5);
                }
                Assert.AreEqual(3, checkCount);

                blockBlob  = container.GetBlockBlobReference("blob3");
                checkCount = 0;
                using (Stream blobStream = blockBlob.OpenWrite(null, optionsWithMD5, opContextWithMD5Check))
                {
                    blobStream.Write(buffer, 0, buffer.Length);
                    blobStream.Write(buffer, 0, buffer.Length);
                }
                Assert.IsNotNull(lastCheckMD5);
                Assert.AreEqual(1, checkCount);

                blockBlob  = container.GetBlockBlobReference("blob4");
                checkCount = 0;
                using (Stream blobStream = blockBlob.OpenWrite(null, optionsWithNoMD5, opContextWithMD5Check))
                {
                    blobStream.Write(buffer, 0, buffer.Length);
                    blobStream.Write(buffer, 0, buffer.Length);
                }
                Assert.IsNull(lastCheckMD5);
                Assert.AreEqual(1, checkCount);

                pageBlob   = container.GetPageBlobReference("blob5");
                checkCount = 0;
                using (Stream blobStream = pageBlob.OpenWrite(buffer.Length * 3, null, optionsWithMD5, opContextWithMD5Check))
                {
                    blobStream.Write(buffer, 0, buffer.Length);
                    blobStream.Write(buffer, 0, buffer.Length);
                }
                Assert.IsNotNull(lastCheckMD5);
                Assert.AreEqual(1, checkCount);

                pageBlob   = container.GetPageBlobReference("blob6");
                checkCount = 0;
                using (Stream blobStream = pageBlob.OpenWrite(buffer.Length * 3, null, optionsWithNoMD5, opContextWithMD5Check))
                {
                    blobStream.Write(buffer, 0, buffer.Length);
                    blobStream.Write(buffer, 0, buffer.Length);
                }
                Assert.IsNull(lastCheckMD5);
                Assert.AreEqual(1, checkCount);
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
 private static void WriteOutPutToBlob(CloudBlockBlob blockBlobReference, string csvStringToWrite)
 {
     using (StreamWriter writer = new StreamWriter(blockBlobReference.OpenWrite()))
     {
         writer.Write(csvStringToWrite);
         writer.Write("\r\n");
     }
 }
Пример #14
0
        public async Task ProcessCinemaPerformances(RegionDef region, int cinemaID, List <FilmInfo> films)
        {
            CineworldService  cws            = new CineworldService();
            List <FilmHeader> filmsForCinema = new List <FilmHeader>();

            foreach (var film in films)
            {
                Task <Dates> td = cws.GetDates(region, cinemaID, film.EDI);
                td.Wait();

                HashSet <DateTime> perfDates = new HashSet <DateTime>();
                if (!td.IsFaulted && td.Result != null && td.Result.dates != null)
                {
                    FilmHeader fh = new FilmHeader()
                    {
                        EDI = film.EDI
                    };
                    filmsForCinema.Add(fh);

                    fh.Performances = new List <PerformanceInfo>();

                    foreach (var date in td.Result.dates)
                    {
                        DateTime performanceDate = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);

                        Task <Performances> tp = cws.GetPerformances(region, cinemaID, film.EDI, date);
                        tp.Wait();

                        if (!tp.IsFaulted && tp.Result != null && tp.Result.performances != null)
                        {
                            foreach (var p in tp.Result.performances)
                            {
                                PerformanceInfo pi = new PerformanceInfo();
                                pi.PerformanceTS = performanceDate.Add(DateTime.ParseExact(p.time, "HH:mm", CultureInfo.InvariantCulture).TimeOfDay);
                                pi.Available     = p.available;
                                pi.Type          = p.Type;
                                pi.BookUrl       = new Uri(p.booking_url);
                                fh.Performances.Add(pi);
                            }
                        }
                    }
                }
            }

            //return;

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr"));

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data");

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsBlob = container.GetBlockBlobReference(String.Format(FilmsPerCinemaFileName, cinemaID));
            using (Stream s = cinemaFilmsBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        await sw.WriteAsync(JsonConvert.SerializeObject(filmsForCinema));
                    }
                }
            }
        }
Пример #15
0
        private void ProcessData()
        {
            //return;

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr"));

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data");

            // Retrieve reference to a blob.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemasUKBlob = container.GetBlockBlobReference(CinemasUKFileName);
            using (Stream s = cinemasUKBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(CinemasUK));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsUKBlob = container.GetBlockBlobReference(FilmsUKFileName);
            using (Stream s = filmsUKBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(FilmsUK));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmCinemasUKBlob = container.GetBlockBlobReference(FilmCinemasUKFileName);
            using (Stream s = filmCinemasUKBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(filmCinemasUK));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsUKBlob = container.GetBlockBlobReference(CinemaFilmsUKFileName);
            using (Stream s = cinemaFilmsUKBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(cinemaFilmsUK));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemasIEBlob = container.GetBlockBlobReference(CinemasIEFileName);
            using (Stream s = cinemasIEBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(CinemasIE));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsIEBlob = container.GetBlockBlobReference(FilmsIEFileName);
            using (Stream s = filmsIEBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(FilmsIE));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmCinemasIEBlob = container.GetBlockBlobReference(FilmCinemasIEFileName);
            using (Stream s = filmCinemasIEBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(filmCinemasIE));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsIEBlob = container.GetBlockBlobReference(CinemaFilmsIEFileName);
            using (Stream s = cinemaFilmsIEBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(cinemaFilmsIE));
                    }
                }
            }

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsPostersBlob = container.GetBlockBlobReference(MovieFilmPostersFileName);
            using (Stream s = filmsPostersBlob.OpenWrite())
            {
                using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
                {
                    using (StreamWriter sw = new StreamWriter(gzipStream))
                    {
                        sw.Write(JsonConvert.SerializeObject(MoviePosters));
                    }
                }
            }

            //Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob mediumfilmsPostersBlob = container.GetBlockBlobReference(MediumFilmPostersFileName);
            //using (Stream s = mediumfilmsPostersBlob.OpenWrite())
            //{
            //    using (var gzipStream = new GZipStream(s, CompressionMode.Compress))
            //    {
            //        using (StreamWriter sw = new StreamWriter(gzipStream))
            //        {
            //            sw.Write(JsonConvert.SerializeObject(mediumposters));
            //        }
            //    }
            //}
        }