GetQueueReference() public method

Gets a reference to the queue at the specified address.
public GetQueueReference ( string queueAddress ) : CloudQueue
queueAddress string Either the name of the queue, or the absolute URI to the queue.
return CloudQueue
        private static void Initialize()
        {
            if (_isStorageInitialized)
                return;

            lock(_initializeLock)
            {
                if (_isStorageInitialized)
                    return;

                CloudStorageAccount.SetConfigurationSettingPublisher((setting, setter) =>
                {
                    setter(RoleEnvironment.GetConfigurationSettingValue(setting));
                });

                var cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting(StorageConstants.StorageConnectionsString);
                _cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient();

                CloudQueue membershipsPumpQueue = _cloudQueueClient.GetQueueReference(StorageConstants.MembershipsPumpQueue);
                membershipsPumpQueue.CreateIfNotExist();

                CloudQueue testMembershipPumpQueue = _cloudQueueClient.GetQueueReference(StorageConstants.TestMembershipPumpQueue);
                testMembershipPumpQueue.CreateIfNotExist();

                CloudQueue testMembershipDeleterQueue = _cloudQueueClient.GetQueueReference(StorageConstants.TestMembershipDeleterQueue);
                testMembershipDeleterQueue.CreateIfNotExist();

                _cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
                _cloudTableClient.CreateTableIfNotExist(StorageConstants.TestTable);

                _isStorageInitialized = true;
            }
        }
Beispiel #2
0
        internal static bool InitializeStorage()
        {
            try
            {
                // 仅为测试目的,如果我们不在计算仿真程序中运行该服务,我们始终使用 dev 存储.
                if (RoleEnvironment.IsAvailable)
                {
                    CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                    {
                        configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                    });
                    StorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                }
                else
                {
                    StorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
                }

                CloudBlobClient blobClient = new CloudBlobClient(StorageAccount.BlobEndpoint, StorageAccount.Credentials);
                CloudBlobContainer container = blobClient.GetContainerReference("videostories");
                container.CreateIfNotExist();
                CloudQueueClient queueClient = new CloudQueueClient(StorageAccount.QueueEndpoint, StorageAccount.Credentials);
                CloudQueue queue = queueClient.GetQueueReference("videostories");
                queue.CreateIfNotExist();
                CloudTableClient tableClient = new CloudTableClient(StorageAccount.TableEndpoint.AbsoluteUri, StorageAccount.Credentials);
                tableClient.CreateTableIfNotExist("Stories");
                return true;
            }
            catch (Exception ex)
            {
                Trace.Write("错误初始化存储: " + ex.Message, "Error");
                return false;
            }
        }
        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()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;
            #if DEBUG
            account = CloudStorageAccount.DevelopmentStorageAccount;
            #else
            account = new CloudStorageAccount(accountAndKey, true);
            #endif

            tableContext = new TableServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            //client = new CloudQueueClient(account.BlobEndpoint.ToString(), account.Credentials);
            qclient = account.CreateCloudQueueClient();
            q = qclient.GetQueueReference("icd9mapplotrequests");
            rows = new List<ICD9MapPlotResultEntry>();
            bclient = account.CreateCloudBlobClient();
            container = bclient.GetContainerReference("results");
            container.CreateIfNotExist();
            client = account.CreateCloudTableClient();
            client.CreateTableIfNotExist("ICD9MapPlotResult");
            client.CreateTableIfNotExist("DoctorDetails");
            client.CreateTableIfNotExist("PatientDetails");
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            return base.OnStart();
        }
Beispiel #5
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;
        }
Beispiel #6
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();
        }
        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);
        }
        public ProxyService()
        {
            Logger.Log.Instance.Active = false;
            CloudStorageAccount storageAccount = null;

            if (RoleSettings.UseDevelopAccount)
                storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            else
                storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(RoleSettings.AccountName, RoleSettings.AccountKey), true);

            this._queueClient = storageAccount.CreateCloudQueueClient();

            Logger.Log.Instance.Info(string.Format("ProxyService. Constructor. Create queue '{0}' client", RoleSettings.JobRequestsQueueName));
            this._queue = _queueClient.GetQueueReference(RoleSettings.JobRequestsQueueName);
            Logger.Log.Instance.Info(string.Format("ProxyService. Queue client created: {0}",
                this._queue == null ? "failed" : "successfully"));
            this._queue.CreateIfNotExist();
        }
        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();
        }
