public async Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var key = GetKeyName(grainType, grainReference);

            try {
                if (this.logger.IsEnabled(LogLevel.Trace))
                {
                    this.logger.Trace((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_ClearingData, "Clearing: GrainType={0} Grainid={1} ETag={2} in Container={3}", grainType, grainReference, grainState.ETag, name);
                }
                await etcdClient.DeleteAsync(key).ConfigureAwait(false);

                grainState.ETag = null;

                if (this.logger.IsEnabled(LogLevel.Trace))
                {
                    this.logger.Trace((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_Cleared, "Cleared: GrainType={0} Grainid={1} ETag={2} in Container={3}", grainType, grainReference, grainState.ETag, name);
                }
            }
            catch (Exception ex)
            {
                logger.Error((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_ClearingError,
                             string.Format("Error clearing: GrainType={0} Grainid={1} ETag={2} in Container={3} Exception={4}", grainType, grainReference, key, name, ex.Message),
                             ex);

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 下线退出
        /// </summary>
        /// <returns></returns>
        private static async Task ExitCommand()
        {
            if (m_client != null)
            {
                string path = $"Client/{m_ClientName}";

                await m_client.DeleteAsync(path);

                await m_client.PutAsync(path, "OffLine");

                await OutputOnlineState();

                m_client.Dispose();
                m_client = null;

                Console.WriteLine($"{m_ClientName}已经关闭");
            }
        }
Ejemplo n.º 3
0
        public async Task GetEtcdProviderData_Languages_ReturnsMockLanguages()
        {
            // Arrange
            const string key = "languages";
            await _etcdClient.DeleteAsync(key);

            await WriteToEtcdAsync("languages.json", key);

            var languages = await ReadLanguageFromEtcdAsync(key);

            var dataRetriever = _serviceProvider.GetRequiredService <IDataRetriever <IEnumerable <MockLanguage> > >();

            // Act
            var actualData = await dataRetriever.GetAsync();

            // Assert
            Assert.NotNull(actualData);
            Assert.Equal(languages.Select(l => l.Alpha2Code), actualData.Select(l => l.Alpha2Code));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Remove a configuration record from the repository by folder and id
        /// </summary>
        /// <param name="folderPath">Folder of configuration record</param>
        /// <param name="id">Id of the configuration record</param>
        public virtual async Task Remove(string folderPath, TKey id)
        {
            if (id.Equals(default(TKey)))
            {
                throw new ArgumentNullException(nameof(id));
            }
            //Ensure the repository is initialised before retreiving item
            await _readyTask.ConfigureAwait(false);

            //Delete the item from the repository
            await _etcdClient.DeleteAsync(CreateEtcdKey(folderPath, id)).ConfigureAwait(false);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            IList <string> uriList     = new List <string>();
            var            controllers = Assembly.GetExecutingAssembly().GetTypes()
                                         .Where(type => typeof(ControllerBase).IsAssignableFrom(type));
            Type routeType = typeof(RouteAttribute);

            foreach (var item in controllers)
            {
                string routeName = string.Empty;
                var    route     = item.CustomAttributes.Where(type => type.AttributeType.IsAssignableFrom(routeType));
                if (route.Count() > 0)
                {
                    routeName = route?.FirstOrDefault()?.ConstructorArguments?.FirstOrDefault().Value.ToString();
                    int inde = routeName.IndexOf("[");
                    routeName = routeName.Substring(0, inde);
                }
                string contName = item.Name.Replace("Controller", string.Empty);
                uriList.Add($"{contName}#{routeName}{contName}");
            }
            string host   = "127.0.0.1";
            int    port   = 2379;
            string putKey = "/test/{0}#{1}";

            using (EtcdClient etcd = new EtcdClient(host, port))
            {
                foreach (var item in uriList)
                {
                    string[] uridata = item.Split('#');
                    etcd.PutAsync(string.Format(putKey, uridata[0], uri.Authority).ToLower(), $"{uri.ToString()}{uridata[1]}");
                }
            }
            lifetime.ApplicationStopped.Register(() =>
            {
                using (EtcdClient etcd = new EtcdClient(host, port))
                {
                    foreach (var item in uriList)
                    {
                        string[] uridata = item.Split('#');
                        etcd.DeleteAsync(string.Format(putKey, uridata[0], uri.Authority).ToLower());
                    }
                }
            });
            app.UseMvc();
        }