public void ParamOverridesTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <readMore> <resultId>6465763031VyprCMCoHYQAAGr@aRsAAAAU4</resultId> </readMore> </function>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); ReadMore readMore = new ReadMore("unittest"); readMore.ResultId = "6465763031VyprCMCoHYQAAGr@aRsAAAAU4"; readMore.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd()) .WithDifferenceEvaluator(DifferenceEvaluators.Default) .Build(); Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString()); }
public void NoResultIdTest() { ReadMore record = new ReadMore("unittest"); var ex = Record.Exception(() => this.CompareXml("N/A", record)); Assert.IsType <ArgumentException>(ex); Assert.Equal("Result ID is required for read more", ex.Message); }
/// <summary> /// Caches Data about Account Lists for an Orgization /// </summary> /// <param name="Org"></param> /// <returns></returns> private async Task CacheAccountList(int Org) { // Items to build our lists var accountList = new Dictionary <string, GLAccount>(); var accountTypeList = new Dictionary <string, GLType>(); // Perform Priming Read ReadByQuery read = new ReadByQuery { ObjectName = "GLACCOUNT", PageSize = 1000 }; var client = GetClient(Org); var onlineResponse = await client.Execute(read); var xmlResult = onlineResponse.Results.First(); xmlResult.EnsureStatusSuccess(); // Process Results ExtractInfoFromXML(xmlResult.Data, xmlResult.ListType, accountList, accountTypeList); int receivedCount = xmlResult.Count; while (receivedCount < xmlResult.TotalCount) { // Read Additional Pages of Data ReadMore more = new ReadMore(xmlResult.ControlId) { ResultId = xmlResult.ResultId }; onlineResponse = await client.Execute(more); xmlResult = onlineResponse.Results.First(); xmlResult.EnsureStatusSuccess(); // Process Results ExtractInfoFromXML(xmlResult.Data, xmlResult.ListType, accountList, accountTypeList); // Increment the Counter receivedCount += xmlResult.Count; } // Save to Cache _cache.Set(String.Format(cacheTypesFormat, Org), accountTypeList.Values.OrderBy(glt => glt.AccountTypeCode).AsEnumerable(), new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(Math.Max(1, _config.CacheMinutes)) }); _cache.Set(String.Format(cacheNameFormat, Org), accountList.Values.OrderBy(acct => acct.AccountTypeCode).ThenBy(acct => acct.AccountCode).AsEnumerable(), new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(Math.Max(1, _config.CacheMinutes)) }); }
public NewsItem(string title, string url, string description, string image, string category) { InitializeComponent(); Img.Height = 150; ImageHeight = 150; ReadMore.Text("READ MORE"); ReadMore.ChangeTextColor("#FFF"); ReadMore.RippleColor(Colors.White); try { var bitmap = new BitmapImage(new Uri(image)); Img.Source = bitmap; } catch { } CategoryLabel.Content = category; _title = title; _url = url; _description = description; label.Text = _title; if (_description.Contains("• ")) { string replace = _description.Replace("• ", ""); if (replace.Contains(""")) { string replace2 = replace.Replace(""", ""); DescriptionText.Text = replace2; } else { DescriptionText.Text = replace; } } else { if (_description.Contains(""")) { string replace2 = _description.Replace(""", ""); DescriptionText.Text = replace2; } else { DescriptionText.Text = _description; } } this.Width = 244; Loaded += NewsItem_Loaded; }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <readMore> <resultId>6465763031VyprCMCoHYQAAGr@aRsAAAAU4</resultId> </readMore> </function>"; ReadMore record = new ReadMore("unittest") { ResultId = "6465763031VyprCMCoHYQAAGr@aRsAAAAU4" }; this.CompareXml(expected, record); }
public void NoResultIdTest() { Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); ReadMore readMore = new ReadMore("unittest"); //readMore.ResultId = "6465763031VyprCMCoHYQAAGr@aRsAAAAU4"; readMore.WriteXml(ref xml); }
/// <summary> /// Returns a Dictionary of all ProjectID (ClientCode.JobCode) to Intacct Records /// </summary> /// <param name="client"></param> /// <returns></returns> private async Task <IDictionary <string, string> > GetProjectIds(OnlineClient client, PerformContext context) { var projectMapping = new Dictionary <string, string>(); ReadByQuery read = new ReadByQuery { ObjectName = "PROJECT", PageSize = 1000 }; read.Fields.Clear(); read.Fields.AddRange(new string[] { "RECORDNO", "PROJECTID" }); context.WriteLine("Loading Project Records from Intacct for comparison"); var response = await client.Execute(read); var xmlResult = response.Results.First(); xmlResult.EnsureStatusSuccess(); var details = xmlResult.Data; foreach (var detail in details) { var custid = detail.Element("PROJECTID"); var rec = detail.Element("RECORDNO"); // Ignore Invalid Data if (custid == null || rec == null) { continue; } if (!projectMapping.ContainsKey(custid.Value)) { projectMapping.Add(custid.Value, rec.Value); } } // Get More Data int receivedCount = xmlResult.Count; while (receivedCount < xmlResult.TotalCount) { // Read Additional Pages of Data ReadMore more = new ReadMore(xmlResult.ControlId) { ResultId = xmlResult.ResultId }; context.WriteLine("Loading Additional Customer Records from Intacct for comparison"); response = await client.Execute(more); xmlResult = response.Results.First(); xmlResult.EnsureStatusSuccess(); // Process Results details = xmlResult.Data; foreach (var detail in details) { var custid = detail.Element("PROJECTID"); var rec = detail.Element("RECORDNO"); // Ignore Invalid Data if (custid == null || rec == null) { continue; } if (!projectMapping.ContainsKey(custid.Value)) { projectMapping.Add(custid.Value, rec.Value); } } // Increment the Counter receivedCount += xmlResult.Count; } // Return the mappings context.WriteLine("Found {0} projects in Intacct", projectMapping.Count); return(projectMapping); }
/// <summary> /// Returns a Dictionary of all Contacts (Names) to Intacct Records /// </summary> /// <param name="client"></param> /// <returns></returns> private async Task <IList <string> > GetContacts(OnlineClient client, PerformContext context) { var nameList = new List <string>(); ReadByQuery read = new ReadByQuery { ObjectName = "CONTACT", PageSize = 1000 }; read.Fields.Clear(); read.Fields.AddRange(new string[] { "CONTACTNAME" }); context.WriteLine("Loading Contact Records from Intacct for comparison"); var response = await client.Execute(read); var xmlResult = response.Results.First(); xmlResult.EnsureStatusSuccess(); var details = xmlResult.Data; foreach (var detail in details) { var contName = detail.Element("CONTACTNAME"); // Ignore Invalid Data if (contName == null) { continue; } if (!nameList.Contains(contName.Value)) { nameList.Add(contName.Value); } } // Get More Data int receivedCount = xmlResult.Count; while (receivedCount < xmlResult.TotalCount) { // Read Additional Pages of Data ReadMore more = new ReadMore(xmlResult.ControlId) { ResultId = xmlResult.ResultId }; context.WriteLine("Loading Additional Contact Records from Intacct for comparison"); response = await client.Execute(more); xmlResult = response.Results.First(); xmlResult.EnsureStatusSuccess(); // Process Results details = xmlResult.Data; foreach (var detail in details) { var contName = detail.Element("CONTACTNAME"); // Ignore Invalid Data if (contName == null) { continue; } if (!nameList.Contains(contName.Value)) { nameList.Add(contName.Value); } } // Increment the Counter receivedCount += xmlResult.Count; } // Return the mappings context.WriteLine("Found {0} contacts in Intacct", nameList.Count); return(nameList); }
public static void Run(ILogger logger) { OnlineClient client = Bootstrap.Client(logger); ReadByQuery query = new ReadByQuery() { ObjectName = "VENDOR", PageSize = 2, // Keep the count to just 2 for the example Fields = { "RECORDNO", "VENDORID", } }; logger.LogInformation("Executing query to Intacct API"); Task <OnlineResponse> task = client.Execute(query); task.Wait(); OnlineResponse response = task.Result; Result result = response.Results[0]; try { dynamic json = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result.Data)); string jsonString = json.ToString(); logger.LogDebug( "Query successful - page 1 [ Total count={0}, Data={1} ]", result.TotalCount, jsonString ); Console.WriteLine("Page 1 success! Number of vendor objects found: " + result.TotalCount + ". Number remaining: " + result.NumRemaining); } catch (NullReferenceException e) { logger.LogDebug("No response in Data. {0}", e); } LogManager.Flush(); int i = 1; while (result.NumRemaining > 0 && i <= 3 && !string.IsNullOrEmpty(result.ResultId)) { i++; ReadMore more = new ReadMore() { ResultId = result.ResultId }; Task <OnlineResponse> taskMore = client.Execute(more); taskMore.Wait(); OnlineResponse responseMore = taskMore.Result; Result resultMore = responseMore.Results[0]; try { dynamic resultMoreJson = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(resultMore.Data)); string resultMoreJsonString = resultMoreJson.ToString(); logger.LogDebug( "Read More successful - page " + i + " [ Total remaining={0}, Data={1} ]", resultMore.NumRemaining, resultMoreJsonString ); Console.WriteLine("Page " + i + " success! Records remaining: " + resultMore.NumRemaining); } catch (NullReferenceException e) { logger.LogDebug("No response in Data. {0}", e); } finally { LogManager.Flush(); } } Console.WriteLine("Successfully read " + i + " pages"); }