public void RequestShuffle(string shuffleId)
        {
            shuffleId = ValidateAndNormalizeContainerName(shuffleId);
            CloudBlobContainer shuffleContainer = this.GetShuffleContainer(shuffleId);

            // Mark the container as no longer able to accept images
            shuffleContainer.Metadata[ReadonlyContainerKey] = bool.TrueString;
            shuffleContainer.SetMetadata();

            // Create the queue message and post it
            CloudQueue shuffleQueue = this.GetShuffleQueue();

            shuffleQueue.CreateIfNotExists();

            ShuffleRequestMessage newShuffleRequest = new ShuffleRequestMessage()
            {
                ShuffleId = shuffleId
            };

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            CloudQueueMessage    message    = new CloudQueueMessage(serializer.Serialize(newShuffleRequest));

            shuffleQueue.AddMessage(message);
        }
        public bool RegisterUser(string activeDirectoryId, int eventId)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);
            var theEvent = this.GetEvent(eventId);
            var notificationMessage = String.Format("{0};User {0} registered with event {1} on {2}. ",
                                            activeDirectoryId, theEvent.Title, DateTime.Now);
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueClient.GetQueueReference("events");
            queue.CreateIfNotExists();
            CloudQueueMessage message = new CloudQueueMessage(notificationMessage);
            queue.AddMessage(message);

            using (var cmd = this.CreateCommand(
                RegistrationInsert,
                new Dictionary<string, object>() {
                { "@UserId", activeDirectoryId },
                { "@EventId", eventId },
                { "@RegistrationDate", DateTime.Now }
                }))
            {
                return cmd.ExecuteNonQuery() > 0;
            }
        }
        // Site creation request to queue
        private void ProcessSiteRequest(string adminEmail)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       =
                queueClient.GetQueueReference(Provisioning.Hybrid.Simple.Common.Consts.StorageQueueName);

            queue.CreateIfNotExists();

            // Pass in data for modification
            var newSiteRequest = new SiteCollectionRequest()
            {
                Title             = txtTitle.Text,
                OwnerIdentifier   = adminEmail,
                TargetEnvironment = drlEnvironment.SelectedValue,
                Template          = drlTemplate.SelectedValue
            };

            // Add entry to queue
            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(newSiteRequest)));
        }
Exemple #4
0
        private void Put(CloudQueue queue, CloudQueueMessage message)
        {
            this.retryPolicy.ExecuteAction(() =>
            {
                for (; ;)
                {
                    try
                    {
                        queue.AddMessage(message);
                        break;
                    }
                    catch (StorageClientException ex)
                    {
                        if (ex.ErrorCode != StorageErrorCode.ResourceNotFound && ex.ExtendedErrorInformation.ErrorCode != QueueErrorCodeStrings.QueueNotFound)
                        {
                            throw;
                        }

                        // We should automatically create a new queue if one is not as yet created.
                        queue.CreateIfNotExist();
                    }
                }
            });
        }
Exemple #5
0
        /// <summary>
        /// Validate the read permission in sastoken for the specified queue
        /// </summary>
        internal void ValidateQueueReadableWithSasToken(CloudQueue queue, string sasToken)
        {
            Test.Info("Verify queue read permission");
            CloudQueue sasQueue = GetQueueBySasToken(queue, sasToken);

            queue.FetchAttributes();
            sasQueue.FetchAttributes();
            int oldMessageCount = queue.ApproximateMessageCount.Value;

            TestBase.ExpectEqual(queue.ApproximateMessageCount.Value, sasQueue.ApproximateMessageCount.Value, "Message count");
            string            content = Utility.GenNameString("message content");
            CloudQueueMessage message = new CloudQueueMessage(content);

            queue.AddMessage(message);
            queue.FetchAttributes();
            sasQueue.FetchAttributes();
            int newMessageCount = queue.ApproximateMessageCount.Value;

            TestBase.ExpectNotEqual(newMessageCount, oldMessageCount, "The message count after adding");
            TestBase.ExpectEqual(queue.ApproximateMessageCount.Value, sasQueue.ApproximateMessageCount.Value, "Message count");
            CloudQueueMessage retrievedMessage = queue.GetMessage();

            queue.DeleteMessage(retrievedMessage);
        }
