public void Clear() { switch (Style) { case Style.RDB: RDBTab.Clear(); RDBCore.ClearData(); break; case Style.HASHER: //TODO: Time to implement me bruh break; case Style.DATA: DataTab.Clear(); DataCore.Clear(); break; } lManager.Enter(Logs.Sender.MANAGER, Logs.Level.NOTICE, "Tab: {0} contents have been cleared.", Page.Text); }
/// <summary> /// Opens form to edit the selected row. /// </summary> private void EditTaskToolStripMenuItem_Click(object sender, EventArgs e) { var row = DataTab.SelectedRows; if (DataTab.AreAllCellsSelected(false) == false && DataTab.SelectedRows.Count != 0) { Task.Name = (string)row[0].Cells[0].Value; Task.Date = (DateTime)row[0].Cells[1].Value; Task.IfToday = (CheckState)row[0].Cells[2].Value; var frm = new TaskForm(Task, true); // ITask argument, edit mode, frm.ShowDialog(); if (frm.DialogResult == DialogResult.OK) { Task.EditTask(DataTab, row[0].Index); statusStrip.Items[0].Visible = false; } } else { MessageBox.Show("Please select correct row.", "Binder", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void BuildBtn_Click(object sender, System.EventArgs e) { try { IsDone = false; UpdateErrorLog(ValidateInput.AssembleMsg()); //string err = MainCTRL.BuildSourceCode(BlockSizeTxt.Text, CacheSizeTxt.Text, // CodeEditorTxt.Text, IsMRU, IsLRU); string err = MainCTRL.BuildSourceCode(BlockSizeTxt.Text, CacheSizeTxt.Text, CodeEditorCtrl.GetCodeEditorRTB(), IsMRU); if (string.IsNullOrEmpty(err)) { int cacheRowCount = 4 * Int32.Parse(BlockSizeTxt.Text) * Int32.Parse(CacheSizeTxt.Text); MainCTRL.InitializeCache(cacheRowCount, Int32.Parse(BlockSizeTxt.Text)); SetCacheDT(MainCTRL.GenerateCacheDT()); int wordSize = DataCleaner.BitCounter(Int32.Parse(BlockSizeTxt.Text)); CacheController.Init(11 - wordSize, wordSize, Int32.Parse(BlockSizeTxt.Text)); UpdateErrorLog(ValidateInput.NoErr()); DataTab.SetTemplateDT(MainCTRL.GenerateDataSGDT()); TextTab.SetTemplateDT(MainCTRL.GenerateTextSGDT()); TextTab.SetColumnWidth(); IsAssembled = true; OperationController.NextAddr = "0x00001000"; } else { UpdateErrorLog(err); IsAssembled = false; } } catch (Exception ex) { IsAssembled = false; MessageBox.Show(ex.Message); } }
public static void ClearAllData() { dtab = new DataTab(); }
public static void NewConnection() { dbcon.NewConnection(Constants.currentConString); dtab = new DataTab(); }
private async void UpdateData() { byte[] requestArr; byte[] responseArr; string errorMess; int code = 0; #if DEBUG _debugCounter++; Debug.WriteLine(_debugCounter); #endif try { var resData = await Task.Run(() => { var ct = _debugCounter; byte[] req; byte[] res; string err; int cd; lock (_syncLock) { cd = ModBusDriver.GetData(out req, out res, out err); } #if DEBUG Debug.WriteLine(ct); Debug.WriteLine("----------------------"); #endif return(new { Req = req, Res = res, Err = err, Cd = cd }); }, _tokenSrc.Token); if (resData == null) { return; } requestArr = resData.Req; responseArr = resData.Res; errorMess = resData.Err; code = resData.Cd; } catch (OperationCanceledException ex) { return; } catch (InvalidOperationException ex) { _timer.Stop(); _timer.Tick -= _dataUpdateHandler; _linkRecoveryTimer.Tick += _connectionRecoveryHandler; _linkRecoveryTimer.Start(); StatusString = "Порт недоступен. Пробую найти указаный порт..."; return; } catch (Exception ex) { using (StreamWriter wr = new StreamWriter("ExceptionsLog.txt", true)) { wr.WriteLine(DateTime.Now); wr.WriteLine(ex.Message); wr.WriteLine(ex.StackTrace); wr.WriteLine(); wr.WriteLine(); } MessageBox.Show("Произошла непредвиденная ошибка"); return; } string rq = ""; string rs = ""; if (requestArr != null) { foreach (var tmp in requestArr) { rq += tmp.ToString("X2"); rq += " "; } } if (responseArr != null) { foreach (var tmp in responseArr) { rs += tmp.ToString("X2"); rs += " "; } } DataTab.Insert(0, new ModbusDataPoint() { ErrorLevel = code, ErrorMessage = errorMess, Index = Index, RequestData = rq, ResponseData = rs }); if ((ModbusConfig.SelectedMemType == Memtype.Coils | ModbusConfig.SelectedMemType == Memtype.Inputs) && ModBusDriver.CoilsArray != null) { DataControlViewModel.UpdateData(ModBusDriver.CoilsArray, ModbusConfig.StartAddress); } else if (ModBusDriver.RegisterArray != null) { DataControlViewModel.UpdateData(ModBusDriver.RegisterArray, ModbusConfig.StartAddress); UpdateEvent?.Invoke(this, new UpdateEventArgs(ModbusConfig.StartAddress, ModBusDriver.RegisterArray)); } var readData = new MBRequestData(); readData.ErrorMessage = errorMess; readData.RequestQuantity = ReadData.RequestQuantity + 1; readData.ValidResponseQuantity = code == 0? ReadData.ValidResponseQuantity + 1: ReadData.ValidResponseQuantity; readData.ValidResponseProportion = (double)readData.ValidResponseQuantity / readData.RequestQuantity * 100; ReadData = readData; StatusString = errorMess; Index++; }
private void OnSingleRegWrite(object sender, EventArgs e) { byte[] requestArr; byte[] responseArr; string errorMess; int code = 0; var con = DataControlViewModel.GetMode(); try { //0-ushort,1-uint,2-ulong,3-hex,4-bin,5-float,6-double,7-coil if (con == 0) { code = ModBusDriver.SetDataSingle(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, Convert.ToUInt16(DataControlViewModel.EditRegister.NumericData), out errorMess); } else if (con == 4) { ushort reg = 0; foreach (var val in DataControlViewModel.EditRegister.BinData) { reg += (ushort)((val.Value ? 1 : 0) * Math.Pow(2, val.Index)); } code = ModBusDriver.SetDataSingle(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, reg, out errorMess); } else if (con == 3) { ushort reg; if (!UInt16.TryParse(DataControlViewModel.EditRegister.NumericData, System.Globalization.NumberStyles.HexNumber, null, out reg)) { WriteStatusString = "Неправильный формат значения..."; return; } code = ModBusDriver.SetDataSingle(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, reg, out errorMess); } else { code = ModBusDriver.SetDataSingle(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, (ushort)(DataControlViewModel.EditRegister.CoilData?1:0), out errorMess); } } catch (FormatException ex) { WriteStatusString = "Введите корректное значение (возможно, в качестве разделителя использована точка вместо запятой"; return; } catch (InvalidOperationException ex) { WriteStatusString = "Порт недоступен"; return; } catch (Exception ex) { WriteStatusString = "Неизвестная ошибка"; return; } string rq = "||WR|| "; string rs = "||WR|| "; if (requestArr != null) { foreach (var tmp in requestArr) { rq += tmp.ToString("X2"); rq += " "; } } if (responseArr != null) { foreach (var tmp in responseArr) { rs += tmp.ToString("X2"); rs += " "; } } DataTab.Insert(0, new ModbusDataPoint() { ErrorLevel = code, ErrorMessage = errorMess, Index = Index, RequestData = rq, ResponseData = rs }); var writeData = new MBRequestData(); writeData.ErrorMessage = errorMess; writeData.RequestQuantity = WriteData.RequestQuantity + 1; writeData.ValidResponseQuantity = code == 0 ? WriteData.ValidResponseQuantity + 1 : WriteData.ValidResponseQuantity; writeData.ValidResponseProportion = (double)writeData.ValidResponseQuantity / writeData.RequestQuantity * 100; WriteData = writeData; WriteStatusString = errorMess; Index++; }
private void OnMultipleWrite(object sender, EventArgs e) { byte[] requestArr; byte[] responseArr; string errorMess; int code = 0; var con = DataControlViewModel.GetMode(); try { //0-ushort,1-uint,2-ulong,3-hex,4-bin,5-float,6-double,7-coil switch (con) { case 0: code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, new[] { Convert.ToUInt16(DataControlViewModel.EditRegister.NumericData) }, null, out errorMess); break; case 1: byte[] bytes = BitConverter.GetBytes(Convert.ToUInt32(DataControlViewModel.EditRegister.NumericData)); ushort[] regs = { BitConverter.ToUInt16(bytes, 2), BitConverter.ToUInt16(bytes, 0) }; code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, regs, null, out errorMess); break; case 2: bytes = BitConverter.GetBytes(Convert.ToUInt64(DataControlViewModel.EditRegister.NumericData)); regs = new[] { BitConverter.ToUInt16(bytes, 6), BitConverter.ToUInt16(bytes, 4), BitConverter.ToUInt16(bytes, 2), BitConverter.ToUInt16(bytes, 0) }; code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, regs, null, out errorMess); break; case 3: ushort reg; if (!UInt16.TryParse(DataControlViewModel.EditRegister.NumericData, NumberStyles.HexNumber, null, out reg)) { WriteStatusString = "Неправильный формат значения..."; return; } code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, new[] { reg }, null, out errorMess); break; case 4: reg = 0; foreach (var val in DataControlViewModel.EditRegister.BinData) { reg += (ushort)((val.Value ? 1 : 0) * Math.Pow(2, val.Index)); } code = ModBusDriver.SetDataSingle(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, reg, out errorMess); break; case 5: bytes = BitConverter.GetBytes(Convert.ToSingle(DataControlViewModel.EditRegister.NumericData)); regs = new[] { BitConverter.ToUInt16(bytes, 2), BitConverter.ToUInt16(bytes, 0) }; code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, regs, null, out errorMess); break; case 6: var doubleVal = Convert.ToDouble(DataControlViewModel.EditRegister.NumericData); bytes = BitConverter.GetBytes(doubleVal); regs = new[] { BitConverter.ToUInt16(bytes, 0), BitConverter.ToUInt16(bytes, 2), BitConverter.ToUInt16(bytes, 4), BitConverter.ToUInt16(bytes, 6) }; code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, regs, null, out errorMess); break; case 7: code = ModBusDriver.SetDataMultiple(out requestArr, out responseArr, DataControlViewModel.EditRegister.Address, new ushort[] { (ushort)(DataControlViewModel.EditRegister.CoilData ? 1 : 0) }, null, out errorMess); break; default: requestArr = new byte[1]; responseArr = new byte[1]; errorMess = "Unreconized condition"; break; } } catch (FormatException ex) { WriteStatusString = "Введите корректное значение (возможно, в качестве разделителя использована точка вместо запятой"; return; } catch (InvalidOperationException ex) { WriteStatusString = "Порт недоступен"; return; } catch (Exception ex) { WriteStatusString = "Неизвестная ошибка"; return; } string rq = "||WR|| "; string rs = "||WR|| "; if (requestArr != null) { foreach (var tmp in requestArr) { rq += tmp.ToString("X2"); rq += " "; } } if (responseArr != null) { foreach (var tmp in responseArr) { rs += tmp.ToString("X2"); rs += " "; } } DataTab.Insert(0, new ModbusDataPoint() { ErrorLevel = code, ErrorMessage = errorMess, Index = Index, RequestData = rq, ResponseData = rs }); var writeData = new MBRequestData(); writeData.ErrorMessage = errorMess; writeData.RequestQuantity = WriteData.RequestQuantity + 1; writeData.ValidResponseQuantity = code == 0 ? WriteData.ValidResponseQuantity + 1 : WriteData.ValidResponseQuantity; writeData.ValidResponseProportion = (double)writeData.ValidResponseQuantity / writeData.RequestQuantity * 100; WriteData = writeData; WriteStatusString = errorMess; Index++; }
public DataTab Put(DataTab request) { return(Patch(request)); }
private DataTab _AssignValues(DataTab request, DocConstantPermission permission, Session session) { if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No record"); } if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "DataTab")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); DataTab ret = null; request = _InitAssignValues <DataTab>(request, permission, session); //In case init assign handles create for us, return it if (permission == DocConstantPermission.ADD && request.Id > 0) { return(request); } var cacheKey = GetApiCacheKey <DataTab>(DocConstantModelName.DATATAB, nameof(DataTab), request); //First, assign all the variables, do database lookups and conversions var pClass = DocEntityDataClass.Get(request.Class?.Id, true, Execute) ?? DocEntityDataClass.Get(request.ClassId, true, Execute); var pDescription = request.Description; var pName = request.Name; var pOrder = request.Order; var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityDataTab, DataTab>(request, permission, session); if (AllowPatchValue <DataTab, bool>(request, DocConstantModelName.DATATAB, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <DataTab, DocEntityDataClass>(request, DocConstantModelName.DATATAB, pClass, permission, nameof(request.Class), pClass != entity.Class)) { entity.Class = pClass; } if (AllowPatchValue <DataTab, string>(request, DocConstantModelName.DATATAB, pDescription, permission, nameof(request.Description), pDescription != entity.Description)) { entity.Description = pDescription; } if (AllowPatchValue <DataTab, string>(request, DocConstantModelName.DATATAB, pName, permission, nameof(request.Name), pName != entity.Name)) { entity.Name = pName; } if (AllowPatchValue <DataTab, int?>(request, DocConstantModelName.DATATAB, pOrder, permission, nameof(request.Order), pOrder != entity.Order)) { if (null != pOrder) { entity.Order = (int)pOrder; } } if (request.Locked && AllowPatchValue <DataTab, bool>(request, DocConstantModelName.DATATAB, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.DATATAB); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <DataTab>(currentUser, nameof(DataTab), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DATATAB); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DATATAB, cacheExpires); return(ret); }
public object Get(DataTab request) => GetEntityWithCache <DataTab>(DocConstantModelName.DATATAB, request, GetDataTab);