Provides a client for accessing the Windows Azure Queue service.
        // Constructor - get settings from a hosted service configuration or .NET configuration file.
        public QueueHelper(string configurationSettingName, bool hostedService)
        {
            if (hostedService)
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                    {
                        var connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                        configSettingPublisher(connectionString);
                    }
                );
            }
            else
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                    {
                        var connectionString = ConfigurationManager.ConnectionStrings[configName].ConnectionString;
                        configSettingPublisher(connectionString);
                    }
                );
            }

            Account = CloudStorageAccount.FromConfigurationSetting(configurationSettingName);

            QueueClient = Account.CreateCloudQueueClient();
            QueueClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.Zero);
        }
        // Constructor - pass in a storage connection string.
        public QueueHelper(string connectionString)
        {
            Account = CloudStorageAccount.Parse(connectionString);

            QueueClient = Account.CreateCloudQueueClient();
            QueueClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.Zero);
        }
 // Constructor - get settings from a hosted service configuration
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueHelper"/> class.
 /// </summary>
 /// <param name="configurationSettingName">Name of the configuration setting.</param>
 /// <remarks></remarks>
 public QueueHelper(string configurationSettingName)
 {
     var connectString = CloudConfigurationManager.GetSetting(configurationSettingName);
     _storageAccount = CloudStorageAccount.Parse(connectString);
     _queueClient = _storageAccount.CreateCloudQueueClient();
     _queueClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.FromSeconds(1));
 }
        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;
            }
        }
        public QueueFrases()
        {
            queueClient = storageAccount.CreateCloudQueueClient();

            this.frasesParaProcessasQueue = this.queueClient.GetQueueReference("frasesparaprocessar");
            this.frasesParaProcessasQueue.CreateIfNotExist();
        }
 public AzureMessageQueue(CloudQueueClient client)
 {
     this.client = client;
     MessageInvisibleTime = 30000;
     PeekInterval = 1000;
     MaximumWaitTimeWhenIdle = 60000;
 }
        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();
        }
        public RepositorioDePagamentosParaProcessar()
        {
            queueClient = storageAccount.CreateCloudQueueClient();

            this.vendasParaProcessasQueue = this.queueClient.GetQueueReference("vendasparaprocessar");
            this.vendasParaProcessasQueue.CreateIfNotExist();
        }
        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();
        }
Exemple #10
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 AzureMessageQueue(CloudQueueClient client)
 {
     this.client = client;
     MessageInvisibleTime = DefaultMessageInvisibleTime;
     PeekInterval = DefaultPeekInterval;
     MaximumWaitTimeWhenIdle = DefaultMaximumWaitTimeWhenIdle;
     BatchSize = DefaultBatchSize;
 }
        public ProcessingQueue()
        {
            _formatter = new BinaryFormatter();

            storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(TableName);
            queue.CreateIfNotExist();
        }
Exemple #13
0
        public ProcessingQueue()
        {
            _formatter = new BinaryFormatter();

            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(TableName);
            queue.CreateIfNotExist();
        }
        public QueueHelper()
        {
            string connectionString = Settings.AzureConnectionString();

            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
            cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient();

            cloudQueueClient.Timeout = Settings.Timeout();
            cloudQueueClient.RetryPolicy = RetryPolicies.Retry(Settings.RetryCount(), TimeSpan.FromSeconds(3));
        }
