Пример #1
0
        public static JobMessage JobStringToJobMessage(string cloudQueueMessage)
        {
            // Description delimiter is |||
            string descriptionDelimiter = "|||";

            try
            {
                string[] projectDescriptionSplitParts;
                projectDescriptionSplitParts = cloudQueueMessage.Split(new string[] { descriptionDelimiter }, StringSplitOptions.None);

                //Console.WriteLine("+++ORIGINAL: " + projectDescription);
                //Console.WriteLine("###PART1: " + projectDescriptionSplitParts[0]);
                //Console.WriteLine("###PART2: " + projectDescriptionSplitParts[1]);

                JobMessage jobMessage = new JobMessage()
                {
                    StorageName          = projectDescriptionSplitParts[0],
                    FilePathPresentation = projectDescriptionSplitParts[1],
                    FilePathResult       = projectDescriptionSplitParts[2],
                    SearchString         = projectDescriptionSplitParts[3]
                };

                return(jobMessage);
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
Пример #2
0
        public static void ProcessQueueMessage([QueueTrigger("analizequeue")] string message, ILogger logger)
        {
            try
            {
                logger.LogInformation(message);

                JobMessage receivedJobMessage = JobMessage.JobStringToJobMessage(message);
                string     storageName        = receivedJobMessage.StorageName;
                string     powerPointFileName = receivedJobMessage.FilePathPresentation;
                string     resultTextFileName = receivedJobMessage.FilePathResult;
                string     searchString       = receivedJobMessage.SearchString;

                // Ausgabe der Elemente des empfangenen JobMessage-Objekts
                logger.LogInformation("Received / Readed Elements: \n" +
                                      "Storage-Name: " + receivedJobMessage.StorageName + "\n" +
                                      "PowerPoint-Filename: " + receivedJobMessage.FilePathPresentation + "\n" +
                                      "ResultText-Filename: " + receivedJobMessage.FilePathResult + "\n" +
                                      "Search-String: " + receivedJobMessage.SearchString + "\n");

                // Get parameters from App.config
                var config = new JobHostConfiguration();
                if (config.IsDevelopment)
                {
                    config.UseDevelopmentSettings();
                }

                // Get connectionString for storage and get access to storageAccount
                string storageConnectionString     = config.StorageConnectionString;
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference(storageName);

                // Retrieve reference to the blobs for the PowerPoint- and result-text-file.
                CloudBlockBlob powerPointBlockBlob = container.GetBlockBlobReference(powerPointFileName);
                CloudBlockBlob resultTextBlockBlob = container.GetBlockBlobReference(resultTextFileName);


                if (!powerPointBlockBlob.Exists())
                {
                    logger.LogWarning("The Blob " + powerPointBlockBlob.Name + " don't exists. Aborded.");
                }

                // Download the Powerpoint
                //MemoryStream cachedPowerPoint = new MemoryStream();
                //powerPointBlockBlob.DownloadToStreamAsync(cachedPowerPoint);

                using (var memoryStream = new MemoryStream())
                {
                    powerPointBlockBlob.DownloadToStream(memoryStream);

                    // Count pages of the PowerPoint-file
                    int numberOfSlides = CountSlides(memoryStream);
                    logger.LogInformation("Found " + numberOfSlides + " slides in " + powerPointBlockBlob.Name);

                    string result = "Search-String: " + searchString + Environment.NewLine + "Number of Slides: " + numberOfSlides;
                    int    foundCounter;
                    for (int i = 0; i < numberOfSlides; i++)
                    {
                        GetSlideIdAndText(out foundCounter, searchString, memoryStream, i);
                        if (foundCounter > 0)
                        {
                            System.Console.WriteLine("Slide #{0}: {1} times found", i + 1, foundCounter);
                            string appendText = Environment.NewLine + "Slide #" + (i + 1) + ": " + foundCounter + " times found";
                            result = result + appendText;
                        }
                    }


                    resultTextBlockBlob.UploadText(result);
                    logger.LogInformation("Finished with:" + Environment.NewLine + result);
                    //powerPointBlockBlob.DeleteIfExists();
                }
            }
            catch (Exception ex)
            {
                logger.LogError("" + ex);
            }
        }