Exemplo n.º 1
0
        private void BuildAndDownLoadDocument2(RealpageData.Resident res, string folder, ClientEntry cle)
        {
            AuthDTO auth = GetAuth(cle);
            var client = new RPXServiceClient();
            client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 00);
            try
            {
                var req = new BuildCollectionDocumentsRequest() { reshid = res.ReshID };

                var resp = client.buildcollectiondocumentsAsync(auth, req);
                var respXml =  resp.Result.Body.buildcollectiondocumentsResult;
                txtResponse.Text = respXml.ToString();
                var fileSizeNode = respXml.Descendants("filesize").FirstOrDefault();
                int fileSizeVal = 0;
                if (fileSizeNode != null)
                {
                    fileSizeVal = Convert.ToInt32(fileSizeNode.Value);
                }
                if (fileSizeVal == 0)
                {
                    //              AddMessage("No files to download for site " + res.SiteID + " Tenant Reshid " + res.ReshID + " Name: " + res.FirstName + " " + res.LastName );
                    return;
                }

                var filename = folder
                    + @"\"
                    + cle.RrsId + "_"
                    + cle.SiteId + "_"
                    + res.ReshID + "_"
                    + StripNumber(res.LastName) + "_" + res.FirstName + "_" + DateTime.Now.ToString("MMddyyyy_HHmm") + ".pdf";

                var reqDL = new DownloadCollectionDocumentRequest() { reshid = res.ReshID };

                var returnDoc =  client.downloadcollectiondocumentAsync(auth, reqDL).Result.Body.downloadcollectiondocumentResult;
                var returnResult = returnDoc.Descendants("Result").FirstOrDefault();
                if (returnResult == null)
                {
                    AddMessage("Result is empty for file pull " + filename);
                    return;
                }
                var retData = returnDoc.Descendants("Result").FirstOrDefault().Value;

                FileStream wFile = new FileStream(filename, FileMode.Create);
                byte[] buffer;
                buffer = Convert.FromBase64String(retData);
                wFile.Write(buffer, 0, buffer.Length);
                wFile.Close();
                AddMessage("File " + filename + "  Has been created ; filesize " + fileSizeVal);
            }
            catch (Exception ex)
            {
                Log.Error("Error Creating File\n" + ex);
                MessageBox.Show("Error Creating File\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void btnDlCollectionDocument_Click(object sender, EventArgs e)
        {
            KeyValuePair<string, string> selectedPair = (KeyValuePair<string,string>) cboSiteList.SelectedItem;

            var folder = txtColl.Text;
            var siteId = selectedPair.Key.Split('_')[1];
            var cboRrsId = selectedPair.Value;
            int resId = 0;
            int.TryParse(txtReshid.Text.Trim(), out resId);
            if (resId == 0 || string.IsNullOrEmpty(cboRrsId))
            {
                MessageBox.Show("Please select a siteId and  enter an ReshId", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            tabCtl.SelectTab("tabRetrieval");
            ClientEntry cle = GetClientEntry(siteId);
            AuthDTO auth = GetAuth(cle);
            var client = new RPXServiceClient();
            client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 00);
            try
            {
                var req = new BuildCollectionDocumentsRequest() { reshid = resId };
                var resp = client.buildcollectiondocuments(auth, req);
                txtResponse.Text = resp.ToString();
                var fileSizeNode = resp.Descendants("filesize").FirstOrDefault();
                int fileSizeVal = 0;
                if (fileSizeNode != null)
                {
                    fileSizeVal = Convert.ToInt32(fileSizeNode.Value);
                }
                if (fileSizeVal == 0)
                {
                    AddMessage("No files to download");
                    return;
                }
                var dirOut = GetOutputFolder(folder, cle);

                var dlFile = dirOut + @"\" + cle.RrsId + "_" + siteId + "_" + resId + "_AdHoc_" + DateTime.Now.ToString("MMddyyyy_HHmm")  + ".pdf";

                var reqDL = new DownloadCollectionDocumentRequest() { reshid = resId };
                string returnDoc = client.downloadcollectiondocument(auth, reqDL).Value;

                FileStream wFile = new FileStream(dlFile, FileMode.Create);
                byte[] buffer;
                buffer = Convert.FromBase64String(returnDoc);
                wFile.Write(buffer, 0, buffer.Length);
                wFile.Close();
                AddMessage("File has been created as " + dlFile + "; FileSize is " + fileSizeVal);
            }
            catch (Exception ex)
            {
                Log.Error("Error Creating File\n" + ex);
                MessageBox.Show("Error Creating File\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }