public static async Task <string> ReportIncident(GeoServiceRef.IncidentTag tag)
        {
            string result = string.Empty;

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GeoServiceRef.IncidentTag));

            using (MemoryStream mem = new MemoryStream())
            {
                ser.WriteObject(mem, tag);
                string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);

                WebClient webClient = new WebClient();
                webClient.Headers["Content-type"] = "application/json;";
                webClient.Headers["AuthID"]       = Globals.User.LiveAuthId;
                webClient.Encoding = Encoding.UTF8;
                result             = await webClient.UploadStringTask(new Uri(Constants.ReportIncidentUrl), data);
            }
            return(result);
        }
Beispiel #2
0
        private async Task ReportTeaseToServer(GeoCoordinate gc, PhotoResult e)
        {
            string serverSyncStatus = string.Empty;

            try
            {
                PanelCategory.Visibility = Visibility.Collapsed;
                ButtonReportIncidentProceed.Visibility = Visibility.Collapsed;
                AddInfoStkPanel.Visibility             = Visibility.Collapsed;
                PanelReportMessage.Visibility          = Visibility.Visible;
                if (Globals.IsDataNetworkAvailable && Globals.IsRegisteredUser)
                {
                    byte[] b = null;

                    if (e.ChosenPhoto != null)
                    {
                        using (BinaryReader br = new BinaryReader(Phone.Utilites.PhotoResizer.ReduceSize(e.ChosenPhoto)))
                        {
                            b = br.ReadBytes((Int32)e.ChosenPhoto.Length);
                        }
                    }

                    GeoServiceRef.IncidentTag tag = new GeoServiceRef.IncidentTag()
                    {
                        Name           = Globals.User.Name,
                        MobileNumber   = Globals.CurrentProfile.MobileNumber,
                        Lat            = (gc == null) ? string.Empty : gc.Latitude.ToString(),
                        Long           = (gc == null) ? string.Empty : gc.Longitude.ToString(),
                        ProfileID      = Convert.ToInt64(Globals.CurrentProfile.ProfileId),
                        SessionID      = string.Empty,
                        Alt            = gc.Altitude.ToString(),
                        GeoDirection   = "1",//"TODO"
                        Speed          = (gc == null || double.IsNaN(gc.Speed)) ? 0 : Convert.ToInt32(gc.Speed),
                        Accuracy       = Math.Round(gc.HorizontalAccuracy),
                        TimeStamp      = DateTime.Now.Ticks,
                        Command        = Category.ToUpper(),
                        MediaContent   = b,
                        AdditionalInfo = AdditionalInfoTB.Text
                    };
                    await LocationServiceWrapper.ReportIncident(tag);

                    PanelReportMessage.Visibility = Visibility.Visible;
                    serverSyncStatus = "Success";
                }
            }
            catch (Exception ex)
            {
                PanelReportMessage.Visibility = Visibility.Collapsed;
                serverSyncStatus = "Fail";
            }
            finally
            {
                if (NavigationService.BackStack != null && NavigationService.BackStack.Count() > 0)
                {
                    NavigationService.RemoveBackEntry();
                }

                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (serverSyncStatus == "Success")
                    {
                        Globals.DisplayToast(CustomMessage.ReportTeaseToServerSuccessText, "basicWrap", "Report incident successful!");
                    }
                    else if (serverSyncStatus == "Fail")
                    {
                        Globals.DisplayToast("Reasons could be " + Environment.NewLine + "  1. GPS is turned off  " + Environment.NewLine + "  2. Unable to reach Guardian Server", "basicWrap", "Report incident failed!");
                    }
                });
            }
        }