コード例 #1
0
        private bool HasModelExtensionAssembly(string tenant, out string assemblyFile, out string @namespace)
        {
            var result = false;

            assemblyFile = null;
            @namespace   = null;

            if (SubscriptionKind.Premium.Equals(this.Tenant.SubscriptionKind) &&
                !string.IsNullOrWhiteSpace(this.Tenant.ModelExtensionAssembly) &&
                !string.IsNullOrWhiteSpace(this.Tenant.ModelExtensionNamespace))
            {
                var extensionsPath = CloudConfiguration.GetConfigurationSetting(ExtensionsPath);
                if (!Path.IsPathRooted(extensionsPath))
                {
                    extensionsPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, extensionsPath);
                }

                assemblyFile = Path.Combine(extensionsPath, string.Format("{0}.dll", this.Tenant.ModelExtensionAssembly));
                @namespace   = this.Tenant.ModelExtensionNamespace;

                result = true;
            }

            return(result);
        }
コード例 #2
0
 private static int GetMaxBatchIterationsPerCycle()
 {
     try
     {
         return(Math.Max(2, Convert.ToInt32(CloudConfiguration.GetConfigurationSetting("MaxBatchIterationsPerCycle"))));
     }
     catch
     {
         TraceHelper.TraceWarning("Bad parameter value: MaxBatchIterationsPerCycle");
         return(4);
     }
 }
コード例 #3
0
 private static int GetExportRequestPollingInterval()
 {
     try
     {
         return(Math.Max(5, Convert.ToInt32(CloudConfiguration.GetConfigurationSetting("ExportRequestPollingInterval"))));
     }
     catch
     {
         TraceHelper.TraceWarning("Bad parameter value: ExportRequestPollingInterval");
         return(10);
     }
 }
コード例 #4
0
 private static int GetStandardQueueBatchSize()
 {
     try
     {
         return(Math.Max(1, Convert.ToInt32(CloudConfiguration.GetConfigurationSetting("StandardBatchProcessingSize"))));
     }
     catch
     {
         TraceHelper.TraceWarning("Bad parameter value: StandardBatchProcessingSize");
         return(8);
     }
 }
コード例 #5
0
        public static MvcHtmlString SurveyLink(this HtmlHelper htmlHelper, string linkText, string tenant, string surveySlug)
        {
            string publicSurveysWebsiteUrl = CloudConfiguration.GetConfigurationSetting("PublicSurveyWebsiteUrl", string.Empty, true);

            var surveyLink = string.Format(CultureInfo.InvariantCulture, "{0}/survey/{1}/{2}", publicSurveysWebsiteUrl, tenant, surveySlug);
            var tagBuilder = new TagBuilder("a");

            tagBuilder.InnerHtml = !string.IsNullOrEmpty(linkText) ? HttpUtility.HtmlEncode(linkText) : string.Empty;
            tagBuilder.MergeAttribute("href", surveyLink);

            return(MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal)));
        }
コード例 #6
0
        public void GetConfigurationSettingThrows()
        {
            var value = CloudConfiguration.GetConfigurationSetting("NonExistentSetting", null, true);

            Assert.AreEqual("default", value);
        }
コード例 #7
0
        public void GetConfigurationSettingReturnsDefault()
        {
            var value = CloudConfiguration.GetConfigurationSetting("NonExistentSetting", "default", false);

            Assert.AreEqual("default", value);
        }
コード例 #8
0
        public void GetConfigurationSettingReturnsNull()
        {
            var value = CloudConfiguration.GetConfigurationSetting("NonExistentSetting");

            Assert.IsNull(value);
        }
コード例 #9
0
        public void GetConfigurationSettingReturnsValue()
        {
            var value = CloudConfiguration.GetConfigurationSetting("ExistentSetting");

            Assert.AreEqual("ok", value);
        }
