private void TestGetRandomSettingReadWrite(object sender, EventArgs e) { FlagErrorOccured = false; if (ListSetting.Count < 1) { MessageBox.Show("ERROR ! List of Settings is empty."); return; } //Log.Save(MsgType.Debug, "", "Begin of method [TestGetRandomSettingReadWrite]"); TxMessage.Clear(); for (int i = 1; i < 11; i++) { TestGetRandomSettingReadWrite(); Application.DoEvents(); if (FlagErrorOccured) { break; } Ms.Message($"{i}", "").NoAlert().Debug(); } //Trace.WriteLine("---------------------------------------------------------------------------------"); //Log.Save(MsgType.Debug, "", "End of method [TestGetRandomSettingReadWrite]"); }
private void FillListFolder(object sender, EventArgs e) { //DbSettings.FolderRename(0, "Root"); ListFolder.Clear(); ListFolder = DbSettings.GetListOfFolders(); FillListSetting(sender, e); string text = string.Empty; foreach (var item in ListFolder) { text += item.IdFolder + " --- " + item.FullPath + Environment.NewLine; } TxMessage.AppendText(text); Print($"Folders = {ListFolder.Count}"); /* * ReturnCode code = ReturnCodeFactory.Error(); * Print("Renaming..."); * foreach (var item in ListFolder) * { * if (item.NameFolder.Length > 8 ) * { * code = DbSettings.FolderRename(item.IdFolder, "Item_" + item.IdFolder.ToString()); * //if (code.Success) Print($"RENAMED {item.FullPath}"); * } * * } * Print("STOP"); */ }
private void EventCreateTestBranch(object sender, EventArgs e) { string MainFolder = "TestBranchForDelete300"; if (DbSettings.FolderExists(MainFolder)) { Ms.Message("ERROR!", $"Folder {MainFolder} already exists").Wire(BxCreateTestBranch).Fail(); return; } ReturnCode code = DbSettings.FolderInsert(DbSettings.RootFolderName, MainFolder); int IdParent = code.IdObject; TxMessage.Clear(); for (int i = 1; i < 301; i++) { code = DbSettings.FolderInsert(IdParent, VxFaker.Hacker.Phrase() + $"_{i}"); Print($"Folder >>> {i} {code.Success}"); int IdParent2 = code.IdObject; /*if (code.Success) * for (int j = 1; j < 11; j++) * { * code = DbSettings.FolderInsert(IdParent2, VxFaker.Person.FullName + $"_{i}_{j}"); * Print($" Folder --- {i} --- {j} --- {code.Success}"); * }*/ } TxMessage.Clear(); Print("Test branch created."); }
/// <summary> /// Waits until it send before returning. /// </summary> /// <param name="message"></param> /// <returns></returns> public virtual async Task <bool> SendAsync(TxMessage message) { NextMessageToSend = message; var task = new Task <bool>(Run); task.Start(); return(await task); }
public void PrintToTextbox(string message) { if (TxMessage.InvokeRequired) { TxMessage.Invoke((MethodInvoker) delegate { PrintInner(message); }); } else { PrintInner(message); } }
/// <summary> /// Takes the distance between the average finger tip position, and the /// Leap Motion sensor, and converts it to a <c>Note</c> to play. /// </summary> /// <param name="frame">The leap motion data containing the finger /// information.</param> /// <returns>Will return a <c>Note</c> if at least one finger has been /// detected within so long of its last call. Otherwise it will return /// a <c>Pause</c>.</returns> public override Data.TxMessage Convert(Leap.Frame frame) { TxMessage result = null; if (frame.Fingers.Any()) { #region FIGURES OUT STEP var avgX = frame.Fingers.Average(x => x.TipPosition.x); var avgY = frame.Fingers.Average(x => x.TipPosition.y); var avgZ = frame.Fingers.Average(x => x.TipPosition.z); var sumOfSquares = Math.Pow(avgX, 2.0) + Math.Pow(avgY, 2.0) + Math.Pow(avgZ, 2.0); var distance = Math.Sqrt(sumOfSquares); if (distance > MaxDistance) { MaxDistance = distance; } var step = (byte)(Math.Round((distance / MaxDistance) * 20.0, 0) + 40.0); #endregion // Saves the step. result = new Note() { Pin = 8, NoteLength = 1, RepeatLength = 1, Step = step }; Console.WriteLine("{0:D3}", step); LastFingerRecordTime = DateTime.Now.Ticks; } else { if (DateTime.Now.Ticks - LastFingerRecordTime <= 2000000) { result = Last ?? DEFAULT_LAST; } else { result = DEFAULT_LAST; } } return(Last = result); }
private void EventGetListOfFolders(object sender, EventArgs e) { TxMessage.Clear(); string names = string.Empty; List <Folder> list = DbSettings.GetListOfFolders(); foreach (var item in list) { names += item.IdFolder + " = " + item.FullPath + Environment.NewLine; } TxMessage.Text = names; }
public void Print(string message) { if (TxMessage.InvokeRequired) { TxMessage.Invoke((MethodInvoker) delegate { TxMessage.AppendText(message + Environment.NewLine); }); } else { TxMessage.AppendText(message + Environment.NewLine); } }
private void PrintInner(string message) { TxMessage.AppendText(message + Environment.NewLine); if (message.StartsWith("ERROR")) { FlagErrorOccured = true; Log.Save(MsgType.Error, string.Empty, message); Ms.Message("ERROR", message).NoAlert().Error(); } if (TxMessage.Text.Length > 200000) { TxMessage.Clear(); } }
private void StartTestTimersForExperiment2(object sender, EventArgs e) { if (ListFolder.Count == 0) { FillListFolder(sender, e); } if (ListSetting.Count == 0) { FillListSetting(sender, e); } TxMessage.Refresh(); Application.DoEvents(); /* * Tm1 = new System.Threading.Timer(TestSelectRandomSetting, null, 1100, 393 + VxFaker.Random.Int(1, 27)); * Tm2 = new System.Threading.Timer(TestSelectRandomSetting, null, 2207, 494 + VxFaker.Random.Int(1, 28)); * Tm3 = new System.Threading.Timer(TestSelectRandomSetting, null, 3311, 395 + VxFaker.Random.Int(1, 29)); * Tm4 = new System.Threading.Timer(TestSelectRandomSetting, null, 4419, 927 + VxFaker.Random.Int(1, 30)); * Tm5 = new System.Threading.Timer(TestActionCreateFolder, null, 5500, 1291 + VxFaker.Random.Int(1, 27)); * Tm6 = new System.Threading.Timer(TestActionAddSettingText, null, 6607, 1594 + VxFaker.Random.Int(1, 28)); * Tm7 = new System.Threading.Timer(TestActionAddSettingInteger64, null, 7711, 1795 + VxFaker.Random.Int(1, 29)); * Tm8 = new System.Threading.Timer(TestActionUpdateRandomSetting, null, 8819, 780 + VxFaker.Random.Int(1, 30)); * Tm9 = new System.Threading.Timer(TestActionUpdateRandomSetting, null, 9900, 871 + VxFaker.Random.Int(1, 27)); */ Tm1 = new System.Threading.Timer(TestSelectRandomSetting, null, 1100, 393 + VxFaker.Random.Int(1, 27)); Tm2 = new System.Threading.Timer(TestSelectRandomSetting, null, 2207, 494 + VxFaker.Random.Int(1, 28)); Tm3 = new System.Threading.Timer(TestSelectRandomSetting, null, 3311, 547 + VxFaker.Random.Int(1, 29)); Tm4 = new System.Threading.Timer(TestSelectRandomSetting, null, 4419, 678 + VxFaker.Random.Int(1, 30)); Tm5 = new System.Threading.Timer(TestActionUpdateRandomSetting, null, 5500, 3300 + VxFaker.Random.Int(1, 27)); // Tm6 = new System.Threading.Timer(TestActionAddSettingText, null, 6607, 1594 + VxFaker.Random.Int(1, 28)); // Tm7 = new System.Threading.Timer(TestActionAddSettingInteger64, null, 7711, 1795 + VxFaker.Random.Int(1, 29)); // Tm8 = new System.Threading.Timer(TestActionUpdateRandomSetting, null, 8819, 780 + VxFaker.Random.Int(1, 30)); // Tm9 = new System.Threading.Timer(TestActionUpdateRandomSetting, null, 9900, 871 + VxFaker.Random.Int(1, 27)); BxTest.Click -= StartTestTimersForExperiment2; BxTest.Click += StopTestTimersForExperiment2; Ms.Message("START Experiment 2", "Timers were started.").Control(BxTest).Info(); TxMessage.Clear(); }
/// <summary> /// The conversion changes the Leap Motion space into a set of cubes. /// It then calculates the average of the finger tips detected by the /// Leap Motion. The cube that contains that average position is /// located, and used to determine a note to send to the Arduino. /// </summary> /// <param name="frame">The leap motion data containing the finger /// information.</param> /// <returns>A note to send to the Arduino. This will always return a /// <c>Note</c>.</returns> public override Data.TxMessage Convert(Leap.Frame frame) { TxMessage result = null; if (frame.Fingers.Any()) { #region FIGURES OUT STEP var avgX = frame.Fingers.Average(x => x.TipPosition.x); var avgY = frame.Fingers.Average(x => x.TipPosition.y); var avgZ = frame.Fingers.Average(x => x.TipPosition.z); var unitX = (avgX - MIN_X) / (MAX_X - MIN_X); var unitY = (avgY - MIN_Y) / (MAX_Y - MIN_Y); var unitZ = (avgZ - MIN_Z) / (MAX_Z - MIN_Z); var scaledX = Math.Round(unitX * RESOLUTION_X, 0) * ScaleX; var scaledY = Math.Round(unitY * RESOLUTION_Y, 0) * ScaleY; var scaledZ = Math.Round(unitZ * RESOLUTION_Z, 0) * ScaleZ; var step = (byte)(scaledX + scaledY + scaledZ); #endregion // Saves the step. result = new Note() { Pin = 8, NoteLength = 1, RepeatLength = 1, Step = step }; } else { result = Last ?? DEFAULT_LAST; } return(Last = result); }
private void OnTxMessageReceived(Socket socket, TxMessage myTxMessage) { // process your message }
public static void PerformTransaction( byte[] senderIpAddress, byte[] recipientIpAddress, string previousTransactionIdHex, string senderBitcoinAddress, string senderPrivateKeyHex, string recipientBitcoinAddress, double transactionAmountInBtc) { var senderShortNetworkAddress = new ShortNetworkAddress(senderIpAddress, 8333); var recipientShortNetworkAddress = new ShortNetworkAddress(recipientIpAddress, 8333); var versionMessage = new VersionMessage(recipientShortNetworkAddress, senderShortNetworkAddress); var transactionMessage = TxMessage.Create( previousTransactionIdHex, senderBitcoinAddress, senderPrivateKeyHex, recipientBitcoinAddress, transactionAmountInBtc); var tcpClient = new TcpClient(recipientShortNetworkAddress.IpString, recipientShortNetworkAddress.Port); var tcpClientStream = tcpClient.GetStream(); var versionMessageBytes = versionMessage.ToBytes(); var transactionMessageBytes = transactionMessage.ToBytes(); tcpClientStream.Write(versionMessageBytes, 0, versionMessageBytes.Length); tcpClientStream.Write(transactionMessageBytes, 0, transactionMessageBytes.Length); var buffer = new byte[0]; while (true) { var bytesToReadCount = tcpClient.Available; if (bytesToReadCount == 0) { Thread.Sleep(100); continue; } var readedData = new byte[bytesToReadCount]; tcpClientStream.Read(readedData, 0, bytesToReadCount); buffer = buffer.Concat(readedData).ToArray(); var header = new Header(buffer); Console.WriteLine( $"{DateTime.Now.ToLongTimeString()}: " + $"incoming message: {header.Command}. " + $"Length: {header.PayloadLength}"); buffer = buffer.Skip(24 + (int)header.PayloadLength).ToArray(); } }
/// <summary> /// Write the <c>NextMessageToSend</c> to the Arduino, and move it to /// the <c>SentMessage</c> property. /// </summary> protected virtual void Write() { Port.Write(NextMessageToSend.Bytes, 0, NextMessageToSend.Bytes.Length); SentMessage = NextMessageToSend; NextMessageToSend = null; }
private void PrintInner(string message) { TxMessage.AppendText(message + Environment.NewLine); }