public static async Task <bool> UpdateSelectionAsync(int IdSel, List <string> TagToRemove)
        {
            try
            {
                string serverIP   = Properties.Settings.Default.ServerIp;
                int    serverPort = Properties.Settings.Default.ServerPort;

                string urlServer = "http://" + serverIP + ":" + serverPort;
                var    client    = new RestClient(urlServer);
                client.Authenticator = new HttpBasicAuthenticator(publicApiLogin, publicApiMdp);
                var request = new RestRequest("selections/" + IdSel, Method.GET);
                client.Timeout           = timeout;
                client.ReadWriteTimeout  = timeout;
                request.Timeout          = timeout;
                request.ReadWriteTimeout = timeout;
                var response = await client.ExecuteTaskAsync(request);

                if (response.IsSuccessful)
                {
                    var Selection = JsonSelectionList.DeserializedJsonAlone(response.Content);
                    if (Selection != null)
                    {
                        if (Selection.state == "closed")
                        {
                            return(false);
                        }

                        var request2 = new RestRequest("/selections/" + IdSel, Method.PUT);

                        foreach (string uid in TagToRemove)
                        {
                            request2.AddParameter("listOfTagPulled", uid);
                        }

                        var client2 = new RestClient(urlServer);
                        client2.Authenticator = new HttpBasicAuthenticator(privateApiLogin, privateApiMdp);
                        LogToFile.LogMessageToFile("------- Start Update selection --------");
                        var response2 = await client2.ExecuteTaskAsync(request2);

                        LogToFile.LogMessageToFile(response2.Content);
                        LogToFile.LogMessageToFile("------- End Updateselection --------");
                        return(response2.IsSuccessful);
                    }
                    return(false);
                }
                return(false);
            }
            catch (Exception error)
            {
                ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error update selection");
                exp.ShowDialog();
                return(false);
            }
        }
        public static string SerializedJsonAlone(JsonSelectionList jsl)
        {
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            return(jsSerializer.Serialize(jsl));
        }
        public static async Task <bool> GetAndStoreSelectionAsync()
        {
            try
            {
                string serverIP   = Properties.Settings.Default.ServerIp;
                int    serverPort = Properties.Settings.Default.ServerPort;

                string urlServer = "http://" + serverIP + ":" + serverPort;
                var    client    = new RestClient(urlServer);
                client.Authenticator = new HttpBasicAuthenticator(publicApiLogin, publicApiMdp);
                var request = new RestRequest("selections", Method.GET);
                client.Timeout           = timeout;
                client.ReadWriteTimeout  = timeout;
                request.Timeout          = timeout;
                request.ReadWriteTimeout = timeout;
                var response = await client.ExecuteTaskAsync(request);

                if (response.IsSuccessful)
                {
                    var ctx = await RemoteDatabase.GetDbContextAsync();

                    ctx.PullItems.Clear();
                    await ctx.SaveChangesAsync();

                    lock (somePublicStaticObject)
                    {
                        var lstSelection = JsonSelectionList.DeserializedJsonList(response.Content);
                        if ((lstSelection != null) && (lstSelection.Length > 0))
                        {
                            foreach (var sel in lstSelection)
                            {
                                if (sel == null)
                                {
                                    LogToFile.LogMessageToFile("------- Start Error in selection --------");
                                    LogToFile.LogMessageToFile(response.Content);
                                    LogToFile.LogMessageToFile("------- End Error in selection --------");
                                    break;
                                }
                            }
                            lastSelection = lstSelection;
                        }
                        else
                        {
                            lastSelection = null;
                        }
                        ctx.Database.Connection.Close();
                        ctx.Dispose();
                        return(true);
                    }
                }
                return(false);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                return(false);
            }
            catch (Exception error)
            {
                ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error getting selection");
                exp.ShowDialog();
                return(false);
            }
        }