Exemplo n.º 1
0
        private void DeserializeConfiguration()
        {
            try
            {
                string json = System.IO.File.ReadAllText(filedata.FilePath).Replace("\r\n", string.Empty).Replace("\t", string.Empty).Replace("  ", String.Empty);;
                json          = Regex.Unescape(json).Replace(@"\s+", "");
                configuration = JsonConvert.DeserializeObject <Configuration>(json);

                if (configuration != null)
                {
                    InitQuestionaires();
                }
            }
            catch (Exception ex)
            {
                Log.Warning("Configuration Deserialization Exception", ex.StackTrace);
                Task.Run(async() => await PopupNavigation.Instance.PushAsync(new MessageBox("Your configuration has an issue, please load another one to proceed", MessageType.Regular, this)));
            }
        }
Exemplo n.º 2
0
        private void Init()
        {
            try
            {
                configuration = AiDataStore.GetConfiguration();
                User          = AiDataStore.GetUser();

                var qns = configuration.Questionaires.Where(x => x.Status == DCAnalytics.Statuses.Partial || x.Status == DCAnalytics.Statuses.Completed).ToList();
                questionaires.IsVisible     = false;
                noquestionaires.IsVisible   = false;
                progressIndicator.IsVisible = true;
                (progressIndicator.Children[0] as ActivityIndicator).IsRunning = true;

                sQLiteQuestionaires.Clear();
                sQLiteQuestionaires = new DatabaseManager().GetSQLiteQuestionaires();

                savedQuestionaires.Clear();
                annotations.Clear();

                qItems.Clear();
                if (qns.Count > 0)
                {
                    foreach (Questionaire qn in qns)
                    {
                        annotations.Add(new SymbolAnnotation
                        {
                            Coordinates = new LatLng(qn.Latitude, qn.Longitude),
                            IconImage   = (ImageSource)"ic_marker.png",
                            IconSize    = 1,
                            IconColor   = Color.Green
                        });

                        qItems.Add(new QItem
                        {
                            ID       = qn.Key,
                            Distance = (location != null) ? Location.CalculateDistance(qn.Latitude, qn.Longitude, location, DistanceUnits.Kilometers) : 0,
                            Name     = (qn.Sections.FirstOrDefault().Questions.FirstOrDefault().Answers.Count() > 0)? qn.Sections.FirstOrDefault().Questions.FirstOrDefault().Answers.FirstOrDefault().AnswerText : qn.Key,
                            Sequence = (qns.IndexOf(qn) % 2 == 0) ? 0 : 1
                        });
                    }
                }

                progressIndicator.IsVisible = false;
                (progressIndicator.Children[0] as ActivityIndicator).IsRunning = false;

                //if no questionaires are saved
                if (qItems.Count == 0)
                {
                    noquestionaires.IsVisible = true;
                    nextPageFAB.IsVisible     = false;
                    questionaires.IsVisible   = false;
                }
                else
                {
                    map.ZoomLevel        = Device.RuntimePlatform == Device.Android ? 10 : 17;
                    map.LogoEnabled      = false;
                    map.CompassEnabled   = true;
                    map.ShowUserLocation = true;
                    map.Annotations      = annotations;
                    if (location != null)
                    {
                        map.Center = new LatLng(location.Latitude, location.Longitude);
                    }

                    questionaires.IsVisible   = true;
                    nextPageFAB.IsVisible     = true;
                    questionaires.ItemsSource = null;
                    questionaires.ItemsSource = qItems;
                }
            }
            catch (Exception ex)
            {
                Log.Warning("SqlLite Exception ", ex.Message);
            }
        }