示例#1
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);
        }
 private void OnContextOnConfigurationPackageAddedEvent(
     object sender,
     PackageAddedEventArgs <ConfigurationPackage> args)
 {
     this.OnConfigPackageAdded.NotifyAsync(
         this,
         new ServiceEventPayloadOnPackageAdded <ConfigurationPackage>(args.Package))
     .GetAwaiter()
     .GetResult();
 }
示例#3
0
        private void CodePackageActivationContext_ConfigurationPackageAddedEvent(object sender,
                                                                                 PackageAddedEventArgs <ConfigurationPackage> e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            ReadSettings(e.Package);
        }
        /// <summary>
        /// Called when a new configuration package has been added during a deployment.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">PackageAddedEventArgs&lt;ConfigurationPackage&gt; instance.</param>
        void ConfigurationPackageAdded(object sender, PackageAddedEventArgs <ConfigurationPackage> e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // Attempt to load the configuration.
            this.LoadConfiguration(e.Package.Path, e.Package.Settings.Sections);
        }
        /// <summary>
        /// ConfigurationProvider constructor.
        /// </summary>
        /// <param name="traceId">A unique identifier used to correlate debugging and diagnostics messages.</param>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="context">CodePackageActivationContext instance.</param>
        /// <param name="logger">IServiceEventSource instance for logging.</param>
        /// <param name="configurationName">The name of the configuration to load. This will be appended to the name of the service when looking for the file (e.g. FrontEnd.Name.json)</param>
        public ConfigurationProvider(Guid traceId, Uri serviceName, ICodePackageActivationContext context, IServiceLogger logger, string configurationName = null)
        {
            if (serviceName == null)
            {
                throw new ArgumentNullException(nameof(serviceName));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Verbose(traceId, ComponentName, "Initializing.");

            this.serviceNameUri    = serviceName;
            this.serviceName       = this.serviceNameUri.Segments[this.serviceNameUri.Segments.Length - 1];
            this.logger            = logger;
            this.ConfigurationName = configurationName;

            // Subscribe to configuration change events if the context was passed. It will not be passed for unit tests.
            context.ConfigurationPackageAddedEvent    += this.ConfigurationPackageAdded;
            context.ConfigurationPackageModifiedEvent += this.ConfigurationPackageModified;
            context.ConfigurationPackageRemovedEvent  += this.ConfigurationPackageRemoved;

            // Create the add event parameters and call.
            var packageEvent = new PackageAddedEventArgs <ConfigurationPackage>
            {
                Package = context.GetConfigurationPackageObject(ConfigurationPackageObjectName)
            };

            this.ConfigurationPackageAdded(null, packageEvent);

            logger.Verbose(traceId, ComponentName, "Finished initializing.");
        }
示例#6
0
        /// <summary>
        /// Called when a new configuration package has been added during a deployment.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">PackageAddedEventArgs&lt;ConfigurationPackage&gt; instance.</param>
        private void CodePackageActivationContext_ConfigurationPackageAddedEvent(object sender, PackageAddedEventArgs <ConfigurationPackage> e)
        {
            Guard.ArgumentNotNull(e, nameof(e));

            // Attempt to load the configuration.
            LoadConfiguration(e.Package.Path, e.Package.Settings.Sections);
        }
示例#7
0
 private void ConfigurationPackageAddedEvent(object sender, PackageAddedEventArgs <ConfigurationPackage> e)
 {
     DumpConfiguration(ConfigurationPackageEvent.Added, e.Package);
 }
示例#8
0
 public void OnDataPackageAddedEvent(PackageAddedEventArgs <DataPackage> e)
 {
     DataPackageAddedEvent?.Invoke(this, e);
 }
示例#9
0
 public void OnConfigurationPackageAddedEvent(PackageAddedEventArgs <ConfigurationPackage> e)
 {
     ConfigurationPackageAddedEvent?.Invoke(this, e);
 }
示例#10
0
 public void OnCodePackageAddedEvent(PackageAddedEventArgs <CodePackage> e)
 {
     CodePackageAddedEvent?.Invoke(this, e);
 }
        private void CodePackageActivationContext_ConfigurationPackageAddedEvent(object sender, PackageAddedEventArgs <ConfigurationPackage> e)
        {
            try
            {
                // Create diagnostic pipeline
                diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("LongRunningActors-EventCollectorService-DiagnosticsPipeline");

                // Log success
                ServiceEventSource.Current.Message("Diagnostics Pipeline successfully created.");
            }
            catch (Exception ex)
            {
                // Log exception
                ServiceEventSource.Current.Error(ex);
            }
        }