private void DownloadLeaseDocumentsPS(List<string> leases, string fn, PSClientEntry cle) { AddMessage("Downloading lease Documents.."); string path = Path.GetDirectoryName(fn); foreach (var leas in leases) { try { DownloadDocumentsPS(cle, leas, path); } catch (Exception ex) { AddMessage("Error downloading documents for " + cle.SiteName + "-" + cle.SiteId + "- LeaseId " + leas); } } }
private void UpdateTokenForClientPS(PSClientEntry clEntry) { var loginFolder = txtEntrataLogins.Text.Trim(); if (string.IsNullOrEmpty(loginFolder)) { AddMessage("Entrata login folder has not been configured; Please use folder location utility"); return; } var dirInfo = new DirectoryInfo(loginFolder); var fileList = dirInfo.GetFiles().OrderByDescending(i => i.CreationTime); foreach (var fitm in fileList) { if (ProcessLoginFilePS(fitm, clEntry)) { break; } } }
private void DownloadDocumentsPS(PSClientEntry clEntry, string leaseId, string folder ) { try { var apiResp = string.Empty; AddMessage("Downloading documents for" + clEntry.SiteName + "-" + clEntry.SiteId + "- LeaseId " + leaseId); var resp = GetLeaseDocumentsPS(clEntry.Subdomain, clEntry.Token, clEntry.SiteId, leaseId); if (string.IsNullOrEmpty(resp)) { AddMessage("Error: Empty repsonse from Doc request for client " + clEntry.SiteName + " - " + clEntry.SiteId + "+ lease " + leaseId ); return; } var respXml = XDocument.Parse(resp); var errMsg = ParseErrorResponse(respXml); if (!string.IsNullOrEmpty(errMsg)) { AddMessage(errMsg); return; } var succMsg = ParseSuccessResponse(respXml); if (!string.IsNullOrEmpty(succMsg)) { AddMessage(succMsg); return; } var dlFile = folder + @"\" + clEntry.RrsId + "_" + clEntry.SiteId + "_" + leaseId + "_" + DateTime.Now.ToString("MMddyyyy_HHmm") + "_"; var dCnt = respXml.Descendants("LeaseDocument").Count(); AddMessage("Document count for client " + clEntry.SiteName + " - " + clEntry.SiteId + " - lease " + leaseId + " : " + dCnt ); SaveRawDocumentPS(respXml, dlFile); AddMessage("Download complete"); } catch (Exception ex) { Log.Error("Error Downloading Documents \n" + ex); MessageBox.Show("Error on API Call \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RetrieveLeasePS(PSClientEntry clEntry) { Cursor.Current = Cursors.WaitCursor; try { var resp = GetLeasePS(clEntry.Subdomain, clEntry.Token, clEntry.SiteId, clEntry.FirstDate); var respXml = XDocument.Parse(resp); var errMsg = ParseErrorResponse(respXml); if (!string.IsNullOrEmpty(errMsg)) { AddMessage(errMsg); return; } UpdateFirstDate(clEntry); var succMsg = ParseSuccessResponse(respXml); if (!string.IsNullOrEmpty(succMsg)) { AddMessage(succMsg); return; } var respNode = respXml.Descendants("response").FirstOrDefault(); if (LeaseFileCount(respNode) == 0) { AddMessage("No lease files found in site " + clEntry.SiteId + ", file not created"); return; } string dir = GetOutputFolderPS(txtRawXML.Text, clEntry); string fullfname = dir + @"\" + GetOutputSubdirPS(clEntry) + "_" + DateTime.Now.ToString("MMddyyyy_HHmm") + ".xml"; string fname = GetOutputSubdirPS(clEntry) + "_" + DateTime.Now.ToString("MMddyyyy_HHmm") + ".xml"; SaveRawFile(respNode, fullfname); AddMessage("XML File saved as " + fname); } catch (Exception ex) { Log.Error("Error on getMitsCollections Call \n" + ex); MessageBox.Show("Error on getMitsCollections Call \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }
private void UpdateFirstDate(PSClientEntry clEntry) { XDocument doc = ccfg.GetConfig(pscliconfig); var clients = ccfg.GetElement(doc, "clients"); var srchRslt = clients.Descendants("client").FirstOrDefault(i => i.Attribute("keyword").Value == clEntry.RrsId); if (srchRslt == null) { AddMessage("Last Pull Date not updatet - No entry found"); return; } AddUpdateChild(srchRslt, "firstdate", DateTime.Today.ToString("yyyy-MM-dd")); clients.Save(pscliconfig); doc = ccfg.GetConfig(pscliconfig); LoadClients_PS(doc); }
private bool ProcessLoginFilePS(FileInfo fitm, PSClientEntry clEntry) { JsonClientEntry entry = null; bool foundSite = false; try { using (var sr = new StreamReader(fitm.FullName)) { var ln = string.Empty; while (sr.Peek() > -1) { ln = sr.ReadLine(); entry = JsonConvert.DeserializeObject<JsonClientEntry>(ln); //AddUpdatePSEntry(entry); var sid = entry.property.id; if (sid.ToString() == clEntry.SiteId) { Log.Debug(string.Format("File {0} SiteId {1}, Token {2} {3} {4} ", fitm.Name, sid, entry.token, entry.token == clEntry.Token ? " = " : " <>", clEntry.Token)); if (entry.token != clEntry.Token) { UpdatePSEntryToken(entry); XDocument doc = ccfg.GetConfig(pscliconfig); LoadClients_PS(doc); } else { AddMessage("Client Entry token is UP-TO-DATE for Site: " + entry.property.name + ", PopertyId : " + entry.property.id); } foundSite = true; break; } } } return foundSite; } catch (Exception ex) { throw; } }
private string GetOutputSubdirPS(PSClientEntry clEntry) { string subDir = (clEntry.RrsId + "_" + clEntry.SiteName).Replace(" ", "_").Replace(",", ""); return subDir; }
private string GetOutputFolderPS(string folderBase, PSClientEntry clEntry) { string subDir = (clEntry.RrsId + "_" + clEntry.SiteName).Replace(" ", "_").Replace(",", ""); string dir = folderBase + @"\" + subDir; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } return dir; }
private PSClientEntry GetClientEntryPS(ListViewItem row) { var cl = new PSClientEntry(); cl.RrsId = row.SubItems[0].Text; cl.SiteId = row.SubItems[1].Text; cl.SiteName = row.SubItems[2].Text; cl.Enabled = Convert.ToBoolean(row.SubItems[4].Text); cl.FirstDate = row.SubItems[5].Text.Replace("-", "/"); cl.Subdomain = row.SubItems[7].Text; cl.Token = row.SubItems[8].Text; return cl; }
private PSClientEntry GetClientEntryPS(string site) { XDocument doc = ccfg.GetConfig(pscliconfig); XElement clientElement = ccfg.GetClientElementForSiteId(doc, site); if (clientElement == null) { return null; } var cl = new PSClientEntry(); cl.RrsId = clientElement.Attribute("keyword") != null ? clientElement.Attribute("keyword").Value : string.Empty; cl.SiteId = clientElement.Descendants("siteid").FirstOrDefault().Value; cl.SiteName = clientElement.Descendants("name").FirstOrDefault().Value; cl.Enabled = Convert.ToBoolean(clientElement.Descendants("enabled").FirstOrDefault().Value); cl.Token = clientElement.Descendants("token").FirstOrDefault().Value; cl.Subdomain = clientElement.Descendants("subdomain").FirstOrDefault().Value; var work =clientElement.Descendants("firstdate").FirstOrDefault(); //.Value; cl.FirstDate = work != null ? work.Value.Replace("-", "/") : DateTime.Today.AddDays(-30).ToString("MM-dd-yyyy"); return cl; }