Exemple #15
0
        public QueuesController(CloudQueueClient cloudQueueClient, IUserPrivilegesRepository userPrivilegesRepository, IUserRepository userRepository)
            : base(userPrivilegesRepository)
        {
            if ((GetStorageAccountFromConfigurationSetting() == null) && (cloudQueueClient == null))
            {
                throw new ArgumentNullException("cloudQueueClient", "Cloud Queue Client cannot be null if no configuration is loaded.");
            }

            this.cloudQueueClient = cloudQueueClient ?? GetStorageAccountFromConfigurationSetting().CreateCloudQueueClient();
            this.userRepository = userRepository;
        }
        private CloudQueueClient _cloudQueueClient; // = null;

        #region metodos comuns a varios TestingQueues

        private void InitStorageAccountAndQueueClient()
        {
            if (_cloudStorageAccount == null)
            {
                _cloudStorageAccount = CloudStorageAccount.Parse(_connectionString);
            }

            if (_cloudQueueClient == null)
            {
                _cloudQueueClient = _cloudStorageAccount.CreateCloudQueueClient();
            }
        }
        public AzureQueueProvider()
        {
            //var accountAndKey = new StorageCredentialsAccountAndKey("cloudmorph", "Q7Vco66yV3hncM/piawqSHyiXZZ8meZdRMAMElOorgE/EHv4t8B18Nn7zUF/7nLu6WSMaZzmjaUo4LUHlWCfyw==");
            //var _storageAccount = new CloudStorageAccount(accountAndKey, true);

            // Retrieve storage account from connection-string
            //_storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            //_storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=bmaigorcloudmorphstorage;AccountKey=Q7Vco66yV3hncM/piawqSHyiXZZ8meZdRMAMElOorgE/EHv4t8B18Nn7zUF/7nLu6WSMaZzmjaUo4LUHlWCfyw==");
            _storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the queue client
            _client = _storageAccount.CreateCloudQueueClient();
        }
        public MsdnQueueSource()
        {
            queueClient = storageAccount.CreateCloudQueueClient();

            this.namespacesQueue = this.queueClient.GetQueueReference("namespaces");
            this.namespacesQueue.CreateIfNotExist();

            this.typesQueue = this.queueClient.GetQueueReference("types");
            this.typesQueue.CreateIfNotExist();

            this.membersQueue = this.queueClient.GetQueueReference("members");
            this.membersQueue.CreateIfNotExist();
        }
        public static void Initialize(string account, string key)
        {
            Uri blobUri = new Uri(string.Format("http://{0}.blob.core.windows.net", account));
            Uri queueUri = new Uri(string.Format("http://{0}.queue.core.windows.net", account));
            Uri tableUri = new Uri(string.Format("http://{0}.table.core.windows.net", account));

            s_credentials = new StorageCredentialsAccountAndKey(account, key);
            s_storageAccount = new CloudStorageAccount(s_credentials, blobUri, queueUri, tableUri);

            s_blobClient = s_storageAccount.CreateCloudBlobClient();
            s_tableClient = s_storageAccount.CreateCloudTableClient();
            s_queueClient = s_storageAccount.CreateCloudQueueClient();
        }
        public PushNotificationsController(CloudQueueClient cloudQueueClient, IPushUserEndpointsRepository pushUserEndpointsRepository, IUserRepository userRepository)
        {
            if (GetStorageAccountFromConfigurationSetting() == null)
            {
                if (cloudQueueClient == null)
                {
                    throw new ArgumentNullException("cloudQueueClient", "Cloud Queue Client cannot be null if no configuration is loaded.");
                }
            }

            this.cloudQueueClient = cloudQueueClient ?? GetStorageAccountFromConfigurationSetting().CreateCloudQueueClient();
            this.userRepository = userRepository;
            this.pushUserEndpointsRepository = pushUserEndpointsRepository;
        }
        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();
        }
Exemple #23
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 PushNotificationController(CloudQueueClient cloudQueueClient, CloudBlobClient cloudBlobClient, IWnsEndpointRepository endpointsRepository, IAccessTokenProvider tokenProvider)
        {
            this.endpointsRepository = endpointsRepository;

            CloudStorageAccount account = null;

            if ((account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) == null)
            {
                if (cloudQueueClient == null)
                {
                    throw new ArgumentNullException("cloudQueueClient", "Cloud Queue Client cannot be null if no configuration is loaded.");
                }
            }

            this.cloudQueueClient = cloudQueueClient ?? account.CreateCloudQueueClient();
            this.blobClient = cloudBlobClient ?? account.CreateCloudBlobClient();

            this.tokenProvider = tokenProvider;
        }
        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();
        }
Exemple #26
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();
        }
Exemple #27
0
        public static CloudQueue InitializeQueue(string queueName)
        {
            CloudQueueClient queueStorage = null;

            if (AzureStorageKey == null)
            {
                var clientStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
                queueStorage = new CloudQueueClient(clientStorageAccount.QueueEndpoint.AbsoluteUri, clientStorageAccount.Credentials);
            }
            else
            {
                byte[] key = Convert.FromBase64String(AzureStorageKey);
                var creds = new StorageCredentialsAccountAndKey(AccountName, key);
                queueStorage = new CloudQueueClient(String.Format("http://{0}.queue.core.windows.net", AccountName), creds);
            }

            CloudQueue queue = queueStorage.GetQueueReference(queueName);
            queue.CreateIfNotExist();
            return queue;
        }
Exemple #28
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();
            }
        }
        public SamplePushUserRegistrationService(HttpContextBase context, WebOperationContext webOperationContext, IPushUserEndpointsRepository pushUserEndpointsRepository, CloudQueueClient cloudQueueClient)
        {
            if ((context == null) && (HttpContext.Current == null))
            {
                throw new ArgumentNullException("context", "Context cannot be null if not running on a Web context.");
            }

            if (pushUserEndpointsRepository == null)
            {
                throw new ArgumentNullException("pushUserEndpointsRepository", "PushUserEndpoints repository cannot be null.");
            }

            if ((cloudQueueClient == null) && (GetStorageAccountFromConfigurationSetting() == null))
            {
                throw new ArgumentNullException("cloudQueueClient", "Cloud Queue Client cannot be null if no configuration is loaded.");
            }

            this.cloudQueueClient = cloudQueueClient ?? GetStorageAccountFromConfigurationSetting().CreateCloudQueueClient();
            this.webOperationContext = webOperationContext;
            this.context = context;
            this.pushUserEndpointsRepository = pushUserEndpointsRepository;
        }