private void comboProcessTypes_SelectionChanged(object sender, SelectionChangedEventArgs e) { ProcessText process = Activator.CreateInstance(e.AddedItems[0].GetType()) as ProcessText; this.lstProperties.SelectedObject = process; UpdateProcessResult(); }
/// <summary> /// Returns an array of two smaller dictionaries /// </summary> /// <returns></returns> private Dictionary <string, int>[] DivideDict() { Dictionary <string, int>[] dictionaries = new Dictionary <string, int> [2]; var half = ProcessText.Count / 2; var firstDict = ProcessText.Take(half).ToDictionary(kv => kv.Key, kv => kv.Value); var secondDict = ProcessText.Skip(half).ToDictionary(kv => kv.Key, kv => kv.Value); dictionaries[0] = firstDict; dictionaries[1] = secondDict; return(dictionaries); }
private void UpdateProcessResult() { ProcessText newProcess = this.lstProperties.SelectedObject as ProcessText; if (null == newProcess) { return; } newProcess.LinkType = _linkType; newProcess.Parent = ParentProcess; MyProcess = newProcess; if (null != newProcess.Output) { this.txtResult.Text = newProcess.Output.ToString(); } }
public void Connect(ProcessText onReceive) { if (!connected) { this.onReceive = onReceive; endPoint = new IPEndPoint(ipAddress, port); udpClient = new UdpClient(port); receivingThread = new Thread(new ThreadStart(ReceiveData)); receivingThread.IsBackground = true; receivingThread.Start(); connected = true; } else { throw new Exception("Already connected"); } }
/// <summary> /// Add a word (key) to the dictionary, if it already exists, add to the value /// </summary> /// <param name="word"></param> private void PopulateWords(string[] words) { foreach (string word in words) { //if word is blank if (word == "") { continue; } //if word already exists in dict if (ProcessText.ContainsKey(word)) { ProcessText[word]++; } //add new word to dict else { ProcessText.Add(word, 1); } } }
private string decode() { //Checks if (!File.Exists(InFile.FullName)) { Messages.AppendLine("InputFile not found: " + InFile.FullName); return("error"); } if (!File.Exists(Options.DecoderPath)) { Messages.AppendLine("Decoder not found: " + Options.DecoderPath); return("error"); } if (!Directory.Exists(OutFile.Directory.FullName)) { Messages.AppendLine("OutDirectory not found, try to create: " + OutFile.Directory.FullName); try { Directory.CreateDirectory(OutFile.Directory.FullName); } catch (Exception ex) { Messages.AppendLine("OutDirectory could not be created: " + OutFile.Directory.FullName); return("error"); } } //djxl --jpeg OutFile Messages.AppendLine("OutFile.Extension.ToLower(): " + OutFile.Extension.ToLower()); if (OutFile.Extension.ToLower() == ".jpg" || OutFile.Extension.ToLower() == ".jpeg") { //argsDecoder.Append("--jpeg "); Params.Add(new jxlNET.Decoder.Parameters.JPEG()); } else if (OutFile.Extension.ToLower() == ".png") { } string args = CmdLine; Messages.AppendLine("Decoder Parameter: " + args); ProcessStartInfo startInfoDecoder = new ProcessStartInfo { Arguments = args, FileName = Options.DecoderPath, WorkingDirectory = Options.WorkingDirectory, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; //SAVE Decoded FILE Messages.AppendLine("Decode File: " + InFile.FullName + " to: " + OutFile.FullName); Process procDecode = new Process(); procDecode.StartInfo = startInfoDecoder; procDecode.Start(); string processDecodeStandardOutput = procDecode.StandardOutput.ReadToEnd(); string processDecodeStandardError = procDecode.StandardError.ReadToEnd(); ProcessText.Append(Environment.NewLine + processDecodeStandardOutput + Environment.NewLine + processDecodeStandardError); //Console.WriteLine("processDecodeStandardOutput: " + processDecodeStandardOutput); //Console.WriteLine("processDecodeStandardError: " + processDecodeStandardError); Messages.AppendLine("Decoding DONE: " + OutFile.FullName); return(ProcessText.Text + Environment.NewLine + Messages.Text); }
public void Replay_Processor(string FileName, double Record, double Playback) { string[] Contents = File.ReadAllLines(FileName); int i = 0; while (i <= Contents.Length - 1) { ProcessText.Text = "Progress: " + ((int)(((double)i / (double)Contents.Length) * 100)).ToString() + "%"; ProcessText.Refresh(); Progress.Value = (int)(((double)i / (double)Contents.Length) * 100); Progress.Refresh(); if (Contents[i].ToLower().StartsWith("YFSVERSI ".ToLower())) { //System.Threading.Thread.Sleep(1000); } else if (Contents[i].ToLower().StartsWith("AIRPLANE ".ToLower())) { //System.Threading.Thread.Sleep(1000); while (i < Contents.Length - 1) { //System.Threading.Thread.Sleep(1000); i += 1; ProcessText.Text = "Progress: " + ((int)(((double)i / (double)Contents.Length) * 100)).ToString() + "%"; ProcessText.Refresh(); Progress.Value = (int)(((double)i / (double)Contents.Length) * 100); Progress.Refresh(); Application.DoEvents(); if (Contents[i].ToLower().StartsWith("NUMRECOR ".ToLower())) { ProcessText.Text = Contents[i]; ProcessText.Refresh(); Application.DoEvents(); //System.Threading.Thread.Sleep(1000); i += 1; while (true) { if (i + 4 < Contents.Length - 1) { double currentvalue; if (!(double.TryParse(Contents[i], out currentvalue))) { //We're now outside of this aircraft scope. Break the loop! //ProcessText.Text = "Break!: " + Contents[i]; //ProcessText.Refresh(); Application.DoEvents(); //System.Threading.Thread.Sleep(1000); break; } else { //ProcessText.Text = "TIME: " + Contents[i] + "NEW: " + (Playback / Record * currentvalue).ToString(); Contents[i] = (Playback / Record * currentvalue).ToString(); //ProcessText.Refresh(); //Application.DoEvents(); //System.Threading.Thread.Sleep(100); } //System.Threading.Thread.Sleep(1000); i += 4; if (ProcessText.Text != ((int)(((double)i / (double)Contents.Length) * 100)).ToString()) { ProcessText.Text = "Progress: " + ((int)(((double)i / (double)Contents.Length) * 100)).ToString() + "%"; ProcessText.Refresh(); Progress.Value = (int)(((double)i / (double)Contents.Length) * 100); Progress.Refresh(); Application.DoEvents(); } } else { ProcessText.Text = "Error at line " + i.ToString() + ": Expected a Flight Record Packet, but got cut short instead!"; ProcessText.ForeColor = System.Drawing.Color.Red; ProcessText.Refresh(); return; } } } } } i += 1; } ProcessText.Text = "Done!"; ProcessText.ForeColor = System.Drawing.Color.Green; Progress.Value = 100; FileNameHolder.ReadOnly = false; File.WriteAllLines(FileNameHolder.Text.Remove(FileNameHolder.Text.Length - 4) + "_Processed.yfs", Contents); RecordingFPS.ReadOnly = false; PlaybackFPS.ReadOnly = false; Process.Text = "Process"; Process.Enabled = true; Browse.Enabled = true; return; }
public async Task SelectTypeLikeIntent(IDialogContext context, LuisResult result) { Dictionary <EntityRecommendation, List <EntityRecommendation> > .Enumerator prefEnum = entitiesPreferences.GetEnumerator(); if (setPreferencesClose == false && confirmWait == false && changePreferenceUnderstand == false) { LinkedList <string> detectedSentences = await ProcessText.InvokeRequestResponseService(result.Query); try { if (entitiesPreferences.Count > 1) { bool foundEntity = false; while (prefEnum.MoveNext()) { LinkedList <string> .Enumerator sentencesEnumerator = detectedSentences.GetEnumerator(); while (sentencesEnumerator.MoveNext()) { if (sentencesEnumerator.Current.Contains(prefEnum.Current.Key.Entity)) {// se è presente l'entità foundEntity = true; resultEntity.Add(prefEnum.Current.Key, new List <string>()); List <EntityRecommendation> .Enumerator typeEnum = prefEnum.Current.Value.GetEnumerator(); bool foundAtMostOneType = false; while (typeEnum.MoveNext() && foundAtMostOneType == false) { if (sentencesEnumerator.Current.Contains(typeEnum.Current.Type) && !typeCattured.Contains(typeEnum.Current.Type)) { foundAtMostOneType = true; typeCattured.Add(typeEnum.Current.Type); if (!valuetedEntities.Contains(prefEnum.Current.Key)) { valuetedEntities.Add(prefEnum.Current.Key); } Dictionary <EntityRecommendation, List <string> > .Enumerator resultEnum = resultEntity.GetEnumerator(); while (resultEnum.MoveNext()) { if (resultEnum.Current.Key.Equals(prefEnum.Current.Key)) { resultEnum.Current.Value.Add(typeEnum.Current.Type); } } resultEnum.Dispose(); } } typeEnum.Dispose(); if (foundAtMostOneType == false) { await context.PostAsync($"No type present! Repeat because I need to know please!"); } } } sentencesEnumerator.Dispose(); } typeCattured.Clear(); if (foundEntity == false) { await context.PostAsync($"No entity is present! Repeat because I need to know!"); } } if (entitiesPreferences.Count == 1) { while (prefEnum.MoveNext()) { resultEntity.Add(prefEnum.Current.Key, new List <string>()); List <EntityRecommendation> .Enumerator typeEnum = prefEnum.Current.Value.GetEnumerator(); bool found = false; while (typeEnum.MoveNext()) { if (result.Query.Contains(typeEnum.Current.Type) && !typeCattured.Contains(typeEnum.Current.Type)) { found = true; typeCattured.Add(typeEnum.Current.Type); if (!valuetedEntities.Contains(prefEnum.Current.Key)) { valuetedEntities.Add(prefEnum.Current.Key); } Dictionary <EntityRecommendation, List <string> > .Enumerator resultEnum = resultEntity.GetEnumerator(); while (resultEnum.MoveNext()) { if (resultEnum.Current.Key.Equals(prefEnum.Current.Key)) { resultEnum.Current.Value.Add(typeEnum.Current.Type); } } resultEnum.Dispose(); } } typeEnum.Dispose(); if (found == false) { await context.PostAsync($"Not type present! Repeat because I need to know please!"); } } prefEnum.Dispose(); } } catch (Exception e) { Debug.Print($"{e.Message}"); } Debug.Print($"entità valutate: {valuetedEntities.Count} == entità da valutare: {entitiesPreferences.Count}"); if (valuetedEntities.Count > 0) { string understandLike = "I understand that you "; Dictionary <EntityRecommendation, List <string> > .Enumerator enumerator = resultEntity.GetEnumerator(); int i = 1; while (enumerator.MoveNext()) { Debug.Print($"Entità: {enumerator.Current.Key.Entity} con tipi: "); double?like = getSentimentByEntity(enumerator.Current.Key); if (like > 0.5) { understandLike += "like "; } if (like <= 0.5) { understandLike += "dislike "; } understandLike += enumerator.Current.Key.Entity + " with type "; List <string> .Enumerator enumerator2 = enumerator.Current.Value.GetEnumerator(); while (enumerator2.MoveNext()) { understandLike += enumerator2.Current + " "; Debug.Print($"{enumerator2.Current}"); } enumerator2.Dispose(); Debug.Print("\n\n\n"); if (i != resultEntity.Count) { understandLike += " and "; } i++; } enumerator.Dispose(); if (valuetedEntities.Count == entitiesPreferences.Count) // se sono state valutate tutte le entità { await context.PostAsync($"{understandLike}, Confirm ? Reponde with yes or no!"); await context.PostAsync("If the type of entity is wrong type 'Type wrong' and repeat again else type 'NO' and i will ask you where i wrong!"); setPreferencesClose = true; confirmWait = true; } else { await context.PostAsync($"{understandLike}"); } } } else { await context.PostAsync("Tell the entity what you like with its type one at time! Thank you!"); } context.Wait(MessageReceived); }
public async Task LearningUserPreferencesIntent(IDialogContext context, LuisResult result) { if (firstAcces == true) { if (setPreferencesClose == true && confirmWait == false && changePreferenceUnderstand == false) { if (result.Entities.Count > 0) { LinkedList <string> detectedSentences = await ProcessText.InvokeRequestResponseService(result.Query); int j = 0; LinkedList <string> .Enumerator enumeratorSentence = detectedSentences.GetEnumerator(); while (enumeratorSentence.MoveNext()) { double?score = await SentimentAnalyzer.GetSentiment(enumeratorSentence.Current, Convert.ToString(j++)); //per ogni entità controllo se sia presente in questa frase IEnumerator <EntityRecommendation> e = result.Entities.GetEnumerator(); while (e.MoveNext()) { if (enumeratorSentence.Current.Contains(e.Current.Entity)) { entityScore.Add(e.Current, score); } } e.Dispose(); } enumeratorSentence.Dispose(); Dictionary <EntityRecommendation, double?> .KeyCollection keys = entityScore.Keys; Dictionary <EntityRecommendation, double?> .KeyCollection.Enumerator key = keys.GetEnumerator(); //controllo se un entità è di più tipi List <EntityRecommendation> copyEntity = new List <EntityRecommendation>(keys); List <string> examinedKeys = new List <string>(); List <EntityRecommendation> resultEntityMultipleType = new List <EntityRecommendation>(); try { while (key.MoveNext()) { if (!examinedKeys.Contains(key.Current.Entity)) { resultEntityMultipleType = copyEntity.FindAll(x => x.Entity.Equals(key.Current.Entity)); examinedKeys.Add(key.Current.Entity); } List <EntityRecommendation> .Enumerator enu = resultEntityMultipleType.GetEnumerator(); if (resultEntityMultipleType.Count == 1) { if (getSentimentByEntity(key.Current) > 0.5) { await context.PostAsync($"I understand what you like {key.Current.Entity}! Confirm ? Respond with yes or no!"); } else { await context.PostAsync($"I understand what you dislike {key.Current.Entity}! Confirm ? Respond with yes or no!"); } resultEntityMultipleType.Clear(); resultEntity = null; confirmWait = true; } if (resultEntityMultipleType.Count > 1) { string question = string.Empty; int i = 1; while (enu.MoveNext()) { if (i == 1) { question = $"{enu.Current.Entity} as "; if (!entitiesPreferences.ContainsKey(enu.Current)) { List <EntityRecommendation> copy = new List <EntityRecommendation>(resultEntityMultipleType); entitiesPreferences.Add(enu.Current, copy); } } if (i < resultEntityMultipleType.Count && i > 0 && !question.Contains(enu.Current.Type)) { question += enu.Current.Type + " or "; } if (i == resultEntityMultipleType.Count && !question.Contains(enu.Current.Type)) { question += enu.Current.Type; } if (i == resultEntityMultipleType.Count) { question += "?"; } i++; } await context.PostAsync(question); setPreferencesClose = false; } List <EntityRecommendation> .Enumerator o = resultEntityMultipleType.GetEnumerator(); while (o.MoveNext()) { Debug.Print(o.Current.Entity + " " + o.Current.Type); } resultEntityMultipleType.Clear(); } } catch (Exception e) { Debug.Print(e.Message);//questa eccezione mi serve per forzare l'uscita dal ciclo } } else { await context.PostAsync("I don't understand who you say! Can you repeat please?"); } } else { await context.PostAsync("Respond to the all question please"); } } else { await context.PostAsync("Rude! Say hello!"); } context.Wait(MessageReceived); }
private string encode() { //Checks if (!File.Exists(InFile.FullName)) { string m = "InputFile not found: " + InFile.FullName; Messages.AppendLine(m); return("error: " + m); } if (!File.Exists(Options.EncoderPath)) { string m = "Encoder not found: " + Options.EncoderPath; Messages.AppendLine(m); return("error: " + m); } if (!Directory.Exists(Options.OutDir)) { Messages.AppendLine("OutDirectory not found, try to create: " + Options.OutDir); try { Directory.CreateDirectory(Options.OutDir); } catch (Exception ex) { string m = "OutDirectory could not be created: " + Options.OutDir; Messages.AppendLine(m); return("error: " + m); } } var watch = System.Diagnostics.Stopwatch.StartNew(); if (File.Exists(InFile.FullName) && AllowedExtensions.Contains(InFile.Extension.ToLower())) { Messages.AppendLine("OutFilePath: " + OutFilePath); //Check if (!Directory.Exists(OutFile.Directory.FullName)) { Messages.AppendLine("OutDirectory not found, try to create: " + OutFile.Directory.FullName); try { Directory.CreateDirectory(OutFile.Directory.FullName); } catch (Exception ex) { string m = "OutDirectory could not be created: " + OutFile.Directory.FullName; Messages.AppendLine(m); return("error: " + m); } } Messages.AppendLine("Encoder Path: " + Options.EncoderPath); string args = CmdLine; Messages.AppendLine("Encoder Parameter: " + args); ProcessStartInfo startInfo = new ProcessStartInfo { Arguments = args, FileName = Options.EncoderPath, WorkingDirectory = Options.WorkingDirectory, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; //SAVE New FILE Messages.AppendLine("Saving File: " + OutFilePath); Process proc = new Process(); proc.StartInfo = startInfo; proc.Start(); string processStandardOutput = proc.StandardOutput.ReadToEnd(); string processStandardError = proc.StandardError.ReadToEnd(); ProcessText.Append(Environment.NewLine + processStandardOutput + Environment.NewLine + processStandardError); //Console.WriteLine("processStandardOutput: " + processStandardOutput); //Console.WriteLine("processStandardError: " + Environment.NewLine + processStandardError); Messages.AppendLine("DONE: " + OutFilePath); // // Nice to have ... // //Decode and check if checksum is the same as orig file in lossless, Option = Validate if (Options.Validate) { // Checksum InFile string checksumOrig = Checksum.SHA256CheckSum(InFile.FullName); Messages.AppendLine("checksumOrig: " + checksumOrig); string DecodedFilePath = Path.Combine(OutFile.Directory.FullName, "verify_" + InFile.Name); FileInfo DecodedFileInfo = new FileInfo(DecodedFilePath); //DECODE Decoder.Decode(OutFile, DecodedFileInfo); //CHECKSUM string checksumDecoded = "failed"; if (File.Exists(DecodedFileInfo.FullName)) { checksumDecoded = Checksum.SHA256CheckSum(DecodedFileInfo.FullName); } Messages.AppendLine("checksumDecoded: " + checksumDecoded); Messages.AppendLine("checksumOrig: " + checksumOrig); } } else { Messages.AppendLine("ERROR: file dos not exist or extension not correct: " + InFile.FullName); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; var elapsedMinutes = TimeSpan.FromMilliseconds(elapsedMs).TotalMinutes; Messages.AppendLine("done. (" + elapsedMinutes + " Minutes)"); return(ProcessText.Text + Environment.NewLine + Messages.Text); }