예제 #1
0
		/// 
		public virtual void inject2Store(string fileName, DisconfValue disconfValue)
		{

			DisconfCenterFile disconfCenterFile = Instance.ConfFileMap.get(fileName);

			// 校验是否存在
			if (disconfCenterFile == null)
			{
				LOGGER.error("cannot find " + fileName + " in store....");
				return;
			}

			if (disconfValue == null || disconfValue.FileData == null)
			{
				LOGGER.error("value is null for {}", fileName);
				return;
			}

			// 存储
			IDictionary<string, DisconfCenterFile.FileItemValue> keMap = disconfCenterFile.KeyMaps;
			if (keMap.Count > 0)
			{
				foreach (string fileItem in keMap.Keys)
				{

					object @object = disconfValue.FileData[fileItem];
					if (@object == null)
					{
						LOGGER.error("cannot find {} to be injected. file content is: {}", fileItem, disconfValue.FileData.ToString());
						continue;
					}

					// 根据类型设置值
					try
					{

						object value = keMap[fileItem].getFieldValueByType(@object);
						keMap[fileItem].Value = value;

					}
					catch (Exception e)
					{
						LOGGER.error("inject2Store filename: " + fileName + " " + e.ToString(), e);
					}
				}
			}

			// 注解式
			if (disconfCenterFile.TaggedWithNonAnnotationFile)
			{

				//
				// 非注解式 或者 注解式的域集合为空,则将 文件内容写到配置库里
				//

				if (disconfCenterFile.Object == null && disconfCenterFile.SupportFileTypeEnum.Equals(SupportFileTypeEnum.PROPERTIES))
				{
					// 如果是采用XML进行配置的,则需要利用spring的reload将数据reload到bean里
					ReloadConfigurationMonitor.reload();
				}
				disconfCenterFile.AdditionalKeyMaps = disconfValue.FileData;
			}
		}
예제 #2
0
		/// 
		public virtual void inject2Store(string key, DisconfValue disconfValue)
		{

			DisconfCenterItem disconfCenterItem = DisconfCenterStore.Instance.ConfItemMap[key];

			// 校验是否存在
			if (disconfCenterItem == null)
			{
				LOGGER.error("cannot find " + key + " in store....");
				return;
			}

			if (disconfValue == null || string.ReferenceEquals(disconfValue.Value, null))
			{
				return;
			}

			// 根据类型设置值
			//
			// 注入仓库
			//
			try
			{

				object newValue = disconfCenterItem.getFieldValueByType(disconfValue.Value);
				disconfCenterItem.Value = newValue;

			}
			catch (Exception e)
			{
				LOGGER.error("key: " + key + " " + e.ToString(), e);
			}

		}