public ActionResult NewOrEdit(Dispatchers model, FormCollection frm) { try { var db = DB.Entities; model.Hire_date = CommonFunction.ChangeFormatDate(frm["Hire_date"]); if (model.ID == 0) { // Edit db.Dispatchers.AddObject(model); } else { // Add new db.AttachTo("Dispatchers", model); db.ObjectStateManager.ChangeObjectState(model, System.Data.EntityState.Modified); } db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <inheritdoc/> public async Task <bool> UpdateAsync(ISyncItem <T> item) { try { var file = await StorageService.AppDataFolder.CreateFileAsync(Path); string json = await file.ReadTextAsync(); if (string.IsNullOrWhiteSpace(json)) { return(false); } else { await Dispatchers.RunOnUIThreadAsync(() => { item.Item = SerializationService.Deserialize <T>(json); }); return(true); } } catch (Exception ex) { Debug.WriteLine($"Storage context failed: {ex}"); return(false); } }
public void DispatchedTasksThrowingExceptionsAreCorrectlyHandled() { List <Task> tasks = new List <Task>(); var mainThread = Thread.CurrentThread; long threadCanary = 0; // Ensure tasks are executed asynchronously Dispatchers.TestingMode = false; Dispatchers.QueueInitialTasks = false; // Dispatch an initial task that throws an exception tasks.Add(Dispatchers.LaunchAPI(() => { Assert.NotSame(mainThread, Thread.CurrentThread); throw new Exception("Test exception for DispatchersTest"); })); // Add 3 tasks to queue each one setting threadCanary to true // to indicate if any task has ran. for (int i = 0; i < 3; i++) { tasks.Add(Dispatchers.LaunchAPI(() => { Assert.NotSame(mainThread, Thread.CurrentThread); threadCanary += 1; })); } Task.WaitAll(tasks.ToArray()); Assert.Equal(3, threadCanary); }
private void RemoveDispatcherMenu() { int idx; do { ShowDispatchersList(); Console.Write("Выберите порядковый номер:\n" + "[0] Назад;\n->"); if (!int.TryParse(Console.ReadLine(), out idx)) { continue; } try { Dispatchers.RemoveAt(--idx); } catch (ArgumentOutOfRangeException) { Console.WriteLine("Неверный порядковый номер диспетчера!\n"); } } while (!(idx == -1 || Dispatchers.Count <= MIN_COUNT_DISPETCHER)); }
public void TestTaskQueueing() { var threadCanary = 0; Dispatchers.TestingMode = true; Dispatchers.QueueInitialTasks = true; List <Task> tasks = new List <Task>(); // Add 3 tasks to the queue, each one incrementing threadCanary to // indicate the task has executed. for (int i = 0; i < 3; ++i) { tasks.Add(Dispatchers.LaunchAPI(() => { threadCanary += 1; })); } Assert.Equal(3, Dispatchers.preInitActionQueue.Count); Assert.Equal(0, threadCanary); Dispatchers.FlushQueuedInitialTasks(); Assert.Equal(3, threadCanary); Assert.Empty(Dispatchers.preInitActionQueue); }
public void ReceiveMessage2(Message2 data) { Debug.Log("ReceiveMessage2 received data:" + data.param2); // relay data to next downstream. Dispatchers <MessageBase> .DispatchRoute <WantToReceiveMessage1>().Relay(data, typeof(WantToReceiveMessage2)); }
public void QueuedTasksAreFlushedOffTheMainThread() { var mainThread = Thread.CurrentThread; long threadCanary = 0; Dispatchers.TestingMode = false; Dispatchers.QueueInitialTasks = true; // Add 3 tasks to queue each one setting threadCanary to true // to indicate if any task has ran. for (int i = 0; i < 3; i++) { Dispatchers.LaunchAPI(() => { Assert.NotSame(mainThread, Thread.CurrentThread); Interlocked.Add(ref threadCanary, 1); }); } Assert.Equal(3, Dispatchers.preInitActionQueue.Count); Assert.Equal(0, Interlocked.Read(ref threadCanary)); // Trigger execution to ensure tasks have fired Dispatchers.FlushQueuedInitialTasks(); Assert.Equal(3, Interlocked.Read(ref threadCanary)); Assert.Empty(Dispatchers.preInitActionQueue); }
public void SendToHandler(string id, IEnvelope envelope) { IDispatchMessage dispatcher; if (Dispatchers.TryGetValue(envelope.MessageType, out dispatcher)) { dispatcher.Dispatch(envelope); } else { IEnumerable <Type> inheritanceChain = Reflector.GetInheritanceChain(envelope.MessageType); Type key = null; if ((key = Dispatchers.Keys.FirstOrDefault(k => inheritanceChain.Contains(k))) != null) { dispatcher = Dispatchers[key]; Dispatchers.AddOrUpdate(envelope.MessageType, x => dispatcher, (x, y) => dispatcher); dispatcher.Dispatch(envelope); } // message is a response to a request message else if (ResponseDispatchers.TryRemove(envelope.CorrelationId, out dispatcher)) { dispatcher.Dispatch(envelope); } } }
public void TestCancellingBackgroundTasksClearsQueue() { // Set testing mode to false to allow for background execution. Dispatchers.TestingMode = false; // Set task queuing to true to ensure that we queue tasks when we // launch them. Dispatchers.QueueInitialTasks = true; // Assert the queue is empty Assert.Empty(Dispatchers.taskQueue); // Add a task to the pre-init queue Dispatchers.LaunchAPI(() => { Console.WriteLine("A queued task"); }); // Assert the task was queued Assert.NotEmpty(Dispatchers.taskQueue); Dispatchers.CancelBackgroundTasks(); // Assert the queue is empty Assert.Empty(Dispatchers.taskQueue); }
/// <summary> /// Set a datetime value, truncating it to the metric's resolution. /// </summary> /// <param name="value"> The [Date] value to set. If not provided, will record the current time. public void Set(DateTimeOffset value = new DateTimeOffset()) { if (disabled) { return; } // The current time of datetime offset. var currentTime = value.DateTime; // InvariantCulture calendar still preserves timezones and locality information, // it just formats them in a way to ease persistence. var calendar = CultureInfo.InvariantCulture.Calendar; Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_datetime_set( handle, year: calendar.GetYear(currentTime), month: calendar.GetMonth(currentTime), day: calendar.GetDayOfMonth(currentTime), hour: calendar.GetHour(currentTime), minute: calendar.GetMinute(currentTime), second: calendar.GetSecond(currentTime), nano: Convert.ToInt64(1000000 * calendar.GetMilliseconds(currentTime)), offset_seconds: Convert.ToInt32((currentTime - value.UtcDateTime).TotalSeconds) );; }); }
/// <summary> /// Creates a new <see cref="MainViewModel"/>. /// </summary> public MainViewModel(RuntimeConfiguration configuration) { Configuration = configuration; Configuration.ConsoleWriter = new SourceStream <string>(); ConsoleList = new ObservableCollection <string>(); Configuration.ConsoleWriter.BindResult(t => Dispatchers.RunOnUIThreadAsync(() => ConsoleList.Add(t))); FileList = new ObservableCollection <string>(); var open = new StreamCommand(OpenCommand); open.BindResult(o => Dispatchers.RunOnUIThreadAsync(() => OpenFolder())); var select = new StreamCommand <string>(SelectCommand); select.BindResult(o => Dispatchers.RunOnUIThreadAsync(() => LoadFile(o))); var start = new StreamCommand(StartCommand); start.BindResult(b => Task.Run(StartProcess)); Commands = new List <ICommand>() { open, select, start }; }
/// <summary> /// Returns the number of errors recorded for the given metric. /// </summary> /// <param name="errorType">The type of the error recorded.</param> /// <param name="pingName">Represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`.</param> /// <returns>the number of errors recorded for the metric.</returns> public Int32 TestGetNumRecordedErrors(Testing.ErrorType errorType, string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; switch (submetric) { case BooleanMetricType _: { return(LibGleanFFI.glean_labeled_boolean_test_get_num_recorded_errors(handle, (int)errorType, ping)); } case CounterMetricType _: { return(LibGleanFFI.glean_labeled_counter_test_get_num_recorded_errors(handle, (int)errorType, ping)); } case StringMetricType _: { return(LibGleanFFI.glean_labeled_string_test_get_num_recorded_errors(handle, (int)errorType, ping)); } default: throw new InvalidOperationException("Can not return errors for this metric type"); } }
public async Task Close() { await Task.WhenAll( Dispatchers .Select(async d => await d.Close()) .ToArray() ); }
//methods public bool checkDispatchers() { if (Dispatchers.Count() >= 2) { return(true); } return(false); }
/// <summary> /// Tests whether a value is stored for the metric for testing purposes only. This function will /// attempt to await the last task (if any) writing to the the metric's storage engine before /// returning a value. /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for Defaults /// to the first value in `sendInPings`</param> /// <returns>true if metric value exists, otherwise false</returns> public bool TestHasValue(string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; return(LibGleanFFI.glean_string_test_has_value(this.handle, ping) != 0); }
public void Set_Employees() { Drivers.Clear(); Dispatchers.Clear(); foreach (var user in IoC.Application_Work.All_Users) { if (user is Employee dr && dr.Position == "Driver") { Drivers.Add(Set_Employee(dr)); }
public ActionResult NewOrEdit(int?id = 0) { var obj = DB.Entities.Dispatchers.FirstOrDefault(m => m.ID == id); if (obj == null) { obj = new Dispatchers(); } return(View(obj)); }
/** * Returns the number of errors recorded for the given metric. * * @param errorType The type of the error recorded. * @param pingName represents the name of the ping to retrieve the metric for. * Defaults to the first value in `sendInPings`. * @return the number of errors recorded for the metric. */ public Int32 TestGetNumRecordedErrors(Testing.ErrorType errorType, string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; return(LibGleanFFI.glean_string_test_get_num_recorded_errors( this.handle, (int)errorType, ping )); }
internal CommandTracer(DbContext context, Dispatchers dispatchers) { DebugCheck.NotNull(context); DebugCheck.NotNull(dispatchers); _context = context; _dispatchers = dispatchers; _dispatchers.AddInterceptor(this); }
/// <summary> /// Set a string value. /// </summary> /// <param name="value">This is a user defined string value. If the length of the string exceeds /// the maximum length, it will be truncated</param> public void Set(string value) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { SetSync(value); }); }
/// <summary> /// Set a JWE value. /// </summary> /// <param name="value"> The [`compact representation`](https://tools.ietf.org/html/rfc7516#appendix-A.2.7) of a JWE value.</param> public void setWithCompactRepresentation(string value) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_jwe_set_with_compact_representation(this.handle, value); }); }
/// <summary> /// Build a JWE value from it's elements and set to it. /// </summary> /// <param name="header">A variable-size JWE protected header.</param> /// <param name="key">A variable-size encrypted key. /// This can be an empty octet sequence.</param> /// <param name="initVector">A fixed-size, 96-bit, base64 encoded Jwe initialization vector. /// If not required by the encryption algorithm, can be an empty octet sequence.</param> /// <param name="cipherText">The variable-size base64 encoded cipher text.</param> /// <param name="authTag">A fixed-size, 132-bit, base64 encoded authentication tag. /// Can be an empty octet sequence.</param> public void Set(string header, string key, string initVector, string cipherText, string authTag) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_jwe_set(this.handle, header, key, initVector, cipherText, authTag); }); }
/// <summary> /// Add to counter value. /// </summary> /// <param name="amount">this is the amount to increment the counter by, defaulting to /// 1 if called without parameters.</param> public void Add(Int32 amount = 1) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { AddSync(amount); }); }
/// <summary> /// Abort a previous `Start` call. No error is recorded if no `Start` was called. /// </summary> public void Cancel() { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_timespan_cancel(handle); }); }
/// <summary> /// Explicitly set the timespan value, in nanoseconds. /// /// This API should only be used if your library or application requires recording /// times in a way that can not make use of `Start`/`Stop`/`Cancel`. /// /// `SetRawNanos` does not overwrite a running timer or an already existing value. /// </summary> /// <param name="elapsedNanos">The elapsed time to record, in nanoseconds.</param> public void SetRawNanos(ulong elapsedNanos) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_timespan_set_raw_nanos(handle, elapsedNanos); }); }
/// <summary> /// Record a single value, in the unit specified by `memoryUnit`, to the distribution. /// </summary> /// <param name="sample">the value</param> public void Accumulate(UInt64 sample) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_memory_distribution_accumulate(handle, sample); }); }
public InterceptableDbCommand(DbCommand command, DbInterceptionContext context, Dispatchers dispatchers = null) { DebugCheck.NotNull(command); DebugCheck.NotNull(context); _command = command; _interceptionContext = context; _dispatchers = dispatchers ?? Interception.Dispatch; }
/// <summary> /// Set a quantity value. /// </summary> /// <param name="value">The value to set. Must be non-negative.</param> public void Set(Int32 value) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_quantity_set(this.handle, value); }); }
/// <summary> /// Abort a previous `Start` call. No error is recorded if no `Start` was called. /// </summary> /// <param name="timerId"> /// The `GleanTimerId` associated with this timing. This allows for concurrent timing /// of events associated with different ids to the same timing distribution metric. /// </param> public void Cancel(GleanTimerId timerId) { if (disabled || timerId == null) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_timing_distribution_cancel(handle, timerId); }); }
/// <summary> /// Appends a string value to one or more string list metric stores. /// If the length of the string exceeds the maximum length, it will be truncated. /// </summary> /// <param name="value">This is a user defined string value.</param> public void Add(string value) { if (disabled) { return; } Dispatchers.LaunchAPI(() => { LibGleanFFI.glean_string_list_add( this.handle, value); }); }