Beispiel #1
0
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");

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

            Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                string configuration = RoleEnvironment.IsAvailable ?
                                       RoleEnvironment.GetConfigurationSettingValue(configName) :
                                       ConfigurationManager.AppSettings[configName];

                configSetter(configuration);
            });

            StorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            CloudTableClient.CreateTablesFromModel(
                typeof(DataContext),
                StorageAccount.TableEndpoint.AbsoluteUri,
                StorageAccount.Credentials);

            return(base.OnStart());
        }
Beispiel #2
0
        /// <summary>
        /// Creates tables from a DataServiceContext derived class.
        /// </summary>
        /// <param name="serviceContextType">A DataServiceContext derived class that defines the table schemas.</param>
        /// <param name="baseAddress">The baseAddress of the table storage endpoint.</param>
        /// <param name="credentials">Storage account credentials.</param>
        /// <remarks>
        /// For each table, the class exposes one or more IQueryable&lt;T&gt; properties, where T is a
        /// TableServiceEntity derived class with the required schema.
        /// </remarks>
        public static void CreateTablesFromModel(Type serviceContextType, string baseAddress,
                                                 StorageCredentials credentials)
        {
            CloudTableClient.CreateTablesFromModel(serviceContextType, baseAddress, credentials);

            var tableStorage = new CloudTableClient(baseAddress, credentials);

            // Execute conditionally for development storage only
            if (tableStorage.BaseUri.IsLoopback)
            {
                TableServiceContext ctx = tableStorage.GetDataServiceContext();

                PropertyInfo[] properties = serviceContextType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                foreach (
                    PropertyInfo table in
                    properties.Where(
                        p =>
                        p.PropertyType.IsGenericType &&
                        p.PropertyType.GetGenericTypeDefinition() == typeof(IQueryable <>)))
                {
                    var entity =
                        Activator.CreateInstance(table.PropertyType.GetGenericArguments()[0]) as TableServiceEntity;
                    if (entity != null)
                    {
                        InitializeTableSchemaFromEntity(tableStorage, table.Name, entity);
                    }
                }
            }
        }
Beispiel #3
0
        static void initializeStorage()
        {
            // Enable CloudStorageAccount.FromConfigurationSetting method.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            try
            {
                // Create the Table for storing words.
                CloudTableClient.CreateTablesFromModel(
                    typeof(WordDataContext),
                    _storageAccount.TableEndpoint.AbsoluteUri,
                    _storageAccount.Credentials);

                // Create the queue for communication if it is not exist.
                CloudQueueClient queueStorage = _storageAccount.CreateCloudQueueClient();
                CloudQueue       queue        = queueStorage.GetQueueReference(_queueName);
                queue.CreateIfNotExist();
            }
            // This method is running in the backend.
            // It will never crash even though there is a big error.
            catch (Exception ex)
            {
                Trace.TraceError("Exception when processing queue item. Message: '{0}'", ex.Message);
            }
        }
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();

            // This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            /// Create data table from MessageDataServiceContext
            /// It is recommended the data tables should be only created once. It is typically done as a
            /// provisioning step and rarely in application code.
            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // dynamically create the tables
            CloudTableClient.CreateTablesFromModel(
                typeof(MessageDataServiceContext),
                account.TableEndpoint.AbsoluteUri,
                account.Credentials);
        }
 static LogEntryDataSource()
 {
     storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
     CloudTableClient.CreateTablesFromModel(
         typeof(LogDataContext),
         storageAccount.TableEndpoint.AbsoluteUri,
         storageAccount.Credentials);
 }
