public bool SaveString(string value, string resourceid, string containerName, string directoryPath)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);

            // Create the container if it doesn't already exist
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            try
            {
                CloudBlob stringblob = dir.GetBlobReference(resourceid);

                string guid = ShortGuidGenerator.NewGuid();

                stringblob.UploadText(value);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool UploadRawImage(System.Drawing.Image img, string newid, string containerName, string directoryPath)
        {
            try
            {
                CloudBlobContainer container = blobClient.GetContainerReference(containerName);
                CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);

                // Create the container if it doesn't already exist
                container.CreateIfNotExist();
                container.SetPermissions(new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

                System.Drawing.Image imgFull = (System.Drawing.Image)img.Clone();

                // Retrieve reference to a blob by username
                CloudBlob blobFull = dir.GetBlobReference(newid);
                using (MemoryStream ms = new MemoryStream())
                {
                    imgFull.Save(ms, ImageFormat.Png);
                    blobFull.UploadByteArray(ms.ToArray());
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public JsonResult QueuePhotoRender(ComicEffectType effect, string photoSource, int intensity)
        {
            // Generate render task
            PhotoTask task = new PhotoTask();

            task.TaskId        = Guid.NewGuid();
            task.Status        = TaskStatus.Queued;
            task.Effect        = effect;
            task.Intensity     = intensity;
            task.FacebookToken = this.Facebook.AccessToken;
            task.SourceUrl     = photoSource;
            task.OwnerUid      = this.ActiveUser.Uid;

            // Queue the task up using Azure Queue services.  Store full task information using Blob storage.  Only the task id is queued.
            // This is done because we need public visibility on render tasks before, during and after the task completes.

            // Save task to storage
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.UploadText(task.ToXml());

            // Queue up task
            CloudQueue        queue   = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.PhotoTaskQueue);
            CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString());

            queue.AddMessage(message, TimeSpan.FromMinutes(5));

            return(this.Json(new ClientPhotoTask(task, null), JsonRequestBehavior.DenyGet));
        }
        /// <summary>
        /// Gets or add an item.
        /// </summary>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="directoryName">Name of the directory.</param>
        /// <param name="addFactory">The function that is called if the item is not found in the remote storage, it is called with the cacheKey and the directoryName and the return value will be uploaded as text.</param>
        /// <returns>
        /// The value
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Value cannot be null or whitespace.
        /// or
        /// Value cannot be null or whitespace.
        /// </exception>
        public string GetOrAdd(string cacheKey, string directoryName, Func <string, string, string> addFactory)
        {
            if (string.IsNullOrWhiteSpace(cacheKey))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(cacheKey));
            }
            if (string.IsNullOrWhiteSpace(directoryName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(directoryName));
            }

            CloudBlobDirectory cloudBlobDirectory = _container.GetDirectoryReference(directoryName);
            CloudBlob          blobReference      = cloudBlobDirectory.GetBlobReference(cacheKey);

            if (blobReference.ExistsAsync().Result)
            {
                return(DownloadAsText(blobReference));
            }

            CloudBlockBlob blockBlobReference = cloudBlobDirectory.GetBlockBlobReference(cacheKey);

            if (!blockBlobReference.ExistsAsync().Result) //double check
            {
                string content = addFactory(cacheKey, directoryName);
                blockBlobReference.UploadTextAsync(content);
                return(content);
            }

            return(DownloadAsText(blobReference));
        }
