public FeatureContext(AppContext appContext, Feature feature) { if (appContext == null) throw new ArgumentNullException(nameof(appContext)); if (feature == null) throw new ArgumentNullException(nameof(feature)); this.AppContext = appContext; this.Feature = feature; this.DbContext = appContext.DbContextCreator(); }
public static Feature StartNew(string context, string name) { if (context == null) throw new ArgumentNullException(nameof(context)); if (name == null) throw new ArgumentNullException(nameof(name)); var feature = new Feature(context, name); feature.Start(); return feature; }
public async Task<DialogResult> ShowAsync(string message, Feature feature, DialogType? type = null) { if (message == null) throw new ArgumentNullException(nameof(message)); if (feature == null) throw new ArgumentNullException(nameof(feature)); var dialog = new MessageDialog(message); UICommandInvokedHandler empty = cmd => { }; dialog.Commands.Add(new UICommand(@"Accept", empty, DialogResult.Accept)); dialog.Commands.Add(new UICommand(@"Cancel", empty, DialogResult.Cancel)); dialog.Commands.Add(new UICommand(@"Decline", empty, DialogResult.Decline)); feature.Pause(); var task = dialog.ShowAsync().AsTask(); var result = await task; feature.Resume(); return (DialogResult)result.Id; }
public void Write(Feature feature, string details = null) { if (feature == null) throw new ArgumentNullException(nameof(feature)); // Stop the feature feature.Stop(); var currentDetails = details; if (feature.TimeSpent != TimeSpan.Zero) { currentDetails = feature.TimeSpent.ToString(@"c"); } using (var context = this.DbContextCreator()) { var featureRow = this.Save(context, feature.Context, feature.Name); FeatureAdapter.InsertFeatureEntry(context, featureRow.Id, currentDetails ?? string.Empty); context.Complete(); } }
private static void InspectFeature(Feature f) { //var buffer = new StringBuilder(); //var ctxName = feature.Context + "(" + feature.Name + ")"; //buffer.Append(ctxName.PadRight(25)); //buffer.Append(' '); //buffer.Append(feature.Details.PadRight(12)); //buffer.Append(' '); //buffer.AppendLine(feature.TimeSpent.TotalMilliseconds.ToString(CultureInfo.InvariantCulture).PadRight(6)); //if (feature.Steps.Any()) //{ // var totalMilliseconds = feature.TimeSpent.TotalMilliseconds; // var remaingTime = totalMilliseconds - (feature.Steps.Select(v => v.TimeSpent.TotalMilliseconds).Sum()); // foreach (var s in feature.Steps.Concat(new[] { new FeatureEntryStep(@"Other", TimeSpan.FromMilliseconds(remaingTime), string.Empty) })) // { // buffer.Append('\t'); // var value = s.Name.Replace(@"Async", string.Empty); // value = Regex.Replace(value, @"[A-Z]", m => @" " + m.Value).TrimStart(); // buffer.Append(value.PadRight(24)); // buffer.Append(' '); // buffer.Append(s.Details.PadRight(4)); // buffer.Append(' '); // var milliseconds = s.TimeSpent.TotalMilliseconds; // var tmp = (milliseconds / totalMilliseconds) * 100; // var graph = new string('-', (int)tmp); // buffer.Append(milliseconds.ToString(CultureInfo.InvariantCulture).PadRight(8)); // buffer.Append(tmp.ToString(@"F2").PadLeft(5)); // buffer.Append(@"% "); // buffer.AppendLine(graph); // } //} //buffer.AppendLine(); //var output = buffer.ToString(); //Debug.WriteLine(output); //Console.WriteLine(output); //File.AppendAllText(@"C:\temp\diagnostics.txt", output); }
private static string InsertVisit(Feature f) { { // TODO : !!! return @"new visit"; } }
private static void InsertActivity(Feature feature, string visit, string activity) { { var copy = activity + @"+" + visit; } }
private static string GetVisit(Feature f) { { // TODO : !!! return null; return "Get from db"; } }
private static List<object> GetDays(Feature feature, DateTime value) { { Thread.Sleep(5); return new List<object>(); } }
private static string CreateVisit(Feature f) { var canCreateActivityForOutlet = CanCreateActivityForOutlet(f); if (canCreateActivityForOutlet.Type != PermissionType.Allow) return null; { var visit = GetVisit(f); if (visit != null) return visit; return InsertVisit(f); } }
public void Write(Feature feature, Exception exception) { if (feature == null) throw new ArgumentNullException(nameof(feature)); if (exception == null) throw new ArgumentNullException(nameof(exception)); using (var context = this.DbContextCreator()) { var featureRow = this.Save(context, feature.Context, feature.Name); var exceptionId = FeatureAdapter.GetOrCreateException(context, exception.ToString()); FeatureAdapter.InsertExceptionEntry(context, featureRow.Id, exceptionId); context.Complete(); } }
private static void CopyActivity(Feature feature, string activity) { var date = SelectDateFromDialog(feature); if (date == null) return; var days = GetDays(feature, date.Value); var isDayActive = IsDayActive(feature, days); if (!isDayActive) return; var isDayInThePast = IsDayInThePast(feature, days); if (isDayInThePast) return; var copyActivity = activity + @"*"; CreateActivity(feature, activity); }
private static PermissionResult CanCreateActivityForOutlet(Feature f) { { { var assignment = "From the for outlet"; if (assignment == null) { // TODO : Display message return PermissionResult.Deny("No outlet assignment"); } var hasAssignment = assignment.Length > 0; if (!hasAssignment) { // TODO : Display message return PermissionResult.Deny("Invalid assignment"); } } //Is R E D Activities Allowed { // TODO : !!! return PermissionResult.Allow.Result; } } }
public Task<DialogResult> ShowAsync(string message, Feature feature, DialogType? type = null) { return Task.FromResult(DialogResult.Cancel); }
private static DateTime? SelectDateFromDialog(Feature feature) { { // TODO : !!! Get from the UI return DateTime.Today.AddDays(1); } }
private static bool IsDayActive(Feature feature, List<object> days) { { //Thread.Sleep(100); // TODO : Query the db return true; } }
private static bool IsDayInThePast(Feature feature, List<object> days) { { // TODO : Query the db //Thread.Sleep(100); return false; } }
private static void CreateActivity(Feature feature, string activity) { { var visit = CreateVisit(feature); if (visit == null) return; InsertActivity(feature, visit, activity); } }