Example #1
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("NumberWorkerRole entry point called", "Information");

            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            QueueUtilities qutil = new QueueUtilities(account);
            CloudQueue     queue = qutil.CreateQueueIfNotExists("numbers");

            while (true)
            {
                CloudQueueMessage msg = queue.GetMessage();
                if (msg != null)
                {
                    int number = Convert.ToInt32(msg.AsString);
                    Trace.WriteLine(string.Format("Processing number: {0}", number), "Information");
                    number--;
                    if (number > 0)
                    {
                        CloudQueueMessage newmsg = new CloudQueueMessage(number.ToString());
                        queue.AddMessage(newmsg);
                    }

                    queue.DeleteMessage(msg);
                }
                else
                {
                    Thread.Sleep(10000);
                    Trace.WriteLine("Working", "Information");
                }
            }
        }
Example #2
0
        public static void NewSearchProductsInDatabase(string stringToSearch, string order)
        {
            string searchIdiomCode = GetSearchCode(stringToSearch);

            InsertIdiomInDatabase(stringToSearch);
            InsertCompleteIdiomInDatabase(stringToSearch, searchIdiomCode);
            QueueUtilities.InsertIdiomInQueue($"{stringToSearch}|{order}");
        }
Example #3
0
        public Processor(CloudStorageAccount account, string requestsQueueName, string responsesQueueName, string filesContainerName)
        {
            this.account = account;
            QueueUtilities qutil = new QueueUtilities(account);

            this.requests  = qutil.CreateQueueIfNotExists(requestsQueueName);
            this.responses = qutil.CreateQueueIfNotExists(responsesQueueName);
            CloudBlobClient blobStorage = this.account.CreateCloudBlobClient();

            this.files = blobStorage.GetContainerReference(filesContainerName);
        }
Example #4
0
        // copies the queue to a single directory for to be burned to e.g. MP3 CD for a car usage..
        private void TsbCopyAllFlat_Click(object sender, EventArgs e)
        {
            if (fbdDirectory.ShowDialog() == DialogResult.OK)
            {
                bool convertToMp3 =
                    MessageBox.Show(
                        DBLangEngine.GetMessage("msgQueryConvertToMP3",
                                                "Convert non-MP3 files to MP3 format?|A query to ask whether to convert files other than MP3 to MP3 format."),
                        DBLangEngine.GetMessage("msgConfirmation",
                                                "Confirm|Used in a dialog title to ask for a confirmation to do something"),
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1) == DialogResult.Yes;

                QueueUtilities.RunWithDialog(this, queueIndex, fbdDirectory.SelectedPath, conn, convertToMp3,
                                             DBLangEngine.GetMessage("msgProcessingFiles",
                                                                     "Processing files...|A message describing a possible lengthy operation with files is running."),
                                             DBLangEngine.GetMessage("msgProgressPercentage",
                                                                     "Progress: {0} %|A message describing some operation progress in percentage."));
            }
        }
Example #5
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("CollatzWorkerRole entry point called", "Information");

            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            QueueUtilities qutil = new QueueUtilities(account);
            CloudQueue     queue = qutil.CreateQueueIfNotExists("numbers");

            CloudQueueClient qclient = account.CreateCloudQueueClient();

            for (int k = 0; k < 11; k++)
            {
                CloudQueue       q = qclient.GetQueueReference("numbers");
                MessageProcessor p = new MessageProcessor(q, this.ProcessMessage);
                p.Start();
            }

            MessageProcessor processor = new MessageProcessor(queue, this.ProcessMessage);

            processor.Run();
        }
Example #6
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("FractalWorkerRole entry point called", "Information");
            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            CloudBlobClient    blobClient    = account.CreateCloudBlobClient();
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("fractalsectors");

            blobContainer.CreateIfNotExist();
            QueueUtilities qutil    = new QueueUtilities(account);
            CloudQueue     queue    = qutil.CreateQueueIfNotExists("fractaltoprocess");
            CloudQueue     outqueue = qutil.CreateQueueIfNotExists("fractalsectors");

            Calculator calculator = new Calculator();

            while (true)
            {
                CloudQueueMessage msg = queue.GetMessage();

                if (msg != null)
                {
                    Trace.WriteLine(string.Format("Processing {0}", msg.AsString));
                    SectorInfo info = SectorUtilities.FromMessageToSectorInfo(msg);

                    if (info.Width > 100 || info.Height > 100)
                    {
                        Trace.WriteLine("Splitting message...");
                        for (int x = 0; x < info.Width; x += 100)
                        {
                            for (int y = 0; y < info.Height; y += 100)
                            {
                                SectorInfo newinfo = info.Clone();
                                newinfo.FromX  = x + info.FromX;
                                newinfo.FromY  = y + info.FromY;
                                newinfo.Width  = Math.Min(100, info.Width - x);
                                newinfo.Height = Math.Min(100, info.Height - y);
                                CloudQueueMessage newmsg = SectorUtilities.FromSectorInfoToMessage(newinfo);
                                queue.AddMessage(newmsg);
                            }
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Processing message...");
                        Sector       sector   = calculator.CalculateSector(info);
                        string       blobname = string.Format("{0}.{1}.{2}.{3}.{4}", info.Id, sector.FromX, sector.FromY, sector.Width, sector.Height);
                        CloudBlob    blob     = blobContainer.GetBlobReference(blobname);
                        MemoryStream stream   = new MemoryStream();
                        BinaryWriter writer   = new BinaryWriter(stream);

                        foreach (int value in sector.Values)
                        {
                            writer.Write(value);
                        }

                        writer.Flush();
                        stream.Seek(0, SeekOrigin.Begin);

                        blob.UploadFromStream(stream);

                        stream.Close();

                        CloudQueueMessage outmsg = new CloudQueueMessage(blobname);
                        outqueue.AddMessage(outmsg);
                    }

                    queue.DeleteMessage(msg);
                }
                else
                {
                    Thread.Sleep(10000);
                    Trace.WriteLine("Working", "Information");
                }
            }
        }