Ejemplo n.º 1
0
        public ServiceConfiguration(ICodePackageActivationContext context)
        {
            this.context = context;
            this.StoreAccountConnectionString             = this.context.GetConfig <string>(SectionName, "StoreAccountConnectionString");
            this.UsageReportingTableName                  = this.context.GetConfig <string>(SectionName, "UsageReportingTableName");
            this.UsageReportingQueueName                  = this.context.GetConfig <string>(SectionName, "UsageReportingQueueName");
            this.PushUsageForWhitelistedSubscriptionsOnly = this.context.GetConfig <bool>(SectionName, "PushUsageForWhitelistedSubscriptionsOnly");

            // Parse WhitelistedSubscriptions, the string should be in format e.g. "xxx;xxx;xxx"
            var subscriptionsString = this.context.GetConfig <string>(SectionName, "WhitelistedSubscriptions");
            var subscriptions       = subscriptionsString?.Split(';');
            var subscriptionList    = new List <Guid>();

            foreach (var sub in subscriptions)
            {
                if (Guid.TryParse(sub, out Guid subId))
                {
                    subscriptionList.Add(subId);
                }
            }

            this.WhitelistedSubscriptions = subscriptionList.AsReadOnly();

            if (this.PushUsageForWhitelistedSubscriptionsOnly && this.WhitelistedSubscriptions.Count <= 0)
            {
                BillingEventSource.Current.Warning(BillingEventSource.EmptyTrackingId, this, "Construction", OperationStates.NoMatch, $"PushUsageForWhitelistedSubscriptionsOnly is true but no subscription in whitelist.");
            }
        }
        private void ReadSettings()
        {
            try
            {
                // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
                ICodePackageActivationContext activationContext = this.Context.CodePackageActivationContext;
                ConfigurationPackage          config            = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
                ConfigurationSection          section           = config.Settings.Sections[ConfigurationSection];

                // Read the MaxQueueSize setting from the Settings.xml file
                if (section.Parameters.Any(p => string.Compare(p.Name,
                                                               MaxQueueSizeParameter,
                                                               StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    ConfigurationProperty parameter = section.Parameters[MaxQueueSizeParameter];
                    if (!string.IsNullOrWhiteSpace(parameter?.Value))
                    {
                        int.TryParse(parameter.Value, out MaxQueueSize);
                    }
                }
                ServiceEventSource.Current.Message($"[{MaxQueueSizeParameter}] = [{MaxQueueSize}]");
            }
            catch (KeyNotFoundException)
            {
                ActorEventSource.Current.Message($"[{MaxQueueSizeParameter}] = [{MaxQueueSize}]");
            }
        }
Ejemplo n.º 3
0
        public static bool TryGetSetting(this ICodePackageActivationContext context, string config, string section, string parameter, out string value)
        {
            value = null;
            try
            {
                var sections = context.GetConfigurationPackageObject(config)?.Settings.Sections;
                if (sections == null || !sections.Contains(section))
                {
                    return(false);
                }

                var parameters = sections[section].Parameters;
                if (parameters == null || !parameters.Contains(parameter))
                {
                    return(false);
                }

                value = parameters[parameter].Value;
                return(true);
            }
            catch (Exception)
            {
                // ignored -- in the case of settings retrieval we want to ignore all failure possibilities and skip straight to return the default value
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static IDictionary <string, string> ToSettingsDictionary(this ICodePackageActivationContext context)
        {
            IDictionary <string, string> rvalues = new Dictionary <string, string>();
            var packages = context.GetConfigurationPackageNames();

            foreach (var package in packages)
            {
                var sections = context.GetConfigurationPackageObject(package).Settings.Sections;
                if (sections?.Any() ?? false)
                {
                    foreach (var section in sections)
                    {
                        if (section.Parameters?.Any() ?? false)
                        {
                            foreach (var parameter in section.Parameters)
                            {
                                string name  = $"{section.Name}.{parameter.Name}";
                                string value = parameter.IsEncrypted ? parameter.DecryptValue().ToString() : parameter.Value;
                                rvalues.Add(name, value);
                            }
                        }
                    }
                }
            }

            return(rvalues);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="System.Fabric.ServiceContext"/> class.
        /// </summary>
        /// <param name="nodeContext">The node context, which contains information about the node
        /// where the stateless service instance is running.</param>
        /// <param name="codePackageActivationContext">The code package activation context,
        /// which contains information from the service manifest and the currently activated code package,
        /// like work directory, context ID etc.</param>
        /// <param name="serviceTypeName">The service type name.</param>
        /// <param name="serviceName">The service name.</param>
        /// <param name="initializationData">The service initialization data,
        /// which represents custom initialization data provided by the creator of the service.</param>
        /// <param name="partitionId">The partition ID.</param>
        /// <param name="replicaOrInstanceId">The replica or instance ID.</param>
        protected ServiceContext(
            NodeContext nodeContext,
            ICodePackageActivationContext codePackageActivationContext,
            string serviceTypeName,
            Uri serviceName,
            byte[] initializationData,
            Guid partitionId,
            long replicaOrInstanceId)
        {
            nodeContext.ThrowIfNull("nodeContext");
            codePackageActivationContext.ThrowIfNull("codePackageActivationContext");
            serviceTypeName.ThrowIfNull("serviceTypeName");
            serviceName.ThrowIfNull("serviceName");

            this.nodeContext = nodeContext;
            this.codePackageActivationContext = codePackageActivationContext;
            this.serviceTypeName     = serviceTypeName;
            this.serviceName         = serviceName;
            this.initializationData  = initializationData;
            this.partitionId         = partitionId;
            this.replicaOrInstanceId = replicaOrInstanceId;
            this.traceId             = String.Concat(partitionId.ToString("B"), ":", replicaOrInstanceId.ToString(CultureInfo.InvariantCulture));

            this.SetServiceAddresses();
        }
        public static T GetConfig <T>(this ICodePackageActivationContext context, string sectionName, string parameterName)
        {
            // Get config package
            var configurationPackage = context?.GetConfigurationPackageObject("Config");

            if (configurationPackage == null)
            {
                throw new InvalidOperationException("ConfigurationPackage is not found.");
            }

            // Get config section
            var configurationSection = configurationPackage.Settings.Sections.FirstOrDefault(s => s.Name.Equals(sectionName, StringComparison.OrdinalIgnoreCase));

            if (configurationSection == null)
            {
                throw new InvalidOperationException($"ConfigurationSection '{sectionName}' is not found.");
            }

            // Get config value
            var configurationProperty = configurationSection.Parameters[parameterName];

            if (configurationProperty == null)
            {
                throw new ArgumentNullException($"ConfigurationProperty '{parameterName}' is null.");
            }

            return((T)Convert.ChangeType(configurationProperty.Value, typeof(T)));
        }
Ejemplo n.º 7
0
        internal ServiceConfiguration(ICodePackageActivationContext activationContext, TraceWriterWrapper trace)
        {
            this.activationContext = Guard.IsNotNull(activationContext, nameof(activationContext));
            this.trace             = Guard.IsNotNull(trace, nameof(trace));

            this.RefreshConfigurationCache();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// ConfigurationProvider constructor.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="context">CodePackageActivationContext instance.</param>
        /// <param name="eventSource">IServiceEventSource instance for logging.</param>
        /// <param name="partition">Partition identifier.</param>
        /// <param name="replica">Replica or instance identifier.</param>
        public ConfigurationProvider(Uri serviceName, ICodePackageActivationContext context, IServiceEventSource eventSource, Guid partition, long replica)
        {
            Guard.ArgumentNotNull(serviceName, nameof(serviceName));
            Guard.ArgumentNotNull(context, nameof(context));

            _serviceNameUri      = serviceName;
            _serviceName         = _serviceNameUri.Segments[_serviceNameUri.Segments.Length - 1];
            _eventSource         = eventSource;
            _partitionId         = partition;
            _replicaOrInstanceId = replica;

            // Subscribe to configuration change events if the context was passed. It will not be passed for unit tests.
            if (null != context)
            {
                context.ConfigurationPackageAddedEvent    += CodePackageActivationContext_ConfigurationPackageAddedEvent;
                context.ConfigurationPackageModifiedEvent += CodePackageActivationContext_ConfigurationPackageModifiedEvent;
                context.ConfigurationPackageRemovedEvent  += Context_ConfigurationPackageRemovedEvent;
            }

            // Configuration has already been loaded by the time we subscribe to the events above, initialize the configuration the first time.
            IList <string>       names = context.GetConfigurationPackageNames();
            ConfigurationPackage pkg   = context.GetConfigurationPackageObject(c_ConfigurationPackageObjectName);

            // Create the add event parameters and call.
            PackageAddedEventArgs <ConfigurationPackage> evt = new PackageAddedEventArgs <ConfigurationPackage>();

            evt.Package = pkg;
            CodePackageActivationContext_ConfigurationPackageAddedEvent(null, evt);
        }
Ejemplo n.º 9
0
        private static int GetEndpointPort(
            ICodePackageActivationContext codePackageActivationContext,
            Type serviceContactType,
            string endpointResourceName)
        {
            var port = 0;

            var endpointName = endpointResourceName;

            if (string.IsNullOrEmpty(endpointName) && (serviceContactType != null))
            {
                endpointName = ServiceNameFormat.GetEndpointName(serviceContactType);
            }

            var endpoints = codePackageActivationContext.GetEndpoints();

            foreach (var endpoint in endpoints)
            {
                if (string.Compare(endpoint.Name, endpointName, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    port = endpoint.Port;
                    break;
                }
            }

            return(port);
        }
        /// <summary>
        /// Adds the HTTPS.
        /// </summary>
        /// <param name="services">The services collection used to configure the Insolvency Service.</param>
        /// <param name="codePackageActivationContext">The code package activation context.</param>
        /// <param name="configuration">The configuration settings used in the Insolvency Service.</param>
        public static void AddHttps(
            this IServiceCollection services,
            ICodePackageActivationContext codePackageActivationContext,
            IConfiguration configuration)
        {
            if (codePackageActivationContext == null)
            {
                return;
            }

            var endpoints = codePackageActivationContext.GetEndpoints();

            if (endpoints.Count == 0)
            {
                return;
            }

            EndpointResourceDescription endpointResourceDescription =
                endpoints.FirstOrDefault(endpoint => endpoint.Protocol == EndpointProtocol.Https);

            if (endpointResourceDescription == null)
            {
                return;
            }

            using (var x509Store = new X509StoreWrapper())
            {
                services.AddHttpsWithCertificate(x509Store, configuration, endpointResourceDescription.Port);
            }
        }
        public MockActorService(
            ICodePackageActivationContext codePackageActivationContext,
            IServiceProxyFactory serviceProxyFactory,
            IActorProxyFactory actorProxyFactory,
            NodeContext nodeContext,
            StatefulServiceContext statefulServiceContext,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider,
                  IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider             = null,
            ActorServiceSettings settings = null

            ) :
            base(
                context: statefulServiceContext,
                actorTypeInfo: actorTypeInfo,
                actorFactory: actorFactory,
                stateManagerFactory: stateManagerFactory,
                stateProvider: stateProvider,
                settings: settings)
        {
            _codePackageActivationContext = codePackageActivationContext;
            _serviceProxyFactory          = serviceProxyFactory;
            _actorProxyFactory            = actorProxyFactory;
            _nodeContext = nodeContext;
        }
Ejemplo n.º 12
0
 public TenantConfiguration(ICodePackageActivationContext context)
 {
     this.context = context;
     this.AdminStore_DefaultConnectionString  = this.context.GetConfig <string>("AdminStore", "DefaultConnectionString");
     this.TenantCache_DefaultConnectionString = this.context.GetConfig <string>("TenantCache", "DefaultConnectionString");
     this.TenantCache_DatabaseId      = this.context.GetConfig <int>("TenantCache", "DatabaseId");
     this.TenantCache_QuotaDatabaseId = this.context.GetConfig <int>("TenantCache", "QuotaDatabaseId");
 }
Ejemplo n.º 13
0
        internal static BSDockerVolumePluginSupportedOs GetOperatingSystem(ICodePackageActivationContext cpac)
        {
            var cpo        = cpac.GetConfigurationPackageObject(Constants.ConfigurationPackageName);
            var section    = cpo.Settings.Sections[Constants.SectionName];
            var paramValue = section.Parameters[Constants.ParameterName].Value;

            return((BSDockerVolumePluginSupportedOs)Enum.Parse(typeof(BSDockerVolumePluginSupportedOs), paramValue));
        }
Ejemplo n.º 14
0
        public static T BindConfiguration <T>(this ICodePackageActivationContext context, string sectionName)
            where T : class, new()
        {
            var instance = new T();

            BindConfiguration <T>(context, sectionName, instance);
            return(instance);
        }
Ejemplo n.º 15
0
 public Uri Build(string servicename)
 {
     if (this._activationContext == null)
     {
         this._activationContext = FabricRuntime.GetActivationContext();
     }
     return(new Uri(_activationContext.ApplicationName + "/" + servicename));
 }
Ejemplo n.º 16
0
        private void ReadSettings()
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            ICodePackageActivationContext activationContext = this.Context.CodePackageActivationContext;
            ConfigurationPackage          config            = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            ConfigurationSection          section           = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            ConfigurationProperty parameter = section.Parameters[ServiceBusConnectionStringParameter];

            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.serviceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                          ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.eventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                          EventHubNameParameter);
            }

            // Read the EventHubClientNumber setting from the Settings.xml file
            this.eventHubClientNumber = DefaultEventHubClientNumber;
            parameter = section.Parameters[EventHubClientNumberParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                int.TryParse(parameter.Value, out this.eventHubClientNumber);
            }

            // Read the MaxRetryCount setting from the Settings.xml file
            this.maxRetryCount = DefaultMaxRetryCount;
            parameter          = section.Parameters[MaxQueryRetryCountParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                int.TryParse(parameter.Value, out this.maxRetryCount);
            }

            // Read the BackoffDelay setting from the Settings.xml file
            this.backoffDelay = DefaultBackoffDelay;
            parameter         = section.Parameters[BackoffDelayParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                int.TryParse(parameter.Value, out this.backoffDelay);
            }
        }
        public DeviceActorService(
            StatefulServiceContext context,
            ActorTypeInformation typeInfo,
            Func <ActorBase> actorFactory     = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            : base(context, typeInfo, actorFactory, stateProvider, settings)
        {
            // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
            ICodePackageActivationContext activationContext = context.CodePackageActivationContext;
            ConfigurationPackage          config            = activationContext.GetConfigurationPackageObject(ConfigurationPackage);
            ConfigurationSection          section           = config.Settings.Sections[ConfigurationSection];

            // Read the ServiceBusConnectionString setting from the Settings.xml file
            ConfigurationProperty parameter = section.Parameters[ServiceBusConnectionStringParameter];

            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.ServiceBusConnectionString = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, ServiceBusConnectionStringParameter),
                          ServiceBusConnectionStringParameter);
            }

            // Read the EventHubName setting from the Settings.xml file
            parameter = section.Parameters[EventHubNameParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.EventHubName = parameter.Value;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, EventHubNameParameter),
                          EventHubNameParameter);
            }

            // Read the QueueLength setting from the Settings.xml file
            parameter = section.Parameters[QueueLengthParameter];
            if (!string.IsNullOrWhiteSpace(parameter?.Value))
            {
                this.QueueLength = DefaultQueueLength;
                int queueLength;
                if (int.TryParse(parameter.Value, out queueLength))
                {
                    this.QueueLength = queueLength;
                }
            }
            else
            {
                throw new ArgumentException(
                          string.Format(ParameterCannotBeNullFormat, QueueLengthParameter),
                          QueueLengthParameter);
            }
        }
 public LocalRuntime(
     NodeContext nodeContext,
     ICodePackageActivationContext codePackageActivationContext,
     ILoggerProvider loggerProvider)
 {
     this.nodeContext = nodeContext ?? throw new ArgumentNullException(nameof(nodeContext));
     this.codePackageActivationContext = codePackageActivationContext ?? throw new ArgumentNullException(nameof(codePackageActivationContext));
     this.loggerProvider = loggerProvider ?? throw new ArgumentNullException(nameof(loggerProvider));
 }
        public VotingService(StatelessServiceContext context)
            : base(context)
        {
            // Create the timer here, so we can do a change operation on it later, avoiding creating/disposing of the
            // timer.
            _healthTimer = new Timer(ReportHealthAndLoad, null, Timeout.Infinite, Timeout.Infinite);

            ICodePackageActivationContext ctx = context.CodePackageActivationContext;
        }