コード例 #10
0
        public static void RegisterTypes(IUnityContainer container, bool roleInitialization)
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            container.RegisterInstance(account);

            // http://msdn.microsoft.com/en-us/library/hh680900(v=pandp.50).aspx
            container.RegisterInstance <IRetryPolicyFactory>(roleInitialization
                ? new DefaultRetryPolicyFactory() as IRetryPolicyFactory
                : new ConfiguredRetryPolicyFactory() as IRetryPolicyFactory);

            container.RegisterType <IDictionary <string, TenantSurveyProcessingInfo>, Dictionary <string, TenantSurveyProcessingInfo> >(new InjectionConstructor());

            var cloudStorageAccountType    = typeof(Microsoft.WindowsAzure.Storage.CloudStorageAccount);
            var retryPolicyFactoryProperty = new InjectionProperty("RetryPolicyFactory", typeof(IRetryPolicyFactory));

            // registering IAzureTable types
            container
            .RegisterType <IAzureTable <SurveyRow>, AzureTable <SurveyRow> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Tables.Surveys),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureTable <QuestionRow>, AzureTable <QuestionRow> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Tables.Questions),
                retryPolicyFactoryProperty);

            // registering IAzureQueue types
            var visibilityTime = TimeSpan.FromSeconds(300);

            container
            .RegisterType <IAzureQueue <SurveyAnswerStoredMessage>, AzureQueue <SurveyAnswerStoredMessage> >(
                SubscriptionKind.Standard.ToString(),
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyAnswerStoredStandard, visibilityTime),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureQueue <SurveyAnswerStoredMessage>, AzureQueue <SurveyAnswerStoredMessage> >(
                SubscriptionKind.Premium.ToString(),
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyAnswerStoredPremium, visibilityTime),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureQueue <SurveyTransferMessage>, AzureQueue <SurveyTransferMessage> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.Queues.SurveyTransferRequest, visibilityTime),
                retryPolicyFactoryProperty);

            // registering IAzureBlobContainer types
            container
            .RegisterType <IAzureBlobContainer <byte[]>, FilesBlobContainer>(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Logos, "image/jpeg"),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureBlobContainer <SurveyAnswersSummary>, EntitiesBlobContainer <SurveyAnswersSummary> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.SurveyAnswersSummaries),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureBlobContainer <List <string> >, EntitiesBlobContainer <List <string> > >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.SurveyAnswersLists),
                retryPolicyFactoryProperty)
            .RegisterType <IAzureBlobContainer <Tenant>, EntitiesBlobContainer <Tenant> >(
                new InjectionConstructor(cloudStorageAccountType, AzureConstants.BlobContainers.Tenants),
                retryPolicyFactoryProperty);

            var cacheEnabledProperty = new InjectionProperty("CacheEnabled", !roleInitialization && Convert.ToBoolean(CloudConfiguration.GetConfigurationSetting("EnableCaching")));

            // registering Store types
            container
            .RegisterType <ISurveyStore, SurveyStore>(cacheEnabledProperty)
            .RegisterType <ITenantStore, TenantStore>(cacheEnabledProperty)
            .RegisterType <ISurveyAnswerStore, SurveyAnswerStore>(new InjectionFactory((c, t, s) => new SurveyAnswerStore(
                                                                                           container.Resolve <ITenantStore>(),
                                                                                           container.Resolve <ISurveyAnswerContainerFactory>(),
                                                                                           container.Resolve <IAzureQueue <SurveyAnswerStoredMessage> >(SubscriptionKind.Standard.ToString()),
                                                                                           container.Resolve <IAzureQueue <SurveyAnswerStoredMessage> >(SubscriptionKind.Premium.ToString()),
                                                                                           container.Resolve <IAzureBlobContainer <List <string> > >())))
            .RegisterType <ISurveyAnswersSummaryStore, SurveyAnswersSummaryStore>()
            .RegisterType <ISurveySqlStore, SurveySqlStore>()
            .RegisterType <ISurveyTransferStore, SurveyTransferStore>();

            // Container for resolving the survey answer containers
            var surveyAnswerBlobContainerResolver = new UnityContainer();

            surveyAnswerBlobContainerResolver.RegisterInstance(account);

            // http://msdn.microsoft.com/en-us/library/hh680900(v=pandp.50).aspx
            surveyAnswerBlobContainerResolver.RegisterInstance <IRetryPolicyFactory>(roleInitialization
                ? new DefaultRetryPolicyFactory() as IRetryPolicyFactory
                : new ConfiguredRetryPolicyFactory() as IRetryPolicyFactory);

            surveyAnswerBlobContainerResolver.RegisterType <IAzureBlobContainer <SurveyAnswer>, EntitiesBlobContainer <SurveyAnswer> >(
                new InjectionConstructor(cloudStorageAccountType, typeof(string)),
                retryPolicyFactoryProperty);

            container.RegisterType <ISurveyAnswerContainerFactory, SurveyAnswerContainerFactory>(
                new InjectionConstructor(surveyAnswerBlobContainerResolver));
        }