Example #1
0
        void QueueMessage(MessageInfo mi, NativeActivityContext context)
        {
            if (mi == null)
            {
                return;
            }
            var        process   = Process.GetProcessFromContext(context);
            IMessaging messaging = context.GetExtension <IMessaging>();

            var qm = messaging.CreateQueuedMessage();

            qm.Template    = mi.Template;
            qm.Key         = mi.Key;
            qm.TargetId    = mi.TargetId;
            qm.Immediately = mi.Immediately;

            qm.Source = $"SendMessage";

            qm.Environment.Add("ProcessId", process.Id);
            qm.Parameters.Append(mi.Parameters, replaceExisiting: true);

            Int64 msgId = messaging.QueueMessage(qm);

            context.TrackRecord($"Message queued successfully {{Id: {msgId}}}");
        }
        public async Task <ServerCommandResult> Execute(RequestCommand cmd, ExpandoObject dataToExec)
        {
            var r    = new ServerCommandResult();
            var qm   = _messaging.CreateQueuedMessage();
            var prms = cmd.parameters;

            qm.Key      = prms.Get <String>("key");
            qm.Template = prms.Get <String>("template");
            qm.TargetId = Int64.Parse(cmd.Id);
            qm.Source   = "ServerCommand";
            qm.Parameters.Append(dataToExec);
            bool immediately = true;

            if (prms.HasProperty(nameof(immediately)))
            {
                immediately = prms.Get <Boolean>(nameof(immediately));
            }
            long msgId = await _messaging.QueueMessageAsync(qm, immediately);

            if (immediately)
            {
                await _messaging.SendMessageAsync(msgId);
            }
            r.Data = $"{{\"status\":\"success\", \"id\":{msgId}}}";
            return(r);
        }