Ejemplo n.º 20
0
 public ServiceConfiguration(NodeContext nodeConext, ICodePackageActivationContext context)
 {
     this.context = context;
     this.DefaultConnectionString = this.context.GetConfig <string>("SocialProvider", "DefaultConnectionString");
     this.MdmAccount         = this.context.GetConfig <string>("SocialProvider", "MdmAccount");
     this.MdmMetricNamespace = this.context.GetConfig <string>("SocialProvider", "MdmMetricNamespace");
     this.Cluster            = this.context.GetConfig <string>("SocialProvider", "Cluster");
     this.NodeName           = nodeConext.NodeName;
 }
Ejemplo n.º 21
0
        internal AkkaClusterCommunicationListener(StatelessServiceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            codePackageActivationContext = context.CodePackageActivationContext;
            // akkaConfig = AkkaConfiguration.GetAkkaConfiguration(Constants.AkkaConfigSection);
        }
Ejemplo n.º 22
0
        public static ConfigurationSection ReadCustomConfigurationSection(this ICodePackageActivationContext context, string customConfigurationSectionName)
        {
            var settingsFile = context.GetConfigurationPackageObject("Config").Settings;

            if (!settingsFile.Sections.Contains(customConfigurationSectionName))
            {
                throw new KeyNotFoundException($"Settings does not contain a section for '{customConfigurationSectionName}'");
            }
            return(settingsFile.Sections[customConfigurationSectionName]);
        }
