Is it possible to show animation in uwp toast notification? - c#

I'm trying to understand if it's possible to show a countdown timer for example or some sort of animation or anything dynamic in toast notification?

Take a look at this article from Microsoft
https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/toast-progress-bar
This shows how to add a progress bar to a Toast Notification in a UWP app.
First you create your Toast Notification with a specific tag
using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications;
public void SendUpdatableToastWithProgress()
{
// Define a tag (and optionally a group) to uniquely identify the notification, in order update the notification data later;
string tag = "weekly-playlist";
string group = "downloads";
// Construct the toast content with data bound fields
var content = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Downloading your weekly playlist..."
},
new AdaptiveProgressBar()
{
Title = "Weekly playlist",
Value = new BindableProgressBarValue("progressValue"),
ValueStringOverride = new BindableString("progressValueString"),
Status = new BindableString("progressStatus")
}
}
}
}
};
// Generate the toast notification
var toast = new ToastNotification(content.GetXml());
// Assign the tag and group
toast.Tag = tag;
toast.Group = group;
// Assign initial NotificationData values
// Values must be of type string
toast.Data = new NotificationData();
toast.Data.Values["progressValue"] = "0.6";
toast.Data.Values["progressValueString"] = "15/26 songs";
toast.Data.Values["progressStatus"] = "Downloading...";
// Provide sequence number to prevent out-of-order updates, or assign 0 to indicate "always update"
toast.Data.SequenceNumber = 1;
// Show the toast notification to the user
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
Then you can use that tag to update the Toast Notification
using Windows.UI.Notifications;
public void UpdateProgress()
{
// Construct a NotificationData object;
string tag = "weekly-playlist";
string group = "downloads";
// Create NotificationData and make sure the sequence number is incremented
// since last update, or assign 0 for updating regardless of order
var data = new NotificationData
{
SequenceNumber = 2
};
// Assign new values
// Note that you only need to assign values that changed. In this example
// we don't assign progressStatus since we don't need to change it
data.Values["progressValue"] = "0.7";
data.Values["progressValueString"] = "18/26 songs";
// Update the existing notification's data by using tag/group
ToastNotificationManager.CreateToastNotifier().Update(data, tag, group);
}

Related

How to add emojis on a bot message and be able to "vote"?

