Пример #1
0
        /// <summary>
        /// Run the cache service verb.
        ///
        /// NOTE: Currently, this is highly reliant on being launched by the launcher.
        /// TODO: Add command line args with HostParameters and ServiceLifetime args so that
        /// this can be used standalone.
        /// </summary>
        public static async Task RunCacheServiceAsync(
            OperationContext context,
            string configurationPath,
            Func <HostParameters, DistributedCacheServiceConfiguration, CancellationToken, IDistributedCacheServiceHost> createHost,
            HostParameters hostParameters    = null,
            bool requireServiceInterruptable = true)
        {
            try
            {
                hostParameters ??= HostParameters.FromEnvironment();

                using var cancellableContext = new CancellableOperationContext(context, default(CancellationToken));
                context = cancellableContext;

                var config = LoadAndWatchPreprocessedConfig <DistributedCacheServiceConfiguration, DistributedCacheServiceConfiguration>(
                    context,
                    configurationPath,
                    hostParameters,
                    out var configHash,
                    c => c);

                await ServiceLifetimeManager.RunDeployedInterruptableServiceAsync(context, async token =>
                {
                    var hostInfo = new HostInfo(hostParameters.Stamp, hostParameters.Ring, new List <string>());

                    var host = createHost(hostParameters, config, token);

                    await DistributedCacheServiceFacade.RunWithConfigurationAsync(
                        logger: context.TracingContext.Logger,
                        host: host,
                        hostInfo: hostInfo,
                        telemetryFieldsProvider: new HostTelemetryFieldsProvider(hostParameters)
                    {
                        ConfigurationId = configHash
                    },
                        config,
                        token: token);;

                    return(BoolResult.Success);
                },
                                                                                  requireServiceInterruptionEnabled : requireServiceInterruptable).ThrowIfFailure();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        private static string ComputeKeySpace(HostInfo hostInfo, DistributedCacheServiceConfiguration configuration, string keyspace)
        {
            string keySpaceString = keyspace;

            if (!string.IsNullOrWhiteSpace(configuration.DistributedContentSettings.KeySpacePrefix))
            {
                keySpaceString = configuration.DistributedContentSettings.KeySpacePrefix + keySpaceString;
            }

            if (configuration.UseStampBasedIsolation)
            {
                keySpaceString = hostInfo.StampId + keySpaceString;
            }

            return(keySpaceString);
        }
        /// <inheritdoc />
        public DistributedCacheServiceArguments(
            ILogger logger,
            IAbsolutePathFileCopier copier,
            IAbsolutePathTransformer pathTransformer,
            IDistributedCacheServiceHost host,
            HostInfo hostInfo,
            CancellationToken cancellation,
            string dataRootPath,
            DistributedCacheServiceConfiguration configuration,
            string keyspace)
        {
            Logger          = logger;
            Copier          = copier;
            PathTransformer = pathTransformer;
            Host            = host;
            HostInfo        = hostInfo;
            Cancellation    = cancellation;
            DataRootPath    = dataRootPath;
            Configuration   = configuration;

            Keyspace = ComputeKeySpace(hostInfo, configuration, keyspace);
        }