Esempio n. 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);
        }
Esempio n. 2
0
        public void GetDocument(DocumentDownloadModel.DocumentRequest docReq)
        {
            RestClient client = new RestClient();

            client.BaseUrl = new Uri(constantfile.BaseUrl);
            RestRequest request = new RestRequest(constantfile.GetDocumentFileUrl, Method.POST); //"api/policies/DownloadFile"

            request.RequestFormat = DataFormat.Json;
            request.Parameters.Clear();

            //DocumentDownloadModel.DocumentRequest doc = new DocumentDownloadModel.DocumentRequest() { Name = "CEHSP A12.05 - EHS Training Program.pdf", Path = "" };
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/octet-stream");
            request.AddObject(docReq);
            try
            {
                //var resp = client.Execute(request);
                string path = FileSystem.Current.LocalStorage.Path + "/" + docReq.Name;
                client.DownloadData(request).SaveAs(path);
                this.downloadDocumentresponse = true;
                //downloadDocumentEvent(this, new EventArgs());
            }
            catch (Exception ex)
            {
                // taskCompletionSource.SetException(ex);
            }


            //var client = new RestClient(constantfile.GetDocumentUrl);
            //var request = new RestRequest(Method.POST);
            //request.AddJsonBody(docReq);
            //client.ExecuteAsync(request, response =>
            //{
            //    this.downloadDocumentresponse = response.RawBytes;
            //    //this.downloadDocumentresponse = Encoding.Unicode.GetString(response.RawBytes, 0, response.Content.Length);


            //    downloadDocumentEvent(this, new EventArgs());
            //});
        }
Esempio n. 3
0
        public static string DownloadFile(string apiPath, DocumentDownloadModel.DocumentRequest requestContent)
        {
            RestClient client = CreateRestClient();

            client.BaseUrl = new Uri(jsseAzureSBURL);

            var path    = jsseAzureSBURL + apiPath;
            var request = new RestRequest(apiPath, Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.Parameters.Clear();
            //request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
            request.AddObject(requestContent);
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/octet-stream");
            string filePath   = string.Empty;
            string statusCode = "";

            try
            {
                filePath   = FileSystem.Current.LocalStorage.Path + "/" + requestContent.Name;
                statusCode = "OKOK";
                client.DownloadData(request).SaveAs(filePath);
                filePath = string.Empty;
            }
            catch (Exception ex)
            {
                // taskCompletionSource.SetException(ex);
            }

            //// byte[] resultFile = null;

            ////resultFile = client.DownloadData(request);


            return(statusCode);
        }
Esempio n. 4
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;
            }
        }