Ejemplo n.º 23
0
        public EventHubCommunicationListener(ServiceContext args, Action <string> messageCallback, Action <Exception> loggerAction)
        {
            ICodePackageActivationContext codePackageContext = args.CodePackageActivationContext;
            ConfigurationPackage          configPackage      = codePackageContext.GetConfigurationPackageObject("Config");
            ConfigurationSection          configSection      = configPackage.Settings.Sections[Constants.EH_CONFIG_SECTION];

            _ehConnString      = (configSection.Parameters[Constants.EH_CONN_STRING]).Value;
            _ehPath            = (configSection.Parameters[Constants.EH_HUB_PATH]).Value;
            _ehConsumerGroup   = (configSection.Parameters[Constants.EH_CONSUMER_GROUP]).Value;
            _storageConnString = (configSection.Parameters[Constants.EH_STORAGE_CONN_STRING]).Value;
        public Task <string> OpenAsync(CancellationToken cancellationToken)
        {
            try
            {
                // Read settings from the DeviceActorServiceConfig section in the Settings.xml file
                ICodePackageActivationContext codePackageActivationContext = this.context.CodePackageActivationContext;
                ConfigurationPackage          config  = codePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage);
                ConfigurationSection          section = config.Settings.Sections[ConfigurationSection];

                // Check if a parameter called DeviceActorServiceUri exists in the DeviceActorServiceConfig config section
                if (section.Parameters.Any(
                        p => string.Compare(
                            p.Name,
                            DeviceActorServiceUriParameter,
                            StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    ConfigurationProperty parameter = section.Parameters[DeviceActorServiceUriParameter];
                    DeviceActorServiceUri = !string.IsNullOrWhiteSpace(parameter?.Value)
                        ? parameter.Value
                        :
                                            // By default, the current service assumes that if no URI is explicitly defined for the actor service
                                            // in the Setting.xml file, the latter is hosted in the same Service Fabric application.
                                            $"fabric:/{this.context.ServiceName.Segments[1]}DeviceActorService";
                }
                else
                {
                    // By default, the current service assumes that if no URI is explicitly defined for the actor service
                    // in the Setting.xml file, the latter is hosted in the same Service Fabric application.
                    DeviceActorServiceUri = $"fabric:/{this.context.ServiceName.Segments[1]}DeviceActorService";
                }

                EndpointResourceDescription serviceEndpoint = this.context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint");
                int port = serviceEndpoint.Port;

                this.listeningAddress = String.Format(
                    CultureInfo.InvariantCulture,
                    "http://+:{0}/{1}",
                    port,
                    String.IsNullOrWhiteSpace(this.appRoot)
                        ? String.Empty
                        : this.appRoot.TrimEnd('/') + '/');

                this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder));
                string publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN);

                ServiceEventSource.Current.Message($"OWIN listening on [{publishAddress}]");

                return(Task.FromResult(publishAddress));
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
                throw;
            }
        }
        public static KvsActorStateProviderSettings LoadFrom(
            ICodePackageActivationContext activationContext,
            string configPackageName,
            string sectionName)
        {
            var settings = new KvsActorStateProviderSettings();

            settings.LoadFromSettings(activationContext, configPackageName, sectionName);

            return(settings);
        }