Exemple #6
0
 private void ListMessagebutton_Click(object sender, EventArgs e)
 {
     try
     {
         var storageAccount                    = "hab1hydstorage";
         var key                               = "UWTY4xDOszXlKJY4qv8fj467xhjScEMZwgT9ooGGJmr0IcqPLEk6RfpVj6esWATabpQDIAkuXd3WLBha6laJtg==";
         StorageCredentials  storeCred         = new StorageCredentials(storageAccount, key);
         CloudStorageAccount cloudStoreAccount = new CloudStorageAccount(storeCred, useHttps: true);
         CloudQueueClient    queueClient       = cloudStoreAccount.CreateCloudQueueClient();
         CloudQueue          azureQueue        = queueClient.GetQueueReference("testqueue");
         azureQueue.CreateIfNotExists();
         CloudQueueMessage insertmessage = new CloudQueueMessage("Hello test message");
         azureQueue.AddMessage(insertmessage);
         var messages = azureQueue.GetMessages(10);
         foreach (var message in messages)
         {
             listBox1.Items.Add(message.AsString);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        protected void BtnPost_Click(object sender, EventArgs e)
        {
            JObject jObject = new JObject();

            jObject.Add("singel", singelRoom.Checked);
            jObject.Add("double", doubleRoom.Checked);
            jObject.Add("travelers", TextBox1.Text);
            jObject.Add("nights", TextBox2.Text);
            jObject.Add("hotelSeniors", TextBox3.Text);
            jObject.Add("name", TextBox4.Text);

            try
            {
                StorageCredentials  creds          = new StorageCredentials(accountName, accountKey); //Account and key are already initialized
                CloudStorageAccount storageAccount = new CloudStorageAccount(creds, useHttps: true);

                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); //Create an instance of a Cloud QueueClient object to access your queue in the storage

                // Retrieve a reference to a specific queue
                CloudQueue queue = queueClient.GetQueueReference("hotelrequestqueue");

                // Create the queue if it doesn't already exist
                queue.CreateIfNotExists();

                //remove any existing messages (just in case)
                queue.Clear();

                // Create a message and add it to the queue.
                CloudQueueMessage message = new CloudQueueMessage(jObject.ToString());
                queue.AddMessage(message);


                //Show in the console that some activity is going on in the Web Role
                Debug.WriteLine("Message '" + message + "'stored in Queue");
            }
            catch (Exception ee) {; }



            try
            {
                StorageCredentials  creds          = new StorageCredentials(accountName, accountKey);
                CloudStorageAccount storageAccount = new CloudStorageAccount(creds, useHttps: true);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

                // Retrieve a reference to a queue
                CloudQueue responsequeue = queueClient.GetQueueReference("hotelresponsequeue");
                try
                {
                    // Create the queue if it doesn't already exist
                    responsequeue.CreateIfNotExists();

                    // retrieve the next message
                    CloudQueueMessage readMessage = responsequeue.GetMessage();


                    // Display message (populate the textbox with the message you just retrieved.
                    TextBox5.Text = readMessage.AsString;

                    //Delete the message just read to avoid reading it over and over again
                    responsequeue.DeleteMessage(responsequeue.GetMessage());
                }
                catch (Exception ee) { Debug.WriteLine("Problem reading from queue"); }
            }
            catch (Exception eee) {; }
        }
        public void addMsg(string JsonMessage)
        {
            CloudQueueMessage msg = new CloudQueueMessage(JsonMessage);

            queue.AddMessage(msg);
        }
        public static void AddQueueItem(CloudQueue queue, string data)
        {
            CloudQueueMessage message = new CloudQueueMessage(data);

            queue.AddMessage(message);
        }
Exemple #10
0
 public void Publish(T message)
 {
     message.Require("message");
     CloudQueue.AddMessage(new CloudQueueMessage(Serializer.Serialize(message)));
 }
Exemple #11
0
        /// <summary>
        /// Send back to watcher a "Posion messsage" and delete from in queue
        /// </summary>
        /// <param name="poisonMessage">the poison message</param>
        /// <returns>Sueccess or not</returns>
        private bool SendPoisonMessage(CloudQueueMessage poisonMessage)
        {
            bool sw = false;

            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(myConfigData.ProcessConfigConn);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                CloudQueue          poisonQueue    = queueClient.GetQueueReference(myConfigData.poisonQueue);
                poisonQueue.CreateIfNotExists();

                MediaButler.Common.ButlerRequest  myButlerRequest  = Newtonsoft.Json.JsonConvert.DeserializeObject <ButlerRequest>(poisonMessage.AsString);
                MediaButler.Common.ButlerResponse myButlerResponse = new Common.ButlerResponse();

                myButlerResponse.MezzanineFiles = myButlerRequest.MezzanineFiles;
                ////Add to Mezzamine Files the control File URL if it exist
                //Becouse it is needed to move/delete the control file from processing to succes or fail
                if (!string.IsNullOrEmpty(myButlerRequest.ControlFileUri))
                {
                    myButlerResponse.MezzanineFiles.Add(myButlerRequest.ControlFileUri);
                }
                myButlerResponse.TimeStampProcessingCompleted = DateTime.Now.ToString();
                myButlerResponse.TimeStampProcessingStarted   = DateTime.Now.ToString();
                myButlerResponse.WorkflowName = myButlerRequest.WorkflowName;
                myButlerResponse.MessageId    = myButlerRequest.MessageId;
                myButlerResponse.TimeStampRequestSubmitted = myButlerRequest.TimeStampUTC;
                myButlerResponse.StorageConnectionString   = myButlerRequest.StorageConnectionString;
                myButlerResponse.Log = "Poison Message";

                //Lookin for Errors in Table Status
                CloudTableClient tableClient       = storageAccount.CreateCloudTableClient();
                CloudTable       table             = tableClient.GetTableReference(MediaButler.Common.Configuration.ButlerWorkflowStatus);
                TableOperation   retrieveOperation =
                    TableOperation.Retrieve <MediaButler.Common.workflow.ProcessSnapShot>(myButlerRequest.WorkflowName, myButlerRequest.MessageId.ToString());
                TableResult retrievedResult = table.Execute(retrieveOperation);
                if (retrievedResult.Result != null)
                {
                    //we have process info
                    var status = (MediaButler.Common.workflow.ProcessSnapShot)retrievedResult.Result;
                    try
                    {
                        var request = Newtonsoft.Json.JsonConvert.DeserializeObject <MediaButler.Common.workflow.ChainRequest>(status.jsonContext);
                        foreach (var error in request.Exceptions)
                        {
                            //myButlerResponse.Log += "\r\n" + error.Message;
                            myButlerResponse.Log += "\r\n" + error;
                        }
                    }
                    catch (Exception X)
                    {
                        Trace.TraceWarning("Unable to load Error LOG in response.log on poison message");
                        myButlerResponse.Log += "\r\n" + X.Message;
                        myButlerResponse.Log += "\r\n" + status.jsonContext;
                    }


                    //Delete register from Status table
                    TableOperation insertOperation = TableOperation.Delete(status);
                    table.Execute(insertOperation);
                }
                //Send Poison Mesagge
                CloudQueueMessage poison = new CloudQueueMessage(Newtonsoft.Json.JsonConvert.SerializeObject(myButlerResponse));
                poisonQueue.AddMessage(poison);
                sw = true;
            }
            catch (Exception X)
            {
                string txt = string.Format("[{0}] at {1} has an error: {2}", this.GetType().FullName, "GetNewMessage", X.Message);
                Trace.TraceError(txt);
            }
            return(sw);
        }
        //*************************************************************************************************************************
        // Instructions:
        // TODO: 1. Create a Storage Account through the Portal and provide your [AccountName] and [AccountKey] in the App.Config
        //          See http://go.microsoft.com/fwlink/?LinkId=325277 for more information
        //       2. Set breakpoints and run the project
        //*************************************************************************************************************************
        static void Main(string[] args)
        {
            Console.WriteLine("Azure Storage Queue Sample\n");

            // Retrieve storage account information from connection string.
            CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create a queue client for interacting with the queue service
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            Console.WriteLine("1. Create a queue");
            // Use the queueClient object to get a reference to the queue you want to use. Create the queue if it doesn't exist.
            CloudQueue queue = queueClient.GetQueueReference("myqueue");

            if (queue.CreateIfNotExists())
            {
                Console.WriteLine("Created queue named: {0}\n", queue.Name);
            }
            else
            {
                Console.WriteLine("Table {0} already exists\n", queue.Name);
            }

            Console.WriteLine("2. Insert a single message into a queue\n");
            // To insert a message into an existing queue, create a new CloudQueueMessage and call the AddMessage method.
            // Note there are multiple overloads to the AddMessage method that allows you to add TTL, visibility delay and others
            queue.AddMessage(new CloudQueueMessage("Hello World"));

            Console.WriteLine("3. Peek at the next message");
            // Peek at the message in the front of a queue without removing it from the queue using PeekMessage (PeekMessages lets you peek >1 message)
            CloudQueueMessage peekedMessage = queue.PeekMessage();

            Console.WriteLine("The peeked message is: {0}\n", peekedMessage.AsString);

            Console.WriteLine("4. Change the contents of a queued message\n");

            // Updates an enqueued message with new contents and update the visibility timeout. For workflow scenarios this could
            // enable you to update the status of a task as well as extend the visibility timeout in order to provide more time for
            // a client continue working on the message before another client can see the message.
            CloudQueueMessage message = queue.GetMessage();

            message.SetMessageContent("Updated contents.");

            queue.UpdateMessage(message, TimeSpan.FromSeconds(0.0), // For the purpose of the sample make the update visible immediately
                                MessageUpdateFields.Content | MessageUpdateFields.Visibility);

            Console.WriteLine("5. De-queue the next message");
            // You de-queue a message in two steps. Call GetMessage at which point the message becomes invisible to any other code reading messages
            // from this queue for the a default period of 30 seconds. To finish removing the message from the queue, you call DeleteMessage.
            // This two-step process ensures that if your code fails to process a message due to hardware or software failure, another instance
            // of your code can get the same message and try again.
            message = queue.GetMessage();
            if (message != null)
            {
                Console.WriteLine("Processing & deleting message with content: {0}\n", message.AsString);
                queue.DeleteMessage(message);
            }

            Console.WriteLine("6. Dequeue N x messages and set visibility timeout to 5 minutes");
            QueueSomeMessages(queue, 21, "sample message content");//Add some messages to be used for the remainder of the steps below

            // Dequeue a batch of 20 messages (up to 32) and set visibility timeout to 5 minutes.
            foreach (CloudQueueMessage msg in queue.GetMessages(20, TimeSpan.FromMinutes(5)))
            {
                Console.WriteLine("Processing & deleting message with content: {0}", msg.AsString);
                // Process all messages in less than 5 minutes, deleting each message after processing.
                queue.DeleteMessage(msg);
            }

            Console.WriteLine("\n7. Get the queue length");

            // The FetchAttributes method asks the Queue service to retrieve the queue attributes, including an approximation of message count
            queue.FetchAttributes();
            int?cachedMessageCount = queue.ApproximateMessageCount;

            Console.WriteLine("Number of messages in queue: {0}\n", cachedMessageCount);

            Console.WriteLine("8. Delete the queue\n");
            queue.Delete();

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Exemple #13
0
 public void StartCrawler()
 {
     cmdQueue.CreateIfNotExists();
     cmdQueue.Clear();
     cmdQueue.AddMessage(new CloudQueueMessage("start"));
 }
Exemple #14
0
        public void Add(string key, string value)
        {
            var message = new CloudQueueMessage(value);

            _queue.AddMessage(message);
        }
Exemple #15
0
        public Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            Console.WriteLine("Reading messages on partition {0}.", context.Lease.PartitionId);
            Console.WriteLine("Starting at message {0}.", context.Lease.SequenceNumber.ToString());
            if (messages != null)
            {
                foreach (var msg in messages)
                {
                    if (msg != null)
                    {
                        processedMsgCount++;
                        Console.WriteLine("Message header");
                        Console.WriteLine("PartitionKey={0};SequenceNumber={1};Offset={2};SizeInBytes={3};EnqueuedTime={4}", msg.PartitionKey, msg.SequenceNumber, msg.Offset, msg.SerializedSizeInBytes.ToString(), msg.EnqueuedTimeUtc.ToString());
                        Console.WriteLine("Message properties");
                        if (msg.Properties.ContainsKey("VehicleType"))
                        {
                            if (msg.Properties["VehicleType"].ToString() == CarType.SUV.ToString())
                            {
                                Console.WriteLine("Found an suv");
                            }
                        }
                        foreach (string propKey in msg.Properties.Keys)
                        {
                            Console.WriteLine("Key={0};value:{1}", propKey, msg.Properties[propKey] as string);
                        }

                        Console.WriteLine("System properties");
                        foreach (string propKey in msg.SystemProperties.Keys)
                        {
                            Console.WriteLine("Key={0};value:{1}", propKey, msg.SystemProperties[propKey] as string);
                        }

                        Console.WriteLine("Message Data");
                        //Deserialize the body
                        var jsonData = Encoding.UTF8.GetString(msg.GetBytes());
                        Console.WriteLine("Raw message={0}", jsonData);
                        try {
                            var reading = JsonConvert.DeserializeObject <VehicleTireReading>(jsonData);
                            if (reading != null)
                            {
                                Console.WriteLine("Reading {0} for vehicle ID:{1} read {2}", reading.ReadingId, reading.VehicleId, reading.ReadingTimeStamp.ToString());
                                Console.WriteLine("HasFlat:{0}", reading.HasFlat);
                                if (reading.HasFlat)
                                {
                                    //send to the isflat queue
                                    ChangeFlatQMsg carInfo = new ChangeFlatQMsg();
                                    carInfo.VehicleId = reading.VehicleId;
                                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureStorage.ConnectionString"));
                                    CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                                    CloudQueue          queue          = queueClient.GetQueueReference("changeflatforcar");
                                    // Create the queue if it doesn't already exist
                                    queue.CreateIfNotExists();
                                    var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(carInfo));
                                    queue.AddMessage(queueMessage);
                                    Console.WriteLine("Flat tire message added to the queue");
                                }

                                foreach (TireReading tr in reading.Readings)
                                {
                                    //Check to see if we have an under/over inflated tire. If so drop it on a queue for notification
                                    if (tr.IsUnderInflated || tr.IsOverInflated)
                                    {
                                        //TODO: Send to check pressure queue
                                    }
                                }
                                Console.WriteLine("Speed:{0}", reading.CurrentSpeed.ToString());
                                Console.WriteLine("Distance:{0}", reading.CurrrentDistanceTraveled.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            //Console.WriteLine("An error occured :", ex.ToString());
                            //If we hit an error, checkpoint so we dont try and  process it again
                            context.CheckpointAsync(msg);
                            //Probably a servializatiion error
                        }
                    }
                    //After every 1000 messages, checkpoint
                    if (processedMsgCount == 1000)
                    {
                        Console.WriteLine("Processed 1000 msgs. Checkpointing at {0}", msg.SequenceNumber.ToString());
                        //CHECKPOINT TO READ FROM THE LAST READ POINT INSTEAD OF THE BEGINNING
                        context.CheckpointAsync(msg);
                        processedMsgCount = 0;
                    }
                }
            }

            return(Task.FromResult <object>(null));
        }
Exemple #16
0
        public override void Run()
        {
            Trace.TraceInformation("WorkerRole1 is running");
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

            table       = tableClient.GetTableReference("htmlURLs");
            HTMLs       = queueClient.GetQueueReference("urls");
            messages    = queueClient.GetQueueReference("status");
            visitedURLs = queueClient.GetQueueReference("visited");
            bool robotsparsed        = false;
            CloudQueueMessage status = null;

            lastTen = new List <String>();
            while (true)
            {
                Thread.Sleep(10);
                if (messages.Exists())
                {
                    status = messages.PeekMessage();
                }
                if (status != null && status.AsString.Equals("Start") && HTMLs != null && !robotsparsed)
                {
                    spider = new Crawler();
                    List <string> urls  = spider.crawlRobots();
                    List <string> urls2 = spider.cnnRobotsCrawl();
                    index       = 0;
                    urlsCrawled = 0;
                    foreach (string url in urls)
                    {
                        HTMLs.AddMessage(new CloudQueueMessage(url));
                    }
                    foreach (string url in urls2)
                    {
                        HTMLs.AddMessage(new CloudQueueMessage(url));
                    }
                    robotsparsed = true;
                    messages.DeleteMessage(messages.GetMessage(TimeSpan.FromMinutes(5)));
                    messages.AddMessage(new CloudQueueMessage("Crawling"));
                }
                else if (status != null && !status.AsString.Equals("Stop") && HTMLs != null && robotsparsed)
                {
                    CloudQueueMessage message = HTMLs.GetMessage(TimeSpan.FromMinutes(5));
                    if (message != null)
                    {
                        HTMLs.DeleteMessage(message);
                        string messageString = message.AsString;
                        if (spider.isAllowed(messageString))
                        {
                            List <string> newLinks = spider.crawlLink(messageString);
                            URL           entry    = null;
                            if (newLinks[0] == "Error")
                            {
                                entry = new URL(messageString, newLinks[0], "Error");
                            }
                            else
                            {
                                entry = new URL(messageString, newLinks[0], "Partition");
                            }
                            if (lastTen.Count < 10)
                            {
                                lastTen.Add(messageString);
                            }
                            else
                            {
                                lastTen.Remove(lastTen[0]);
                                lastTen.Add(messageString);
                            }
                            if (spider.visited().Contains(messageString))
                            {
                                index++;
                            }
                            urlsCrawled++;
                            TableOperation insertOperation = TableOperation.InsertOrReplace(entry);
                            table.ExecuteAsync(insertOperation);
                            //var result = table.BeginExecute(insertOperation,
                            //new AsyncCallback(onTableExecuteComplete), entity);
                            //result.AsyncWaitHandle.WaitOne();
                            if (newLinks.Count > 1)
                            {
                                for (int i = 2; i < newLinks.Count - 1; i++)
                                {
                                    HTMLs.AddMessageAsync(new CloudQueueMessage(newLinks[i]));
                                }
                            }
                        }
                        URL            tableEntry     = new URL("Index", index.ToString(), "IndexCount");
                        TableOperation indexOperation = TableOperation.InsertOrReplace(tableEntry);
                        table.Execute(indexOperation);
                        URL            tableEntry2       = new URL("urls", urlsCrawled.ToString(), "URLs");
                        TableOperation urlCountOperation = TableOperation.InsertOrReplace(tableEntry2);
                        table.Execute(urlCountOperation);
                        URL            lastTenEntry;
                        TableOperation lastTenOp;
                        for (int i = 0; i < lastTen.Count; i++)
                        {
                            lastTenEntry = new URL(i.ToString(), lastTen[i], "LastTen");
                            lastTenOp    = TableOperation.InsertOrReplace(lastTenEntry);
                            table.Execute(lastTenOp);
                        }
                    }
                    else
                    {
                        messages.DeleteMessage(status);
                    }
                }
            }
            //     try
            //       {
            //           this.RunAsync(this.cancellationTokenSource.Token).Wait();
            //       }
            //       finally
            //       {
            //           this.runCompleteEvent.Set();
            //       }
        }
Exemple #17
0
        public async Task <IActionResult> Index(PowerpointFile powerpointFile)
        {
            // Create a local file in the ./data/ directory for uploading and downloading
            string localPath = "";
            //powerpointFile.FileTitle = powerpointFile.MyFile.FileName;
            string results_fileName  = "results_" + Guid.NewGuid().ToString() + ".txt";
            string localFilePath_txt = Path.Combine(localPath, results_fileName);



            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageacc = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString);



            Microsoft.Azure.Storage.CloudStorageAccount queueStorageAccount = Microsoft.Azure.Storage.CloudStorageAccount.Parse(connectionString);



            // Create a BlobServiceClient object which will be used to create a container client
            CloudBlobClient blobClient = storageacc.CreateCloudBlobClient();

            CloudQueueClient queueClient = queueStorageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a queue.
            CloudQueue queue = queueClient.GetQueueReference(queueName);

            // Create the queue if it doesn't already exist.
            queue.CreateIfNotExists();


            // Create the container and return a container client object
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            await container.CreateIfNotExistsAsync();

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(results_fileName);

            blockBlob.Properties.ContentType = "text/plain";

            // Write text to the file
            await System.IO.File.WriteAllTextAsync(localFilePath_txt, "Working on ppt_xx.pptx");

            using (var filestream = System.IO.File.OpenRead(localFilePath_txt))
            {
                await blockBlob.UploadFromStreamAsync(filestream);

                //send message to Queue
                CloudQueueMessage message = new CloudQueueMessage(blockBlob.Uri.ToString());
                queue.AddMessage(message);
            }

            /*
             * https://github.com/jayesh-tanna/azure-blob/blob/master/AzureBlob/AzureBlob.API/Controllers/UserController.cs
             */

            if (Microsoft.Azure.Storage.CloudStorageAccount.TryParse(connectionString, out Microsoft.Azure.Storage.CloudStorageAccount storageAccount))
            {
                await container.CreateIfNotExistsAsync();

                //MS: Don't rely on or trust the FileName property without validation. The FileName property should only be used for display purposes.
                var picBlob = container.GetBlockBlobReference(powerpointFile.MyFile.FileName);

                await picBlob.UploadFromStreamAsync(powerpointFile.MyFile.OpenReadStream());

                //send message to Queue
                CloudQueueMessage message = new CloudQueueMessage(picBlob.Uri.ToString());
                queue.AddMessage(message);

                // return Ok(picBlob.Uri);
            }



            return(Redirect("/Home/LinkPage"));
        }
Exemple #18
0
        public async Task <HttpResponseMessage> ProcessIdcardPostAsync()
        {
            InitEnvironment();

            #region Step1-Step2. 첨부된 파일을 Web App의 Map Path에 복사하고, 이를 Blob Container에 업로드
            MultipartFormdataStreamBlobUploader multipartFormdataStreamBlobUploader = new MultipartFormdataStreamBlobUploader(provider, storageAccount, container);
            listUrlBlob = await multipartFormdataStreamBlobUploader.UploadAttachedFileToBlobContainer(this.Request, blobPrefixString);

            #endregion

            #region Step3. 저장한 blob 위치를 인지서비스에 전달하여 OCR 및 Face 정보 추출
            try
            {
                foreach (UrlBlob urlBlob in listUrlBlob)
                {
                    //OCR 호출
                    List <string> contentsOcr = await CognitiveServicesCallHelper.CognitiveServicePostAsync(
                        CloudConfigurationManager.GetSetting("CognitiveServicesKeyVision"),
                        "https://eastasia.api.cognitive.microsoft.com/vision/v1.0/ocr?language=ko&detectOrientation=true",
                        urlBlob.url);

                    //OCR 결과를 건별로 Queue에 넣음, trace 표시
                    foreach (string content in contentsOcr)
                    {
                        CloudQueueMessage message = new CloudQueueMessage(content);
                        queue.AddMessage(message);

                        Trace.WriteLine("OCR: " + content);
                    }

                    //Face Detection 호출
                    List <string> contentsFace = await CognitiveServicesCallHelper.CognitiveServicePostAsync(
                        CloudConfigurationManager.GetSetting("CognitiveServicesKeyVision"),
                        "https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceAttributes=age,gender,headPose,glasses,accessories",
                        urlBlob.url);

                    //Face 결과를 trace 표시
                    foreach (string content in contentsFace)
                    {
                        List <FaceDetectResult> faceDetectResults = JsonConvert.DeserializeObject <List <FaceDetectResult> >(content);

                        if (faceDetectResults.Count > 0)
                        {
                            Trace.WriteLine("Face: " + content);
                            Trace.WriteLine("FaceId: " + faceDetectResults[0].faceId);

                            HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.OK, new JsonFaceId(faceDetectResults[0].faceId));

                            return(message);
                        }
                    }
                }
                // return empty FaceId if no faces were found.
                return(Request.CreateResponse(HttpStatusCode.OK, new JsonFaceId("")));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
            #endregion
        }
Exemple #19
0
        // POST: api/User
        public async Task <IHttpActionResult> Post(List <BatchScan> scanResults)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                int    batchId    = 0;
                string retailerId = null;

                foreach (var scanResult in scanResults)
                {
                    long ean_upc;
                    long.TryParse(scanResult.BarcodeValue, out ean_upc);
                    if (ean_upc == 0)
                    {
                        ean_upc = 999999999;
                    }

                    //Create new scan object to add in table

                    var scanObject = new ScanResult()
                    {
                        Id                 = Guid.NewGuid().ToString(),
                        BarcodeValue       = ean_upc,
                        AgentID            = scanResult.AgentID,
                        RetailerID         = scanResult.RetailerID,
                        ValidationResponse = scanResult.ValidationResponse,
                        isValid            = false,
                        isAgentNotified    = false,
                        ScanDate           = scanResult.ScanDate,
                        ScanLocationLat    = scanResult.ScanLocationLat,
                        ScanLocationLong   = scanResult.ScanLocationLong,
                        BatchID            = scanResult.BatchID,
                        isProcessed        = false,
                    };

                    db.ScanResults.Add(scanObject);
                    if (batchId == 0)
                    {
                        batchId = Convert.ToInt32(scanResult.BatchID);
                    }
                    if (retailerId == null)
                    {
                        retailerId = scanResult.RetailerID;
                    }
                }

                try
                {
                    await db.SaveChangesAsync();

                    //Insert Message in Queue
                    StorageCredentials  credentails = new StorageCredentials(accountName, accountkey);
                    CloudStorageAccount account     = new CloudStorageAccount(credentails, true);
                    CloudQueueClient    queueCLient = account.CreateCloudQueueClient();
                    CloudQueue          queue       = queueCLient.GetQueueReference("proscanqueue");
                    queue.CreateIfNotExists();

                    CloudQueueMessage message = new CloudQueueMessage(batchId + "&" + retailerId);
                    queue.AddMessage(message);
                }
                catch (DbUpdateException dbex)
                {
                    return(Ok(dbex.Message));
                }

                return(Ok("Scan table successfully updated"));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
Exemple #20
0
        public void SendMessageToQueue()
        {
            var message = new CloudQueueMessage(MessageText);

            cloudQueue.AddMessage(message);
        }
Exemple #21
0
        public void PutMessage(MsgBusPayload payload)
        {
            CloudQueueMessage msg = new CloudQueueMessage(JsonConvert.SerializeObject(payload));

            queue.AddMessage(msg);
        }
 public void QueueMessage_Test(string message)
 {
     queueReference.AddMessage(new CloudQueueMessage(string.Format(message, DateTime.Now.ToString("g"))), TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(30));
 }
 public void SendMessage(CloudQueue queue, string msg)
 {
     queue.AddMessage(new CloudQueueMessage(msg));
 }
Exemple #24
0
        //Dodaje poruku u red
        public void AddToQueue(string messageContent)
        {
            CloudQueueMessage message = new CloudQueueMessage(messageContent);

            queue.AddMessage(message);
        }
 protected void AddQueueMessage(long rowKey)
 {
     RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
     .ExecuteAction(
         () => Queue.AddMessage(new CloudQueueMessage(rowKey.ToString(CultureInfo.InvariantCulture))));
 }
        public Guid EnqueueProvisioningJob(ProvisioningJob job)
        {
            // Prepare the Job ID
            Guid jobId = Guid.NewGuid();

            // Connect to the Infrastructural Site Collection
            using (var context = PnPPartnerPackContextProvider.GetAppOnlyClientContext(PnPPartnerPackSettings.InfrastructureSiteUrl))
            {
                // Set the initial status of the Job
                job.JobId  = jobId;
                job.Status = ProvisioningJobStatus.Pending;

                // Convert the current Provisioning Job into a Stream
                Stream stream = job.ToJsonStream();

                // Get a reference to the target library
                Web  web  = context.Web;
                List list = web.Lists.GetByTitle(PnPPartnerPackConstants.PnPProvisioningJobs);
                Microsoft.SharePoint.Client.File file = list.RootFolder.UploadFile(String.Format("{0}.job", jobId), stream, false);

                Microsoft.SharePoint.Client.User ownerUser = web.EnsureUser(job.Owner);
                context.Load(ownerUser);
                context.ExecuteQueryRetry();

                ListItem item = file.ListItemAllFields;

                item[PnPPartnerPackConstants.ContentTypeIdField]       = PnPPartnerPackConstants.PnPProvisioningJobContentTypeId;
                item[PnPPartnerPackConstants.TitleField]               = job.Title;
                item[PnPPartnerPackConstants.PnPProvisioningJobStatus] = ProvisioningJobStatus.Pending.ToString();
                item[PnPPartnerPackConstants.PnPProvisioningJobError]  = String.Empty;
                item[PnPPartnerPackConstants.PnPProvisioningJobType]   = job.GetType().FullName;

                FieldUserValue ownerUserValue = new FieldUserValue();
                ownerUserValue.LookupId = ownerUser.Id;
                item[PnPPartnerPackConstants.PnPProvisioningJobOwner] = ownerUserValue;

                item.Update();

                context.ExecuteQueryRetry();

                // Check if we need to enqueue a message in the Azure Storage Queue, as well
                // This happens when the Provisioning Job has to be executed in Continous mode
                if (PnPPartnerPackSettings.ContinousJobHandlers.ContainsKey(job.GetType()))
                {
                    // Get the storage account for Azure Storage Queue
                    CloudStorageAccount storageAccount =
                        CloudStorageAccount.Parse(PnPPartnerPackSettings.StorageQueueConnectionString);

                    // Get queue ... and create if it does not exist
                    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                    CloudQueue       queue       = queueClient.GetQueueReference(PnPPartnerPackSettings.StorageQueueName);
                    queue.CreateIfNotExists();

                    // Add entry to queue
                    ContinousJobItem content = new ContinousJobItem {
                        JobId = job.JobId
                    };
                    queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(content)));
                }
            }

            return(jobId);
        }
        /// <summary>
        /// Send back to watcher a "Posion messsage" and delete from in queue
        /// </summary>
        /// <param name="poisonMessage">the poison message</param>
        /// <returns>Sueccess or not</returns>
        private bool SendPoisonMessage(CloudQueueMessage poisonMessage)
        {
            bool sw = false;

            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_Configuration.ProcessConfigConn);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                CloudQueue          poisonQueue    = queueClient.GetQueueReference(_Configuration.poisonQueue);
                poisonQueue.CreateIfNotExists();
                Common.ResourceAccess.IButlerStorageManager storageManager = Common.ResourceAccess.BlobManagerFactory.CreateBlobManager(_Configuration.ProcessConfigConn);


                //1. Create Butler Response
                ButlerRequest  myButlerRequest  = Newtonsoft.Json.JsonConvert.DeserializeObject <ButlerRequest>(poisonMessage.AsString);
                ButlerResponse myButlerResponse = new Common.ButlerResponse();

                myButlerResponse.MezzanineFiles = myButlerRequest.MezzanineFiles;
                ////Add to Mezzamine Files the control File URL if it exist
                //Becouse it is needed to move/delete the control file from processing to succes or fail
                if (!string.IsNullOrEmpty(myButlerRequest.ControlFileUri))
                {
                    myButlerResponse.MezzanineFiles.Add(myButlerRequest.ControlFileUri);
                }
                myButlerResponse.TimeStampProcessingCompleted = DateTime.Now.ToString();
                myButlerResponse.TimeStampProcessingStarted   = DateTime.Now.ToString();
                myButlerResponse.WorkflowName = myButlerRequest.WorkflowName;
                myButlerResponse.MessageId    = myButlerRequest.MessageId;
                myButlerResponse.TimeStampRequestSubmitted = myButlerRequest.TimeStampUTC;
                myButlerResponse.StorageConnectionString   = myButlerRequest.StorageConnectionString;
                myButlerResponse.Log = "Poison Message";

                //2. Lookin for Errors in Table Status
                string processId   = myProcessHandler.getProcessId(myButlerRequest.ControlFileUri, myButlerRequest.MessageId.ToString());
                var    processSnap = storageManager.readProcessSanpShot(myButlerRequest.WorkflowName, processId);

                if (processSnap != null)
                {
                    //2.1 Load Erros
                    dynamic dynObj    = Newtonsoft.Json.JsonConvert.DeserializeObject((processSnap).jsonContext);
                    var     errorList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >((dynObj.Exceptions.ToString()));
                    foreach (var errorTxt in errorList)
                    {
                        myButlerResponse.Log += "\r\n" + errorTxt;
                    }
                    //2.2 Update status
                    processSnap.CurrentStep = Configuration.poisonFinishProcessStep;
                    storageManager.PersistProcessStatus(processSnap);
                }
                else
                {
                    //No process execution, fatal error
                    //Update satus no process Status
                    workflow.ProcessSnapShot psPoison = new workflow.ProcessSnapShot(myButlerResponse.WorkflowName, processId);
                    psPoison.CurrentStep = Configuration.workflowFatalError;
                    storageManager.PersistProcessStatus(psPoison);
                }

                //3. Send Poison Mesagge
                CloudQueueMessage poison = new CloudQueueMessage(Newtonsoft.Json.JsonConvert.SerializeObject(myButlerResponse));
                poisonQueue.AddMessage(poison);
                sw = true;

                //4. Send On Error HTTP Callback Notification
                try
                {
                    var    StorageManager           = ResourceAccess.BlobManagerFactory.CreateBlobManager(_Configuration.ProcessConfigConn);
                    string jsonProcessConfiguration = StorageManager.GetButlerConfigurationValue(
                        ProcessConfigKeys.DefualtPartitionKey,
                        myButlerRequest.WorkflowName + ".config");

                    var processConfiguration = new ResourceAccess.jsonKeyValue(jsonProcessConfiguration);

                    if (processConfiguration.Read(ProcessConfigKeys.MediaButlerHostHttpCallBackOnError) != "")
                    {
                        //POST
                        string url = processConfiguration.Read(ProcessConfigKeys.MediaButlerHostHttpCallBackOnError);
                        using (var client = new HttpClient())
                        {
                            var content = new StringContent(
                                StorageManager.readProcessSanpShot(myButlerRequest.WorkflowName, processId).jsonContext,
                                Encoding.UTF8, "application/json");
                            var result = client.PostAsync(url, content).Result;
                            Trace.TraceInformation("Http Post Notification Result: " + result.ToString());
                        }
                    }
                }
                catch (Exception X)
                {
                    Trace.TraceError("HTTP CALLBACK ERROR " + X.Message);
                }
            }
            catch (Exception X)
            {
                string txt = string.Format("[{0}] at {1} has an error: {2}", this.GetType().FullName, "GetNewMessage", X.Message);
                Trace.TraceError(txt);
            }
            return(sw);
        }
