private void MergeInto(CallbackSemantics semantics, CallbackOptions option)
 {
     if (IsSpecified(option) && !semantics.IsSpecified(option))
     {
         semantics.SetOption(option, HasOption(option));
     }
 }
 public void SetOption(CallbackOptions options, bool enabled)
 {
     _options = enabled
              ? _options | options
              : _options & ~options;
     _specified = _specified | options;
 }
Beispiel #3
0
 public static extern bool CreateTimerQueueTimer(
     out IntPtr handle,
     IntPtr queueHandle,
     TimerCallback callback,
     IntPtr callbackParameter,
     uint msBeforeFirstCall,
     uint intervalInMs, // if zero, timer is signaled only once
     CallbackOptions callbackOptions);
        public static string GetCallbackReference([NotNull] this Control thisValue, CallbackOptions options)
        {
            Page page = thisValue.AsPage();
            ClientScriptManager cs = page.ClientScript;

            return(string.IsNullOrEmpty(options.Target)
                                ? cs.GetCallbackEventReference(thisValue, options.Argument, options.OnCallbackCompleteName, options.OnBeforeCallbackScript, options.OnErrorName,
                                                               options.Asynchronous)
                                : cs.GetCallbackEventReference(options.Target, options.Argument, options.OnCallbackCompleteName, options.OnBeforeCallbackScript, options.OnErrorName,
                                                               options.Asynchronous));
        }
Beispiel #5
0
        private async Task <DialogTurnResult> FinishSettingsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //_logger.LogInformation("SettingsDialog.FinishSettingsStepAsync");

            await ShowCurrentSettingsAsync(stepContext, cancellationToken);

            await stepContext.EndDialogAsync(cancellationToken : cancellationToken);

            var callbackOptions = new CallbackOptions();

            callbackOptions.UpdateSettings = true;

            return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), callbackOptions, cancellationToken));
        }
 public SemanticsHandler(
     IHandler handler, CallbackOptions options)
     : base(handler)
 {
     _semantics = new CallbackSemantics(options);
 }
 public bool IsSpecified(CallbackOptions options)
 {
     return((_specified & options) == options);
 }
 public bool HasOption(CallbackOptions options)
 {
     return((_options & options) == options);
 }
 public CallbackSemantics(CallbackOptions options)
 {
     _options = _specified = options;
 }
 public static IHandler Semantics(
     this IHandler handler, CallbackOptions options)
 {
     return(handler == null ? null
          : new SemanticsHandler(handler, options));
 }