Ejemplo n.º 26
0
        public ServiceConfiguration(NodeContext nodeConext, ICodePackageActivationContext context)
        {
            this.context = context;

            this.OnlyHttps                 = this.context.GetConfig <bool>("RequestListener", "OnlyHttps");
            this.MdmAccount                = this.context.GetConfig <string>("RequestListener", "MdmAccount");
            this.MdmMetricNamespace        = this.context.GetConfig <string>("RequestListener", "MdmMetricNamespace");
            this.Cluster                   = this.context.GetConfig <string>("RequestListener", "Cluster");
            this.NodeName                  = nodeConext.NodeName;
            this.AcisCertificateThumbprint = this.context.GetConfig <string>("RequestListener", "AcisCertificateThumbprint");
        }
Ejemplo n.º 27
0
        public static T GetSetting <T>(this ICodePackageActivationContext context, string sectionName, string settingName, T defaultValue = default(T))
        {
            string stringValue;

            if (TryGetSetting(context, "Config", sectionName, settingName, out stringValue))
            {
                return(TypeHelpers.ConvertValue <T>(stringValue));
            }

            return(defaultValue);
        }
Ejemplo n.º 28
0
        public static T GetSetting <T>(this ICodePackageActivationContext context, SettingKey <T> key, T defaultValue = default(T))
        {
            string stringValue;

            if (TryGetSetting(context, key.Configuration, key.Section, key.Parameter, out stringValue))
            {
                return(TypeHelpers.ConvertValue <T>(stringValue));
            }

            return(defaultValue);
        }
