Exemple #1
0
        private static async Task RunXAMLChanges()
        {
            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(UriString);

                response.EnsureSuccessStatusCode();

                using (HttpContent content = response.Content)
                {
                    var responseBody = await response.Content.ReadAsStringAsync();

                    var message = JsonConvert.DeserializeObject <XamlPayload>(responseBody, JsonSerializerSettingsConverter.Settings);

                    if (!string.IsNullOrEmpty(message.XAML) || !string.IsNullOrEmpty(message.PreserveXML))
                    {
                        if (XamlPayload.XAML == null)
                        {
                            XamlPayload = message;
                            await LiveXamlHelper.PreviewXaml(message.XAML, ContentPageSync);
                        }

                        bool areXamlSame = XamlPayload.CompareTo(message) == 0;
                        if (!areXamlSame)
                        {
                            XamlPayload = message;
                            await LiveXamlHelper.PreviewXaml(message.XAML, ContentPageSync);
                        }
                    }
                }
            }
        }
        static async Task Main(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            await StartConnectionAsync();

            _connection.On <string, XamlPayload>("XamlPlaygroundSync", (name, message) =>
            {
                if (XamlPayload.XAML == null)
                {
                    XamlPayload = message;
                    Console.WriteLine($"{name} said1: {XamlPayload.XAML} ,{XamlPayload.PreserveXML}");
                }

                bool areXamlSame = XamlPayload.CompareTo(message) == 0;
                if (!areXamlSame)
                {
                    XamlPayload = message;
                    Console.WriteLine($"{name} said2: {XamlPayload.XAML} ,{XamlPayload.PreserveXML}");
                }
            });

            //_connection.On<string, XamlPayload>("XamlPlaygroundSync", (name, message) =>
            //{
            //	if (XamlPayload.XAML == null)
            //	{
            //		XamlPayload = message;
            //		Console.WriteLine($"{name} said: {XamlPayload.XAML} ,{XamlPayload.PreserveXML}");
            //	}

            //	bool areXamlSame = XamlPayload.CompareTo(message) == 0;
            //	if (!areXamlSame)
            //	{
            //		XamlPayload = message;
            //		Console.WriteLine($"{name} said: {XamlPayload.XAML} ,{XamlPayload.PreserveXML}");
            //	}
            //});

            Console.ReadLine();
            await DisposeAsync();
        }