Beispiel #6
0
        static ViewDataSource()
        {
            storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["OgdiConfigConnectionString"]);

            CloudTableClient.CreateTablesFromModel(
                typeof(ViewDataContext),
                ConfigurationManager.AppSettings["TableStorageEndpoint"],
                storageAccount.Credentials);
        }
        static DatasetInfoDataSource()
        {
            StorageAccount = CloudStorageAccount.Parse(OgdiConfiguration.GetValue("DataConnectionString"));

            CloudTableClient.CreateTablesFromModel(
                typeof(DatasetInfoDataContext),
                StorageAccount.TableEndpoint.AbsoluteUri,
                StorageAccount.Credentials);
        }
Beispiel #8
0
        public override void ActivateOptions()
        {
            base.ActivateOptions();
            var cloudStorageAccount =
                CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(TableStorageConnectionStringName));

            _tableEndpoint = cloudStorageAccount.TableEndpoint.AbsoluteUri;
            CloudTableClient.CreateTablesFromModel(typeof(LogServiceContext), _tableEndpoint, cloudStorageAccount.Credentials);
            _ctx = new LogServiceContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials);
        }
Beispiel #9
0
 private void InitBd()
 {
     Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
     {
         configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
     });
     storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
     CloudTableClient.CreateTablesFromModel(typeof(NewsDB_AzureDataContext), storageAccount.TableEndpoint.AbsoluteUri,
                                            storageAccount.Credentials);
     context             = new NewsDB_AzureDataContext(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);
     context.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
 }
Beispiel #10
0
        public GuestBookService(string connectionString)
        {
            storageAccount = CloudStorageAccount.FromConfigurationSetting(connectionString);
            string endpoint    = storageAccount.TableEndpoint.AbsoluteUri;
            var    credentials = storageAccount.Credentials;

            CloudTableClient.CreateTablesFromModel(typeof(GuestBookTableServiceContext), endpoint, credentials);
            tableServiceContext = new GuestBookTableServiceContext(endpoint, credentials)
            {
                RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1))
            };
        }
        public TableTraceListener()
        {
            Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });
            account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            context = new DataServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            CloudTableClient.CreateTablesFromModel(typeof(DataServiceContext),
                                                   account.TableEndpoint.AbsoluteUri, account.Credentials);
        }
        static EventMessageDataSource()
        {
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            CloudTableClient.CreateTablesFromModel(
                typeof(EventMessageDataContext),
                storageAccount.TableEndpoint.AbsoluteUri,
                storageAccount.Credentials);
        }
        public FunnyAppRepository()
        {
            _storageAccount = CloudStorageAccount.FromConfigurationSetting(Utils.ConfigurationString);

            CloudTableClient.CreateTablesFromModel(
                typeof(FunnyAppContext),
                _storageAccount.TableEndpoint.AbsoluteUri,
                _storageAccount.Credentials);

            _entitySetName = typeof(TEntity).Name;
            _storageAccount.CreateCloudTableClient().CreateTableIfNotExist(_entitySetName);

            this._context = new FunnyAppContext(_storageAccount.TableEndpoint.AbsoluteUri, _storageAccount.Credentials);

            this._context.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
        }
Beispiel #14
0
        void Application_Start(object sender, EventArgs e)
        {
            /// This code sets up a handler to update CloudStorageAccount instances when their corresponding
            // configuration settings change in the service configuration file.
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // Provide the configSetter with the initial value
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            var account = CloudStorageAccount.FromConfigurationSetting("TableDataConnectionString");

            // dynamically create the tables
            CloudTableClient.CreateTablesFromModel(typeof(MessageDataServiceContext),
                                                   account.TableEndpoint.AbsoluteUri, account.Credentials);
            CloudTableClient.CreateTablesFromModel(typeof(StaffMessageDataServiceContext),
                                                   account.TableEndpoint.AbsoluteUri, account.Credentials);
        }
Beispiel #15
0
        private ApplicationInitAzureTables()
        {
            CloudStorageAccount acc = CloudStorageAccount.DevelopmentStorageAccount;

            CloudTableClient.CreateTablesFromModel(typeof(AzureRayaDataContext), acc.TableEndpoint.ToString(), acc.Credentials);
        }