CreateIfNotExist() public method

Creates the queue if it does not exist.
public CreateIfNotExist ( ) : bool
return bool
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 100;

            //Initialize Indexer
            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("CrawlerStorage"));

            //Initialize URL Queue
            urlQueueClient = storageAccount.CreateCloudQueueClient();
            urlQueue = urlQueueClient.GetQueueReference("urlqueue");
            if (urlQueue.CreateIfNotExist())
            {
                //Add first URL to the queue
                CloudQueueMessage firstURL = new CloudQueueMessage(startURL);
                urlQueue.AddMessage(firstURL);
            }

            //Initialize Index Queue
            indexQueueClient = storageAccount.CreateCloudQueueClient();
            indexQueue = indexQueueClient.GetQueueReference("indexqueue");
            indexQueue.CreateIfNotExist();

            //Initialize Database Blob
            databaseClient = storageAccount.CreateCloudBlobClient();
            databaseContainer = databaseClient.GetContainerReference("wordfrequencies");
            databaseContainer.CreateIfNotExist();
            var permission = databaseContainer.GetPermissions();
            permission.PublicAccess = BlobContainerPublicAccessType.Container;
            databaseContainer.SetPermissions(permission);

            return base.OnStart();
        }
        public override bool OnStart()
        {
            //EF stuff -- do not initialize db
            Database.SetInitializer<SqlStorageContext>(null);

            // Set the maximum number of concurrent connections  -- do we need this??
            //ServicePointManager.DefaultConnectionLimit = 12;

            // Create the queue if it does not exist already
            var connectionString = CloudConfigurationManager.GetSetting("CloudStore.ConnectionString");
            var account = CloudStorageAccount.Parse(connectionString);
            var client = account.CreateCloudQueueClient();
            _queue = client.GetQueueReference(QueueName);
            _queue.CreateIfNotExist();

            // set diagnostics
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            // Windows Azure logs
            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);    //60 sec is min
            config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;    //Undefined == everything

            var diagAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

            var roleInstanceDiagnosticManager =
                diagAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId,
                                                                   RoleEnvironment.CurrentRoleInstance.Role.Name,
                                                                   RoleEnvironment.CurrentRoleInstance.Id);
            roleInstanceDiagnosticManager.SetCurrentConfiguration(config);

            return base.OnStart();
        }
Esempio n. 3
0
 public AnObjectEventConsumer()
 {
     var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Storage"));
     var queueClient = storageAccount.CreateCloudQueueClient();
     _queue = queueClient.GetQueueReference("anobjectqueue");
     _queue.CreateIfNotExist();
 }
