public override async ValueTask RenderTypeDeclarationAsync( RenderingTypeScriptDefinitions notification, ActivityType activityType, ActivityDescriptor activityDescriptor, ActivityDefinition activityDefinition, StringBuilder writer, CancellationToken cancellationToken = default) { var targetTypeSchema = activityDefinition.Properties.FirstOrDefault(x => x.Name == nameof(HttpEndpoint.Schema))?.Expressions.Values.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(targetTypeSchema)) { var jsonSchema = await JsonSchema.FromJsonAsync(targetTypeSchema, cancellationToken); var generator = new TypeScriptGenerator(jsonSchema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Interface, TypeScriptVersion = 4 }); var typeScriptType = $"{activityDefinition.Name}Output"; var jsonSchemaTypes = generator.GenerateFile(typeScriptType) .Replace("\r\n", "\n") .Replace("export interface", "declare class"); writer.AppendLine(jsonSchemaTypes); } await base.RenderTypeDeclarationAsync(notification, activityType, activityDescriptor, activityDefinition, writer, cancellationToken); }
public virtual async ValueTask RenderTypeDeclarationAsync( RenderingTypeScriptDefinitions notification, ActivityType activityType, ActivityDescriptor activityDescriptor, ActivityDefinition activityDefinition, StringBuilder writer, CancellationToken cancellationToken = default) { var typeName = activityDefinition.Name; var inputProperties = activityDescriptor.InputProperties; var outputProperties = activityDescriptor.OutputProperties; var interfaceDeclaration = $"declare interface {typeName}"; writer.AppendLine($"{interfaceDeclaration} {{"); foreach (var property in inputProperties) { await RenderActivityPropertyAsync(notification, writer, property.Name, property.Type, activityType, activityDescriptor, activityDefinition, cancellationToken); } foreach (var property in outputProperties) { await RenderActivityPropertyAsync(notification, writer, property.Name, property.Type, activityType, activityDescriptor, activityDefinition, cancellationToken); } writer.AppendLine("}"); }
protected override IEnumerable <ActivityDescriptor> Describe() { yield return(ActivityDescriptor.ForTrigger <HttpRequestTrigger>( Category, T["HTTP Request Trigger"], T["Triggers when an incoming HTTP request is received."], T["Done"])); yield return(ActivityDescriptor.ForAction <HttpRequestAction>( Category, T["HTTP Request"], T["Execute a HTTP request."], T["Done"])); }
protected override IEnumerable <ActivityDescriptor> Describe() { yield return(ActivityDescriptor.ForAction <ReadLine>( Category, T["Read Line"], T["Read a line from the console."], T["Done"])); yield return(ActivityDescriptor.ForAction <WriteLine>( Category, T["Write Line"], T["Write a line to the console."], T["Done"])); }
public static IActivity InstantiateActivity(this ActivityDescriptor descriptor, JToken token = default) { var activityObject = token == null ? Activator.CreateInstance(descriptor.ActivityType) : token.ToObject(descriptor.ActivityType, JsonSerializer.Create(new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); var activity = (IActivity)activityObject; activity.Descriptor = descriptor; return(activity); }
private Engine MakeEngine(int numActivities) { Engine engine = new Engine(); engine.Randomness = new Random(0); ActivityDatabase activities = engine.ActivityDatabase; for (int i = 1; i < numActivities; i++) { ActivityDescriptor activityDescriptor = new ActivityDescriptor("a" + i); Inheritance inheritance = new Inheritance(activities.RootActivity.MakeDescriptor(), activityDescriptor); activities.CreateToDo(inheritance); } return(engine); }
protected virtual ValueTask RenderActivityPropertyAsync( RenderingTypeScriptDefinitions notification, StringBuilder writer, string propertyName, Type propertyType, ActivityType activityType, ActivityDescriptor activityDescriptor, ActivityDefinition activityDefinition, CancellationToken cancellationToken = default) { var typeScriptType = notification.GetTypeScriptType(propertyType); writer.AppendLine($"{propertyName}(): {typeScriptType};"); return(new ValueTask()); }
private ActivityType CreateWebhookActivityType(WebhookDefinition webhook) { var typeName = webhook.Name; var displayName = webhook.Name; var descriptor = new ActivityDescriptor { Type = typeName, DisplayName = displayName, Category = WebhookActivityCategory, Outcomes = new[] { OutcomeNames.Done }, Traits = ActivityTraits.Trigger, InputProperties = new[] { new ActivityInputDescriptor( nameof(HttpEndpoint.Methods), typeof(HashSet <string>), ActivityInputUIHints.Dropdown, "Request Method", "Specify what request method this webhook should handle. Leave empty to handle both GET and POST requests", new[] { "", "GET", "POST" }, "Webhooks", 0, "POST", SyntaxNames.Literal, new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid }) } }; async ValueTask <IActivity> ActivateActivityAsync(ActivityExecutionContext context) { var activity = await _activityActivator.ActivateActivityAsync <HttpEndpoint>(context); activity.Path = webhook.Path; activity.ReadContent = true; activity.TargetType = webhook.PayloadTypeName is not null and not "" ? Type.GetType(webhook.PayloadTypeName) : throw new Exception($"Type {webhook.PayloadTypeName} not found"); return(activity); } return(new ActivityType { TypeName = webhook.Name, Type = typeof(HttpEndpoint), Description = webhook.Description is not null and not "" ? webhook.Description : $"A webhook at {webhook.Path}", DisplayName = webhook.Name, ActivateAsync = ActivateActivityAsync, Describe = () => descriptor });
private void simulate(Engine engine, StatList <DateTime, double> efficiencies) { for (int i = 0; i < efficiencies.NumItems; i++) { DateTime when = efficiencies.GetValueAtIndex(i).Key; if (engine.Test_ChooseExperimentOption().HasError) { break; // not enough data to run more experiments } // make a list of experiment options List <SuggestedMetric> experimentOptions = engine.ChooseExperimentOptions(when); // Skip setting difficulties for now. // Task difficulties could be set via something like: // experimentOptions[0].PlannedMetric.DifficultyEstimate.NumEasiers++; // Make an experiment ExperimentSuggestion suggestion = engine.Experiment(experimentOptions, when); if (!suggestion.Experiment.Started) { engine.PutExperimentInMemory(suggestion.Experiment); } // Do the suggestion double efficiency = efficiencies.FindPreviousItem(when, false).Value; double duration = 1.0 / efficiency; ActivityDescriptor activityDescriptor = suggestion.ActivitySuggestion.ActivityDescriptor; Activity activity = engine.ActivityDatabase.ResolveDescriptor(activityDescriptor); Metric metric = activity.DefaultMetric; Participation participation = new Participation(when, when.AddDays(duration), activityDescriptor); participation.EffectivenessMeasurement = new CompletionEfficiencyMeasurement(metric, true, 0); participation.EffectivenessMeasurement.DismissedActivity = true; RelativeEfficiencyMeasurement measurement = engine.Make_CompletionEfficiencyMeasurement(participation); participation.EffectivenessMeasurement.Computation = measurement; engine.PutParticipationInMemory(participation); } engine.FullUpdate(); DateTime lastDay = efficiencies.GetLastValue().Key; for (int i = 1; i < efficiencies.NumItems; i++) { ListItemStats <DateTime, double> item = efficiencies.GetValueAtIndex(i - 1); ListItemStats <DateTime, double> nextItem = efficiencies.GetValueAtIndex(i); Distribution estimatedEfficiency = engine.EfficiencySummarizer.GetValueDistributionForDates(item.Key, nextItem.Key, true, false); System.Diagnostics.Debug.WriteLine("True efficiency at " + item.Key + " = " + item.Value + ", estimated efficiency = " + estimatedEfficiency.Mean); } System.Diagnostics.Debug.WriteLine("Test done"); }
// Given a Justification, return an appropriate label string, replacing the activity name with "this" if appropriate private string getLabel(Justification justification, ActivityDescriptor activityDescriptor) { string text = justification.Label; string name = activityDescriptor.ActivityName; // In practice, the activity name should only ever appear once in this label. // This check is just to make sure that if the user types a weird activity name like "How", then a label like "How much you should enjoy How" doesn't turn into "this much you should enjoy this". // Although it would be more robust to pass around message builders and resolve the final message here, that would also be more confusing. It is nice for the justifications to simply be strings. // This check isn't completely perfect because it doesn't account for cases where the activity name doesn't appear in the justification at all, // and it can also get confused if the justification contains an activity name that contains this activity name, // but in practice this should be fine, and even if it works incorrectly it just creates a confusing message. if (this.containsExactlyOneInstance(text, name)) { return(text.Replace(name, "this")); } return(text); }
protected override IEnumerable <ActivityDescriptor> Describe() { yield return(ActivityDescriptor.ForAction <ForEach>( ControlFlowCategory, T["For Each"], T["Iterate over a list of items."], T["Next"], T["Done"])); yield return(ActivityDescriptor.ForAction <IfElse>( ControlFlowCategory, T["If/Else"], T["Evaluate a boolean condition and continues execution based on the outcome."], T["True"], T["False"])); yield return(ActivityDescriptor.ForAction <SetVariable>( PrimitivesFlowCategory, T["Set Variable"], T["Set a custom variable on the workflow."], T["Done"])); }
private void ensureAutocompleteUpdated() { if (this.autocompleteUpdated) { return; } string query = this.textBox.Text; List <ProtoActivity> protoActivities = new List <ProtoActivity>(); List <Activity> activities = new List <Activity>(); if (query != null && query != "") { ActivityDescriptor activityDescriptor = new ActivityDescriptor(query); activityDescriptor.PreferAvoidCompletedToDos = true; activityDescriptor.RequiresPerfectMatch = false; // search for some protoactivities protoActivities = this.protoActivity_database.TextSearch(query, this.maxNumResults / 2); // try to fill out the results with activities activities = this.activityDatabase.FindBestMatches(activityDescriptor, this.maxNumResults - protoActivities.Count); // if we didn't find enough activities, try to fill out the rest with protoactivities if (activities.Count + protoActivities.Count < this.maxNumResults) { protoActivities = this.protoActivity_database.TextSearch(query, this.maxNumResults - activities.Count); } } this.putAutocomplete(activities, protoActivities); if (activities.Count < 1 && protoActivities.Count < 1) { // If there are no results, show an explanatory title this.largeFont_autocomplete_gridLayout.PutLayout(this.titleLayout, 0, 0); // If there are no matches, also show a button for jumping directly to the root this.footer.SubLayout = this.rootActivity_buttonLayout; } else { // If there are matches, don't need to show the button for jumping to the root this.footer.SubLayout = null; } this.autocompleteUpdated = true; }
protected override IEnumerable <ActivityDescriptor> Describe() { yield return(ActivityDescriptor.ForTrigger <HttpRequestTrigger>( Category, T["HTTP Request Trigger"], T["Triggers when an incoming HTTP request is received."], T["Done"])); yield return(ActivityDescriptor.For <HttpRequestAction>( Category, T["HTTP Request"], T["Execute a HTTP request."], false, true, a => a.SupportedStatusCodes.Select(x => T[x.ToString()]))); yield return(ActivityDescriptor.ForAction <HttpResponseAction>( Category, T["HTTP Response"], T["Write a HTTP response."], T["Done"])); }
protected override async ValueTask RenderActivityPropertyAsync( RenderingTypeScriptDefinitions notification, StringBuilder writer, string propertyName, Type propertyType, ActivityType activityType, ActivityDescriptor activityDescriptor, ActivityDefinition activityDefinition, CancellationToken cancellationToken = default) { if (propertyName != nameof(HttpEndpoint.Output)) { await base.RenderActivityPropertyAsync(notification, writer, propertyName, propertyType, activityType, activityDescriptor, activityDefinition, cancellationToken); return; } var targetTypeName = activityDefinition.Properties.First(x => x.Name == nameof(HttpEndpoint.TargetType)).Expressions.Values.FirstOrDefault(); var targetTypeSchema = activityDefinition.Properties.First(x => x.Name == nameof(HttpEndpoint.Schema)).Expressions.Values.FirstOrDefault(); var typeScriptType = notification.GetTypeScriptType(propertyType); if (!string.IsNullOrWhiteSpace(targetTypeName)) { var type = Type.GetType(targetTypeName); if (type != null) { typeScriptType = notification.GetTypeScriptType(type); } } else if (!string.IsNullOrWhiteSpace(targetTypeSchema)) { typeScriptType = $"{activityDefinition.Name}Output"; } writer.AppendLine($"{propertyName}(): {typeScriptType}"); }
private List <LayoutChoice_Set> renderJustification(Justification justification, int indent, ActivityDescriptor activityDescriptor, int indexInParent) { string prefix = this.times("....", indent); // add any custom description List <LayoutChoice_Set> results = new List <LayoutChoice_Set>(); // add the specific values double currentMean = Math.Round(justification.Value.Mean, 3); double stddev = Math.Round(justification.Value.StdDev, 3); double weight = Math.Round(justification.Value.Weight, 1); string whatText = this.getLabel(justification, activityDescriptor) + " = " + currentMean + " +/- " + stddev + " (weight = " + weight + ")"; // add additional information for some specific types of justifications InterpolatorSuggestion_Justification interpolatorJustification = justification as InterpolatorSuggestion_Justification; // determine the appropriate list index to show string indexString; if (indent % 2 == 0) { indexString = "" + (indexInParent + 1); } else { indexString = "abcdefghijklmnopqrstuvwxyz".Substring(indexInParent, 1); } results.Add(this.newTextBlock(prefix, indexString + ": ", whatText, indent)); Composite_SuggestionJustification compositeJustification = justification as Composite_SuggestionJustification; if (compositeJustification != null) { // if there are multiple children, explain that this value was computed based on the children int childIndent = indent + 1; // We show non-composite children first to make the output easier to read List <Justification> compositeChildren = new List <Justification>(); List <Justification> plainChildren = new List <Justification>(); foreach (Justification child in compositeJustification.Children) { if (child is Composite_SuggestionJustification) { compositeChildren.Add(child); } else { plainChildren.Add(child); } } int childIndex = 0; foreach (Justification child in plainChildren.Concat(compositeChildren)) { List <LayoutChoice_Set> childLayouts = this.renderJustification(child, childIndent, activityDescriptor, childIndex); childIndex++; results.AddRange(childLayouts); } } return(results); }
// update feedback based on a change in the text void UpdateFeedback() { // update user interface ActivityDescriptor descriptor = this.WorkInProgressActivityDescriptor; string oldText = this.suggestedActivityName; if (descriptor == null) { this.suggestedActivityName = ""; this.autocompleteLayout.setText(""); // hide the Help button if it's there this.responseLayout.SubLayout = null; } else { IEnumerable <Activity> autocompletes = this.Autocompletes; List <String> autocompleteNames = new List <string>(); foreach (Activity suggestion in autocompletes) { autocompleteNames.Add(suggestion.Name); } if (autocompleteNames.Count > 0) { String firstActivity_name = autocompleteNames[0]; this.suggestedActivityName = firstActivity_name; if (firstActivity_name == descriptor.ActivityName) { // perfect match, so display nothing this.autocompleteLayout.setText(""); } else { // Update suggestion if (!this.AutoAcceptAutocomplete) { // Not auto-accepting the autocomplete; remind the user that they have to push enter for (int i = 0; i < autocompleteNames.Count; i++) { autocompleteNames[i] = autocompleteNames[i] + "?"; } } string suggestionText = String.Join("\n\n", autocompleteNames); this.autocompleteLayout.setText(suggestionText); } // make the autocomplete suggestion appear this.responseLayout.SubLayout = this.autocompleteLayout; } else { // no matches this.suggestedActivityName = ""; // show a help button this.responseLayout.SubLayout = this.autocomplete_longHelpLayout; } } // inform the layout engine that there was a change in the text if (oldText == null || oldText == "") { this.AnnounceChange(true); } }
private Task <IShape> CreateCardShapeAsync(ActivityDescriptor descriptor, CancellationToken cancellationToken) { var activity = descriptor.InstantiateActivity(); return(activityShapeFactory.BuildCardShapeAsync(activity, cancellationToken)); }
public ActivityDescriptorSelectedEventArgs(ActivityDescriptor activityDescriptor) { ActivityDescriptor = activityDescriptor; }
public static IActivity InstantiateActivity(this ActivityDescriptor descriptor, string json) { var token = json != null?JToken.Parse(json) : default; return(InstantiateActivity(descriptor, token)); }