Beispiel #11
0
        public override bool OnStart()
        {
            // 设置的最大并发连接数
            ServicePointManager.DefaultConnectionLimit = 12;

            // 有关处理配置更改信息
            // 请参阅 MSDN 主题在  http://go.microsoft.com/fwlink/?LinkId=166357.

            // 如果没有被初始化,初始化存储.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });
            this._storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            CloudBlobClient blobClient = new CloudBlobClient(this._storageAccount.BlobEndpoint, this._storageAccount.Credentials);
            this._container = blobClient.GetContainerReference("videostories");
            this._container.CreateIfNotExist();
            this._container.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
            CloudQueueClient queueClient = new CloudQueueClient(this._storageAccount.QueueEndpoint, this._storageAccount.Credentials);
            this._queue = queueClient.GetQueueReference("videostories");
            this._queue.CreateIfNotExist();
            CloudTableClient tableClient = new CloudTableClient(this._storageAccount.TableEndpoint.AbsoluteUri, this._storageAccount.Credentials);
            tableClient.CreateTableIfNotExist("Stories");

            // 配置诊断程序.
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10d);
            config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(10d);
            config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(10d);
            config.Directories.DataSources.Add(new DirectoryConfiguration()
            {
                Path = RoleEnvironment.GetLocalResource("DiagnosticStore").RootPath,
                Container = "videostorydiagnosticstore",
                DirectoryQuotaInMB = 200
            });
            config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(10d);
            Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(true);
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            RoleEnvironment.Changing += new EventHandler<RoleEnvironmentChangingEventArgs>(RoleEnvironment_Changing);

            return base.OnStart();
        }
Beispiel #12
0
        public override bool OnStart()
        {
            Store = new DocumentStore { ConnectionStringName = "RavenDB" };
            Store.Initialize();
            RavenSession = Store.OpenSession();

            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("LeadgenQueue"));
            // Create the queue client
            Client = storageAccount.CreateCloudQueueClient();
            CloudQueue queue = Client.GetQueueReference("listingsearch");

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

            IsStopped = false;
            return base.OnStart();
        }
        public static void Initialize()
        {
            lock (_lock)
            {
                CloudStorageAccount storageAccount =
                    CloudStorageAccount.FromConfigurationSetting(Utils.ConfigurationString);
                storageAccount.CreateCloudTableClient();

                _blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = _blobClient.GetContainerReference(Utils.CloudBlobKey);

                BlobContainerPermissions permissions = container.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                container.SetPermissions(permissions);
                container.CreateIfNotExist();

                QueueClient = storageAccount.CreateCloudQueueClient();
                CloudQueue queue = QueueClient.GetQueueReference(Utils.CloudQueueKey);
                queue.CreateIfNotExist();
            }
        }
Beispiel #14
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();
        }
