public static string GetValue(this SmartProperty property, object value) { var stringValue = value.ToString(); if (string.IsNullOrEmpty(stringValue)) { return(string.Empty); } switch (property.Type) { case PropertyType.Date: // try default date conversion try { var date = DateTime.Parse(stringValue); return(date.ToString(DateFormat)); } // if fails then probably an excel date catch { var date = DateTime.FromOADate(Convert.ToDouble(value.ToString())); return(date.ToString(DateFormat)); } case PropertyType.DateTime: // try default date conversion try { var dateTime = DateTime.Parse(stringValue); return(dateTime.ToString($"{DateFormat} {TimeFormat}")); } // if fails then probably an excel date catch { var dateTime = DateTime.FromOADate(Convert.ToDouble(value.ToString())); return(dateTime.ToString($"{DateFormat} {TimeFormat}")); } case PropertyType.Time: // try default date conversion try { var time = DateTime.Parse(stringValue); return(time.ToString(TimeFormat)); } // if fails then probably an excel date catch { var time = DateTime.FromOADate(Convert.ToDouble(value.ToString())); return(time.ToString(TimeFormat)); } default: return(value.ToString()); } }
/// <summary> /// Returns the property's value converted to T. Used for when a different type is needed /// that the property has, for example a DateTime? when the property is of type DataTime. /// Properties can't have a type of DateTime? as Nullable types aren't supported in DataTables. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="smartProperty">The property.</param> /// <returns>The propertys' value converted to T.</returns> public static T GetValue <T>(SmartProperty smartProperty) { if (smartProperty == null) { throw new ArgumentNullException("smartProperty"); } TryConvert(typeof(T), smartProperty.Value, out object result); return((T)result); }
public void IsDistinctUntilChangedTrueCase() { var p = new SmartProperty <string>(null, true); var count = 0; p.PropertyChanged += (_, __) => count++; p.Value = "hello"; // raised p.Value = "hello"; // doesn't raise count.Is(1); }
public SmartProperty GetSmartProperty() { SmartProperty retVal = null; if (isSmart) { retVal = smartValue; } return(retVal); }
public void IsDistinctUntilChangedFalseCase() { var p = new SmartProperty <string>(null, false); var count = 0; p.PropertyChanged += (_, __) => count++; p.Value = "hello"; // raised p.Value = "hello"; // raised count.Is(2); }
public SmartProperty(object target) { _value = _binding = null; if (target is SmartProperty) { _binding = target as SmartProperty; } else { _value = target; } }
public void RaisePropertyChanged() { bool called = false; string propertyName = null; var p = new SmartProperty <string>(); p.PropertyChanged += (_, e) => { called = true; propertyName = e.PropertyName; }; p.Value = "change"; called.IsTrue(); propertyName.Is("Value"); }
/// <summary> /// Handles changed smartproperties /// </summary> /// <param name="sender">the event-sender</param> /// <param name="e">the event arguments</param> private void SmartPropertyChanged(object sender, PropertyChangedEventArgs e) { SmartProperty smart = sender as SmartProperty; if (smart != null) { if (values.ContainsValue(smart)) { var item = values.First(n => n.Value == smart); OnPropertyChanged(new PropertyChangedEventArgs(item.Key)); } else { smart.PropertyChanged -= SmartPropertyChanged; } } }
public void ConstructorWithDefaultValue() { var p = new SmartProperty <string>("hello"); p.Value.Is("hello"); }
/// <summary> /// Удалить значение smart-свойства из глобальной таблицы значений свойств. /// </summary> /// <param name="property">smart-свойство.</param> public void ResetValue(SmartProperty property) { PropertyValues.ResetValue(this, property); }
/// <summary> /// Установить значение smart-свойства. /// </summary> /// <param name="property">smart-свойство.</param> /// <param name="value">Значение smart-свойства.</param> public void SetValue(SmartProperty property, object value) { PropertyValues.SetValue(this, property, value); }
private static void SetPropertyValue(SmartProperty smartProperty, object value) { if (value == null) { smartProperty.ValueBehaviour = ValueBehaviour.Unchanged; smartProperty.Value = null; } else if (value == DBNull.Value) { smartProperty.ValueBehaviour = ValueBehaviour.Clear; smartProperty.Value = null; } else if (value.ToString() == string.Empty) { smartProperty.ValueBehaviour = ValueBehaviour.Empty; smartProperty.Value = string.Empty; } else { smartProperty.ValueBehaviour = ValueBehaviour.None; smartProperty.Value = value.ToString(); } }
internal static SmartFormatProperties CreateSmartFormatProperties( string soGuid, string server, string name, string displayname, string methodname, string methoddisplayname, bool methodislist, System.Collections.Generic.Dictionary <string, K2Field> SOInputs, System.Collections.Generic.Dictionary <string, K2Field> SOReturns, string connection) { Guid smoGuid; SmartObjectClientServer svr = new SmartObjectClientServer(); svr.CreateConnection(); svr.Connection.Open(connection); SmartObject so = svr.GetSmartObject(name); smoGuid = so.Guid; SmartFormatProperties properties = new SmartFormatProperties(); properties.Locals["Guid"] = new Local("Guid", soGuid); //properties.Locals["Server"] = new Local("Server", "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=Localhost;Port=5555"); properties.Locals["Server"] = new Local("Server", connection); properties.Locals["Name"] = new Local("Name", name); properties.Locals["DisplayName"] = new Local("DisplayName", displayname); properties.Locals["MethodName"] = new Local("MethodName", methodname); properties.Locals["MethodDisplayName"] = new Local("MethodDisplayName", methoddisplayname); properties.Locals["IsList"] = new Local("IsList", new K2Field(new K2FieldPart[] { new ValueTypePart(methodislist) })); properties.Locals["MethodType"] = new Local("MethodType", "execute"); foreach (SmartProperty item in so.Properties) { properties.Properties.Add(item.Name, new Property(item.Name, item.Name, null, item.Type.ToString(), item.IsUnique)); } //Add inputs foreach (var item in SOInputs) { if (so.Methods[methodname].InputProperties.Contains(item.Key)) { SmartProperty prop = so.Methods[methodname].InputProperties[item.Key]; properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value)); } foreach (SmartParameter itemParams in so.Methods[methodname].Parameters) { if (itemParams.Name == item.Key) { SmartProperty prop = so.Methods[methodname].Parameters[item.Key]; properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value)); } } } //Map return properties foreach (SmartProperty item in so.Methods[methodname].ReturnProperties) { bool found = false; //Search and see if we have passed a mapped item if (SOReturns != null) { foreach (var SetReturnItem in SOReturns) { if (SetReturnItem.Key == item.Name) { SmartProperty prop = so.Methods[methodname].ReturnProperties[SetReturnItem.Key]; properties.Returns.Add(prop.Name, new Return(prop.Name, SetReturnItem.Value, prop.Type.ToString())); found = true; } } } //If no mapped item found set a null value. if (found == false) { properties.Returns.Add(item.Name, new Return(item.Name, item.Name, item.IsUnique, null, item.Type.ToString())); } } return(properties); }
/// <summary> /// Sets a value of a particular column of this dynamic Result object /// </summary> /// <param name="name">the columnName</param> /// <param name="value">the new value of the column</param> /// <returns>a value indicating whether the requested column was found</returns> private bool SetValue(string name, object value) { bool retVal = values.ContainsKey(name /*.ToUpper()*/); if (retVal || Extendable) { if (!retVal) { object v = value; if (value is DynamicResult || value is SmartProperty) { v = new object(); } else if (value is Image) { v = new byte[0]; } types.Add(name /*.ToUpper()*/, v?.GetType() ?? typeof(object)); } Type t = types[name /*.ToUpper()*/]; if (value == null) { value = DBNull.Value; } else { if (!t.IsAssignableFrom(value.GetType()) && !(value is DynamicResult) && !(value is SmartProperty)) { if (value is Image && t == typeof(byte[])) { Image img = value as Image; MemoryStream mst = new MemoryStream(); img.Save(mst, ImageFormat.Jpeg); mst.Close(); value = mst.ToArray(); } else { LogEnvironment.LogDebugEvent(null, string.Format("Target-Type for {0} is: {1}", name, t.FullName), (int)LogSeverity.Report, "DataAccess"); if (value is IConvertible) { try { value = TypeConverter.Convert(value, t); } catch (Exception ex) { LogEnvironment.LogEvent( string.Format("Error while converting new value of {0} to type {1}: {2}", name, t.FullName, ex), LogSeverity.Warning, "DataAccess"); } } } } else if (value is SmartProperty) { types[name /*.ToUpper()*/] = typeof(object); } } if (!retVal || !(values[name /*.ToUpper()*/] is SmartProperty && (values[name /*.ToUpper()*/] as SmartProperty).SetterMethod != null)) { object oldValue = retVal ? values[name /*.ToUpper()*/] : null; SmartProperty smart = oldValue as SmartProperty; if (smart != null) { smart.PropertyChanged -= SmartPropertyChanged; } else { INotifyCollectionChanged notifyCollection = oldValue as INotifyCollectionChanged; if (notifyCollection != null) { notifyCollection.CollectionChanged -= ChildCollectionChanged; } } values[name /*.ToUpper()*/] = value; smart = value as SmartProperty; if (smart != null) { smart.PropertyChanged += SmartPropertyChanged; } else { INotifyCollectionChanged notifyCollection = value as INotifyCollectionChanged; if (notifyCollection != null) { notifyCollection.CollectionChanged += ChildCollectionChanged; } } if (controller != null && autoSave) { controller.Save(this); } } else { (values[name /*.ToUpper()*/] as SmartProperty).Value = value; } (from z in values where (z.Value is SmartProperty && ((SmartProperty)z.Value).MonitoredProperties == null) || z.Key.Equals(name, StringComparison.OrdinalIgnoreCase) /*.ToUpper()*/ select new PropertyChangedEventArgs(z.Key)) .ToList().ForEach(n => OnPropertyChanged(n)); } return(retVal); }
/// <summary> /// Возвратить значение smart-свойства. /// </summary> /// <param name="property">smart-свойство.</param> /// <returns>Значение smart-свойства.</returns> /// <exception cref="SmartPropertyException" /> public object GetValue(SmartProperty property) { return(PropertyValues.GetValue(this, property)); }
public void DefaultConstructorSetNullValue() { var p = new SmartProperty <string>(); p.Value.IsNull(); }
public virtual IEnumerable<Candle> GetLastCandles(string instrument, int periodInMinutes, int nbOfCandles, DateTime? endDateTime = null) { if (string.IsNullOrWhiteSpace(instrument)) { throw new ArgumentException("Empty instrument"); } instrument = instrument.Trim(); if (instrument.Length != MinInstrumentLenght) { throw new ArgumentException($"Invalid instrument {instrument}"); } List<Candle> candles; try { List<OANDARestLibrary.TradeLibrary.DataTypes.Candle> candleResponse; if (endDateTime.HasValue) { var endTimeRef = EscapeDateValue(endDateTime.Value); var startTimeRef = EscapeDateValue(endDateTime.Value.AddMinutes(-nbOfCandles * periodInMinutes - 1)); candleResponse = this.proxy.GetCandlesAsync(new CandlesRequest { candleFormat = ECandleFormat.midpoint, granularity = GetGranularity(periodInMinutes), instrument = instrument, includeFirst = true, end = endTimeRef, start = startTimeRef }).Result; } else { var includeFirstRef = new SmartProperty<bool>(); candleResponse = this.proxy.GetCandlesAsync(new CandlesRequest { candleFormat = ECandleFormat.midpoint, granularity = GetGranularity(periodInMinutes), instrument = instrument, includeFirst = includeFirstRef, count = nbOfCandles + 1, }).Result; } candles = candleResponse.Where(x => x.complete) .OrderBy(x => x.time) .Select(x => new Candle(x.openMid, x.highMid, x.lowMid, x.closeMid, x.time.SafeParseDate().GetValueOrDefault())) .ToList(); } catch (Exception ex) { Console.WriteLine(ex); throw; } return candles; }