public void PerformAction(ContractAttribute attribute, bool inverse = false) { var money = GameStats.Instance.Money; money = money + attribute.GetModifiedValue(inverse); GameStats.Instance.ChangeValue(StatType.Money, money); }
public void ContractAttribute_contractInterfaceProperty_via_ctor() { Type expected = typeof(Object); ContractAttribute target = new ContractAttribute(expected); Assert.AreEqual <Type>(expected, target.ContractInterface); }
public void PerformAction(ContractAttribute attribute, bool inverse = false) { var time = GameStats.Instance.TimePerContract; time = time + (attribute.GetModifiedValue(inverse) * time); GameStats.Instance.ChangeValue(StatType.TimePerContract, time); }
public void PerformAction(ContractAttribute attribute, bool inverse = false) { var goodMultiplier = GameStats.Instance.GoodMultiplier; var amountChange = goodMultiplier * (attribute.GetModifiedValue(inverse) / 100); goodMultiplier = goodMultiplier + amountChange; GameStats.Instance.ChangeValue(StatType.GoodMultiplier, goodMultiplier); }
protected virtual void UpdateAttributeLocales(ContractAttribute contractAttribute, ContractAttributeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(contractAttribute, x => x.Name, localized.Name, localized.LanguageId); } }
public virtual void UpdateContractAttribute(ContractAttribute contractAttribute) { if (contractAttribute == null) { throw new ArgumentNullException(nameof(contractAttribute)); } _contractAttributeRepository.Update(contractAttribute); _cacheManager.RemoveByPattern(GSContractServiceDefaults.ContractAttributesPatternCacheKey); _cacheManager.RemoveByPattern(GSContractServiceDefaults.ContractAttributeValuesPatternCacheKey); _eventPublisher.EntityUpdated(contractAttribute); }
/// <summary> /// 扫描Contract特性的类,并创建实例。 /// </summary> /// <param name="dlls">指定的要被扫描的dll。</param> private void ScanContractAttribute(string[] dlls) { foreach (string dll in dlls) { Assembly assembly = Assembly.LoadFile(dll); Type[] types = assembly.GetTypes(); foreach (Type clazz in types) { if (clazz.IsClass) { //1.扫描类的Contract特性 //获取属性 Attribute attributeContractAttribute = clazz.GetCustomAttribute(typeof(ContractAttribute)); if (attributeContractAttribute == null)//如果该类没有Contract特性 { continue; } ContractAttribute contractAttribute = (ContractAttribute)attributeContractAttribute; string contractName = clazz.Name.Substring(0, 1).ToLower() + (clazz.Name.Length > 1 ? clazz.Name.Substring(1) : string.Empty); if (!string.IsNullOrWhiteSpace(contractAttribute.Name))//如果设置了ContractAttribute的Name值 { contractName = contractAttribute.Name; } if (BeanContainer.ContainsKey(contractName)) { throw new BeanCreationException(string.Format("不能创建‘{0}’,已经存在该实例。", contractName)); } //添加实例到容器中 object clazzInstance = Activator.CreateInstance(clazz);//创建类的实例 BeanContainer.Add(contractName, new BeanInfo() { Bean = clazzInstance, AtrributeType = AtrributeType.Contract }); } //end : if (clazz.IsClass) } //end : foreach (Type clazz in types) } //end : foreach (string dll in dlls) }
public virtual ContractAttributeModel PrepareContractAttributeModel(ContractAttributeModel model, ContractAttribute contractAttribute, bool excludeProperties = false) { Action <ContractAttributeLocalizedModel, int> localizedModelConfiguration = null; if (contractAttribute != null) { model = model ?? contractAttribute.ToModel <ContractAttributeModel>(); PrepareContractAttributeValueSearchModel(model.ContractAttributeValueSearchModel, contractAttribute); localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(contractAttribute, entity => entity.Name, languageId, false, false); }; } if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
public void ContractAttribute_ctor_argumentNullException_on_null_contract() { ContractAttribute target = new ContractAttribute(null); }
public void ContractAttribute_ctor() { ContractAttribute target = new ContractAttribute(typeof(Object)); Assert.IsNotNull(target); }
public void ContractAttribute_default_ctor() { var target = new ContractAttribute(); Assert.IsNotNull(target); }
protected virtual ContractAttributeValueSearchModel PrepareContractAttributeValueSearchModel(ContractAttributeValueSearchModel searchModel, ContractAttribute contractAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (contractAttribute == null) { throw new ArgumentNullException(nameof(contractAttribute)); } searchModel.ContractAttributeId = contractAttribute.Id; searchModel.SetGridPageSize(); return(searchModel); }
public virtual ContractAttributeValueListModel PrepareContractAttributeValueListModel(ContractAttributeValueSearchModel searchModel, ContractAttribute contractAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (contractAttribute == null) { throw new ArgumentNullException(nameof(contractAttribute)); } var contractAttributeValues = _contractAttributeService.GetContractAttributeValues(contractAttribute.Id); var model = new ContractAttributeValueListModel { Data = contractAttributeValues.PaginationByRequestModel(searchModel) .Select(value => value.ToModel <ContractAttributeValueModel>()), Total = contractAttributeValues.Count }; return(model); }
public void PerformAction(ContractAttribute attribute, bool inverse = false) { GameStats.Instance.UpdateContract(attribute.GetModifiedValueInt(inverse)); }
public void ContractAttribute_contractInterfaceProperty_via_default_ctor() { var target = new ContractAttribute(); Assert.IsNull(target.ContractInterface); }
/// <summary> /// 程序入口。 /// </summary> /// <param name="args"></param> static void Main(string[] args) { //启动容器 Container container = ContainerFactory.CreateContainer(); try { container.Start(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("按任意键退出。"); Console.ReadKey(); return; } WcfConfig config = null; if (!File.Exists("WcfConfig.xml")) { Console.WriteLine("找不到指定的文件WcfConfig.xml。"); return; } try { string xml = File.ReadAllText("WcfConfig.xml"); config = XmlSerializeUtil.XmlStringToObject <WcfConfig>(xml); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("按任意键退出。"); Console.ReadKey(); return; } if (config == null) { Console.WriteLine("WcfConfig.xml内容不合法。"); return; } if (string.IsNullOrWhiteSpace(config.BindingType)) { Console.WriteLine("WcfConfig.xml的BindingType节点的值不合法。"); return; } if (!"WebHttpBinding".Equals(config.BindingType) && !"BasicHttpBinding".Equals(config.BindingType) && !"NetTcpBinding".Equals(config.BindingType)) { Console.WriteLine("WcfConfig.xml的BindingType节点的值不合法。"); return; } #region 读取dll中的服务 //从dll文件中获取服务 string pathBusiness = @"./business/"; string[] files = Directory.GetFiles(pathBusiness, "*.dll"); foreach (string file in files) { try { Assembly assembly = Assembly.LoadFrom(file);//加载dll if (assembly != null) { Type[] classes = assembly.GetTypes(); //从dll中获取class foreach (Type type in classes) //遍历classes中实现了接口的class { if (type.IsClass && !type.IsAbstract) { Type[] interfaces = type.GetInterfaces(); foreach (Type t in interfaces)//遍历interfaces中有ServiceContract特性的interface { object[] attrsContract = t.GetCustomAttributes(typeof(ServiceContractAttribute), false); if (attrsContract != null && attrsContract.Length > 0) { ServiceInfo si = new ServiceInfo { ServiceName = type.Name, ServiceDll = type.Assembly.ManifestModule.Name, ServiceType = type, ContractType = t, ContractName = t.Name, ContractDll = t.Assembly.ManifestModule.Name, }; try { Attribute attributeContractAttribute = type.GetCustomAttribute(typeof(ContractAttribute)); if (attributeContractAttribute == null) { //si.Host = new ServiceHost(type); continue; } else { ContractAttribute contractAttribute = (ContractAttribute)attributeContractAttribute; string beanName = type.Name.Substring(0, 1).ToLower() + (type.Name.Length > 1 ? type.Name.Substring(1) : string.Empty); if (!string.IsNullOrWhiteSpace(contractAttribute.Name)) { beanName = contractAttribute.Name; } if (Container.BeanContainer.ContainsKey(beanName)) { if ("BasicHttpBinding".Equals(config.BindingType))//当协议类型为BasicHttpBinding时,创建Host实例需指定基地址。 { Uri baseAddress = new Uri(string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + t.Name.Substring(1)); si.Host = new ServiceHost(Container.BeanContainer[beanName].Bean, baseAddress); } else { si.Host = new ServiceHost(Container.BeanContainer[beanName].Bean); } } else { continue; } } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } wcfServers.Add(si.ServiceName, si); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } #endregion #region 设置Host foreach (KeyValuePair <string, ServiceInfo> kv in wcfServers) { kv.Value.Host.Opened += Host_Opened; kv.Value.Host.Closed += Host_Closed; if ("WebHttpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new WebHttpBinding() { CrossDomainScriptAccessEnabled = config.WebHttpBinding.CrossDomainScriptAccessEnabled, MaxReceivedMessageSize = config.WebHttpBinding.MaxReceivedMessageSize, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); se.Behaviors.Add(new WebHttpBehavior() { HelpEnabled = true, DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json, DefaultBodyStyle = WebMessageBodyStyle.Wrapped }); kv.Value.Host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute { RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed }); } else if ("BasicHttpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new BasicHttpBinding() { AllowCookies = config.BasicHttpBinding.AllowCookies, CloseTimeout = new TimeSpan(config.BasicHttpBinding.CloseTimeout * 10000000), OpenTimeout = new TimeSpan(config.BasicHttpBinding.OpenTimeout * 10000000), SendTimeout = new TimeSpan(config.BasicHttpBinding.SendTimeout * 10000000), ReceiveTimeout = new TimeSpan(config.BasicHttpBinding.ReceiveTimeout * 10000000), BypassProxyOnLocal = config.BasicHttpBinding.BypassProxyOnLocal, HostNameComparisonMode = HostNameComparisonMode.StrongWildcard, MaxBufferPoolSize = config.BasicHttpBinding.MaxBufferPoolSize, MaxReceivedMessageSize = config.BasicHttpBinding.MaxReceivedMessageSize, MessageEncoding = WSMessageEncoding.Text, TextEncoding = Encoding.GetEncoding(config.BasicHttpBinding.TextEncoding), UseDefaultWebProxy = config.BasicHttpBinding.UseDefaultWebProxy, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); } else if ("NetTcpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new NetTcpBinding(SecurityMode.None) { CloseTimeout = new TimeSpan(config.NetTcpBinding.CloseTimeout * 10000000), OpenTimeout = new TimeSpan(config.NetTcpBinding.OpenTimeout * 10000000), SendTimeout = new TimeSpan(config.NetTcpBinding.SendTimeout * 10000000), ReceiveTimeout = new TimeSpan(config.NetTcpBinding.ReceiveTimeout * 10000000), TransferMode = TransferMode.StreamedResponse, TransactionProtocol = TransactionProtocol.OleTransactions, TransactionFlow = config.NetTcpBinding.TransactionFlow, HostNameComparisonMode = HostNameComparisonMode.StrongWildcard, MaxBufferPoolSize = config.NetTcpBinding.MaxBufferPoolSize, MaxReceivedMessageSize = config.NetTcpBinding.MaxReceivedMessageSize, MaxBufferSize = config.NetTcpBinding.MaxBufferSize, ListenBacklog = config.NetTcpBinding.ListenBacklog, MaxConnections = config.NetTcpBinding.MaxConnections, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("net.tcp://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); } //设置默认服务实例及运行线程 ServiceBehaviorAttribute serviceBehavior = kv.Value.Host.Description.Behaviors.Find <ServiceBehaviorAttribute>(); if (null == serviceBehavior) { serviceBehavior = new ServiceBehaviorAttribute { InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Multiple }; kv.Value.Host.Description.Behaviors.Add(serviceBehavior); } serviceBehavior.InstanceContextMode = InstanceContextMode.Single; serviceBehavior.UseSynchronizationContext = false; serviceBehavior.ConcurrencyMode = ConcurrencyMode.Multiple; ServiceThrottlingBehavior throttle = kv.Value.Host.Description.Behaviors.Find <ServiceThrottlingBehavior>(); if (throttle == null) { throttle = new ServiceThrottlingBehavior(); throttle.MaxConcurrentCalls = 2147483647; throttle.MaxConcurrentSessions = 2147483647; throttle.MaxConcurrentInstances = 2147483647; kv.Value.Host.Description.Behaviors.Add(throttle); } kv.Value.Host.Open(); } Console.WriteLine("按下任意键退出服务!"); Console.ReadKey(); foreach (KeyValuePair <string, ServiceInfo> kv in wcfServers) { if (kv.Value.Host.State == CommunicationState.Opened) { kv.Value.Host.Close(); } } #endregion Console.WriteLine("正在退出..."); System.Threading.Thread.Sleep(1000); }
public virtual ContractAttributeValueModel PrepareContractAttributeValueModel(ContractAttributeValueModel model, ContractAttribute contractAttribute, ContractAttributeValue contractAttributeValue, bool excludeProperties = false) { if (contractAttribute == null) { throw new ArgumentNullException(nameof(contractAttribute)); } Action <ContractAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (contractAttributeValue != null) { model = model ?? contractAttributeValue.ToModel <ContractAttributeValueModel>(); localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(contractAttributeValue, entity => entity.Name, languageId, false, false); }; } model.ContractAttributeId = contractAttribute.Id; if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }