Esempio n. 1
0
		private void UpdateOption(OptionDefType option)
		{

			string value = string.Empty;
			try
			{
				if (option.Encrypted)
				{
					value = OptionApi.GetEncrypted(option.Name, _entropy);
				}
				else
				{
					value = OptionApi.GetString(option.Name);
				}
			}
			catch (Exception ex)
			{
				Logger.LogError(ex);
			}

			option.Text = new string[] { value };

			bool bAllowOverride = true;
			try
			{
				bAllowOverride = OptionApi.AllowUserOverride(option.Name);
			}
			catch (Exception ex)
			{
				Logger.LogError(ex);
			}
			option.IsOverrideAllowed = bAllowOverride;

		}
		private OptionDefType InitialiseEncryptedOptionPrivately(OptionDefType op, string optionGroupName, string groupInstanceName)
		{
			op.Encrypted = true;
			op.EncryptedSpecified = true;
			op.DataType = OptionDataTypeEnum.String;
			op.DataTypeSpecified = true;
			op.Text = new string[] { OptionApi.GetEncrypted(optionGroupName, groupInstanceName, op.Name, _entropy) };

			return op;
		}
Esempio n. 3
0
		void IVisitor.Visit(OptionDefType option)
		{
		}
Esempio n. 4
0
		private static Dictionary<int, string> GetEnumValues(OptionDefType uiOption)
		{
			string rangeText = uiOption.ValueRange;
			if (string.IsNullOrEmpty(rangeText))
			{
				return null;
			}

			string[] values = rangeText.Split(',');
			var result = new Dictionary<int, string>();
			foreach (string s in values)
			{
				string[] bits = s.Split(new[] {'='}, 2);
				int val;
				if (Int32.TryParse(bits[0], out val))
				{
					result.Add(val, bits[1]);
				}
			}
			return result;
		}
Esempio n. 5
0
		private static IOption CreateShellOptionInternal(Category shellSubCategory, OptionDefType uiOption,
		                                                 string defaultValue)
		{
			IOption shellOption = null;
			string s = !string.IsNullOrEmpty(string.Concat(uiOption.Text)) ? string.Concat(uiOption.Text) : defaultValue;

			if (string.IsNullOrEmpty(s))
			{
				s = string.Empty;
			}

			bool canOverride = uiOption.IsOverrideAllowed;
			switch (uiOption.DataType)
			{
				case OptionDataTypeEnum.Boolean:
					{
						bool val = GetBool(s);
						shellOption = new BoolOption(uiOption.Name, val, val, canOverride)
						              	{
						              		DisplayName = uiOption.DisplayText,
						              		Description = uiOption.DisplayText,
						              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
						              		SubCategory = shellSubCategory
						              	};
						break;
					}
				case OptionDataTypeEnum.Integer:
					{
						int val = GetInt(s);
						shellOption = new IntegerOption(uiOption.Name, val, val, canOverride)
						              	{
						              		DisplayName = uiOption.DisplayText,
						              		Description = uiOption.DisplayText,
						              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
						              		SubCategory = shellSubCategory
						              	};
						break;
					}
				case OptionDataTypeEnum.String:
					{
						if (uiOption.Encrypted)
						{
							shellOption = new EncryptionOption(uiOption.Name, s, s, canOverride)
							              	{
							              		DisplayName = uiOption.DisplayText,
							              		Description = uiOption.DisplayText,
							              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
							              		SubCategory = shellSubCategory
							              	};
						}
						else
						{
							shellOption = new StringOption(uiOption.Name, s, s, canOverride)
							              	{
							              		DisplayName = uiOption.DisplayText,
							              		Description = uiOption.DisplayText,
							              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
							              		SubCategory = shellSubCategory,
							              		IsPrimaryKey = uiOption.IsPrimaryKey
							              	};
						}
						break;
					}
				case OptionDataTypeEnum.Color:
					{
						var val = GetColor(s);
						shellOption = new ColorOption(uiOption.Name, val, val, canOverride)
						              	{
						              		DisplayName = uiOption.DisplayText,
						              		Description = uiOption.DisplayText,
						              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
						              		SubCategory = shellSubCategory
						              	};
						break;
					}
				case OptionDataTypeEnum.KeyValueRange:
					{
						int val = GetInt(s);
						shellOption = new EnumOption(uiOption.Name, val, val, canOverride, GetEnumValues(uiOption))
						              	{
						              		DisplayName = uiOption.DisplayText,
						              		Description = uiOption.DisplayText,
						              		Category = shellSubCategory == null ? null : shellSubCategory.Parent,
						              		SubCategory = shellSubCategory
						              	};

						break;
					}
				case OptionDataTypeEnum.Format:
				case OptionDataTypeEnum.Range:
				default:
					{
						// do nothing. these need to be converted
#if DEBUG
						throw new NotImplementedException();
#else
						break;
#endif
					}
			}

			return shellOption;
		}
