Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //List<MissingPerson> dic = JsonData.MissingPeopleList("el","lala");

            ReceivedInfo str = JsonData.IncomingJson("");
            int          x   = 0;
        }
        private static InfoExport GetCoronaInfo()
        {
            string      infoJSON = "";
            WebRequest  request  = WebRequest.Create(feedUrl);
            WebResponse response = request.GetResponse();

            Debug.WriteLine(((HttpWebResponse)response).StatusDescription);

            using (Stream dataStream = response.GetResponseStream())
            {
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
                infoJSON = responseFromServer;
                // Display the content.
                Debug.WriteLine(responseFromServer);
            }
            response.Close();

            ReceivedInfo infObj = JsonConvert.DeserializeObject <ReceivedInfo>(infoJSON);

            InfoExport export = new InfoExport
            {
                Countries        = int.Parse(infObj.Results[0].Total_affected_countries),
                New_cases_today  = int.Parse(infObj.Results[0].Total_new_cases_today),
                New_deaths_today = int.Parse(infObj.Results[0].Total_new_deaths_today),
                Total_cases      = int.Parse(infObj.Results[0].Total_cases),
                Total_deaths     = int.Parse(infObj.Results[0].Total_deaths)
            };

            return(export);
        }
Exemplo n.º 3
0
        public static MWLog ToMWLog(DbDataReader reader)
        {
            ReceivedInfo info = new ReceivedInfo
            {
                Seq         = Convert.ToInt64(reader["seq"]),
                Exchange    = reader["exchange"].ToString(),
                RoutingKey  = reader["routing_key"].ToString(),
                Queue       = reader["queue"].ToString(),
                DeliverTag  = Convert.ToUInt64(reader["deliver_tag"]),
                ConsumerTag = reader["consumer_tag"].ToString(),
                Redelivered = Convert.ToBoolean(reader["redelivered"]),
                PropertySeq = Convert.ToInt64(reader["property_seq"]),
                Payload     = reader["payload"].ToString(),
                InsDate     = Convert.ToDateTime(reader["ins_date"]),
                UpdDate     = Convert.ToDateTime(reader["upd_date"])
            };
            ReceivedProps prop = new ReceivedProps
            {
                Seq         = Convert.ToInt64(reader["seq"]),
                Headers     = JsonConvert.DeserializeObject <Dictionary <string, object> >(reader["headers"].ToString()),
                HeadersJSON = JsonConvert.SerializeObject(ModelConverter.ConvertToHeadersBase64(reader["headers"].ToString()), Formatting.Indented),
                InsDate     = Convert.ToDateTime(reader["ins_date"]),
                UpdDate     = Convert.ToDateTime(reader["upd_date"])
            };
            MWLog mwLog = new MWLog
            {
                Info = info,
                Prop = prop
            };

            return(mwLog);
        }