Esempio n. 4
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            DiagnosticMonitor.Start("DiagnosticsConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // read storage account configuration settings
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter)
                => configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)));

            var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // initialize blob storage
            CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
            container = blobStorage.GetContainerReference("converteddata");

            // initialize queue storage
            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
            queue = queueStorage.GetQueueReference("workercommands");

            Trace.TraceInformation("Creating container and queue...");

            bool storageInitialized = false;
            while (!storageInitialized)
            {
                try
                {
                    // create the blob container and allow public access
                    container.CreateIfNotExist();
                    var permissions = container.GetPermissions();
                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                    container.SetPermissions(permissions);

                    // create the message queue
                    queue.CreateIfNotExist();
                    storageInitialized = true;
                }
                catch (StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError("Storage services initialization failure. "
                          + "Check your storage account configuration settings. If running locally, "
                          + "ensure that the Development Storage service is running. Message: '{0}'", e.Message);
                        Thread.Sleep(5000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return base.OnStart();
        }
 public AddMessagesExample( String queueName)
 {
     CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
     CloudQueueClient cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient();
     cloudQueue = cloudQueueClient.GetQueueReference(queueName);
     cloudQueue.CreateIfNotExist();
 }
Esempio n. 6
0
 public DefaultJobSupplier()
 {
     Logger.Log.Instance.Info(string.Format("DefaultJobSupplier. Constructor. Create queue '{0}' client", RoleSettings.JobRequestsQueueName));
     _queue = AzureClient.Instance.QueueClient.GetQueueReference(RoleSettings.JobRequestsQueueName);
     Logger.Log.Instance.Info(string.Format("DefaultJobSupplier. Queue client created: {0}", 
         _queue == null ? "failed" : "successfully"));
     _queue.CreateIfNotExist();
 }
Esempio n. 7
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // Restart the role upon all configuration changes
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                try
                {
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                }
                catch (RoleEnvironmentException e)
                {
                    Trace.TraceError(e.Message);
                    System.Threading.Thread.Sleep(5000);
                }
            });

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

            // initialize queue storage
            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();

            requestQueue = queueStorage.GetQueueReference("requests");
            responseQueue = queueStorage.GetQueueReference("responses");

            bool storageInitialized = false;
            while (!storageInitialized)
            {
                try
                {
                    // create the message queue
                    requestQueue.CreateIfNotExist();
                    responseQueue.CreateIfNotExist();

                    storageInitialized = true;
                }
                catch (StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError("Storage services initialization failure. "
                          + "Check your storage account configuration settings. If running locally, "
                          + "ensure that the Development Storage service is running. Message: '{0}'", e.Message);
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return base.OnStart();
        }
Esempio n. 8
0
        public ProcessingQueue()
        {
            _formatter = new BinaryFormatter();

            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(TableName);
            queue.CreateIfNotExist();
        }
        public ProcessingQueue()
        {
            _formatter = new BinaryFormatter();

            storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(TableName);
            queue.CreateIfNotExist();
        }
Esempio n. 10
0
        public SingleDeliveryQueueClient(CloudStorageAccount account, string queueName)
        {
            var queueClient = account.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(queueName);
            queue.CreateIfNotExist();

            tableClient = account.CreateCloudTableClient();
            tableClient.CreateTableIfNotExist(TableName);
        }
        public AzureQueueTraceListener(string applicationName, string queueConnectionString, string queueName = "tracelogs")
        {
            if (string.IsNullOrEmpty(applicationName))
                throw new ArgumentNullException("applicationName",
                    "You must define an ApplicationName to log trace messages");

            ApplicationName = applicationName;
            var storageAccount = CloudStorageAccount.Parse(queueConnectionString);
            var queueClient = storageAccount.CreateCloudQueueClient();
            _queue = queueClient.GetQueueReference(queueName);
            _queue.CreateIfNotExist();
        }
Esempio n. 12
0
        SearchEngine()
        {
            // Instantiate the AzureDirectory storage object for use by Lucene
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(CloudSettingsResolver.GetConfigSetting(configName));
            });
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting("BlobStorageEndpoint");
            _Directory = new AzureDirectory(cloudStorageAccount, "LuceneStorage", new RAMDirectory());

            // Create search index queue
            CloudQueueClient client = cloudStorageAccount.CreateCloudQueueClient();
            _CloudQueue = client.GetQueueReference("searchindexqueue");
            _CloudQueue.CreateIfNotExist();
        }
Esempio n. 13
0
 // Initialize
 public void Initialize(string queueName)
 {
     // create the queue
     try
     {
         // ?? why is this API behavior different from Tables?
         physicalQueue = cloudAccount.QueueClient.GetQueueReference(queueName);
         physicalQueue.CreateIfNotExist();
     }
     catch (StorageClientException ex)
     {
         // TODO: not sure what to do with the exception
         throw ex;
     }
 }
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("QueueInterRole"));
            var queueClient = storageAccount.CreateCloudQueueClient();
            _queue = queueClient.GetQueueReference("myqueue");
            _queue.CreateIfNotExist();

            return base.OnStart();
        }
        public void Setup()
        {
            client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient();

            nativeQueue = client.GetQueueReference(QueueName);

            nativeQueue.CreateIfNotExist();
            nativeQueue.Clear();

            queue = new AzureMessageQueue(client)
                        {
                            PurgeOnStartup = PurgeOnStartup
                        };

            queue.Init(QueueName,true);
        }
