如何在收到新订单时显示通知

时间:2016-08-23 11:53:56

标签: c# wordpress woocommerce uwp

我正在为UWP(C#)编写应用程序,它是餐厅的管理面板。它需要从WordPress网站接收订单。我组织了这样的WooCommerce接收

public async void Down()
{
    RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
    WCObject wc = new WCObject(rest);
    //Get all products
    var orders = await wc.GetOrders();
    string date = orders[0].date_created + "+0:00";
    DateTime dt = DateTime.Parse(date);
    string convertedDate = dt.ToString("dd/MM/yyyy HH:mm:ss");

    try
    {
        date1.Text = convertedDate;
        adress1.Text = orders[0].shipping.address_1.ToString() 
            + "                     " + orders[0].shipping.address_2;
        name1.Text = orders[0].billing.first_name.ToString();
    }
    catch (Exception e)
    {
        Debug.WriteLine(e.Message);
        Debug.WriteLine(e.StackTrace);
    }
}

我需要该应用来监控新订单的创建,如果有新订单,请提供类似弹出窗口的内容吗?

1 个答案:

答案 0 :(得分:0)

如果您的意思是您的应用程序可能已关闭并且您想要获取消息,那么您需要查看BackgroundTasks: Create and register a background task that runs in a separate process

您可以使用TimeTrigger每15分钟监控一次新订单。 或MaintenanceTrigger

并显示吐司,如果有新代码,请使用以下代码:

 void ShowToast(string whattext)
    {
        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
        XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
        stringElements[0].AppendChild(toastXml.CreateTextNode(whattext));
        ToastNotification toast = new ToastNotification(toastXml);

        toast.Activated += ToastActivated;
        toast.Dismissed += ToastDismissed;
        toast.Failed += ToastFailed;

        ToastNotificationManager.CreateToastNotifier().Show(toast);
    }

    private void ToastFailed(ToastNotification sender, ToastFailedEventArgs args) { }
    private void ToastDismissed(ToastNotification sender, ToastDismissedEventArgs args) { }
    private void ToastActivated(ToastNotification sender, object args) { }

如果您想查看有效申请中的订单 - 只需使用DispatcherTimer