Exemple #1
0
        public async Task <UnlockedPosts> getPostAttachmentAsync(int obsId)
        {
            await sem.WaitAsync();

            Uri uri = new Uri(string.Format("https://saabstudent2020.azurewebsites.net/observation/" + obsId + "/attachment", string.Empty));
            HttpResponseMessage response = await client.GetAsync(uri);

            UnlockedPosts temp = null;

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                temp = MakeUnlockedPost(content);
                if (temp == null)
                {
                    switch (Device.RuntimePlatform)
                    {
                    case Device.Android:
                        DependencyService.Get <SnackInterface>().SnackbarShow("Post #" + obsId + " does not have an image");
                        break;

                    case Device.iOS:
                        CrossToastPopUp.Current.ShowToastMessage("Post #" + obsId + " does not have an image");
                        break;

                    default:
                        break;
                    }
                }



                else
                {
                    temp.obsID = obsId;
                }
                sem.Release();
                return(temp);
            }

            switch (Device.RuntimePlatform)
            {
            case Device.Android:
                DependencyService.Get <SnackInterface>().SnackbarShow("Failed to unlock post #" + obsId);
                break;

            case Device.iOS:
                CrossToastPopUp.Current.ShowToastMessage("Failed to unlock post #" + obsId);
                break;

            default:
                break;
            }


            sem.Release();
            return(temp);
        }
        public static async Task unlockTracker()
        {
            if (App.user != null && App.conn != null && GlobalFuncs.mvm.tracked != null && prevUnlock != GlobalFuncs.mvm.tracked.Id)
            {
                await Task.Run(async() => {
                    prevUnlock = GlobalFuncs.mvm.tracked.Id;
                    int temp   = GlobalFuncs.mvm.tracked.Id;
                    if (!CrossConnectivity.Current.IsConnected)
                    {
                        switch (Device.RuntimePlatform)
                        {
                        case Device.Android:
                            DependencyService.Get <SnackInterface>().SnackbarShowIndefininte("Internet is not available");
                            break;

                        case Device.iOS:
                            CrossToastPopUp.Current.ShowToastMessage("Internet is not available");
                            break;

                        default:
                            break;
                        }

                        while (!CrossConnectivity.Current.IsConnected)
                        {
                            await Task.Delay(100);
                        }
                        switch (Device.RuntimePlatform)
                        {
                        case Device.Android:
                            DependencyService.Get <SnackInterface>().SnackbarShow("Internet connection has been established");
                            break;

                        case Device.iOS:
                            CrossToastPopUp.Current.ShowToastMessage("Internet connection has been established");
                            break;

                        default:
                            break;
                        }
                    }


                    UnlockedPosts attachment = await App.conn.getPostAttachmentAsync(temp);
                    uvm.addUnlockedPost(mvm.RemovePost(temp), attachment);
                    GlobalFuncs.mvm.tracked = null;
                });
            }
        }
Exemple #3
0
 public void addUnlockedPost(PostListElement x, UnlockedPosts attachment)
 {
     App.user.unlockedSet.Add(x.Id);
     images.Add(attachment.imgBytes);
     Items.Add(new PostListElement()
     {
         Id          = x.Id,
         Subject     = x.Subject,
         Body        = x.Body,
         Created     = x.Created,
         LastUpdated = x.LastUpdated,
         Position    = x.Position,
         Dist        = "",
         Img         = ImageSource.FromStream(() => new MemoryStream(attachment.imgBytes))
     });
     App.user.saveImage(x.Id, attachment.imgBytes);
 }
Exemple #4
0
        private UnlockedPosts MakeUnlockedPost(string content)
        {
            if (content.Length < 100)
            {
                return(null);
            }
            string id      = "";
            int    counter = 7;

            while (content[counter] != ',')
            {
                id += content[counter];
                counter++;
            }
            counter = 23 + id.Length;
            content = content.Substring(counter);
            content = content.Remove(content.Length - 3, 3);
            UnlockedPosts temp = new UnlockedPosts(int.Parse(id), content);

            return(temp);
        }