Esempio n. 16
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });
            var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            //initialize queue
            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
            _queue = queueStorage.GetQueueReference("bngapn_verbosity");
            Trace.TraceInformation("Creating queue...");

            CloudTableClient tableStorage = storageAccount.CreateCloudTableClient();

            bool storageInitialized = false;
            while (!storageInitialized)
            {
                try
                {
                    _queue.CreateIfNotExist();
                    storageInitialized = true;
                }
                catch(StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError("Storage services initialization failure. "
            + "Check your storage account configuration settings. If running locally, "
            + "ensure that the Development Storage service is running. Message: '{0}'", e.Message);
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return base.OnStart();
        }
Esempio n. 17
0
        public override bool OnStart()
        {
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            ServicePointManager.DefaultConnectionLimit = 12;

            var storageAccount = CloudStorageAccount.FromConfigurationSetting(Utils.ConfigurationString);

            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
            _queue = queueStorage.GetQueueReference(Utils.CloudQueueKey);

            _queue.CreateIfNotExist();

            return base.OnStart();
        }
Esempio n. 18
0
        public AzureMessageQueue(CloudStorageAccount cloudStorageAccount, string inputQueueName, string errorQueueName)
        {
            if (inputQueueName == null) throw new ArgumentNullException("inputQueueName");
            if (errorQueueName == null) throw new ArgumentNullException("errorQueueName");

            inputQueueName = inputQueueName.ToLowerInvariant();
            errorQueueName = errorQueueName.ToLowerInvariant();

            cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient();

            inputQueue = cloudQueueClient.GetQueueReference(inputQueueName);
            inputQueue.CreateIfNotExist();

            cloudQueueClient.GetQueueReference(errorQueueName).CreateIfNotExist();

            this.inputQueueName = inputQueueName;
            this.errorQueueName = errorQueueName;
        }
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            //Initialize Storage
            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("CrawlerStorage"));

            //Create Scheduler Queue
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference("urlschedulerqueue");
            queue.CreateIfNotExist();

            //Add first URL to the queue
            CloudQueueMessage firstURL = new CloudQueueMessage(startURL);
            queue.AddMessage(firstURL);

            return base.OnStart();
        }
Esempio n. 20
0
        /// <summary>
        /// This is where we get the role instance configured and ready to begin processing
        /// STAHC jobs
        /// </summary>
        /// <returns>True if succesfully configured. False otherwise</returns>
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 64;

            DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration()
                {
                    CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                    SampleRate = TimeSpan.FromSeconds(30)
                });

            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration()
                {
                    CounterSpecifier = @"\Network Interface(*)\Bytes Total/sec",
                    SampleRate = TimeSpan.FromSeconds(30)
                });

            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(5);
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;
            config.Logs.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(5);
            config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
            config.PerformanceCounters.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1);
            config.WindowsEventLog.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(5);

            DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

            // restart the role upon all configuration changes
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // read storage account configuration settings
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            // get the scratch path
            scratchPath = RoleEnvironment.GetLocalResource(Constants.AzureScratchName).RootPath;

            // get the time to sleep between runs of the queue monitoring loop
            queueSleepTime = int.Parse(
                RoleEnvironment.GetConfigurationSettingValue("QueueSleepTime"),
                CultureInfo.InvariantCulture);

            // get the max time (seconds) that the server should take to process a queue job
            maxJobLength = int.Parse(
                RoleEnvironment.GetConfigurationSettingValue("MaxJobLength"),
                CultureInfo.InvariantCulture);

            // get the storage container to be used for processing job data
            jobContainer = RoleEnvironment.GetConfigurationSettingValue("JobContainer");

            // get queue data/configuration
            storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // get the name of the queue used for this job set
            var queueName = RoleEnvironment.GetConfigurationSettingValue("StachQueueName");

            // get the queues
            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
            queueStorage.RetryPolicy = RetryPolicies.RetryExponential(3, TimeSpan.FromSeconds(10));

            stahcJobQueue = queueStorage.GetQueueReference(queueName);
            stahcJobQueue.CreateIfNotExist();

            // report on read values
            Trace.WriteLine(string.Format("QueueSleepTime: '{0}'",
                queueSleepTime.ToString(CultureInfo.InvariantCulture)), "Verbose");
            Trace.WriteLine(string.Format("MaxJobLength: '{0}'",
                maxJobLength.ToString(CultureInfo.InvariantCulture)), "Verbose");
            Trace.WriteLine(string.Format("JobContainer: '{0}'", jobContainer), "Verbose");
            Trace.WriteLine(string.Format("StachQueueName: '{0}'", queueName), "Verbose");

            // read-in/download all source files
            DownloadStagingFiles();

            // loop through and execute each of the actions (if any) provided in the staging file
            var stagingControlFile = Path.Combine(
                scratchPath,
                Constants.StagingActionsFileName);

            if (File.Exists(stagingControlFile))
            {
                var sucessful = RunStagingActions(stagingControlFile);

                if (!sucessful)
                {
                    Trace.TraceError(
                        "Unable to complete staging actions. Review logs for more detail.");
                    return sucessful;
                }
            }

            return base.OnStart();
        }
