Exemplo n.º 1
0
        public static string PublishJob(MediaJobNotification jobNotification, bool webHook)
        {
            string jobPublication = string.Empty;

            if (jobNotification != null && jobNotification.EventType == MediaJobNotificationEvent.JobStateChange &&
                (jobNotification.Properties.NewState == JobState.Error ||
                 jobNotification.Properties.NewState == JobState.Canceled ||
                 jobNotification.Properties.NewState == JobState.Finished))
            {
                if (webHook)
                {
                    string        settingKey    = Constants.AppSettingKey.MediaJobNotificationStorageQueueName;
                    string        queueName     = AppSetting.GetValue(settingKey);
                    MessageClient messageClient = new MessageClient();
                    messageClient.AddMessage(queueName, jobNotification);
                }
                else
                {
                    EntityClient entityClient = new EntityClient();
                    string       tableName    = Constants.Storage.TableName.JobPublish;
                    string       partitionKey = jobNotification.Properties.AccountName;
                    string       rowKey       = jobNotification.Properties.JobId;
                    JobPublish   jobPublish   = entityClient.GetEntity <JobPublish>(tableName, partitionKey, rowKey);
                    if (jobPublish != null)
                    {
                        tableName = Constants.Storage.TableName.JobPublishProtection;
                        ContentProtection contentProtection = entityClient.GetEntity <ContentProtection>(tableName, partitionKey, rowKey);
                        string            accountName       = jobPublish.PartitionKey;
                        string            accountKey        = jobPublish.MediaAccountKey;
                        MediaClient       mediaClient       = new MediaClient(accountName, accountKey);
                        IJob job = mediaClient.GetEntityById(MediaEntity.Job, rowKey) as IJob;
                        if (job != null)
                        {
                            mediaClient.SetProcessorUnits(job, ReservedUnitType.Basic);
                            if (jobNotification.Properties.NewState == JobState.Finished)
                            {
                                PublishContent(mediaClient, job, jobPublish, contentProtection);
                            }
                            string messageText = GetNotificationMessage(accountName, job);
                            MessageClient.SendText(messageText, jobPublish.MobileNumber);
                        }
                        if (contentProtection != null)
                        {
                            tableName = Constants.Storage.TableName.JobPublishProtection;
                            entityClient.DeleteEntity(tableName, contentProtection);
                        }
                        tableName = Constants.Storage.TableName.JobPublish;
                        entityClient.DeleteEntity(tableName, jobPublish);
                    }
                }
            }
            return(jobPublication);
        }
Exemplo n.º 2
0
        public void UploadBlock(string userId, Stream inputStream, string containerName, string directoryPath,
                                string fileName, int blockIndex, bool lastBlock)
        {
            string blockId = Convert.ToBase64String(BitConverter.GetBytes(blockIndex));

            CloudBlockBlob blob = GetBlob(containerName, directoryPath, fileName);

            blob.PutBlock(blockId, inputStream, null);

            string tableName    = Constants.Storage.TableName.FileUpload;
            string partitionKey = userId;
            string rowKey       = blob.Name;

            if (blockIndex == 0)
            {
                BlockUpload blockUpload = new BlockUpload();
                blockUpload.PartitionKey = partitionKey;
                blockUpload.RowKey       = rowKey;
                blockUpload.BlockIds     = new string[] { blockId };
                _tracker.UpsertEntity(tableName, blockUpload);
            }
            else
            {
                BlockUpload   blockUpload = _tracker.GetEntity <BlockUpload>(tableName, partitionKey, rowKey);
                List <string> blockIds    = new List <string>(blockUpload.BlockIds);
                blockIds.Add(blockId);
                blockUpload.BlockIds = blockIds.ToArray();
                _tracker.UpdateEntity(tableName, blockUpload);
            }

            if (lastBlock)
            {
                BlockUpload blockUpload = _tracker.GetEntity <BlockUpload>(tableName, partitionKey, rowKey);
                blob.PutBlockList(blockUpload.BlockIds);
                _tracker.DeleteEntity(tableName, blockUpload);
            }
        }