Ejemplo n.º 29
0
        public static string GetSetting(this ICodePackageActivationContext context, string sectionName, string settingName, string defaultValue = null)
        {
            string stringValue;

            if (TryGetSetting(context, "Config", sectionName, settingName, out stringValue))
            {
                return(stringValue);
            }

            return(defaultValue);
        }
 /// <summary>
 /// Returns an instance of <see cref="StatefulServiceContext"/> using the specified arguments.
 /// </summary>
 /// <param name="codePackageActivationContext">Activation context</param>
 /// <param name="serviceTypeName">Name of the service type</param>
 /// <param name="serviceName">The URI that should be used by the ServiceContext</param>
 /// <param name="partitionId">PartitionId</param>
 /// <param name="replicaId">ReplicaId</param>
 /// <param name="initializationData">initialization data</param>
 /// <returns>The constructed <see cref="StatefulServiceContext"/></returns>
 public static StatefulServiceContext Create(ICodePackageActivationContext codePackageActivationContext, string serviceTypeName, Uri serviceName, Guid partitionId, long replicaId, byte[] initializationData = null)
 {
     return(new StatefulServiceContext(
                new NodeContext("Node0", new NodeId(0, 1), 0, "NodeType1", "localhost"),
                codePackageActivationContext,
                serviceTypeName,
                serviceName,
                initializationData,
                partitionId,
                replicaId
                ));
 }