Exemplo n.º 4
0
        public void PostTripWithPinpointsTest()
        {
            var data = new List <UserModel>
            {
                new UserModel()
                {
                    Id = 1, Token = "aa", Username = "******", Password = "******", Email = "@gmail"
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <UserModel> >();

            mockSet.As <IQueryable <UserModel> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <UserModel> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <UserModel> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <UserModel> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var options = new DbContextOptionsBuilder <MyDbContext>()
                          .Options;

            var mockContext = new Mock <MyDbContext>(options);

            mockContext.Setup(x => x.Users).Returns(mockSet.Object);

            mockContext.SetupProperty(x => x.Trips);
            mockContext.SetupProperty(x => x.PinPoints);

            var service = new TripController(mockContext.Object);

            var titudesArray = new Titudes[1];

            var a = new Titudes()
            {
                Lat  = 20,
                Long = 20
            };

            titudesArray[0] = a;

            var model = new ReceivedInfo()
            {
                Token     = "aa",
                Name      = "test",
                From      = DateTime.Now,
                To        = DateTime.Now,
                Pinpoints = titudesArray
            };

            var _ = service.PostTripWithPinpoints(model);

            mockContext.Verify(x => x.Add(It.IsAny <TripModel>()), Times.Once);
        }
Exemplo n.º 5
0
        private void ReceiveInfo()
        {
            // Get Port from app.config or use default :9050
            int port = 0;

            Int32.TryParse(ConfigurationManager.AppSettings["port"], out port);
            if (port == 0)
            {
                port = 9050;
            }

            var ServerEndPoint = new IPEndPoint(IPAddress.Any, port);
            var socket         = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            // TODO: SocketException might happen here
            socket.Bind(ServerEndPoint);
            var sender = new IPEndPoint(IPAddress.Any, 0);
            var Remote = (EndPoint)(sender);

            while (true)
            {
                try
                {
                    byte[] data = new byte[128];

                    int    recv    = socket.ReceiveFrom(data, ref Remote);
                    string message = Encoding.ASCII.GetString(data, 0, recv);

                    MusicInfo info = ParseDataToInfo(message);

                    ReceivedInfo?.Invoke(this, new ReceiveEventArgs(info));
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
Exemplo n.º 6
0
        private async void RefreshBar_Click(object sender, RoutedEventArgs e)
        {
            if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet())
            {
                string UniqueID         = AppStorage.UniqueAppID.SetValue(Guid.NewGuid().ToString());
                string ModificationDate = AppStorage.ModificationDate.GetValue();

                string result = "";

                try
                {
                    IMissingsService ms = new MissingsService(AzureUrl.GetUrl());

                    if (ModificationDate != "")
                    {
                        result = await ms.GetLatestMissings(ModificationDate);

                        //result = await ms.GetLatestMissings("2043");
                    }
                    else
                    {
                        result = await ms.GetLatestMissings();
                    }


                    ReceivedInfo receivedInfo = JsonData.IncomingJson(result);

                    AppStorage.ModificationDate.SaveValue(receivedInfo.timestamp);

                    if (!receivedInfo.missings.Equals(null) && receivedInfo.missingsString != "")
                    {
                        FileManagement.SaveFile("MissingPeople.json", receivedInfo.missingsString);

                        List <string> ImagesList = receivedInfo.ImagesList;

                        if (ImagesList.Count() != 0)
                        {
                            foreach (var imageName in ImagesList)
                            {
                                string[] number = imageName.Split('.');
                                if (Convert.ToInt32(number[0]) >= 0 && Convert.ToInt32(number[0]) <= 37)
                                {
                                    FileManagement.SaveImageAsync(imageName);
                                }
                            }
                        }
                    }
                    if (receivedInfo.found.Count() != 0)
                    {
                        AppStorage.SkippedItems.Merge(receivedInfo.found);
                    }

                    string ResultJson = "[" + receivedInfo.missingsString + "]";

                    List <MissingPerson> Mis = new List <MissingPerson>();

                    Mis = JsonData.MissingPeopleList("el", ResultJson, navigationParameter).OrderByDescending(x => x.DateMissing).ToList <MissingPerson>();


                    if (Mis.Count() != 0)
                    {
                        txt.Visibility          = Visibility.Collapsed;
                        itemGridView.Visibility = Visibility.Visible;
                        string SkippedItemsString = AppStorage.SkippedItems.Get();

                        String[] Skipped = SkippedItemsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        if (Skipped.Count() != 0)
                        {
                            foreach (var item in Skipped)
                            {
                                Int32 Intitem       = Convert.ToInt32(item);
                                var   stuffToRemove = Mis.SingleOrDefault(s => s.ID == Intitem);
                                if (stuffToRemove != null)
                                {
                                    Mis.Remove(stuffToRemove);
                                }
                            }
                        }
                        int i = 0;
                        foreach (MissingPerson item in Mis)
                        {
                            oc.Insert(i, item);
                            i++;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            else if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet() == false)
            {
                MessageDialog dialog = new MessageDialog("Δεν υπάρχει ενεργή σύνδεση στο διαδίκτυο.", "Σφάλμα σύνδεσης");
                await dialog.ShowAsync();
            }
        }
        // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
        async void DismissedEventHandler(SplashScreen sender, object e)
        {
            dismissed = true;

            //AppStorage.ModificationDate.RemoveValue();
            //FileManagement.DeleteFile("MissingPeople.json");

            if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet())
            {
                string UniqueID = AppStorage.UniqueAppID.SetValue(Guid.NewGuid().ToString());

                string ModificationDate = AppStorage.ModificationDate.GetValue();

                string result = "";

                try
                {
                    IMissingsService ms = new MissingsService(AzureUrl.GetUrl());

                    if (ModificationDate != "")
                    {
                        result = await ms.GetLatestMissings(ModificationDate);
                    }
                    else
                    {
                        result = await ms.GetLatestMissings();
                    }

                    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                    ReceivedInfo receivedInfo = JsonData.IncomingJson(result);

                    AppStorage.ModificationDate.SaveValue(receivedInfo.timestamp);


                    if (!receivedInfo.missings.Equals(null) && receivedInfo.missingsString != "")
                    {
                        FileManagement.SaveFile("MissingPeople.json", receivedInfo.missingsString);

                        List <string> ImagesList = receivedInfo.ImagesList;

                        if (ImagesList.Count() != 0)
                        {
                            foreach (var imageName in ImagesList)
                            {
                                string[] number = imageName.Split('.');
                                if (Convert.ToInt32(number[0]) >= 0 && Convert.ToInt32(number[0]) <= 37)
                                {
                                    FileManagement.SaveImageAsync(imageName);
                                }
                            }
                        }
                    }
                    if (receivedInfo.found.Count() != 0)
                    {
                        AppStorage.SkippedItems.Merge(receivedInfo.found);
                    }
                }
                catch (Exception)
                {
                }
            }
            else if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet() == false)
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                localSettings.Values["Popup"] = "true";
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootFrame.Navigate(typeof(MainPage));
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            });
        }
Exemplo n.º 8
0
        private async void RefreshBar_Click(object sender, RoutedEventArgs e)
        {
            if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet() == true)
            {
                string UniqueID         = AppStorage.UniqueAppID.SetValue(Guid.NewGuid().ToString());
                string ModificationDate = AppStorage.ModificationDate.GetValue();

                string result = "";

                try
                {
                    IMissingsService ms = new MissingsService(AzureUrl.GetUrl());

                    if (ModificationDate != "")
                    {
                        result = await ms.GetLatestMissings(ModificationDate);
                    }
                    else
                    {
                        result = await ms.GetLatestMissings();
                    }


                    ReceivedInfo receivedInfo = JsonData.IncomingJson(result);

                    AppStorage.ModificationDate.SaveValue(receivedInfo.timestamp);

                    if (!receivedInfo.missings.Equals(null) && receivedInfo.missingsString != "")
                    {
                        FileManagement.SaveFile("MissingPeople.json", receivedInfo.missingsString);

                        List <string> ImagesList = receivedInfo.ImagesList;

                        if (ImagesList.Count() != 0)
                        {
                            foreach (var imageName in ImagesList)
                            {
                                string[] number = imageName.Split('.');
                                if (Convert.ToInt32(number[0]) >= 0 && Convert.ToInt32(number[0]) <= 37)
                                {
                                    FileManagement.SaveImageAsync(imageName);
                                }
                            }
                        }
                    }
                    if (receivedInfo.found.Count() != 0)
                    {
                        AppStorage.SkippedItems.Merge(receivedInfo.found);
                    }
                    EnableLiveTile.CreateLiveTile.ShowliveTile();
                }
                catch (Exception)
                {
                }
            }
            else if (WindowsStore.Connectivity.Connectivity.ConnectedToTheInternet() == false)
            {
                MessageDialog dialog = new MessageDialog("Δεν υπάρχει ενεργή σύνδεση στο διαδίκτυο.", "Σφάλμα σύνδεσης");
                await dialog.ShowAsync();
            }
        }