Beispiel #11
0
        private async Task StoreReportInDB(ITurnContext context, CallbackOptions options, ReportAnswers answers)
        {
            var userProfileTemporary = await _userProfileTemporaryAccessor.GetAsync(context);

            await Task.Run(() =>
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource     = Consts.DB_SERVER;
                builder.UserID         = Consts.DB_USER;
                builder.Password       = Consts.DB_PASSWORD;
                builder.InitialCatalog = Consts.DB_NAME;

                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    for (int i = 0; i < options.GeneratedPoints.Length; i++)
                    {
                        var attractor = options.GeneratedPoints[i].X;

                        StringBuilder isb = new StringBuilder();
#if RELEASE_PROD
                        isb.Append("INSERT INTO reports (");
#else
                        isb.Append("INSERT INTO reports_dev (");
#endif
                        // isb.Append("id,"); Automatically incremented from the CREATE TABLE... id uniqueidentifier default NEWSEQUENTIALID() primary key command
                        isb.Append("user_id,");
                        isb.Append("platform,");
                        isb.Append("datetime,");
                        isb.Append("visited,");
                        isb.Append("point_type,");
                        if (!string.IsNullOrEmpty(answers.Intent))
                        {
                            isb.Append("intent_set,");
                        }
                        isb.Append("artifact_collected,");
                        isb.Append("fucking_amazing,");
                        isb.Append("rating_meaningfulness,");
                        isb.Append("rating_emotional,");
                        isb.Append("rating_importance,");
                        isb.Append("rating_strangeness,");
                        isb.Append("rating_synchroncity,");
                        isb.Append("text,");
                        isb.Append("photos,");
                        if (userProfileTemporary.IntentSuggestions != null && userProfileTemporary.IntentSuggestions.Length > 0)
                        {
                            isb.Append("intent_suggestions,");
                            isb.Append("time_intent_suggestions_set,");
                        }
                        isb.Append("what_3_words,");
                        if (!string.IsNullOrEmpty(options.NearestPlaces[i]))
                        {
                            isb.Append("nearest_place,");
                            isb.Append("country,");
                        }
                        isb.Append("short_hash_id,");
                        isb.Append("num_water_points_skipped,");
                        isb.Append("gid,");
                        isb.Append("tid,");
                        isb.Append("lid,");
                        isb.Append("idastep,");
                        isb.Append("idacount,");
                        isb.Append("type,");
                        isb.Append("x,");
                        isb.Append("y,");
                        isb.Append("center,");
                        isb.Append("latitude,");
                        isb.Append("longitude,");
                        if (attractor.center.bearing != null)
                        {
                            isb.Append("distance,");
                            isb.Append("initial_bearing,");
                            isb.Append("final_bearing,");
                        }
                        isb.Append("side,");
                        isb.Append("distance_err,");
                        isb.Append("radiusM,");
                        isb.Append("number_points,");
                        isb.Append("mean,");
                        isb.Append("rarity,");
                        isb.Append("power_old,");
                        isb.Append("power,");
                        isb.Append("z_score,");
                        isb.Append("probability_single,");
                        isb.Append("integral_score,");
                        isb.Append("significance,");
                        isb.Append("probability");
                        isb.Append(") VALUES (");
                        isb.Append($"'{userProfileTemporary.UserId}',");       // sha256 hash of channel-issued userId
                        isb.Append($"'{(int)Enum.Parse(typeof(Enums.ChannelPlatform), context.Activity.ChannelId)}',");
                        isb.Append($"'{context.Activity.Timestamp}',");        // datetime
                        isb.Append($"'{(answers.WasPointVisited ? 1 : 0)}',"); // point visited or not?
                        isb.Append($"'{options.PointTypes[i].ToString()}',");  // point type enum as a string
                        if (!string.IsNullOrEmpty(answers.Intent))
                        {
                            isb.Append($"'{SanitizeString(answers.Intent)}',");                                     // intent set by user
                        }
                        isb.Append($"'{(answers.ArtifactCollected ? 1 : 0)}',");                                    // were artifact(s) collected?
                        isb.Append($"'{(answers.WasFuckingAmazing ? 1 : 0)}',");                                    // "yes" or "no" to the was it wow and astounding question
                        isb.Append($"'{SanitizeString(answers.Rating_Meaningfulness)}',");                          // Rating_Meaningfulness
                        isb.Append($"'{SanitizeString(answers.Rating_Emotional)}',");                               // Rating_Emotional
                        isb.Append($"'{SanitizeString(answers.Rating_Importance)}',");                              // Rating_Importance
                        isb.Append($"'{SanitizeString(answers.Rating_Strangeness)}',");                             // Rating_Strangeness
                        isb.Append($"'{SanitizeString(answers.Rating_Synchronicty)}',");                            // Rating_Synchronicty
                        isb.Append($"'{SanitizeString(answers.Report)}',");                                         // text
                        isb.Append($"'{(answers.PhotoURLs != null ? string.Join(",", answers.PhotoURLs) : "")}',"); // photos
                        if (userProfileTemporary.IntentSuggestions != null && userProfileTemporary.IntentSuggestions.Length > 0)
                        {
                            isb.Append($"'{string.Join(",", SanitizeString(userProfileTemporary.IntentSuggestions))}',"); // intent suggestions
                            isb.Append($"'{userProfileTemporary.TimeIntentSuggestionsSet}',");
                        }
                        isb.Append($"'{(!string.IsNullOrEmpty(options.What3Words[i]) ? options.What3Words[i] : "")}',");
                        if (!string.IsNullOrEmpty(options.NearestPlaces[i]))
                        {
                            isb.Append($"'{options.NearestPlaces[i].Substring(0, options.NearestPlaces[i].IndexOf("(") - 1)}',");
                            isb.Append($"'{options.NearestPlaces[i].Substring(options.NearestPlaces[i].IndexOf("(") + 1).Replace(")", "")}',");
                        }
                        isb.Append($"'{options.ShortCodes[i]}',");
                        isb.Append($"'{options.NumWaterPointsSkipped[i]}',");

                        //isb.Append($"'{attractor.GID}',");// was hardcoded at 23 in Fatumbot3
                        var shaGid = "";
                        if (options.ShaGids != null && options.ShaGids.Length >= 1)
                        {
                            shaGid = (options.ShaGids.Length == 1 ? options.ShaGids[0] : options.ShaGids[i]);
                        }
                        isb.Append($"'{shaGid}',");

                        isb.Append($"'{attractor.TID}',");
                        isb.Append($"'{attractor.LID}',");
                        isb.Append($"'{i+1}',");                            // idastep (which element in idacount array)
                        isb.Append($"'{options.GeneratedPoints.Length}',"); // total idacount
                        isb.Append($"'{attractor.type}',");
                        isb.Append($"'{attractor.x}',");
                        isb.Append($"'{attractor.y}',");
                        isb.Append($"geography::Point({attractor.center.point.latitude},{attractor.center.point.longitude}, 4326),");
                        isb.Append($"'{attractor.center.point.latitude}',");
                        isb.Append($"'{attractor.center.point.longitude}',");
                        if (attractor.center.bearing != null)
                        {
                            isb.Append($"'{attractor.center.bearing.distance}',");
                            isb.Append($"'{attractor.center.bearing.initialBearing}',");
                            isb.Append($"'{attractor.center.bearing.finalBearing}',");
                        }
                        isb.Append($"'{attractor.side}',");
                        isb.Append($"'{attractor.distanceErr}',");
                        isb.Append($"'{attractor.radiusM}',");
                        isb.Append($"'{attractor.n}',");
                        isb.Append($"'{attractor.mean}',");
                        isb.Append($"'{attractor.rarity}',");
                        isb.Append($"'{attractor.power_old}',");
                        isb.Append($"'{attractor.power}',");
                        isb.Append($"'{attractor.z_score}',");
                        isb.Append($"'{attractor.probability_single}',");
                        isb.Append($"'{attractor.integral_score}',");
                        isb.Append($"'{attractor.significance}',");
                        isb.Append($"'{attractor.probability}'");
                        isb.Append(")");
                        var insertSql = isb.ToString();
                        Console.WriteLine("SQL:" + insertSql.ToString());

                        using (SqlCommand command = new SqlCommand(insertSql, connection))
                        {
                            // TODO: another way to execute the command? As it's only insert and don't need to read the results here
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                string commandResult = "";
                                while (reader.Read())
                                {
                                    //commandResult += $"{reader.GetString(0)} {reader.GetString(1)}\n";
                                }
                                //context.SendActivityAsync(commandResult);
                            }
                        }
                    }
                }
            });
        }
        // Used as a callback to restart the main dialog (i.e. prompt user for next action) after middleware-intercepted actions
        // (like sending a location or sending "help", which interrupt the normal dialog flow) or long tasks like getting attractors etc.
        // have completed their work on a background thread
        public async Task RepromptMainDialog(ITurnContext turnContext, Dialog dialog, CancellationToken cancellationToken, CallbackOptions callbackOptions = null)
        {
            if (!Helpers.IsRandoLobby(turnContext) && !turnContext.Activity.ChannelId.Equals(ChannelPlatform.discord.ToString()))
            {
                var conversationStateAccesor = _conversationState.CreateProperty <DialogState>(nameof(DialogState));
                var dialogSet = new DialogSet(conversationStateAccesor);
                dialogSet.TelemetryClient = dialog.TelemetryClient;
                dialogSet.Add(dialog);
                var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);

                await dialogContext.ReplaceDialogAsync(nameof(MainDialog), callbackOptions, cancellationToken);

                await _conversationState.SaveChangesAsync(dialogContext.Context, false, cancellationToken);
            }
        }