private Task ProcessFiles() { return(Task.Run(async() => { var fileInfos = new DirectoryInfo(FilePath).GetFiles(FilePattern); foreach (var fileInfo in fileInfos) { var newNumLines = await GetLineCount(fileInfo.FullName); var oldFileInfoPair = FileLineMap.FirstOrDefault(fi => fi.Key.Name == fileInfo.Name); if (!oldFileInfoPair.Equals(default(KeyValuePair <FileInfo, int>)) && oldFileInfoPair.Key.LastWriteTime != fileInfo.LastWriteTime) { // update the # of lines (other FileInfo properties will be refreshed in RemoveDeletedFiles) if (FileLineMap.TryUpdate(oldFileInfoPair.Key, newNumLines, oldFileInfoPair.Value)) { OutputFunction.Invoke($"Changed: {fileInfo.Name}, {newNumLines - oldFileInfoPair.Value}"); } } // new file else { if (oldFileInfoPair.Key?.Name != fileInfo.Name && FileLineMap.TryAdd(fileInfo, newNumLines)) { OutputFunction.Invoke($"Created: {fileInfo.Name}, {newNumLines}"); } } } // no need to wait for this Task.Factory.StartNew(RemoveDeletedFiles, CancellationToken); }, CancellationToken)); }
public override void BeginMonitor() { Task.Factory.StartNew(() => { var t = new Timer(_interval) { AutoReset = true }; t.Elapsed += async delegate { try { await Timer_Elapsed(); } catch (Exception e) { OutputFunction.Invoke(e.Message); } finally { // if anything happens, restart the timer t.Start(); } }; t.Start(); }, CancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
/// <summary> /// The classic Render functions, which lets you supply the maximum width and the function /// which has to be used for printing. /// </summary> /// <param name="data"> /// A data object <see cref="IList<IList<System.Object>>"/> /// </param> /// <param name="outputFunction"> /// A delegate to the output function <see cref="OutputFunction"/> /// </param> /// <param name="maximumWidth"> /// the maximum width of the table <see cref="System.Int32"/> /// </param> public void Render(IList <IList <object> > data, OutputFunction outputFunction, int maximumWidth) { int[] lengths = null; List <int> tmp = new List <int>(Header.Count); foreach (TextTools.Header headerEntry in Header) { tmp.Add(headerEntry.Name.Length); } lengths = tmp.ToArray(); // it's always the empty list that gets the rockets down if (data.Count > 0) { lengths = GetLongestDataEntryLengthArray(data); // determine the maximum length for (int i = 0; i < lengths.Length; i++) { if (Header[i].Name.Length > lengths[i]) { lengths[i] = Header[i].Name.Length; } if (Header[i].MinimumLength > lengths[i]) { lengths[i] = Header[i].MinimumLength; } else if (Header[i].MaximumLength < lengths[i]) { lengths[i] = Header[i].MaximumLength; } } } // build and print the header StringBuilder sb = new StringBuilder(); for (int i = 0; i < lengths.Length; i++) { sb.Append(Trim(Header[i].Alignment, Header[i].Name, lengths[i])); sb.Append(" "); } sb.Append("\n"); outputFunction(sb.ToString()); // build and print the rows foreach (IList <object> obj in data) { sb = new StringBuilder(); for (int i = 0; i < lengths.Length; i++) { sb.Append(Trim(Header[i].CellAlignment, obj[i].ToString(), lengths[i])); sb.Append(" "); } sb.Append("\n"); outputFunction(sb.ToString()); } }
public IOFunctionEventArgs(OutputFunction Out1, OutputFunction Out2, OutputFunction Out3, OutputFunction Out4, InputFunction In1, InputFunction In2) { _out1 = Out1; _out2 = Out2; _out3 = Out3; _out4 = Out4; _in1 = In1; _in2 = In2; }
/// <summary> /// Gets the input and output functions. Used in instances of the enums 'OutputFunction', 'InputFunction'. /// Triggers the event to commit the values (output, input functions) to the eventHandler in GuiSimpleForm. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { OutputFunction Out1 = (OutputFunction)checkedListOutputIO1.SelectedIndex; OutputFunction Out2 = (OutputFunction)checkedListOutputIO2.SelectedIndex; OutputFunction Out3 = (OutputFunction)checkedListOutputIO3.SelectedIndex; OutputFunction Out4 = (OutputFunction)checkedListOutputIO4.SelectedIndex; InputFunction In1 = (InputFunction)checkedListInputIO1.SelectedIndex; InputFunction In2 = (InputFunction)checkedListInputIO2.SelectedIndex; ReadButtonClicked_IOFunctions.Invoke(this, new IOFunctionEventArgs(Out1, Out2, Out3, Out4, In1, In2)); this.Close(); }
/// <summary>Calculates and returns the Node's <see cref="Output" /> value.</summary> /// <remarks>Input is equal to the weights multiplied by the source <see cref="Neuron" />'s Output.</remarks> /// <returns>A double.</returns> public virtual double Evaluate() { if (In.Count > 0) { Input = In.Sum(e => e.Weight * e.Source.Evaluate()); } Output = ActivationFunction.Compute(Input); if (OutputFunction != null) { Output = OutputFunction.Compute(Input); } return(Output); }
private int OutputFunctionToInt(OutputFunction outputMode) { int _result = 0; switch (outputMode) { case OutputFunction.Off: _result = 0; break; case OutputFunction.Manually: _result = 1; break; case OutputFunction.LimitSwitch1: _result = 2; break; case OutputFunction.LimitSwitch2: _result = 3; break; case OutputFunction.LimitSwitch3: _result = 4; break; case OutputFunction.LimitSwitch4: _result = 5; break; case OutputFunction.CoarseFlow: _result = 7; break; case OutputFunction.FineFlow: _result = 8; break; case OutputFunction.Ready: _result = 9; break; case OutputFunction.ToleranceExceeded: _result = 10; break; case OutputFunction.ToleranceUnderrun: _result = 11; break; case OutputFunction.ToleranceExceededUnderrun: _result = 12; break; case OutputFunction.Alert: _result = 13; break; case OutputFunction.DL1DL2: _result = 14; break; case OutputFunction.Empty: _result = 21; break; case OutputFunction.DeviceStatus: _result = 22; break; } return(_result); }
private OutputFunction IntToOutputFunction(int outputMode) { OutputFunction _result = OutputFunction.Off; switch (outputMode) { case 0: _result = OutputFunction.Off; break; case 1: _result = OutputFunction.Manually; break; case 2: _result = OutputFunction.LimitSwitch1; break; case 3: _result = OutputFunction.LimitSwitch2; break; case 4: _result = OutputFunction.LimitSwitch3; break; case 5: _result = OutputFunction.LimitSwitch4; break; case 7: _result = OutputFunction.CoarseFlow; break; case 8: _result = OutputFunction.FineFlow; break; case 9: _result = OutputFunction.Ready; break; case 10: _result = OutputFunction.ToleranceExceeded; break; case 11: _result = OutputFunction.ToleranceUnderrun; break; case 12: _result = OutputFunction.ToleranceExceededUnderrun; break; case 13: _result = OutputFunction.Alert; break; case 14: _result = OutputFunction.DL1DL2; break; case 21: _result = OutputFunction.Empty; break; case 22: _result = OutputFunction.DeviceStatus; break; } return(_result); }
/// <summary> /// Evaluates the state. /// </summary> /// <returns></returns> public override double Evaluate() { // guarantee updates to Input base.Evaluate(); if (In.Count > 0) { // is hidden unit - apply memory states // Input is equal to combined input weights with bias values R = ResetGate.Compute(Rx * Input + Rh * H + Rb); Z = MemoryGate.Compute(Zx * Input + Zh * H + Zb); var htP = ActivationFunction.Compute(Input + R * H); H = (1.0 - Z) * H + Z * htP; Output = OutputFunction?.Compute(H) ?? H; } return(Output); }
public override void BeginMonitor() { Task.Factory.StartNew(() => { _watcher.EnableRaisingEvents = true; OutputFunction.Invoke("Monitor running."); while (true) { if (CancellationToken.IsCancellationRequested) { OutputFunction.Invoke("Monitoring has been cancelled."); // do any clean up here CancellationToken.ThrowIfCancellationRequested(); } } }, CancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
private async void FileEventHandler(object sender, FileSystemEventArgs args) { await Task.Factory.StartNew(async() => { var numLines = 0; var changeType = WatcherChangeTypes.Deleted; if (args.ChangeType == WatcherChangeTypes.Changed) { changeType = WatcherChangeTypes.Created; var oldNumLines = 0; var newNumLines = await GetLineCount(args.FullPath); var kvp = FileLineMap.FirstOrDefault(i => i.Key.Name == args.FullPath); if (kvp.Key != default(FileInfo)) { oldNumLines = kvp.Value; changeType = WatcherChangeTypes.Changed; } numLines = newNumLines - oldNumLines; FileLineMap[new FileInfo(args.FullPath)] = newNumLines; } var sb = new StringBuilder($"{changeType}: {args.Name}"); if (changeType != WatcherChangeTypes.Deleted) { sb.Append($", {numLines}"); } OutputFunction.Invoke(sb.ToString()); }, CancellationToken); }
private void FileError(object sender, ErrorEventArgs args) { OutputFunction.Invoke($"File Error: {args.GetException().Message}"); }
/// <summary> /// Executes an arbitrary list of command inputs (separated by newlines, semicolons, ...) /// </summary> /// <param name="commands">The command string to parse.</param> /// <param name="outputter">The output function to call, or null if none.</param> public void ExecuteCommands(string commands, OutputFunction outputter) { CommandQueue queue = CommandScript.SeparateCommands("command_line", commands, this).ToQueue(this); queue.Outputsystem = outputter; queue.Execute(); }
/// <summary> /// The classic Render functions, which lets you supply the maximum width and the function /// which has to be used for printing. /// </summary> /// <param name="data"> /// A data object <see cref="IList<IList<System.Object>>"/> /// </param> /// <param name="outputFunction"> /// A delegate to the output function <see cref="OutputFunction"/> /// </param> /// <param name="maximumWidth"> /// the maximum width of the table <see cref="System.Int32"/> /// </param> public void Render(IList<IList<object>> data, OutputFunction outputFunction, int maximumWidth) { int[] lengths = null; List<int> tmp = new List<int>(Header.Count); foreach (TextTools.Header headerEntry in Header) tmp.Add(headerEntry.Name.Length); lengths = tmp.ToArray(); // it's always the empty list that gets the rockets down if (data.Count > 0) { lengths = GetLongestDataEntryLengthArray(data); // determine the maximum length for (int i = 0; i < lengths.Length; i++) { if (Header[i].Name.Length > lengths[i]) { lengths[i] = Header[i].Name.Length; } if (Header[i].MinimumLength > lengths[i]) { lengths[i] = Header[i].MinimumLength; } else if (Header[i].MaximumLength < lengths[i]) { lengths[i] = Header[i].MaximumLength; } } } // build and print the header StringBuilder sb = new StringBuilder(); for (int i = 0; i < lengths.Length; i++) { sb.Append(Trim(Header[i].Alignment, Header[i].Name, lengths[i])); sb.Append(" "); } sb.Append("\n"); outputFunction(sb.ToString()); // build and print the rows foreach (IList<object> obj in data) { sb = new StringBuilder(); for (int i = 0; i < lengths.Length; i++) { sb.Append(Trim(Header[i].CellAlignment, obj[i].ToString(), lengths[i])); sb.Append(" "); } sb.Append("\n"); outputFunction(sb.ToString()); } }