Ejemplo n.º 1
0
        public async Task RunTask()
        {

            await Task.Run(async () =>
            {
                var request = new WorkTaskModel();
                try
                {
                    request = JsonConvert.DeserializeObject<WorkTaskModel>(task.AsString);
                    request.Validate();

                    switch (request.RequestType)
                    {
                        case TaskListEnumeration.PersistNewPaste:
                            await storageManager.PersistWorkTask(ScribbleWorkerRoleResource.Table, request);// request.RequestData, request.Id);
                            Trace.TraceInformation("Deleting processed message from the queue");
                            await ScribbleWorkerRoleResource.Queue.DeleteMessageAsync(task, cancellationToken);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("error: " + ex.Message
                                    + "error Trace: " + ex.StackTrace
                                    + request.ToString());
                    ScribbleWorkerRoleResource.Queue.DeleteMessage(task);
                }
            },cancellationToken);
        }
Ejemplo n.º 2
0
 public static ScribblePersistDataModel GetScribbleDataModel(WorkTaskModel task, StorageIdentifier storageIdForRequest)
 {
     return new ScribblePersistDataModel(storageIdForRequest){
         RequestId = task.RequestId,
         Data = cryptoHelper.GetEncryptedString(task.RequestData),
         UrlId = task.Id
     };
 }
Ejemplo n.º 3
0
        public static WorkTaskModel GenerateWorkTaskModel(string workTaskAsString)
        {
            var newTask = new WorkTaskModel()
            {
                RequestId = Guid.NewGuid(),
                RequestType = TaskListEnumeration.PersistNewPaste
            };

            newTask.Id = IdUrlGenerator.GetIdForRequest();
            newTask.RequestData = workTaskAsString;
            return newTask;
        }
Ejemplo n.º 4
0
 /*
  *{"RequestType":0,"Id":1212,"RequestData":"keyan is testing","RequestId":"a450ac54-1b69-4d0c-b5a9-f16c08a442b7"}
  *
  *
  */
 static void Main(string[] args)
 {
     var x = new WorkTaskModel()
     {
         Id = 1212,
         RequestData = "keyan is testing",
         RequestId = Guid.NewGuid(),
         RequestType = TaskListEnumeration.PersistNewPaste
     };
     Console.WriteLine(JsonConvert.SerializeObject(x));
     Console.Read();
     //trial();
     testCert();
 }
Ejemplo n.º 5
0
        public static WorkTaskModel GenerateWorkTaskModel(byte[] WorkTaskAsBytes, Encoding WorkTaskEncoding)
        {
            var newTask = new WorkTaskModel()
            {
                RequestId = new Guid(),
                RequestType = TaskListEnumeration.PersistNewPaste
            };

            try
            {
                var workTaskString = WorkTaskEncoding.GetString(WorkTaskAsBytes); //WorkTaskAsBytes
                newTask.Id = IdUrlGenerator.GetIdForRequest();
                newTask.RequestData = workTaskString;
                return newTask;
            }
            catch (Exception ex)
            {
                Trace.TraceError("Parsing request byte failed for: " + newTask + " input char seq :" + WorkTaskAsBytes);
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public static async Task<WorkTaskModel> GetWorkTask(string scribbleUrl)
        {
            try
            {


                var scribbleId = ScribbleWebEndpointResources.UrlFactory.GetUrlId(scribbleUrl);
                var storageIdentifier = ScribbleWebEndpointResources.StorageHelper.GetIdentifier(scribbleId);
                var result =
                    await
                        ScribbleWebEndpointResources.Table.GetDataAsync<ScribblePersistDataModel>(
                            storageIdentifier.Partitionkey.ToString(), storageIdentifier.RowKey.ToString());
                //ScribblePersistDataModel persistedTask = result.Result;
                var returnModel = new WorkTaskModel();
                if (result.HttpStatusCode == (int) StorageStatusCode.success &&
                    result.Result.GetType() == typeof (ScribblePersistDataModel))
                {
                    var persistedTask = (ScribblePersistDataModel) result.Result;
                    returnModel.Id = persistedTask.UrlId;
                    var tmpstring =
                        ScribbleWebEndpointResources.ScribbleCryptographyHandler.GetDecryptedString(persistedTask.Data);
                    returnModel.RequestData = tmpstring;
                    returnModel.RequestId = persistedTask.RequestId;
                }

                return returnModel;
            }
            catch (CryptographicException exception)
            {
                Trace.TraceError("Decryption failed. " + exception.Message);
                throw;
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error reading from azure storage. " + ex.Message);
                throw;
            }
        }
Ejemplo n.º 7
0
 public async Task PersistWorkTask(CloudTable table, WorkTaskModel task)
 {
     //convert this to storage model
     var tableEntity = ScribbleDataModelAdapter.GetScribbleDataModel(task, storageHelper.GetIdentifier(task.Id));
     await table.PersistDataAsync(tableEntity);
 }