Exemple #1
0
        public async Task <bool> viewDocument(string selectedDocName)
        {
            await Isfavourite(selectedDocName);

            if (!isFavorite)//!isFavorite
            {
                DocumentDownloadModel.DocumentRequest dr = new DocumentDownloadModel.DocumentRequest();
                dr.Path = "";
                dr.Name = selectedDocName;// "GEHSI E07.23 - Cleanup of PCB Spills.pdf";//"";GEHSI E02.01 - Spill Reporting.pdf
                if (returnOS == "Available")
                {
                    string statusCode = ServiceBusRelay.DownloadFile("api/policies/DownloadFile", dr);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
        public void SetOnlineDocumentsToLocal()
        {
            string policyUrl = constantfile.GetPolicyUrl;

            //call policy last modified from sqlite
            GetSQLiteLastSyncDate();// App.PoliciesRepo.GetSQLiteLastSyncDate();

            // App.PoliciesRepo.UpdateSync();

            if (lastSyncSqliteDate != string.Empty)
            {
                policyUrl = policyUrl + "?lastSyncDate=" + lastSyncSqliteDate;
            }


            ServiceBusRelay.GetAsync <List <PolicyModel.DocType> >(policyUrl).ContinueWith((taskResponse) =>
            {
                var docResult = taskResponse;
                docResult.Wait();
                var docs = new List <PolicyModel.DocType>(docResult.Result);

                bool areModifications = false;
                foreach (var item in docs)
                {
                    foreach (PolicyModel.DocSubType pd in item.DocSubTypes)
                    {
                        int ss = pd.Documents.Count();
                        if (ss > 0)
                        {
                            areModifications = true;
                            break;
                        }
                    }
                    if (areModifications)
                    {
                        break;
                    }
                }
                if (areModifications)
                {
                    List <Policies> OfflineList = new List <Policies>();
                    IEnumerable <PolicyModel.DocSubType[]> docsublist = docs.Where(c => (c.Name == "GEHSI" || c.Name == "CEHSP")).Select(x => x.DocSubTypes).Distinct();
                    //IEnumerable<PolicyModel.DocSubType[]> docsublist = docs.Select(x => x.DocSubTypes).Distinct();
                    //int docTypeID = 0;
                    List <Dictionary <string, string> > dictList = new List <Dictionary <string, string> >();

                    foreach (var item in docsublist)
                    {
                        int i = 0;
                        foreach (var docItem in item)
                        {
                            Dictionary <string, string> docTypeDictionary = new Dictionary <string, string>();
                            docTypeDictionary.Add(docItem.Name.ToString(), (i + 1).ToString());
                            dictList.Add(docTypeDictionary);

                            docTypeDictionary = null;
                            i = i + 1;
                        }
                    }

                    foreach (var item in docs)
                    {
                        int i          = 0;
                        int DocID      = 1;
                        PolicySubTypes = new string[5];
                        foreach (PolicyModel.DocSubType pd in item.DocSubTypes)
                        {
                            PolicySubTypes[i] = pd.Name.ToString();
                            int j             = 1;
                            foreach (PolicyModel.Document orgDoc in pd.Documents)
                            {
                                Policies OfflineSingleP     = new Policies();
                                OfflineSingleP.DocId        = DocID;
                                OfflineSingleP.DocType      = orgDoc.DocType;
                                OfflineSingleP.DocSubType   = orgDoc.DocSubType;
                                OfflineSingleP.DocName      = orgDoc.DocumentName;
                                OfflineSingleP.ModifiedDate = orgDoc.Modified;
                                OfflineSingleP.ModifiedBy   = orgDoc.ModifiedBy;
                                OfflineSingleP.IsFavourite  = false;
                                if (orgDoc.DocType == "CEHSP" || orgDoc.DocType == "GEHSI")
                                {
                                    OfflineSingleP.DocSubTypeID = getDocumentSubTypeID(dictList, orgDoc.DocSubType);//j;
                                }
                                else
                                {
                                    OfflineSingleP.DocSubTypeID = 1;
                                }


                                OfflineList.Add(OfflineSingleP);
                                OfflineSingleP = null;

                                DocID = DocID + 1;
                            }
                            j = j + 1;
                            i = i + 1;
                        }
                    }

                    //delete data from sqlite
                    App.PoliciesRepo.DeleteAllPolicies();

                    //insert data to sqlite
                    //  App.PoliciesRepo.AddAllPolicies(OfflineList);
                    // App.PoliciesRepo.UpdateLastModified(OfflineList);
                }
            });
        }
Exemple #3
0
        public void UpdateLastModified(List <Policies> OfflineList)
        {
            try
            {
                foreach (var item in OfflineList)
                {
                    //check here for existing record in sqlite
                    string docName = item.DocName;
                    //docName = docName.Remove(docName.Length - 4);

                    List <Policies> plist    = dbConnSync.Table <Policies>().Where(c => c.DocName == docName).ToList();
                    int             docCount = plist.Count();
                    if (docCount > 0)
                    {
                        string dateval = item.ModifiedDate;
                        //dbConn.UpdateAsync("update policies set ModifiedDate=" + item.ModifiedDate + " where DocName=" + docName);

                        //String[] args = new String[] { dateval, docName };
                        //string qry = "update Policies set ModifiedDate=? where DocName=?";
                        //////dbConn.update(TABLE_LATLONG, values, "Loc_lati=? AND Loc_longi=?", args);
                        //////dbConn.ExecuteAsync("Policies", values,"", args);
                        //dbConn.ExecuteScalarAsync<Policies>(qry,args);
                        //string sss = "Delete from policies where DocName='" + docName + "'";
                        dbConn.ExecuteAsync("Delete from policies where DocName='" + docName + "'");
                        //dbConnSync.Execute("Delete from policies where DocName='" + docName + "'");
                        Policies ps = new Policies();
                        ps.DocId        = plist[0].DocId;
                        ps.DocName      = docName;
                        ps.DocSubType   = plist[0].DocSubType;
                        ps.DocSubTypeID = plist[0].DocSubTypeID;
                        ps.DocType      = plist[0].DocType;
                        ps.IsFavourite  = plist[0].IsFavourite;
                        ps.ModifiedBy   = item.ModifiedBy;
                        ps.ModifiedDate = dateval;

                        //dbConn.InsertAsync(new Policies {  DocId= plist[0].DocId, DocSubType= plist[0].DocSubType, DocSubTypeID= plist[0].DocSubTypeID, DocType= plist[0].DocType, IsFavourite= plist[0].IsFavourite, DocName = item.DocName, ModifiedDate= item.ModifiedDate, ModifiedBy= item.ModifiedBy });
                        dbConn.InsertAsync(ps);
                        //dbConn.UpdateAsync(ps);

                        if (plist[0].IsFavourite)
                        {
                            DocumentDownloadModel.DocumentRequest dr = new DocumentDownloadModel.DocumentRequest();
                            dr.Path = "";
                            dr.Name = docName;
                            /* network check*/

                            ServiceBusRelay.DownloadFile("api/policies/DownloadFile", dr);
                        }
                        ps = null;
                    }
                    else
                    {
                        dbConn.InsertAsync(item);
                    }
                }
                SetLastModifiedDate();
            }
            catch (Exception ex)
            {
                //docName = ex.Message;
                throw;
            }
        }