Esempio n. 21
0
 public AzureDocumentExecutor(CloudStorageAccount account)
 {
     var client = account.CreateCloudQueueClient();
     queue = client.GetQueueReference("documents");
     queue.CreateIfNotExist();
 }
 /// <summary>
 /// Instance the QueueStorageHandler class and create a queue container if not exist
 /// </summary>
 /// <param name="queueContainerName">Container name for the queues</param>
 public QueueStorageHandler(string queueContainerName)
 {
     CloudQueue = CloudQueueClient.GetQueueReference(queueContainerName);
     CloudQueue.CreateIfNotExist();
 }
 public QueueJobChunkDispatcher(IJobChunkRegistrator jobChunkRegistrator)
 {
     _jobChunkRegistrator = jobChunkRegistrator;
     _queue = AzureClient.Instance.QueueClient.GetQueueReference(RoleSettings.JobsChunksQueueName);
     _queue.CreateIfNotExist();
 }
Esempio n. 24
0
        private static void LoadConfigSettings()
        {
            _storageAccount = CloudStorageAccount.FromConfigurationSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");

            _queueClient = _storageAccount.CreateCloudQueueClient();

            // Get and create the container
            _cloudQueue = _queueClient.GetQueueReference("email-queue");

            _cloudQueue.CreateIfNotExist();
        }
