コード例 #1
0
ファイル: DBSource.cs プロジェクト: Holy87/circuminfo
        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>());
                }
            }
        }