public void LoadTemplate() { var filename = GetTemplateFilename(); try { var template = JsonSerializer.Deserialize <Template>(File.ReadAllText(filename), _options); Pathes.Clear(); foreach (var path in template.Pathes) { Pathes.Add(path); } foreach (var value in template.Values) { if (!Values.Any(each => each.Value == value.Value)) { Values.Add(value); } } ValuesChanged?.Invoke(this, EventArgs.Empty); PathesChanged?.Invoke(this, EventArgs.Empty); } catch { LoadEnvValues(); } }
private void OnRobotChange(RobotType newRobot) { _CurrentRobot = newRobot; _isInitializing = true; switch (newRobot) { case RobotType.ChainRobot: InitializeChainRobot(); break; case RobotType.CableCar: InitializeCableCar(); break; case RobotType.TwoAxisGimbal: InitializeTwoAxisGimbal(); break; case RobotType.SimpleCar: InitializeSimpleCar(); break; } _isInitializing = false; RobotChanged?.Invoke(this, new RobotChangedEventArgs(newRobot)); ValuesChanged?.Invoke(this, new RobotValuesChangedEventArgs((int)driveSpeed.Value, (int)innerMotorSpeed.Value, (int)horizontalTurnSpeed.Value, (int)verticalTurnSpeed.Value)); }
private void CalculateThumbPosition(float touchX, float touchY) { float thumbRelativeX = touchX - Width / 2f; float thumbRelativeY = touchY - Height / 2f; float thumbDistance = (float)Math.Sqrt(Math.Pow(thumbRelativeX, 2) + Math.Pow(thumbRelativeY, 2)); ThumbAngle = CalculateAngle(thumbRelativeX, thumbRelativeY); if (thumbDistance > Width / 2f - ThumbSize) { thumbDistance = Width / 2f - ThumbSize; } _thumbPositionX = (int)(Math.Cos(MathUtils.ToRadians(ThumbAngle)) * thumbDistance) + Width / 2; _thumbPositionY = (int)(Math.Sin(MathUtils.ToRadians(ThumbAngle)) * thumbDistance) + Height / 2; // Normalize to percentage ThumbDistance = 100f / (Width / 2f) * thumbDistance; ThumbX = 100f / (Width / 2f) * (float)(Math.Cos(MathUtils.ToRadians(ThumbAngle)) * thumbDistance) * 2f; ThumbY = 100f / (Width / 2f) * (float)(Math.Sin(MathUtils.ToRadians(ThumbAngle)) * thumbDistance) * 2f; ValuesChanged?.Invoke(this, EventArgs.Empty); }
protected virtual void _opcGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps) { if (NumItems == 0) { return; } ValuesChanged <IComparable> vc = new ValuesChanged <IComparable>(); //特别注意,下标是1,而不是0 for (int i = 1; i <= NumItems; i++) { //ClientHandles var clientHandle = (int)ClientHandles.GetValue(i); var value = ItemValues.GetValue(i); //更新的值 if (null == value) { continue; } var opcitem = (from TagConfigElement item in ss.tags select item).Single(cuc => clientHandle == cuc.ClientHandle); opcitem.setValue(value); vc.values.Add(new ValueChanged <IComparable>() { tagName = opcitem.name, value = (IComparable)value }); } Parallel.ForEach(EventPushList, c => c.OpcValuesChanged(vc)); log.InfoFormat("_opcGroup_DataChange,opc值改变:{0}", vc); }
protected override async Task roundtrip() { string cmd = "compass"; string resp = await commTask.SendAndReceive(cmd); if (!string.IsNullOrWhiteSpace(resp)) { double yaw; if (double.TryParse(resp.Trim(), out yaw)) { int iYaw = (int)Math.Round(yaw); if (iYaw != lastYaw) { this.Yaw = iYaw; lastYaw = iYaw; ValuesChanged?.Invoke(this); } return; } } Debug.WriteLineIf(!cancellationToken.IsCancellationRequested, "MotionPlug: roundtrip() : could not parse response: '" + resp + "'"); }
protected async Task DoPage(int page, int perPage) { Take = perPage; CurrentPage += page; Values = await Page.Invoke(CurrentPage, Take); await ValuesChanged.InvokeAsync(Values); }
public void ChangeDirection(int index) { if (index >= 0 && index < DirectionOptions.Length) { currentDirection = (MoveDirection)index; ValuesChanged?.Invoke(this, EventArgs.Empty); } }
public void Clear() { Values.Clear(); ValuesChanged?.Invoke(this, EventArgs.Empty); Pathes.Clear(); PathesChanged?.Invoke(this, EventArgs.Empty); }
void OnValuesChanged(params KeyValuePair <string, object>[] values) { if (values == null || values.Length == 0) { return; } ValuesChanged?.Invoke(this, new ResourcesChangedEventArgs(values)); }
private void OnValuesChanged(bool forceSort = true) { if (forceSort) { OnValueChangesNeedSorting(); } ValuesChanged?.Invoke(this, EventArgs.Empty); }
void StyleSheetsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: ValuesChanged?.Invoke(this, ResourcesChangedEventArgs.StyleSheets); break; } }
// On mouse up private void HSLPickerMouseUp(object sender, MouseEventArgs e) { if (_trackMode == 0) { return; } // release capture Capture = false; _trackMode = 0; // notify client ValuesChanged?.Invoke(this, new EventArgs()); }
private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { var a = sender as Slider; if (!_isInitializing) { TextBlock txt = FindName(a.Name + "Tb") as TextBlock; txt.Text = e.NewValue.ToString(); _driveSpeed = (int)driveSpeed.Value; _innerMotorSpeed = (int)innerMotorSpeed.Value; _horizontalTurnSpeed = (int)horizontalTurnSpeed.Value; _verticalTurnSpeed = (int)verticalTurnSpeed.Value; ValuesChanged?.Invoke(this, new RobotValuesChangedEventArgs(DriveSpeed, CurveInnerMotorSpeed, HorizontalTurnSpeed, VerticalTurnSpeed)); } }
public void RemoveCode() { if (string.IsNullOrEmpty(CurrentValue)) { if (Values.Count > 0) { var value = Values.Pop(); CurrentValue = value.ToString(); } } else { CurrentValue = CurrentValue.Substring(0, CurrentValue.Length - 1); } ValuesChanged?.Invoke(this, EventArgs.Empty); }
protected async Task DoSort(string header) { if (SortDirection != SortDirection.Ascending) { SortDirection = SortDirection.Ascending; } else { SortDirection = SortDirection.Descending; } SortBy = header; Values = await Sort.Invoke(header, SortDirection); await ValuesChanged.InvokeAsync(Values); }
private void HandleTextBoxTextChanges(ref DarkUI.Controls.DarkTextBox textBox, ref float element) { float newValue; bool validFloat = Single.TryParse(textBox.Text, out newValue); if (validFloat) { textBox.ForeColor = DefaultLightForeColor; element = newValue; ValuesChanged?.Invoke(this, new Vector2ChangedEventArgs(_x, _y, _internalUpdate)); } else { textBox.ForeColor = InvalidValueForeColor; } }
public void ChangeSpeed(int speed) { if (speed < MinSpeed) { speed = MinSpeed; } else if (speed > MaxSpeed) { speed = MaxSpeed; } if (speed != Speed) { Speed = speed; ValuesChanged?.Invoke(this, EventArgs.Empty); } }
private bool CulculateCore(Func <double, double, double> func) { bool result; try { var arg1 = Values.Pop(); var arg2 = Values.Pop(); Values.Push(func(arg2, arg1)); result = true; } catch (Exception) { result = false; } ValuesChanged?.Invoke(this, EventArgs.Empty); return(result); }
public void AddCode(char code) { if ('0' <= code && code <= '9' || code == '.') { CurrentValue = CurrentValue + code; } else { ProcessCurrentValue(); if (code == '+') { Add(); } else if (code == '-') { Subtract(); } else if (code == '*') { Multiply(); } else if (code == '/') { Divide(); } } ValuesChanged?.Invoke(this, EventArgs.Empty); void ProcessCurrentValue() { if (string.IsNullOrEmpty(CurrentValue)) { return; } if (double.TryParse(CurrentValue, out var value)) { Values.Push(value); CurrentValue = string.Empty; } } }
private void LoadValueAndPathes(string filename, string trim = null) { var currentDirectory = Directory.GetCurrentDirectory(); var templates = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories); foreach (var template in templates) { var lines = File.ReadAllLines(template); var relativePath = Path.GetRelativePath(currentDirectory, template); if (!string.IsNullOrEmpty(trim)) { relativePath = relativePath.Substring(0, relativePath.Length - trim.Length); } var valueAndPathes = Parse(lines); foreach (var path in valueAndPathes.Select(each => new EnvironmentValuePath { Path = relativePath, Name = each.name, Value = each.value })) { Pathes.Add(path); } foreach (var value in valueAndPathes) { if (!Values.Any(each => each.Value == value.value)) { Values.Add(new EnvironmentValue { Value = value.value, Description = value.name }); } } } var valueDic = Values.ToDictionary(each => each.Value); ValuesChanged?.Invoke(this, EventArgs.Empty); PathesChanged?.Invoke(this, EventArgs.Empty); }
public void UpdateData(Security sec, decimal price) { var ps = sec.PriceStep ?? 1; var list = new List <KeyValuePair <Level1Fields, object> >(); if (RandomGen.GetBool()) { list.Add(new KeyValuePair <Level1Fields, object>(Level1Fields.BestBidPrice, price - RandomGen.GetInt(1, 10) * ps)); } if (RandomGen.GetBool()) { list.Add(new KeyValuePair <Level1Fields, object>(Level1Fields.BestAskPrice, price + RandomGen.GetInt(1, 10) * ps)); } var now = DateTimeOffset.Now; ValuesChanged?.Invoke(sec, list, now, now); }
public void ReadCurrentEnvironment() { var currentDirectory = Directory.GetCurrentDirectory(); var configPath = Path.Combine(currentDirectory, "envmanager.json"); if (File.Exists(configPath)) { var configString = File.ReadAllText(configPath); var configs = JsonSerializer.Deserialize <ConfigItem[]>(configString, _options); foreach (var config in configs) { Values.Add(new EnvironmentValue { Value = config.Value, Description = config.Description }); } ValuesChanged?.Invoke(this, EventArgs.Empty); } }
/// <summary> /// Called when node values set gets changed. /// </summary> public virtual void OnValuesChanged() { ValuesChanged?.Invoke(); }
internal void Add(StyleSheets.StyleSheet styleSheet) { StyleSheets = StyleSheets ?? new List <StyleSheets.StyleSheet>(2); StyleSheets.Add(styleSheet); ValuesChanged?.Invoke(this, ResourcesChangedEventArgs.StyleSheets); }
/// <summary> /// 获取值是否改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //Debug.WriteLine("Tmr_Elapsed"); if (null == oldrecord || null == valueChangedCallback) { return; } MysqlContext db = new MysqlContext(dbconfigname); var ps = MysqlContext.plcvalue.GetProperties(); //所有属性 Dictionary <string, IComparable> changeddic = new Dictionary <string, IComparable>(); //改变的值的字典 object newobject = null; try { newobject = getFirstRecord(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return; } finally { db.Dispose(); } lock (lockobj) { ps.ToList().ForEach(p => { if (!p.Name.Equals("id")) { var q = new FastReflection.FastProperty(p); var v1 = (IComparable)q.Get(newobject); var v2 = (IComparable)q.Get(oldrecord); if ((null == v1 && null != v2) || (null != v1 && v1.CompareTo(v2) != 0)) { changeddic.Add(p.Name, v1); } else { // log.DebugFormat("检测值是否改变{0}") } } }); } if (changeddic.Count > 0) { IValuesChanged <IComparable> ivc = new ValuesChanged <IComparable>(changeddic.Count); changeddic.ToList().ForEach(kv => { //var instance = (EventPush.Package.ITagName)Activator.CreateInstance(typeof(SetValuePack<>).MakeGenericType(kv.Value.GetType())); db = new MysqlContext(dbconfigname); try { IValueChanged <IComparable> vc = new ValueChanged <IComparable>(); vc.tagName = db.TagColPairs.First(t => t.colName.Equals(kv.Key)).tagName; vc.value = kv.Value; ivc.values.Add(vc); } catch (Exception ex) { log.Warn("数据库值改变,创建改变包时失败", ex); return; } finally { db.Dispose(); } }); log.DebugFormat("有{0}项值的改变,改变的包为:{1}", changeddic.Count, ivc.ToString()); valueChangedCallback.Invoke(ivc); } }
private void OnValuesChanged() { OnValuesNeedSorting(); ValuesChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Called when node values set gets changed. /// </summary> public virtual void OnValuesChanged() { ValuesChanged?.Invoke(); Surface.OnNodeValuesEdited(this); }
private void RaiseValuesChanged(Security security, IEnumerable <KeyValuePair <Level1Fields, object> > changes, DateTimeOffset serverTime, DateTimeOffset localTime) { ValuesChanged?.Invoke(security, changes, serverTime, localTime); }
private void ValuesChangedHandler(Security security, IEnumerable <KeyValuePair <Level1Fields, object> > changes, DateTimeOffset serverTime, DateTime localTime) { AddGuiAction(() => ValuesChanged.SafeInvoke(security, changes, serverTime, localTime)); }
protected virtual void OnValuesChanged(IBrush brush) { ValuesChanged?.Invoke(this, brush); }