Esempio n. 25
0
        public JsonModels.UploadReponse AddDocumentElement(int projectId, string description, Stream fileStream, string fileName, string userName)
        {
            Project p = pa.GetProject(projectId);
            BlobStorageAccessor ba = new BlobStorageAccessor();
            string location = null;
            string[] s2 = fileName.Split('.');
            string extention = s2[s2.Count() - 1].ToLower();

            UserAccessor ua = new UserAccessor();
            User u = ua.GetUser(userName);
            string fullName = u.firstName +" " +  u.lastName;

            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(messageQueueName);
            queue.CreateIfNotExist();
            string documentText = "";

            //string PDFLocation = "notset";
            if (extention == "pdf")
            {
                location = ba.uploadPDF(fileStream, false).ToString();
                UploadManager um = new UploadManager();
                //location = um.stampThatShit(location, fullName, null);
                //documentText = um.ExtractText(location);
            }
            else if (extention == "doc" || extention == "docx")
            {
                location = ba.uploadDOC(fileStream, false, "."+extention).ToString();
            }
            else if (extention == "ppt" || extention == "pptx")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else if( extention == "xls" || extention == "xlsx")
            {
                location = ba.uploadUnknown(fileStream,false, extention).ToString();
            }
            else if (extention == "rtf")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else if (extention == "txt")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else
            {
                //upload unknown file type. do this or display message
                Uri result = ba.uploadUnknown(fileStream, false, extention);
                if (result == null)
                {
                    return null;
                }
                else
                {
                    location = result.ToString();
                }
            }
            String FileName = Guid.NewGuid().ToString();
            string uniqueBlobName = string.Format("{0}{1}", FileName, ".pdf");
            string docThumb = "";
            if (extention == "pdf")
            {
                docThumb = location;
            }
            else
            {
                docThumb = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"pdfs/" + uniqueBlobName;
            }
            ProjectElement_Document pe = new ProjectElement_Document
            {
                description = description,
                documentLocation = location,
                title = fileName,
                documentText = documentText,
                documentThumbnailLocation = docThumb
            };
            int projectElementId = pa.AddProjectElement(p, pe);
            if (extention == "doc" || extention == "docx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Word2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "ppt" || extention == "pptx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/PowerPoint2Pdf", 0, 0, "", uniqueBlobName));
                queue.AddMessage(message);
            }
            else if( extention == "xls" || extention == "xlsx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Excel2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "rtf")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/RichText2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "txt")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Text2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            if (extention == "pdf")
            {
                return new JsonModels.UploadReponse { id = projectElementId, fileURL = location, name = fileName, artifactURL = location };
            }
            return new JsonModels.UploadReponse { id = projectElementId, fileURL = location, artifactURL = docThumb, name = fileName };
        }
Esempio n. 26
0
        public JsonModels.UploadReponse UploadPictureElement(int projectId, Stream pictureStream, string fileName, bool isCoverPicture = false)
        {
            try
            {
                BlobStorageAccessor blobStorageAccessor = new BlobStorageAccessor();
                UploadManager uploadManager = new UploadManager();
                ProjectAccessor projectAccessor = new ProjectAccessor();

                //initiate queue message
                storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
                queueClient = storageAccount.CreateCloudQueueClient();
                queue = queueClient.GetQueueReference(messageQueueName);
                queue.CreateIfNotExist();

                string imageURI = blobStorageAccessor.uploadImage(pictureStream, false).ToString();
                Project p = pa.GetProject(projectId);
                if (isCoverPicture)
                {
                    string FileNameThumb1 = Guid.NewGuid().ToString();
                    string artifactURL1 = string.Format("{0}{1}", FileNameThumb1, ".jpeg");
                    CloudQueueMessage message3 = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, p.id, "thumbnail", "ProjectPicture", 266, 266, "", artifactURL1));
                    queue.AddMessage(message3);
                    p.coverPictureThumbnail = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString() + "thumbnails/" + artifactURL1;
                    p.coverPicture = imageURI;

                    p.dateModified = DateTime.Now;

                    Project newP = projectAccessor.UpdateProject(p);
                    return new JsonModels.UploadReponse { id = p.id, fileURL = imageURI, name = fileName, galeriaURL = "noGalleryURL", artifactURL = artifactURL1, description = "default description" };
                }
                else
                {
                    string FileNameThumb = Guid.NewGuid().ToString();
                    string artifactURL = string.Format("{0}{1}", FileNameThumb, ".jpeg");
                    ProjectElement_Picture pe = new ProjectElement_Picture
                    {
                        title = GetTitle(fileName),
                        pictureLocation = imageURI,
                        pictureThumbnailLocation = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"thumbnails/" + artifactURL
                    };
                    int projectElementId = pa.AddProjectElement(p, pe);
                    if (projectElementId == -1)
                    {
                        logAccessor.CreateLog(DateTime.Now, "ProjectManager - UploadPictureElement", "problem saving project element - 165 ProjectManager");
                        return null;
                    }

                    //string FileNameGaleria = Guid.NewGuid().ToString();
                    //string galleryURL = string.Format("{0}{1}", FileNameGaleria, ".jpeg");

                    CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, projectElementId, "thumbnail", "PictureElement", 635, 397, "", artifactURL));
                    //CloudQueueMessage message2 = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, projectElementId, "thumbnail", "PictureElement_Galleria", 1000, 750, "", galleryURL));
                    queue.AddMessage(message);
                    //queue.AddMessage(message2);
                    return new JsonModels.UploadReponse { id = projectElementId, fileURL = imageURI, name = fileName, galeriaURL = "galleryURL", artifactURL = artifactURL, description = null };
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "ProjectManager - UploadPictureElement", ex.StackTrace);
                return null;
            }
        }
Esempio n. 27
0
        public void Init(Address address, bool transactional)
        {
            useTransactions = transactional;
            queue = client.GetQueueReference(address.Queue);
            queue.CreateIfNotExist();

            if (PurgeOnStartup)
                queue.Clear();
        }
Esempio n. 28
0
        public string ComputeICD9MapPlotData(string ICD9Code, DateTime startTime, DateTime endTime)
        {
            #if DEBUG
            account = CloudStorageAccount.DevelopmentStorageAccount;
            #else
            account = new CloudStorageAccount(accountAndKey, true);
            #endif
            //client = new CloudQueueClient(account.BlobEndpoint.ToString(), account.Credentials);
            qclient = account.CreateCloudQueueClient();
            q = qclient.GetQueueReference("icd9mapplotrequests");
            q.CreateIfNotExist();

            string OperationID = Guid.NewGuid().ToString();

            string starttime = startTime.Ticks.ToString();

            string endtime = endTime.Ticks.ToString();

            q.AddMessage(new CloudQueueMessage(string.Format("{0}|{1}|{2}|{3}",ICD9Code,starttime,endtime,OperationID)));

            return OperationID;
        }
