Esempio n. 1
0
        private void LoadData()
        {
            ServerGet s = new ServerGet();

            s.callback = ApplyPacket;

            Messenger.Default.Send <ServerGet>(s);
        }
Esempio n. 2
0
        private void GET(ServerGet SG)
        {
            Messenger.Default.Send <Busy>(new Busy()
            {
                busy = true
            });
            //  try
            //  {
            Messenger.Default.Send <NotificationMessage>(new NotificationMessage(API_HOST + " " + API_TOKEN));
            WebRequest request = WebRequest.Create(API_HOST);

            request.Method = WebRequestMethods.Http.Get;
            var response = request.GetResponse();

            using (System.IO.Stream stream = response.GetResponseStream())
            {
                using (System.IO.StreamReader SR = new System.IO.StreamReader(stream))
                {
                    string res = SR.ReadToEnd();
                    Console.WriteLine(res);
                    ServerAdd[] result  = JsonConvert.DeserializeObject <ServerAdd[]>(res);
                    int         length  = result.Length;
                    string[]    id      = new string[length];
                    string[]    title   = new string[length];
                    string[]    content = new string[length];

                    for (int i = 0; i < length; i++)
                    {
                        id[i]      = result[i]._id;
                        title[i]   = result[i].title;
                        content[i] = result[i].content;
                        Console.WriteLine(result[i]._id);
                    }

                    DM.SyncAll(id, title, content);

                    SG.callback(id, title, content);

                    System.Threading.Thread.Sleep(500);
                    Messenger.Default.Send <Busy>(new Busy()
                    {
                        busy = false
                    });
                }
            }
            //  }

            /* catch (Exception e)
             * {
             *   Messenger.Default.Send<NotificationMessage>(new NotificationMessage(e.GetBaseException()+" "+ e.Message));
             *   System.Windows.MessageBox.Show("YOU ARE OFFLINE", "ERROR");
             * }*/
        }