Beispiel #1
0
 private void CleanDatabase()
 {
     try
     {
         var documentDatabase = new DocumentDatabase();
         documentDatabase.DeleteAll();
         var recentDatabase = new RecentDatabase();
         recentDatabase.DeleteAll();
     }
     catch (Exception ex)
     {
         throw new Exception(message:ex.Message);
     }
    
 }
        private List<Document> GetDocuments(string search)
        {
            var lstDocuments = new List<Document>();
            try
            {
                var database = new DocumentDatabase();
                lstDocuments = database.GetItems(search).ToList();
                if (!lstDocuments.Any())
                {
                    if (CrossConnectivity.Current.IsConnected == false)
                    {
                        throw new Exception(message: "Please check internet connectivity.");
                    }

                    var agent = new DocumentServiceAgent();
                    Task<string> docList;
                    if(search == "0")
                        docList = agent.GetDocumentTaskAsync("");
                    else
                        docList = agent.GetDocumentTaskAsync(search);
                    
                    docList.Wait();

                    JObject parsed = JObject.Parse(docList.Result);
                    var msg = parsed["Message"].ToObject<string>();
                    if (!string.IsNullOrEmpty(msg))
                    {
                        if (msg.ToUpper().Equals(Constants.INVALID_TOKEN_MSG.ToUpper()))
                        {							
                            throw new Exception(message: msg);
                        }
                    }

                    var docWebList = JsonConvert.DeserializeObject<DocumentWebResponse>(docList.Result);
                    CommonHelper.UpdateTokenInfo(docWebList.Token);	
                    if (docWebList.ErrorCount > 0)
                    {
                       throw new Exception(message:docWebList.Message);
                    }
                    else
                    {
                        foreach (var item in docWebList.Documents)
                        {
						    item.Ext = ImageHelper.GetImageSrc(item.Ext);
                            database.SaveItem(item);
                        }
                        lstDocuments = database.GetItems(search).ToList();
                    }
                }

            }
            catch (InvalidOperationException ex)
            {
                throw new Exception(message: "Server not responding");
            }
            catch (Exception ex)
            {
                throw new Exception(message: ex.Message);
            }
            return lstDocuments;
        }