Esempio n. 6
0
		private static IOption CreateShellOption(Category shellSubCategory, OptionDefType uiOption)
		{
			return CreateShellOptionInternal(shellSubCategory, uiOption, GetDataTypeDefaultValue(uiOption.DataType));
		}
Esempio n. 7
0
		public static void SetValueRange(Category shellSubCategory, OptionGroupInstance shellOptionGroupInstance,
		                                 OptionDefType option, bool setDefaultValue)
		{
			Dictionary<string, string> attrs = OptionApi.GetAttributeList(GetOptionGroupTypeName(shellSubCategory),
			                                                              shellOptionGroupInstance.Name, option.Name);

			string valueRange = null;
			if (attrs.TryGetValue("ValueRange", out valueRange))
			{
				option.ValueRange = valueRange;

				string defaultValue = null;
				if (setDefaultValue && attrs.TryGetValue("DefaultValue", out defaultValue))
				{
					option.Text = new[] {defaultValue};
				}
			}
		}
Esempio n. 8
0
		void IVisitorWithContext.Visit(OptionDefType option, object context)
		{
			XmlNode optionGroupNode = (XmlNode) context;
			XmlNode optionNode = _xmlDoc.CreateNode(XmlNodeType.Element, option.Name, this._namespaceURI);

			VisitOptionDefType(option, optionNode);
			optionGroupNode.AppendChild(optionNode);
		}
		private void AddNewGroupInstance(UIOptionGroupType grpType, IEnumerable<OptionGroupInstance> vwInsts, out bool bAnyAdded)
        {
            Dictionary<string, OptionInfo> groupDefs = OptionApi.GetGroupDefinitions(grpType.Name);

			// Initially false until something is added.
			bAnyAdded = false;

			foreach (OptionGroupInstance vwInst in vwInsts)
            {
				if (_bDeploymentIconOnly && !vwInst.Deploy)
				{
					// The user has chosen "Deployment icons only" but this option
					// doesn't have a deployment icon.
					continue;
				}

				// By arriving at this point we know that something has been added.
				bAnyAdded = true;

                var groupInstType = new UIOptionGroupInstanceType()
                {
                    Name = vwInst.Name,
                    DisplayText = vwInst.DisplayName,
					Deploy = vwInst.Deploy
                };

                List<OptionDefType> optDefs = new List<OptionDefType>();
                foreach (IOption opt in vwInst.SubOptions)
                {
                    var optdef = new OptionDefType()
                    {
                        Name = opt.Name,
                        DisplayText = opt.DisplayName,
                    };


                    optdef.DataType = ConvertDataType(opt.DataType);

                    if (optdef.Name == "Password")
                    {
                        optdef.Encrypted = true;
						optdef.EncryptedSpecified = true;
						optdef.DataType = OptionDataTypeEnum.String;
						optdef.DataTypeSpecified = true;
					}

                    optdef.Text = new string[] { opt.StringValue };

                    OptionInfo optInfo = (from oi in groupDefs.Values
                                          where oi.Name.Equals(optdef.Name, StringComparison.InvariantCultureIgnoreCase)
                                          select oi).FirstOrDefault();
                    if (optInfo != null)
                    {
                        optDefs.Add(optdef);
                    }
                }
                groupInstType.OptionDef = optDefs.ToArray();
                grpType.OptionGroupInstances.Add(groupInstType);
            }
        }
 public void Visit(OptionDefType option)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
		private void VisitOptionDefType(OptionDefType option, object context)
		{
			VisitOptionBaseType(option, context);

			XmlNode optionNode = (XmlNode) context;
			option.Text = new string[] { optionNode.InnerText };

			XmlAttribute readOnly = optionNode.Attributes["ReadOnly"];
			if (readOnly != null)
			{
				option.ReadOnly = Boolean.Parse(readOnly.Value);
				option.ReadOnlySpecified = true;
			}

			XmlAttribute rangeMin = optionNode.Attributes["RangeMin"];
			if (rangeMin != null)
			{
				option.RangeMin = Decimal.Parse(rangeMin.Value);
				option.RangeMinSpecified = true;
			}

			XmlAttribute rangeMax = optionNode.Attributes["RangeMax"];
			if (rangeMax != null)
			{
				option.RangeMax = Decimal.Parse(rangeMax.Value);
				option.RangeMaxSpecified = true;
			}

			XmlAttribute noDefaultValue = optionNode.Attributes["NoDefaultValue"];
			if (noDefaultValue != null)
			{
				option.NoDefaultValue = Boolean.Parse(noDefaultValue.Value);
				option.NoDefaultValueSpecified = true;
			}

			XmlAttribute dataType = optionNode.Attributes["DataType"];
			if (dataType != null)
			{
				option.DataType = (OptionDataTypeEnum) Enum.Parse(typeof(OptionDataTypeEnum), dataType.Value);
				option.DataTypeSpecified = true;
			}

			XmlAttribute isEncrypted = optionNode.Attributes["Encrypted"];
			if (isEncrypted != null)
			{
				option.Encrypted = Boolean.Parse(isEncrypted.Value);
				option.EncryptedSpecified = true;
			}

			XmlAttribute valueRange = optionNode.Attributes["ValueRange"];
			if (valueRange != null)
			{
				option.ValueRange = valueRange.Value;
			}

			XmlAttribute isPrimaryKey = optionNode.Attributes["IsPrimaryKey"];
			if (isPrimaryKey != null)
			{
				option.IsPrimaryKey = Boolean.Parse(isPrimaryKey.Value);
			}
		}