Ejemplo n.º 5
0
        public bool ConvertPictureToJpeg(string pictureId, string containerName, string directoryPath)
        {
            try
            {
                // Retrieve a reference to a container
                CloudBlobContainer sourceContainer = blobClient.GetContainerReference(containerName);
                CloudBlobDirectory sourceDir       = sourceContainer.GetDirectoryReference(directoryPath);

                // Retrieve reference to the stored preview blob
                CloudBlob sourceBlob = sourceDir.GetBlobReference(pictureId);

                System.Drawing.Image imgStored;
                using (MemoryStream ms = new MemoryStream())
                {
                    sourceBlob.DownloadToStream(ms);
                    imgStored = System.Drawing.Image.FromStream(ms);
                }

                if (imgStored != null)
                {
                    UploadPictureToBlobStorage(imgStored, pictureId, containerName, directoryPath, 540, 540, 140, 140, true, false, 80);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        private void RemoveTask(RenderTask task)
        {
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.RenderTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.DeleteIfExists();
        }
Ejemplo n.º 7
0
 public IStreamingItem GetItem(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     return(new BlobStreamingItem(_directory.GetBlobReference(name)));
 }
Ejemplo n.º 8
0
        public void DeleteFile(string filename)
        {
            string containerName = ContainerFromPath(filename);
            string prefix        = PrefixFromPath(filename);

            CloudBlobContainer container = Client.GetContainerReference(containerName);
            CloudBlobDirectory b         = container.GetDirectoryReference(STEM.Sys.IO.Path.GetDirectoryName(prefix));

            b.GetBlobReference(STEM.Sys.IO.Path.GetFileName(prefix)).DeleteIfExists();
        }
Ejemplo n.º 9
0
 private CloudBlob GetBlobReference(string blobName)
 {
     if (container != null)
     {
         return(container.GetBlobReference(blobName));
     }
     else
     {
         return(directory.GetBlobReference(blobName));
     }
 }
        /// <summary>
        /// Stores a Page Attachment.
        /// </summary>
        /// <param name="pageFullName">The Page Info that owns the Attachment.</param>
        /// <param name="name">The name of the Attachment, for example "myfile.jpg".</param>
        /// <param name="sourceStream">A Stream object used as <b>source</b> of a byte stream,
        /// i.e. the method reads from the Stream and stores the content properly.</param>
        /// <param name="overwrite"><c>true</c> to overwrite an existing Attachment.</param>
        /// <returns><c>true</c> if the Attachment is stored, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="pageFullName"/>, <paramref name="name"/> or <paramref name="sourceStream"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="pageFullName"/>, <paramref name="name"/> are empty or if <paramref name="sourceStream"/> does not support reading.</exception>
        public bool StorePageAttachment(string pageFullName, string name, System.IO.Stream sourceStream, bool overwrite)
        {
            if (pageFullName == null)
            {
                throw new ArgumentNullException("pageFullName");
            }
            if (pageFullName.Length == 0)
            {
                throw new ArgumentException("pageFullName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }
            if (sourceStream == null)
            {
                throw new ArgumentNullException("sourceStream");
            }
            if (!sourceStream.CanRead)
            {
                throw new ArgumentException("Cannot read from Source Stream", "sourceStream");
            }

            try {
                var containerRef = _client.GetContainerReference(_wiki + "-attachments");

                if (BlobExists(_wiki + "-attachments", BuildNameForBlobStorage(pageFullName)) == null)
                {
                    CloudBlobDirectory directoryRef = containerRef.GetDirectoryReference(BuildNameForBlobStorage(pageFullName));
                    directoryRef.GetBlobReference(".stw.dat").UploadText("");
                }

                string blobName = BlobExists(_wiki + "-attachments", BuildNameForBlobStorage(pageFullName) + "/" + BuildNameForBlobStorage(name));
                if (!overwrite && blobName != null)
                {
                    return(false);
                }

                blobName = blobName != null ? blobName : BuildNameForBlobStorage(pageFullName) + "/" + BuildNameForBlobStorage(name);

                var blobRef = containerRef.GetBlockBlobReference(blobName);
                blobRef.UploadFromStream(sourceStream);

                return(true);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
        public bool SaveJsonResource(string resourcetype, string containerName, string directoryPath, string resourceid, string json, bool ensurecontainerexists)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);

            if (ensurecontainerexists)
            {
                // Create the container if it doesn't already exist
                container.CreateIfNotExist();
                container.SetPermissions(new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }

            try
            {
                CloudBlob jsblob   = dir.GetBlobReference(resourceid + ".js");
                CloudBlob jsonblob = dir.GetBlobReference(resourceid);

                string guid = ShortGuidGenerator.NewGuid();

                if (resourcetype != null)
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourcetype + "_ready($" + guid + ",'" + containerName + "','" + resourceid + "');");
                }
                else
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourceid.Replace("-", "") + "_ready($" + guid + ",'" + containerName + "');");
                }
                jsonblob.UploadText(json);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        private byte[] GetStoredImage(string storageKey)
        {
            byte[]             image     = null;
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.RenderContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoDirectory);
            CloudBlob          photoBlob = directory.GetBlobReference(storageKey);

            using (MemoryStream stream = new MemoryStream())
            {
                photoBlob.DownloadToStream(stream);
                image = stream.ToArray();
            }
            return(image);
        }
Ejemplo n.º 13
0
 private void UpdateTask(RenderTask task)
 {
     try
     {
         CloudBlobContainer container    = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
         CloudBlobDirectory directory    = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.RenderTaskDirectory);
         CloudBlob          progressBlob = directory.GetBlobReference(task.TaskId.ToString());
         progressBlob.UploadText(task.ToXml());
     }
     catch (Exception x)
     {
         this.Log.Error("Unable to update render progress", x);
     }
 }
Ejemplo n.º 14
0
        public bool DeletePicture(string id, string containerName, string directoryPath)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);


            try
            {
                // Retrieve reference to the stored preview blob
                CloudBlob blobStored = dir.GetBlobReference(id);
                blobStored.DeleteIfExists();

                CloudBlob blobStoredT = dir.GetBlobReference(id + "_t");
                blobStoredT.DeleteIfExists();


                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private async Task <Tuple <Stream, string> > GetFileStream(CancellationToken cancellationToken, CloudBlobDirectory directory, string blobName)
        {
            var blobReference = directory.GetBlobReference(blobName);
            var blobStream    = new MemoryStream();

            await blobReference.DownloadToStreamAsync(blobStream, null, new BlobRequestOptions()
            {
                DisableContentMD5Validation = true
            }, null, cancellationToken);

            blobStream.Position = 0;

            var decryptedStream = _encryptionService.Decrypt(blobStream);

            return(new Tuple <Stream, string>(decryptedStream, blobReference.Properties.ContentType));
        }
        public string GetJsonResource(string container, string directory, string resourceid)
        {
            // Retrieve a reference to a container
            CloudBlobContainer cont = blobClient.GetContainerReference(container);
            CloudBlobDirectory dir  = cont.GetDirectoryReference(directory);

            try
            {
                CloudBlob jsonblob = dir.GetBlobReference(resourceid);
                return(jsonblob.DownloadText());
            }
            catch
            {
                return("");
            }
        }
Ejemplo n.º 17
0
        MessageTransportContext DownloadPackage(CloudQueueMessage message)
        {
            var buffer = message.AsBytes;

            EnvelopeReference reference;

            if (AzureMessageOverflows.TryReadAsEnvelopeReference(buffer, out reference))
            {
                if (reference.StorageContainer != _cloudBlob.Uri.ToString())
                {
                    throw new InvalidOperationException("Wrong container used!");
                }
                var blob = _cloudBlob.GetBlobReference(reference.StorageReference);
                buffer = blob.DownloadByteArray();
            }
            return(new MessageTransportContext(message, buffer, _queueName));
        }
        public async Task <string> GetFileInFolder(string folderName, string fileName)
        {
            CloudBlobContainer cloudBlobContainer = new CloudBlobContainer(new System.Uri(azureStorageCredentials.StorageUri),
                                                                           new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(azureStorageCredentials.StorageToken));

            folderName = folderName.Replace("\\", "");
            CloudBlobDirectory blobDirectory = cloudBlobContainer.GetDirectoryReference(folderName);
            CloudBlob          blob          = blobDirectory.GetBlobReference(fileName);
            string             text;

            using (var memoryStream = new MemoryStream())
            {
                blob.DownloadToStream(memoryStream);
                text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            return(await System.Threading.Tasks.Task.Run(() => EncryptionHelper.Decrypt(text)));
        }
Ejemplo n.º 19
0
        public bool BlobExist(string containerName, string directoryPath, string resourceId)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);

            CloudBlobDirectory dir = container.GetDirectoryReference(directoryPath);

            try
            {
                CloudBlob blob = dir.GetBlobReference(resourceId);
                blob.FetchAttributes();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> GetLeagueImages(string idName)
        {
            var blobClient = _storageAccount.CreateCloudBlobClient();

            CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference(_azureBlobStorageSettings.ContainerName);
            CloudBlobDirectory directory          = cloudBlobContainer.GetDirectoryReference($"{_azureBlobStorageSettings.DirReference}/leagues");

            var imgBlob = directory.GetBlobReference($"{idName}.png");

            if (await imgBlob.ExistsAsync())
            {
                var imgLink = imgBlob.Uri.ToString();

                return(Ok(imgLink));
            }

            return(NotFound(new ApiError($"Image not found!")));
        }
        public bool SaveJsonResource(string resourcetype, string containerName, string directoryPath, string resourceid, string json)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);

            string[]           pathTokens = directoryPath.Split('/');
            CloudBlobDirectory dir        = container.GetDirectoryReference(pathTokens[0]);

            if (pathTokens.Length > 1)
            {
                for (var i = 1; i < pathTokens.Length; i++)
                {
                    dir = dir.GetSubdirectory(pathTokens[i]);
                }
            }

            // Create the container if it doesn't already exist
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            try
            {
                CloudBlob jsblob = dir.GetBlobReference(resourceid + ".js");

                string guid = ShortGuidGenerator.NewGuid();

                if (resourcetype != null)
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourcetype + "_ready($" + guid + ",'" + containerName + "', '" + resourceid + "', '" + directoryPath + "');");
                }
                else
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourceid.Replace("-", "") + "_ready($" + guid + ",'" + containerName + "', '" + directoryPath + "');");
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool DeleteString(string resourceid, string containerName, string directoryPath)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);

            try
            {
                // Retrieve reference to the stored preview blob
                CloudBlob stringblob = dir.GetBlobReference(resourceid);
                stringblob.DeleteIfExists();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        public bool MovePicture(string sourcePictureId, string sourceContainerName, string sourceDirectoryPath, string targetPictureId, string targetContainerName, string targetDirectoryPath)
        {
            try
            {
                // Retrieve a reference to a container
                CloudBlobContainer sourceContainer = blobClient.GetContainerReference(sourceContainerName);
                CloudBlobDirectory sourceDir       = sourceContainer.GetDirectoryReference(sourceDirectoryPath);

                CloudBlobContainer targetContainer = blobClient.GetContainerReference(targetContainerName);
                CloudBlobDirectory targetDir       = targetContainer.GetDirectoryReference(targetDirectoryPath);

                // Create the Target container if it doesn't already exist
                targetContainer.CreateIfNotExist();
                targetContainer.SetPermissions(new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

                // Retrieve reference to the stored preview blob
                CloudBlob sourceBlob = sourceDir.GetBlobReference(sourcePictureId);

                System.Drawing.Image imgStored;
                using (MemoryStream ms = new MemoryStream())
                {
                    sourceBlob.DownloadToStream(ms);
                    imgStored = System.Drawing.Image.FromStream(ms);
                }

                CloudBlob targetBlob = targetDir.GetBlobReference(targetPictureId);
                using (MemoryStream ms = new MemoryStream())
                {
                    imgStored.Save(ms, ImageFormat.Png);
                    targetBlob.UploadByteArray(ms.ToArray());
                }

                sourceBlob.DeleteIfExists();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary>
        /// Creates a new Directory.
        /// </summary>
        /// <param name="path">The path to create the new Directory in.</param>
        /// <param name="name">The name of the new Directory.</param>
        /// <returns><c>true</c> if the Directory is created, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="path"/> or <paramref name="name"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty or if the directory does not exist, or if the new directory already exists.</exception>
        public bool CreateDirectory(string path, string name)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }

            try {
                var containerRef = _client.GetContainerReference(_wiki);
                if (BlobExists(_wiki, BuildNameForBlobStorage(path)) == null)
                {
                    throw new ArgumentException("Directory does not exist", "path");
                }
                if (BlobExists(_wiki, BuildNameForBlobStorage(Path.Combine(path, name))) != null)
                {
                    throw new ArgumentException("Directory already exists", "name");
                }
                CloudBlobDirectory directoryRef = containerRef.GetDirectoryReference(BuildNameForBlobStorage(Path.Combine(path, name)));
                directoryRef.GetBlobReference(".stw.dat").UploadText("");

                return(true);
            }
            catch (StorageClientException ex) {
                if (ex.ErrorCode == StorageErrorCode.BlobAlreadyExists)
                {
                    throw new ArgumentException("Directory already exists", "name");
                }
                if (ex.ErrorCode == StorageErrorCode.BlobNotFound)
                {
                    throw new ArgumentException("Directory does not exist", "path");
                }
                throw ex;
            }
        }
Ejemplo n.º 25
0
        public override void DeleteFile(string file)
        {
            try
            {
                if (FileExists(file))
                {
                    string containerName = ContainerFromPath(file);
                    string prefix        = PrefixFromPath(file);

                    CloudBlobContainer container = Client.GetContainerReference(containerName);
                    CloudBlobDirectory b         = container.GetDirectoryReference(STEM.Sys.IO.Path.GetDirectoryName(prefix));

                    b.GetBlobReference(STEM.Sys.IO.Path.GetFileName(prefix)).DeleteIfExists();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 26
0
        public bool Reprocess(string id, string containerName, string directoryPath, int maxWidth, int maxHeight, int maxWidthT, int maxHeightT)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlobDirectory dir       = container.GetDirectoryReference(directoryPath);

            // Retrieve reference to the stored preview blob
            CloudBlob blobStored = dir.GetBlobReference(id);

            System.Drawing.Image imgStored;
            using (MemoryStream ms = new MemoryStream())
            {
                blobStored.DownloadToStream(ms);
                imgStored = System.Drawing.Image.FromStream(ms);
            }

            UploadPictureToBlobStorage(imgStored, "pic", containerName, "pictures", maxWidth, maxHeight, maxWidthT, maxHeightT, true, false, 100L);

            return(true);
        }
Ejemplo n.º 27
0
        public virtual CloudBlobEx GetBlobReference(string blobName, DateTimeOffset?snapshotTime)
        {
            if (blobName == null)
            {
                throw new ArgumentNullException(nameof(blobName));
            }


            CloudBlob[] cloudBlobArray = new CloudBlob[this.failoverExecutor.AllElements.Length];
            for (int i = 0; i < this.failoverExecutor.AllElements.Length; i++)
            {
                CloudBlobDirectory directory = this.failoverExecutor.AllElements[i];
                CloudBlob          cloudBlob = directory.GetBlobReference(blobName);
                cloudBlobArray[i] = cloudBlob;
            }

            CloudBlobEx cloudBlobEx = new CloudBlobEx(this.Container, this.failoverExecutor.FailoverToken, cloudBlobArray);

            return(cloudBlobEx);
        }
Ejemplo n.º 28
0
        protected JsonResult QueueRender(RenderTask task)
        {
            // Queue the task up using Azure Queue services.  Store full task information using Blob storage.  Only the task id is queued.
            // This is done because we need public visibility on render tasks before, during and after the task completes.

            // Save task to storage
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.RenderTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.UploadText(task.ToXml());

            // Queue up task
            CloudQueue        queue   = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.RenderTaskQueue);
            CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString());

            queue.AddMessage(message, TimeSpan.FromMinutes(5));

            return(this.Json(new ClientRenderTask(task), JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 29
0
        public JsonResult RenderProgress(string taskId)
        {
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.RenderTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(taskId);

            XmlSerializer serializer = new XmlSerializer(typeof(RenderTask));

            using (MemoryStream stream = new MemoryStream())
            {
                blob.DownloadToStream(stream);
                stream.Seek(0, SeekOrigin.Begin);
                RenderTask task = (RenderTask)serializer.Deserialize(stream);

                if (task.OwnerUid != this.ActiveUser.Uid)
                {
                    throw new Exception("Unknown task");
                }

                ClientRenderTask clientTask = new ClientRenderTask(task);
                if (task.Status == TaskStatus.Complete && task.ComicId.HasValue)
                {
                    // Load completed comic from database
                    try
                    {
                        this.EntityContext.TryAttach(this.ActiveUser);
                        Data.Comic comic = this.EntityContext.TryGetUnpublishedComic(task.ComicId.Value, this.ActiveUser);
                        clientTask.Comic = new ClientComic(comic);
                    }
                    finally
                    {
                        this.EntityContext.TryDetach(this.ActiveUser);
                    }
                }

                return(this.Json(clientTask, JsonRequestBehavior.AllowGet));
            }

            throw new Exception("Unknown task");
        }
Ejemplo n.º 30
0
        public ActionResult QueueRender(ComicEffectType effect, int intensity)
        {
            // Generate render task
            ProfileTask task = new ProfileTask();

            task.TaskId        = Guid.NewGuid();
            task.Status        = TaskStatus.Queued;
            task.Effect        = effect;
            task.Intensity     = intensity;
            task.OwnerUid      = this.ActiveUser.Uid;
            task.FacebookToken = this.Facebook.AccessToken;
            task.StorageKey    = this.ActiveUser.Uid.ToString();

            // Queue the task up using Azure Queue services.  Store full task information using Blob storage.  Only the task id is queued.
            // This is done because we need public visibility on render tasks before, during and after the task completes.

            // Save task to storage
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.ProfileTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.UploadText(task.ToXml());

            // Queue up task
            CloudQueue        queue   = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.ProfileTaskQueue);
            CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString());

            queue.AddMessage(message, TimeSpan.FromMinutes(5));

            //Session autoshare
            bool autoShareFeed = false;

            if (this.Session[SESSION_AUTO_SHARE] == null)
            {
                autoShareFeed = true;
                this.Session[SESSION_AUTO_SHARE] = true;
            }

            return(this.View("Render", new ViewFacebookRender(new ClientProfileTask(task), autoShareFeed)));
        }