Esempio n. 29
0
        public override bool OnStart( )
        {
            DiagnosticMonitor.Start( "DiagnosticsConnectionString" );

            RoleEnvironment.Changing += new EventHandler<RoleEnvironmentChangingEventArgs>( RoleEnvironmentChanging );

            CloudStorageAccount.SetConfigurationSettingPublisher( ( configName, configSetter ) => configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) ) );
            CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting( "DataConnectionString" );

            container = storageAccount.CreateCloudBlobClient( ).GetContainerReference( "fotogolpics" );
            queue = storageAccount.CreateCloudQueueClient( ).GetQueueReference( "fotogolthumbs" );

            Trace.TraceInformation( "Creating container and queue..." );

            bool storageInitialized = false;
            while ( !storageInitialized )
            {
                try
                {
                    container.CreateIfNotExist( );
                    BlobContainerPermissions permissions = container.GetPermissions( );
                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                    container.SetPermissions( permissions );

                    queue.CreateIfNotExist( );
                    storageInitialized = true;
                }
                catch ( StorageClientException e )
                {
                    if ( e.ErrorCode != StorageErrorCode.TransportError )
                        throw;

                    Trace.TraceError( "Storage services initialization failure. Check your storage account configuration settings. If running locally, ensure that the Development Storage service is running. Message: '{0}'", new object[] { e.Message } );
                    Thread.Sleep( 5000 );
                }
            }
            return base.OnStart( );
        }
Esempio n. 30
0
        public override void Run()
        {
            Trace.WriteLine("BackgroundProcesses entry point called", "Information");
            Trace.WriteLine(Thread.CurrentThread.Name, "Information");
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
                Trace.WriteLine("storage account configured", "Information");
                queueClient = storageAccount.CreateCloudQueueClient();
                queue = queueClient.GetQueueReference(messageQueueName);
                queue.CreateIfNotExist();
                queue.Clear();
            }
            catch (Exception e)
            {
                LogAccessor logAccessor = new LogAccessor();
                logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString());
            }
            while (true)
            {
                try
                {
                    CloudQueueMessage msg = queue.GetMessage();

                    if (msg != null)
                    {
                        Trace.WriteLine("Queue Message Recieved", "Information");
                        // parse message retrieved from queue
                        string userFullName = "";
                        string presetDocURL = "";
                        var messageParts = msg.AsString.Split(new char[] { ',' });
                        var mediaURI = messageParts[0];
                        int ID = Int32.Parse(messageParts[1]);
                        var operation = messageParts[2];
                        var type = messageParts[3];
                        int displayWidth = Int32.Parse(messageParts[4]);
                        int displayHeight = Int32.Parse(messageParts[5]);
                        try
                        {
                            userFullName = messageParts[6];
                            presetDocURL = messageParts[7];
                        }
                        catch (Exception)
                        {

                        }
                        if (operation.Equals("thumbnail"))
                        {
                            UploadManager uploadManager = new UploadManager();

                            string thumbnailURI = uploadManager.generateThumbnail(mediaURI, ID, type, displayWidth, displayHeight, presetDocURL);
                        }
                        else if (operation.Equals("documentConversion"))
                        {
                            UploadManager uploadManager = new UploadManager();
                            uploadManager.convertDocument(mediaURI, type, ID, userFullName, presetDocURL);
                        }
                        else if (operation.Equals("userDocumentConversion"))
                        {
                            UploadManager uploadManager = new UploadManager();
                            uploadManager.convertUserDocument(mediaURI, type, ID, userFullName, presetDocURL);
                        }
                        queue.DeleteMessage(msg);
                    }

                    Thread.Sleep(500);
                    //Trace.WriteLine("Working - thread sleep", "Information");
                }
                catch (Exception e)
                {
                    LogAccessor logAccessor = new LogAccessor();
                    logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString());
                }
            }
        }