/// <summary> /// Initializes a new instance of the <see cref="ConfigController"/> class /// </summary> /// <param name="log">Log</param> /// <param name="appsManager">apps manager</param> /// <param name="serviceVersionInfo">info about version of service</param> /// <param name="buildVersionInfo">build version info</param> public ConfigController(ILog log, IAppsManager appsManager, IServiceVersionInfo serviceVersionInfo, IBuildVersionInfo buildVersionInfo) { this.log = log; this.appsManager = appsManager; this.serviceVersionInfo = serviceVersionInfo; this.buildVersionInfo = buildVersionInfo; }
/// <summary> /// Enumerates the list of versions specified by the version range /// </summary> /// <param name="serviceVersionInfo">info on version of the service</param> /// <returns>Returns a list of strings, where each string is a version in the range</returns> public List <string> EnumerateVersions(IServiceVersionInfo serviceVersionInfo) { if (this.parseError || this.outOfRange) { return(null); } return(serviceVersionInfo.EnumerateVersions(this.minVersion, this.maxVersion)); }
/// <summary> /// Initializes a new instance of the <see cref="BaseVersionRangeAttribute"/> class. /// </summary> /// <param name="serviceVersionInfo">service version info</param> /// <param name="versionRange">attribute string for the version range</param> public BaseVersionRangeAttribute(IServiceVersionInfo serviceVersionInfo, string versionRange) { this.versionRange = versionRange; // first, parse the version range string to make sure it has the correct format bool result = this.ParseVersionRange(serviceVersionInfo, this.versionRange); // if versionRange parses OK, then check that the range numbers are compatible with the service version info if (result) { this.outOfRange = !this.IsRangeValid(serviceVersionInfo); } if (this.outOfRange || this.parseError) { this.minVersion = new ApiVersionInfo(0, 0); this.maxVersion = new ApiVersionInfo(0, 0); } }
/// <summary> /// Checks if the version range specified by the string is compatible with the supported versions as specified by /// the <c>SystemVersionInfo</c> class. /// </summary> /// <param name="serviceVersionInfo">service version info</param> /// <returns>true if the range is valid</returns> private bool IsRangeValid(IServiceVersionInfo serviceVersionInfo) { // next, make sure the version range numbers are compatible with the service version info if (!serviceVersionInfo.Validate(this.minVersion)) { return(false); } if (!serviceVersionInfo.Validate(this.maxVersion)) { return(false); } // check that minVersion is <= maxVersion int comparison = this.minVersion.CompareTo(this.maxVersion); if (comparison == 1) { // minVersion appears to be > maxVersion return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceVersionInfo"/> class /// </summary> /// <param name="serviceVersionInfo">info of version of service</param> public ServiceVersionInfo(IServiceVersionInfo serviceVersionInfo) { this.FirstMajorVersion = serviceVersionInfo.FirstMajorVersion; this.NumMajorVersions = serviceVersionInfo.NumMajorVersions; this.ValidVersions = serviceVersionInfo.ValidVersions; }
/// <summary> /// Initializes the IoC registry with default values /// </summary> /// <param name="serviceVersionInfo">info of version of service</param> protected BaseRegistry(IServiceVersionInfo serviceVersionInfo) { // Short-lived container needed to read clientID, certThumbprint, and vaultURL via ISettingsReader // This container injects its own settingsReader class. // OLD code for creating a "short-lived" container // Container shortLivedContainer = new Container(x => x.For<ISettingsReader>().Use<SettingsReader>()); // SettingsReader settingsReader = (SettingsReader)shortLivedContainer.GetInstance<ISettingsReader>(); // shortLivedContainer.Dispose(); bool enableAzureSettingsReaderTracing = false; ISettingsReader settingsReader = new AzureSettingsReader(enableAzureSettingsReaderTracing); string clientID = settingsReader.ReadValue("AADEmbeddedSocialClientId"); string vaultUrl = settingsReader.ReadValue("KeyVaultUri"); string certThumbPrint = settingsReader.ReadValue("SocialPlusCertThumbprint"); StoreLocation storeLocation = StoreLocation.LocalMachine; string signingKey = settingsReader.ReadValue("SigningKey"); int serviceBusBatchIntervalMs = int.Parse(settingsReader.ReadValue("ServiceBusBatchIntervalMs")); enableAzureSettingsReaderTracing = bool.Parse(settingsReader.ReadValue("EnableAzureSettingsReaderTracing")); this.Scan( scan => { scan.AssembliesFromPath(Environment.CurrentDirectory); scan.LookForRegistries(); scan.WithDefaultConventions(); // scan.TheCallingAssembly(); // scan.With(new ControllerConvention()); }); // initialize the ILog to use debug output in an emulated role, and event source output in Azure Log log; if (RoleEnvironment.IsEmulated) { log = new Log(LogDestination.Debug, Log.DefaultCategoryName); } else { log = new Log(LogDestination.EventSource, Log.DefaultCategoryName); } this.For <ILog>().Singleton().Use(log); // This SettingsReader does not use KV; it's used to read regular (not protected) cloud configuration settings this.For <ISettingsReader>().Singleton().Use <AzureSettingsReader>().Ctor <bool>("isTracingEnabled").Is(enableAzureSettingsReaderTracing); // Initialize KV, asynchronous SettingsReader, ConnectionStringProvider, CTStore, CBStore, QueueManagers this.For <ICertificateHelper>().Singleton().Use <CertificateHelper>().Ctor <string>("certThumbprint").Is(certThumbPrint) .Ctor <string>("clientID").Is(clientID) .Ctor <StoreLocation>("storeLocation").Is(storeLocation); this.For <IKeyVaultClient>().Singleton().Use <AzureKeyVaultClient>(); this.For <IKV>().Singleton().Use <KV>().Ctor <string>("clientID").Is(clientID) .Ctor <string>("vaultUrl").Is(vaultUrl) .Ctor <string>("certThumbprint").Is(certThumbPrint) .Ctor <StoreLocation>("storeLocation").Is(storeLocation); this.For <ISettingsReaderAsync>().Singleton().Use <KVSettingsReader>(); this.For <IConnectionStringProvider>().Singleton().Use <ConnectionStringProvider>(); this.For <ICTStoreManager>().Singleton().Use <CTStoreManager>(); this.For <ICBStoreManager>().Singleton().Use <CBStoreManager>(); this.For <IQueueManager>().Singleton().Use <QueueManager>().Ctor <int>("batchIntervalMs").Is(serviceBusBatchIntervalMs); // Initialize the rest of the managers this.For <ISessionTokenManager>().Use <SessionTokenManager>(); this.For <IAppsManager>().Use <AppsManager>(); this.For <IIdentitiesManager>().Singleton().Use <IdentitiesManager>(); this.For <IUsersManager>().Use <UsersManager>(); this.For <ITopicsManager>().Use <TopicsManager>(); this.For <IViewsManager>().Use <ViewsManager>(); this.For <IRelationshipsManager>().Use <RelationshipsManager>(); this.For <ILikesManager>().Use <LikesManager>(); this.For <IPinsManager>().Use <PinsManager>(); this.For <ICommentsManager>().Use <CommentsManager>(); this.For <IRepliesManager>().Use <RepliesManager>(); this.For <IActivitiesManager>().Use <ActivitiesManager>(); this.For <INotificationsManager>().Use <NotificationsManager>(); this.For <ISearchManager>().Singleton().Use <SearchManager>(); this.For <IBlobsManager>().Use <BlobsManager>(); this.For <IPushNotificationsManager>().Use <PushNotificationsManager>(); this.For <IPopularTopicsManager>().Use <PopularTopicsManager>(); this.For <IPopularUsersManager>().Use <PopularUsersManager>(); this.For <ITopicNamesManager>().Use <TopicNamesManager>(); this.For <IReportsManager>().Use <ReportsManager>(); //Initialize the metric loggers this.For <IPerformanceMetrics>().Singleton().Use <LogPerformanceMetrics>(); this.For <IApplicationMetrics>().Singleton().Use <LogApplicationMetrics>(); this.For <IMetricsConfig>().Singleton().Use <LogMetricsConfig>(); // Build a composite auth manager var aadAuthManager = this.For <IAuthManager>().Use <AADAuthManager>(); var spAuthManager = this.For <IAuthManager>().Use <SocialPlusAuthManager>(); var anonAuthManager = this.For <IAuthManager>().Use <AnonAuthManager>(); var msaAuthManager = this.For <IAuthManager>().Use <OAuthManager>().Ctor <IdentityProviders>("identityProvider").Is(IdentityProviders.Microsoft); var fbAuthManager = this.For <IAuthManager>().Use <OAuthManager>().Ctor <IdentityProviders>("identityProvider").Is(IdentityProviders.Facebook); var gAuthManager = this.For <IAuthManager>().Use <OAuthManager>().Ctor <IdentityProviders>("identityProvider").Is(IdentityProviders.Google); var tAuthManager = this.For <IAuthManager>().Use <OAuthManager>().Ctor <IdentityProviders>("identityProvider").Is(IdentityProviders.Twitter); this.For <ICompositeAuthManager>().Singleton().Use <CompositeAuthManager>() .Ctor <IAuthManager>("aadAuthManager").Is(aadAuthManager) .Ctor <IAuthManager>("spAuthManager").Is(spAuthManager) .Ctor <IAuthManager>("anonAuthManager").Is(anonAuthManager) .Ctor <IAuthManager>("msaAuthManager").Is(msaAuthManager) .Ctor <IAuthManager>("fbAuthManager").Is(fbAuthManager) .Ctor <IAuthManager>("gAuthManager").Is(gAuthManager) .Ctor <IAuthManager>("tAuthManager").Is(tAuthManager); this.For <IHandleGenerator>().Use <HandleGenerator>(); this.For <ITopicsStore>().Use <TopicsStore>(); this.For <IUsersStore>().Use <UsersStore>(); this.For <IAppsStore>().Use <AppsStore>(); this.For <ILikesStore>().Use <LikesStore>(); this.For <IPinsStore>().Use <PinsStore>(); this.For <IUserRelationshipsStore>().Use <UserRelationshipsStore>(); this.For <ITopicRelationshipsStore>().Use <TopicRelationshipsStore>(); this.For <ICommentsStore>().Use <CommentsStore>(); this.For <IRepliesStore>().Use <RepliesStore>(); this.For <INotificationsStore>().Use <NotificationsStore>(); this.For <IActivitiesStore>().Use <ActivitiesStore>(); this.For <IBlobsMetadataStore>().Use <BlobsMetadataStore>(); this.For <IPushRegistrationsStore>().Use <PushRegistrationsStore>(); this.For <IBlobsStore>().Use <BlobsStore>(); this.For <ITopicNamesStore>().Use <TopicNamesStore>(); this.For <IContentReportsStore>().Use <ContentReportsStore>(); this.For <IUserReportsStore>().Use <UserReportsStore>(); this.For <IAVERTStore>().Use <AVERTStore>(); this.For <IFanoutTopicsQueue>().Use <FanoutTopicsQueue>(); this.For <IFanoutActivitiesQueue>().Use <FanoutActivitiesQueue>(); this.For <IFollowingImportsQueue>().Use <FollowingImportsQueue>(); this.For <IResizeImagesQueue>().Use <ResizeImagesQueue>(); this.For <ILikesQueue>().Use <LikesQueue>(); this.For <IRelationshipsQueue>().Use <RelationshipsQueue>(); this.For <IReportsQueue>().Use <ReportsQueue>(); this.For <ISearchQueue>().Use <SearchQueue>(); // Initialize the build service info and the service version info. For service version, use the existing one, using the fancy use lambda notation this.For <IBuildVersionInfo>().Use <BuildVersionInfo>(); this.For <IServiceVersionInfo>().Singleton().Use(ctx => serviceVersionInfo); }
/// <summary> /// Initializes a new instance of the <see cref="BuildsController"/> class /// </summary> /// <param name="serviceVersionInfo">info about version of service</param> /// <param name="buildVersionInfo">build version info</param> public BuildsController(IServiceVersionInfo serviceVersionInfo, IBuildVersionInfo buildVersionInfo) { this.serviceVersionInfo = serviceVersionInfo; this.buildVersionInfo = buildVersionInfo; }
/// <summary> /// Initializes a new instance of the <see cref="VersionedDirectRouteProvider"/> class. /// </summary> /// <param name="serviceVersionInfo">service version</param> public VersionedDirectRouteProvider(IServiceVersionInfo serviceVersionInfo) { this.serviceVersionInfo = serviceVersionInfo; }
/// <summary> /// Performs the work of parsing the version range string. /// </summary> /// <param name="serviceVersionInfo">service version info</param> /// <param name="versionRange">the version range string</param> /// <returns>true if the version string parses successfully</returns> private bool ParseVersionRange(IServiceVersionInfo serviceVersionInfo, string versionRange) { string versionPattern = @"(All)|(Min)|(Cur)|[vV](\d+).(\d+)"; string firstVersion = null, secondVersion = null; int separatorPosition = versionRange.IndexOf('-'); if (separatorPosition >= 0) { firstVersion = versionRange.Substring(0, separatorPosition); var match = Regex.Match(firstVersion, versionPattern); if (match.Success) { bool isAll = match.Groups[1].Value.Equals(All); bool isMin = match.Groups[2].Value.Equals(Min); bool isCur = match.Groups[3].Value.Equals(Cur); if (isAll) { // cannot have a version range that begins with All and a hypen that follows this.parseError = true; return(false); } else if (isMin) { this.minVersion = serviceVersionInfo.GetMinVersion(); } else if (isCur) { this.minVersion = serviceVersionInfo.GetMaxVersion(); } else { int major = int.Parse(match.Groups[4].Value); int minor = int.Parse(match.Groups[5].Value); if (major < 0 || minor < 0) { this.parseError = true; return(false); } this.minVersion = new ApiVersionInfo(major, minor); } } else { this.parseError = true; return(false); } secondVersion = versionRange.Substring(separatorPosition + 1); match = Regex.Match(secondVersion, versionPattern); if (match.Success) { bool isAll = match.Groups[1].Value.Equals(All); bool isMin = match.Groups[2].Value.Equals(Min); bool isCur = match.Groups[3].Value.Equals(Cur); if (isAll) { // cannot have a version range that has a hypen and then All this.parseError = true; return(false); } else if (isMin) { // cannot have a version range that has a hypen and then Min this.parseError = true; return(false); } else if (isCur) { this.maxVersion = serviceVersionInfo.GetMaxVersion(); } else { int major = int.Parse(match.Groups[4].Value); int minor = int.Parse(match.Groups[5].Value); if (major < 0 || minor < 0) { this.parseError = true; return(false); } this.maxVersion = new ApiVersionInfo(major, minor); } } else { this.parseError = true; return(false); } } else { firstVersion = versionRange; var match = Regex.Match(firstVersion, versionPattern); if (match.Success) { bool isAll = match.Groups[1].Value.Equals(All); bool isMin = match.Groups[2].Value.Equals(Min); bool isCur = match.Groups[3].Value.Equals(Cur); if (isAll) { this.minVersion = serviceVersionInfo.GetMinVersion(); this.maxVersion = serviceVersionInfo.GetMaxVersion(); } else if (isMin) { this.minVersion = serviceVersionInfo.GetMinVersion(); this.maxVersion = serviceVersionInfo.GetMinVersion(); } else if (isCur) { this.minVersion = serviceVersionInfo.GetMaxVersion(); this.maxVersion = serviceVersionInfo.GetMaxVersion(); } else { int major = int.Parse(match.Groups[4].Value); int minor = int.Parse(match.Groups[5].Value); if (major < 0 || minor < 0) { this.parseError = true; return(false); } this.minVersion = new ApiVersionInfo(major, minor); this.maxVersion = new ApiVersionInfo(major, minor); } } else { this.parseError = true; return(false); } } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Registry"/> class /// </summary> /// <param name="serviceVersionInfo">info of version of service</param> public Registry(IServiceVersionInfo serviceVersionInfo) : base(serviceVersionInfo) { this.For <IAuthenticationFilter>().Singleton().Use <AuthenticationFilter>(); }
/// <summary> /// Initializes a new instance of the <see cref="Registry"/> class /// </summary> /// <param name="serviceVersionInfo">info of version of service</param> public Registry(IServiceVersionInfo serviceVersionInfo) : base(serviceVersionInfo) { }