Esempio n. 12
0
		void IVisitorWithContext.Visit(UIOptionGroupInstanceType optionGroupInstance, object context)
		{
			XmlNode optionGroupNode = (XmlNode) context;

			List<OptionDefType> optionDefs = new List<OptionDefType>();
			foreach (XmlNode node in optionGroupNode.ChildNodes)
			{
				if (node.NodeType == XmlNodeType.Comment)
					continue;

				OptionDefType option = new OptionDefType();
				optionDefs.Add(option);
				option.Accept(this, node);
			}

			optionGroupInstance.OptionDef = new OptionDefType[optionDefs.Count];

			Array.Copy(optionDefs.ToArray(), optionGroupInstance.OptionDef, optionDefs.Count);
		}
Esempio n. 13
0
		void IVisitorWithContext.Visit(OptionDefType option, object context)
		{
			VisitOptionDefType(option, context);
		}
Esempio n. 14
0
		void IVisitor.Visit(OptionDefType option)
		{
			// Create the option def for option group

			_admFileWriter.StartPolicy(option.DisplayText);
			_admFileWriter.StartKeyName(this._optionGroupLocation);

			string value = String.Concat(option.Text);
			if (option.Encrypted)
			{
				if (String.IsNullOrWhiteSpace(_optionGroupInstance) || String.IsNullOrWhiteSpace(_optionGroupType))
				{
					value = Workshare.Interop.Options.OptionApi.GetProcessedString(option.Name, value, _entropy);
				}
				else
				{
					value = Workshare.Interop.Options.OptionApi.GetProcessedString(_optionGroupType, _optionGroupInstance, option.Name, value, _entropy);
				}
			}

			_admFileWriter.AddPart(option.DisplayText, option.DataType, option.Name, value);
			_admFileWriter.EndPolicy();

		}
Esempio n. 15
0
		void IVisitorWithContext.Visit(UIOptionGroupInstanceType optionGroupInstance, object context)
		{
			XmlNode optionGroupInstanceNode = (XmlNode) context;

			optionGroupInstance.Name = optionGroupInstanceNode.Name;
			List<OptionDefType> optionDefs = new List<OptionDefType>();
			foreach (XmlNode node in optionGroupInstanceNode.ChildNodes)
			{
				OptionDefType option = new OptionDefType();
				optionDefs.Add(option);
				option.Accept(this, node);
			}

			XmlAttribute Deploy = optionGroupInstanceNode.Attributes["Deployed"];
			if (Deploy != null)
			{
				optionGroupInstance.Deploy = Boolean.Parse(Deploy.Value);
			}

			optionGroupInstance.OptionDef = new OptionDefType[optionDefs.Count];

			Array.Copy(optionDefs.ToArray(), optionGroupInstance.OptionDef, optionDefs.Count);
		}