I made a MEME command of Discord Bot that posts a list of memes from phpMyAdmin DB. But it is not about that. I want to add specific emojis on that bot message that people could press on those emojis and kinda vote.
It is how it posts:
It is what I want to do:
[Command("meme")]
public async Task meme(CommandContext commandInfo, int id = -1, SocketUserMessage userMsg, string emoteName)
{
var description = "";
MySqlClient.Connect();
if (id == -1)
{
var query = "SELECT * FROM memes;";
var memeReader = MySqlClient.GetDataReader(query);
if (memeReader == null) return;
while (memeReader.Read())
{
var memeid = memeReader.GetUInt64("id");
var title = memeReader.GetString("title");
description += $"**{memeid}** {title}\n";
}
}
var memeEmbed = new DiscordEmbedBuilder()
{
Color = DiscordColor.Gold,
Title = "**The Meme of The Year**",
Description = description
};
var msg = await commandInfo.Channel.SendMessageAsync(embed: memeEmbed);
}
Adding Reactions
Assuming you are using Discord.Net, you need to react to your own message using the AddReactionAsync method.
Adding Emojis
Emojis are unicode characters. To use them, pass the utf-code (e.g. "\uD83D\uDC4C") as an argument to the constructor of the Emoji` object.
await userMsg.AddReactionAsync(new Emoji("\U0001f643"));
Adding Emotes
An Emote is a 'custom Emoji' which can be set by server admins/mods.
As an argument you need to pass a custom Emote string, like this "<:thonkang:282745590985523200>".
A safe wrapper to catch non-existing emotes could look like that (taken from the docs).
public async Task ReactWithEmoteAsync(SocketUserMessage userMsg, string escapedEmote)
{
if (Emote.TryParse(escapedEmote, out var emote))
{
await userMsg.AddReactionAsync(emote);
}
}
https://docs.stillu.cc/guides/emoji/emoji.html
Counting Reactions
As a second step you need to listen to user-events, when they react to your post. This should be done in a separate event handler, as your poll will likely be up for several hours/days.
Here is an example on how to implement an event handler
You then need to keep track of the reactions and need to associate it with the matching database entry.

How to Assign a Dynamic Value to a Toast Notification

I am creating a toast notification for a UWP app, and I have run into a snag. I desire to send the user a message with a quote from an author;
I have a list of 137 quotes that I am reading from, so the toast notification cannot have a static quote or author value. Here's the notification structure:
// Global quote variables
static string quote;
static string author;
// Toast struct
ToastContent toastContent = new ToastContent() {
Visual = new ToastVisual() {
BindingGeneric = new ToastBindingGeneric() {
Children = {
// Bold title text
new AdaptiveText() {
Text = "Motivational Reminder"
},
// Body text
new AdaptiveText() {
Text = quote
}
},
// Small attribution text
Attribution = new ToastGenericAttributionText() {
Text = author
}
}
},
// Notification on-click
Launch = new QueryString() {
{"action", "nothing" }
}.ToString()
};
I init the quote and author variables from another function before creating the toast, of course. I've debugged the program, and I can see that the variables get initialized before I try and make the toast, but they always come out as null:
The RawValue value should resemble the quote in the above picture. How can I otherwise assign a dynamic value to my notification?
I have looked through the Microsoft notification docs, but they always have text present in the example, rather than sourcing it from an outside variable. See here.

Application name in Windows 10's timeline - WinForms

I have the following code:
UserActivitySession _currentActivity;
private async Task GenerateActivityAsync()
{
// Get the default UserActivityChannel and query it for our UserActivity. If the activity doesn't exist, one is created.
UserActivityChannel channel = UserActivityChannel.GetDefault();
UserActivity userActivity = await channel.GetOrCreateUserActivityAsync("Test");
// Populate required properties
userActivity.VisualElements.DisplayText = ActivityName.Text; //ActivityName is textbox
userActivity.ActivationUri = new Uri(ActivityUri.Text); //ActivityUri is also textbox
userActivity.VisualElements.Description = "This is test item";
userActivity.VisualElements.Attribution =
new UserActivityAttribution(new Uri("http://via.placeholder.com/16x16"))
{ AlternateText = "Test123" };
//Save
await userActivity.SaveAsync(); //save the new metadata
// Dispose of any current UserActivitySession, and create a new one.
_currentActivity?.Dispose();
_currentActivity = userActivity.CreateSession();
}
And it results in something like on the screenshot: https://imgur.com/a/LK0NHAa
I want my app's name to be displayed after the dash character (the dash is inserted there by Windows).
You code specifies this:
userActivity.VisualElements.DisplayText = ActivityName.Text;
tried changing the DisplayText to the value you want?
Getting app name:
var pack = Package.Current.Id.Name;

Open new mail interaction window in Genesys Interaction Workspace

I got the task to show the "new outbound mail" dialog in Genesys IWS upon an external event from a webservice. I put my IWS extension in place and it loads and can provide a webservice interface.
My main problem now is that I don't understand how I can open the interactions window from my code. I tried to get an instance of it by using:
IInteractionsWindow interactionsView = Container.Resolve<IInteractionsWindow>();
interactionsView.Create();
interactionsView.ShowView();
This actually works only halfway, as I get a new window, but it's completely empty. Do I need to load every single region on its own? Is there a simpler way to achieve my goals in a fully integrated way?
UPDATE: I have now tried to achieve things using the Platform SDK although I have no idea if this really helps me in showing the "new mail" window to the agent. I tried with the following code:
interactionServerProtocol = new InteractionServerProtocol(new Endpoint(new Uri("tcp://ixnServer:7319")));
interactionServerProtocol.ClientName = "CRMIntegrationModule";
interactionServerProtocol.ClientType = InteractionClient.AgentApplication;
contactServerProtocol = new UniversalContactServerProtocol(new Endpoint(new Uri("tcp://ucsServer:5130")));
contactServerProtocol.ClientName = "CRMIntegrationModule";
interactionServerProtocol.Open();
contactServerProtocol.Open();
RequestSubmit request = RequestSubmit.Create();
request.InteractionType = "Outbound";
request.InteractionSubtype = "OutboundNew";
request.MediaType = "email";
request.Queue = "default";
EventAck response = interactionServerProtocol.Request(request) as EventAck;
if (response != null)
{
string id = Convert.ToString(response.Extension["InteractionId"]);
RequestInsertInteraction insertRequest = RequestInsertInteraction.Create();
insertRequest.InteractionAttributes = new InteractionAttributes
{
Id = id,
MediaTypeId = "email",
TypeId = "Outbound",
SubtypeId = "OutboundNew",
TenantId = 101,
Status = new NullableStatuses(Statuses.Pending),
Subject = "Testmail",
EntityTypeId = new NullableEntityTypes(EntityTypes.EmailOut)
};
insertRequest.EntityAttributes = new EmailOutEntityAttributes()
{
FromAddress = "dummy#gmx.net",
ToAddresses = "dummy#gmx.net",
};
insertRequest.InteractionContent = new InteractionContent()
{
Text = "This is the e-mail body."
};
contactServerProtocol.Send(insertRequest);
RequestPlaceInQueue queueRequest = RequestPlaceInQueue.Create();
queueRequest.InteractionId = id;
queueRequest.Queue = "default";
interactionServerProtocol.Send(queueRequest);
}
interactionServerProtocol.Close();
contactServerProtocol.Close();
The bad thing is the response from the interaction server which is:
attr_ref_id [int] = 2
attr_error_code [int] = 34
attr_error_desc [str] = "Client is not logged in"
I think this could be related to not being logged in correctly somehow but I have not a single clue how to achieve this. Any help?
UPDATE 2 I could send an e-mail using the Platform SDK, but this is not what I really want. The initial question is still valid, as I just want to invoke the interactions window and that's it. The other stuff is up to the user. Is it possible?
You need to use PlatformSDK. add Genesyslab.platform.webmedia.protocols.dll
After that you can use *webmedia.tserver.request, under that tab there is requestWeb or sth.
channelService.RegisterEvents(tServerChannel, new Action<Genesyslab.Enterprise.Model.Channel.IClientChannel>
In your main module(have Initialize method), need to registerevent like that. You can put a button or sth, then you can trigger event or you can use commandchain after logon, is up to you.
Good luck.
I made use of the given command chains:
public IObjectContainer Container { get; set; }
public void NewItem(string contactId, string emailAddress)
{
IAgent agent = Container.Resolve<IAgent>();
IRoutingBasedManager routingManager = Container.Resolve<IRoutingBasedManager>();
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("CommandParameter", agent.FirstMediaEmail);
parameters.Add("TargetId", contactId);
parameters.Add("OwnerId", agent.ConfPerson.EmailAddress);
parameters.Add("Destination", emailAddress);
parameters.Add("RecentIndex", contactId);
bool todo = routingManager.RequestToDo("CreateNewOutboundEmail", RoutingBasedTarget.Contact, parameters);
if (todo && parameters.ContainsKey("RoutingBaseCommand"))
{
IChainOfCommand chainOfCommand = parameters["RoutingBaseCommand"] as IChainOfCommand;
if (chainOfCommand != null)
{
chainOfCommand.Execute(parameters["RoutingBaseCommandParameters"]);
}
}
}

Monotouch EKEvent Notes not being saved

What am I doing wrong here? currentEvent.Title prints correctly. currentEvent.Notes is always blank..
public void CalendarEvents()
{
EKEventStore store = new EKEventStore();
EKCalendar calendar = store.DefaultCalendarForNewEvents;
// Query the event
if (calendar != null)
{
// Add a new event
EKEvent newEvent = EKEvent.FromStore(store);
newEvent.Title = "Lunch at McDonalds";
newEvent.Calendar = calendar;
newEvent.StartDate = DateTime.Now.Date;
newEvent.EndDate = DateTime.Now.Date.AddDays(4);
newEvent.Availability = EKEventAvailability.Free;
newEvent.Notes = "hello";
store.SaveEvent(newEvent, EKSpan.ThisEvent, new IntPtr());
// Searches for every event in the next year
NSPredicate predicate = store.PredicateForEvents(NSDate.Now,DateTime.Now.AddDays(360),new EKCalendar[] {calendar});
store.EnumerateEvents(predicate, delegate(EKEvent currentEvent, ref bool stop)
{
// Perform your check for an event type
Console.WriteLine(currentEvent.Title);
Console.WriteLine(currentEvent.Notes);
});
}
}
The API likely has changed because the above won't compile 'as-is'. So I updated your:
store.SaveEvent(newEvent, EKSpan.ThisEvent, new IntPtr());
to
NSError error;
store.SaveEvent(newEvent, EKSpan.ThisEvent, out error);
Otherwise, using the latest MonoTouch, I get both strings displayed in the "Application Output" (app running on device).
Lunch at McDonalds
hello
Maybe that was fixed when the API was modified ?

Categories

Resources