Beispiel #15
0
        private static void InitializeStorage()
        {
            if (_storageInitialized)
            {
                return;
            }

            lock (_locker)
            {
                try
                {
                    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                    _blobStorage = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer blobContainer = _blobStorage.GetContainerReference("logitems");
                    blobContainer.CreateIfNotExist();

                    _queueStorage = storageAccount.CreateCloudQueueClient();
                    CloudQueue queue = _queueStorage.GetQueueReference("logmessages");
                    queue.CreateIfNotExist();
                }
                catch (System.Net.WebException)
                {
                    throw new System.Net.WebException("Storage services initialization failure. "
                        + "Check your storage account configuration settings. If running locally, "
                        + "ensure that the Development Storage service is running.");

                }

                _storageInitialized = true;
            }
        }
        private void InitializeStorage()
        {
            if (storageInitialized)
            {
                return;
            }

            lock (_look)
            {
                if (storageInitialized)
                {
                    return;
                }

                try
                {
                    // read account configuration settings
                    CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting(Utils.ConfigurationString);

                    // create blob container for images
                    blobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container = blobClient.GetContainerReference(Utils.CloudBlobKey);
                    container.CreateIfNotExist();

                    // configure container for public access
                    var permissions = container.GetPermissions();
                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                    container.SetPermissions(permissions);

                    // create queue to communicate with worker role
                    queueClient = storageAccount.CreateCloudQueueClient();
                    CloudQueue queue = queueClient.GetQueueReference(Utils.CloudQueueKey);
                    queue.CreateIfNotExist();
                }
                catch (WebException exception)
                {
                    Trace.Write(exception.Message);
                }

                storageInitialized = true;
            }
        }
Beispiel #17
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 };
        }
Beispiel #18
0
        private void CreateOnceContainerAndQueue()
        {
            if (s_createdContainerAndQueue)
                return;
            lock (s_lock)
            {
                if (s_createdContainerAndQueue)
                {
                    return;
                }

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

                    blobStorage = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container = blobStorage.GetContainerReference("program");

                    container.CreateIfNotExist();

                    var permissions = container.GetPermissions();

                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;

                    container.SetPermissions(permissions);

                    queueStorage = storageAccount.CreateCloudQueueClient();
                    CloudQueue queue = queueStorage.GetQueueReference("programqueue");

                    queue.CreateIfNotExist();
                }
                catch (WebException)
                {
                    // display a nice error message if the local development storage tool is not running or if there is
                    // an error in the account configuration that causes this exception
                    throw new WebException("The Windows Azure storage services cannot be contacted " +
                         "via the current account configuration or the local development storage tool is not running. " +
                         "Please start the development storage tool if you run the service locally!");
                }

                s_createdContainerAndQueue = true;
            }
        }
Beispiel #19
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;
            }
        }
        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;
        }
Beispiel #21
0
 private CloudQueue callQueue()
 {
     // Get Reference to Queue Storage
     queueClient1 = new CloudQueueClient(storageAccount.QueueEndpoint, storageAccount.Credentials);
     CloudQueue queue1 = queueClient1.GetQueueReference("replicaagent");
     queue1.CreateIfNotExist();
     string q= queue1.ToString();
     //Trace.WriteLine(" %%%%%%%%%%%  Queuename is %%%%%%%% : " + q);
     return queue1;
 }
Beispiel #22
0
        private void InitializeStorage()
        {
            if (storageInitialized)
            {
                return;
            }

            lock (gate)
            {
                if (storageInitialized)
                {
                    return;
                }

                try
                {
                    // read account configuration settings
                    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                    // create blob container for images
                    blobStorage = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container = blobStorage.GetContainerReference("guestbookpics");
                    container.CreateIfNotExist();

                    // configure container for public access
                    var permissions = container.GetPermissions();
                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                    container.SetPermissions(permissions);

                    // create queue to communicate with worker role
                    queueStorage = storageAccount.CreateCloudQueueClient();
                    CloudQueue queue = queueStorage.GetQueueReference("guestthumbs");
                    queue.CreateIfNotExist();

                }
                catch (WebException)
                {
                    throw new WebException("Storage services initialization failure. "
                       + "Check your storage account configuration settings. If running locally, "
                       + "ensure that the Development Storage service is running.");
                }

                storageInitialized = true;
            }
        }
 private static Uri GetBaseUriForQueues(CloudQueueClient client)
 {
     // ugly way to find the base URI for the queue service, but there's no .BaseUri on a CloudQueueClient
     return new Uri(client.GetQueueReference("foo").Uri.AbsoluteUri.Replace("/foo", string.Empty));
 }