Exemple #28
0
        public void PutMessage(object itm)
        {
            var msg = SerializeObject(itm);

            _queue.AddMessage(new CloudQueueMessage(msg));
        }
Exemple #29
0
        public static IForm <OrderQuery> BuildForm()
        {
            OnCompletionAsyncDelegate <OrderQuery> processOrder = async(context, state) =>
            {
                await Task.Run(() =>
                {
                    state.NoOrder      = $"OR-{DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss")}";
                    state.TanggalOrder = DateTime.Now;
                    // Retrieve storage account from connection string.
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                        ConfigurationManager.AppSettings["StorageConnectionString"]);

                    // Create the queue client.
                    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

                    // Retrieve a reference to a queue.
                    CloudQueue queue = queueClient.GetQueueReference("order");

                    // Create the queue if it doesn't already exist.
                    queue.CreateIfNotExists();

                    // Create a message and add it to the queue.
                    CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(state));
                    queue.AddMessage(message);
                }
                               );
            };
            var builder = new FormBuilder <OrderQuery>(false);
            var form    = builder
                          .Field(nameof(Nama))
                          .Field(nameof(Alamat))
                          .Field(nameof(Telpon))
                          .Field(nameof(Email))
                          .Field(nameof(Pesanan))

                          /*
                           * .Field(nameof(Jumlah), validate:
                           *  async (state, value) =>
                           *  {
                           *      var result = new ValidateResult { IsValid = true, Value = value, Feedback = "barang tersedia" };
                           *      var jml = int.Parse(value.ToString());
                           *      var stok = datas.StockBarang[state.Pesanan];
                           *      if (jml <= 0)
                           *      {
                           *          result.Feedback = $"Serius dulu lah bos belanjanya, masa beli sejumlah {jml} ?";
                           *          result.IsValid = false;
                           *      }
                           *      else
                           *      if (jml > stok)
                           *      {
                           *          result.Feedback = $"Board {state.Pesanan} stoknya hanya tinggal {stok} buah";
                           *          result.IsValid = false;
                           *          //result.Value = 0;
                           *      }
                           *      return result;
                           *  })*/
                          .Confirm(async(state) =>
            {
                var pesan = $"Pesanan {state.TipePesanan.ToString()} bos {state.Nama} adalah {state.Pesanan}, sudah ok bos ?";
                return(new PromptAttribute(pesan));
            })
                          .Message("Makasih dah order disini bos, segera kami proses!")
                          .OnCompletion(processOrder)
                          .Build();

            return(form);
        }
Exemple #30
0
 public string StartCrawl()
 {
     signalQueue.Clear();
     signalQueue.AddMessage(new CloudQueueMessage("crawl"));
     return("crawling");
 }