Esempio n. 16
0
		void IVisitor.Visit(OptionDefType option)
		{
			string value = String.Concat(option.Text);
			if (option.Encrypted)
			{
				if (String.IsNullOrWhiteSpace(_optionGroupInstance) || String.IsNullOrWhiteSpace(_optionGroupType))
				{
					value = Workshare.Interop.Options.OptionApi.GetProcessedString(option.Name, value, _entropy);
				}
				else
				{
					value = Workshare.Interop.Options.OptionApi.GetProcessedString(_optionGroupType, _optionGroupInstance, option.Name, value, _entropy);
				}
			}

			_regFileWriter.WriteValue(option.Name, value);
		}
 public void Visit(OptionDefType option, object context)
 {
 }
        public void Visit(UIOptionGroupType optionGroup)
        {
            if (_bAdmin)
            {
                return;
            }
            /// Go through registry and construct group instances
            ReadOnlyCollection<string> groupInstArray = OptionApi.GetOptionGroups(optionGroup.Name);
     
            Dictionary<string, OptionInfo> groupDefs = OptionApi.GetGroupDefinitions(optionGroup.Name);
            foreach (string groupInstName in groupInstArray)
            {   
                Dictionary<string, OptionInfo> groupInstData = OptionApi.GetOptionGroupData(optionGroup.Name, groupInstName);

                UIOptionGroupInstanceType groupInst = new UIOptionGroupInstanceType() { Name = groupInstName };
                List<OptionDefType> deftypes = new List<OptionDefType>();

                foreach (OptionInfo optinfo in groupDefs.Values)
                {
                    var op = new OptionDefType
                    {
                        Name = optinfo.Name,                        
                        DisplayText = optinfo.DisplayText,
                    };

                    op.IsPrimaryKey = Boolean.Parse(optinfo.GetAttribute("IsPrimaryKey"));

                    OptionDataTypeEnum dt;

                    if (Enum.TryParse(optinfo.DataType, true, out dt))
                    {
                        op.DataType = dt;
                        op.DataTypeSpecified = true;    /// This is required to be set :(, as we are checking this attributes :(, don't like it.
                    }

                    if (op.Name == "Password")
                    {
						op = InitialiseEncryptedOptionPrivately(op, optionGroup.Name, groupInstName);
                    }
                    else
                    {
                        OptionInfo datainfo;
                        if (groupInstData.TryGetValue(optinfo.Name, out datainfo))
                        {
                            op.Text = new string[] { datainfo.Value };
                            op.IsOverrideAllowed = datainfo.CanOverride;
                        }
                        else
                        {
                            op.Text = new string[] { optinfo.Value };   // default value
                            op.IsOverrideAllowed = optinfo.CanOverride;
                        }
                    }

                    deftypes.Add(op);
                }

                groupInst.OptionDef = deftypes.ToArray();
                optionGroup.OptionGroupInstances.Add(groupInst);
            }
        }
Esempio n. 19
0
 void IVisitor.Visit(OptionDefType option)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
		private void VisitOptionDefType(OptionDefType option, object context)
		{
			VisitOptionBaseType(option, context);

			XmlNode optionNode = (XmlNode) context;
			string optionValue = String.Concat(option.Text);

			if (option.EncryptedSpecified)
			{
				XmlAttribute isEncrypted = _xmlDoc.CreateAttribute("Encrypted");
				isEncrypted.Value = option.Encrypted.ToString();
				optionNode.Attributes.Append(isEncrypted);
			}

			if (option.ReadOnlySpecified)
			{
				XmlAttribute isReadOnly = _xmlDoc.CreateAttribute("ReadOnly");
				isReadOnly.Value = option.ReadOnly.ToString();
				optionNode.Attributes.Append(isReadOnly);
			}

			if (option.RangeMinSpecified)
			{
				XmlAttribute rangeMin = _xmlDoc.CreateAttribute("RangeMin");
				rangeMin.Value = option.RangeMin.ToString();
				optionNode.Attributes.Append(rangeMin);
			}

			if (option.RangeMaxSpecified)
			{
				XmlAttribute rangeMax = _xmlDoc.CreateAttribute("RangeMax");
				rangeMax.Value = option.RangeMax.ToString();
				optionNode.Attributes.Append(rangeMax);
			}

			if (option.NoDefaultValueSpecified)
			{
				XmlAttribute noDefaultValue = _xmlDoc.CreateAttribute("NoDefaultValue");
				noDefaultValue.Value = option.NoDefaultValue.ToString();
				optionNode.Attributes.Append(noDefaultValue);
			}

			if (!string.IsNullOrEmpty(option.ValueRange))
			{
				XmlAttribute valueRange = _xmlDoc.CreateAttribute("ValueRange");
				valueRange.Value = option.ValueRange;
				optionNode.Attributes.Append(valueRange);
			}

			XmlAttribute dataType = _xmlDoc.CreateAttribute("DataType");
			dataType.Value = option.DataType.ToString();
			optionNode.Attributes.Append(dataType);

			if (option.Encrypted)
			{
				if (String.IsNullOrWhiteSpace(_optionGroupInstance) || String.IsNullOrWhiteSpace(_optionGroupType))
				{
					optionNode.InnerText = Workshare.Interop.Options.OptionApi.GetProcessedString(optionNode.Name, optionValue, _entropy);
				}
				else
				{
					optionNode.InnerText = Workshare.Interop.Options.OptionApi.GetProcessedString(_optionGroupType, _optionGroupInstance, optionNode.Name, optionValue, _entropy);
				}
			}
			else
			{
				optionNode.InnerText = optionValue;
			}
		}