Beispiel #24
0
        public HttpResponseMessage Put(HttpRequestMessage request, string id, bool? commit)
        {
            // 请确保该存储帐户是准备好了.
            if (Global.StorageAccount == null)
            {
                if (!Global.InitializeStorage())
                {
                    return this.CreateStringResponse(HttpStatusCode.BadRequest,
                        "该服务目前不可用.请稍后再试.");
                }
            }
            if (string.IsNullOrEmpty(id))
            {
                return this.CreateStringResponse(HttpStatusCode.BadRequest, "必需的参数标识已丢失.");
            }
            if (commit == null || !commit.Value)
            {
                return this.CreateStringResponse(HttpStatusCode.BadRequest, "当前仅支持 \"commit=true\" 选项.");
            }

            try
            {
                CloudBlobClient blobClient = new CloudBlobClient(Global.StorageAccount.BlobEndpoint, Global.StorageAccount.Credentials);
                CloudBlobContainer container = blobClient.GetContainerReference("videostories");
                CloudBlob configBlob = container.GetBlobReference(id + ".xml");

                // 我们其实不需要这些属性.我们只是检查blob是否存在.
                // 如果blob不存在,将引发 StorageClientException,所以我们跳至 catch 块.
                configBlob.FetchAttributes();

                // 添加到队列的作业.
                CloudQueueClient queueClient = new CloudQueueClient(Global.StorageAccount.QueueEndpoint, Global.StorageAccount.Credentials);
                CloudQueue queue = queueClient.GetQueueReference("videostories");
                queue.AddMessage(new CloudQueueMessage(id));

                // 返回一个空的成功消息.
                return this.CreateStringResponse(HttpStatusCode.NoContent, "");

            }
            catch (StorageClientException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return this.CreateStringResponse(HttpStatusCode.NotFound, "请求的Story不存在");
                }

                // 一般错误,跟踪并返回泛用消息.
                Trace.Write("处理blob错误: " + ex.Message, "Error");
                return this.CreateStringResponse(HttpStatusCode.InternalServerError,
                    "该服务目前不可用.请稍后再试.");
            }
        }
Beispiel #25
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("BigjobAzureAgent entry point called", "Information");// information warning and errors.
            System.Diagnostics.Trace.TraceInformation("Change in Entry Point");
            //GET reference to Queue Storage
            queueClient = new CloudQueueClient(storageAccount.QueueEndpoint, storageAccount.Credentials);

            CloudQueue queue = queueClient.GetQueueReference(applicationName);
            queue.CreateIfNotExist();
            while (true)
            {
                //IAsyncResult result = queue.BeginGetMessage(null, null);
                //CloudQueueMessage jobId = queue.EndGetMessage(result);
                Trace.WriteLine("In WHile Loop", "Warning");
                CloudQueueMessage queueMessage = queue.GetMessage(new TimeSpan(1,0,0));

                if (queueMessage == null)
                {
                    Thread.Sleep(1000);
                    continue;
                }
                else
                {
                    Trace.WriteLine("BigjobAzureAgent got queue message: " + queueMessage.AsString + " MsgId: "
                        + queueMessage.Id + " Pop Receipt: " + queueMessage.PopReceipt
                        + " Visibility: " + queueMessage.NextVisibleTime, "Information");
                }
                if (queueMessage.AsString == "STOP")
                {
                    //put STOP message back in queue
                    //queue.AddMessage(queueMessage);
                    break; //exit while loop and worker role
                }
                else
                {
                    string jobId = queueMessage.AsString; //queue message contains id of subjob to execute
                    if (ExecuteSubJob(jobId))
                    {
                        //success - delete message
                        UpdateState(jobId, "Done");
                        Trace.WriteLine(" queue value is : " + queue.ToString());
                        queue.DeleteMessage(queueMessage);
                        /*queue.DeleteMessage(queueMessage.Id, queueMessage.PopReceipt);

                        getCloudBlobContainer().GetBlobReference(jobId).Delete(); */
                    }
                    else
                    {
                        //failure
                        UpdateState(jobId, "New");
                        queue.AddMessage(queueMessage); //put message back in queue
                    }

                }
            } //end while loop
        }
Beispiel #26
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());
                }
            }
        }