Ejemplo n.º 31
0
 public MockServiceContext(NodeContext nodeContext, ICodePackageActivationContext codePackageActivationContext,
     string serviceTypeName, Uri serviceName, byte[] initializationData, Guid partitionId,
     long replicaOrInstanceId)
     : base(
         nodeContext,
         codePackageActivationContext,
         serviceTypeName,
         serviceName,
         initializationData,
         partitionId,
         replicaOrInstanceId)
 {
 }
 /// <summary>
 /// Adding this method to support DI/Testing 
 /// We need to do some work to create the actor object and make sure it is constructed completely
 /// In local testing we can inject the components we need, but in a real cluster
 /// those items are not established until the actor object is activated. Thus we need to 
 /// have this method so that the tests can have the same init path as the actor would in prod
 /// </summary>
 /// <returns></returns>
 public async Task InternalActivateAsync(ICodePackageActivationContext context, IServiceProxyFactory proxyFactory)
 {
     this.tokenSource = new CancellationTokenSource();
     this.builder = new ServiceUriBuilder(context, InventoryServiceName);
     this.ServiceProxyFactory = proxyFactory;
 }
 public ServiceUriBuilder(ICodePackageActivationContext context, string applicationInstance, string serviceInstance)
 {
     this.ActivationContext = context;
     this.ApplicationInstance = applicationInstance;
     this.ServiceInstance = serviceInstance;
 }