示例#1
0
        public static async Task <Message> checkMessages()
        {
            bool updated = await TextHandler.isUpToDate(MESSAGEFILE);

            if (!updated)
            {
                string xml = await TextHandler.download_text(MESSAGEFILE);

                try {
                    Message message = ObjectSerializer <Message> .FromXml(xml);

                    if (message.ID > Settings.LastMessage)
                    {
                        return(message);
                    }
                    else
                    {
                        return(null);
                    }
                } catch (Exception) {
                    return(null);
                }
            }

            return(null);
        }
示例#2
0
        public static async Task <Object> getSource <T>(string name, bool preload)
        {
            System.Diagnostics.Debug.WriteLine("GET SOURCE DI " + name);
            if (preload)
            {
                System.Diagnostics.Debug.WriteLine("IL FILE IN PRELOAD");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("IL FILE IN DOWNLOAD");
            }
            string file = name + ".xml";
            string text;
            bool   updated;
            ObservableCollection <T> collezione;

            if (!preload)
            {
                updated = await TextHandler.isUpToDate(file);

                System.Diagnostics.Debug.WriteLine("Aggiornamento " + name + ": " + updated);
            }
            else
            {
                updated = true;
            }
            if (updated)
            {
                try
                {
                    text = await TextHandler.getFileString(file);

                    collezione = ObjectSerializer <ObservableCollection <T> > .FromXml(text);

                    return(collezione);
                }
                catch (InvalidOperationException ec)
                {
                    System.Diagnostics.Debug.WriteLine(name);
                    System.Diagnostics.Debug.WriteLine(ec.Message);
                    return(new ObservableCollection <T>());
                }
            }
            else
            {
                try
                {
                    text = await TextHandler.download_text("getData.php?file=" + file);

                    collezione = ObjectSerializer <ObservableCollection <T> > .FromXml(text);

                    TextHandler.saveText(file, text);
                    return(collezione);
                }
                catch (System.InvalidOperationException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString() + "RISCARICO IL FILE");
                    return(new ObservableCollection <T>());
                }
            }
        }