private static IEnumerable<TLCombinator> CreateCombinatorsFromJsonArrayObjects(JsonArrayObjects objects, string nameKey, TLTypesBox typesBox) { return objects.ConvertAll( x => new TLCombinator(x.Get(nameKey)) { Number = (uint) x.JsonTo<int>("id"), Parameters = x.ArrayObjects("params") .ConvertAll(param => new TLCombinatorParameter(param.Get("name"),param.Get("type")) {Type = typesBox[param.Get("type")]}), Type = typesBox[x.Get("type")] }).Where(combinator => !HasBuiltInSerializer(combinator.Number)).ToList(); }
private static IEnumerable<object> ParseAllowedValues(JsonArrayObjects json, FieldSchema schema) { if (json == null) { return null; } if (json.Count == 0) { return new object[0]; } var parser = GetParserFor(schema); if (parser != null) { return json.ConvertAll(parser.Invoke); } // Fallback to returning an array of JsonObjects return json; }
public static List<dynamic> ExpenseUpdate(DateTime date, float vat, JsonArrayObjects jsonAllocation, JsonArrayObjects jsonExpense) { DictionaryToDynamicMapper mapperAllocation = new DictionaryToDynamicMapper("InvoiceAllocation"); var allocation = mapperAllocation.Map(jsonAllocation.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))); var expenses = jsonExpense != null ? (new DictionaryToDynamicMapper("InvoiceExpense")).Map(jsonExpense.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))).ToList() : new List<dynamic>(); #region Capex expenses.ForEach(c => c.AmountCAPEX = 0); var accounts = DynamicRepository.GetByView("AccountCode", FilterCriteriaSet.And.In( allocation.Where(c=>c.capexopex == 0).Select(c => (Guid)c.AccountCodeId).Distinct().ToList(), "Id")); foreach (dynamic item in allocation.Where(c => c.CapexOpex == 0)) { int usefulLife = accounts.Where(c => c.Id == item.AccountCodeId).Select(c => c.UsefulLife).FirstOrDefault() ?? 0; ExpenseUpdateAddCapex(expenses, item.Amount, vat, date, usefulLife); } ExpenseRound(expenses, allocation, true); #endregion #region Opex decimal amountOpexAllocation = allocation.Where(c => c.CapexOpex == 1).Sum(c => (decimal)c.Amount); ExpenseUpdateSyncOpex(expenses, amountOpexAllocation, date); ExpenseRound(expenses, allocation, false); #endregion expenses.RemoveAll(c => c.Amount == 0 && c.AmountCAPEX == 0); return expenses; }
internal static JsonObject Generate(TransitionInput transitionInput, ServerInfo serverInfo) { var jsonObject = new JsonObject(); if (serverInfo.BuildNumber >= ServerVersionConstants.BuildNumberJira5) { var id = new JsonObject { { "id", transitionInput.Id.ToString() } }; jsonObject.Add("transition", id.ToJson()); } else { jsonObject.Add("transition", transitionInput.Id.ToString()); } if (transitionInput.Comment != null) { var comment = CommentJsonGenerator.Generate(transitionInput.Comment, serverInfo).ToJson(); if (serverInfo.BuildNumber >= ServerVersionConstants.BuildNumberJira5) { var jsonComment = new JsonArrayObjects { new JsonObject { { "add", comment } } }; var jsonUpdate = new JsonObject { { "comment", jsonComment.ToJson() } }; jsonObject.Add("update", jsonUpdate.ToJson()); } else { jsonObject.Add("comment", comment); } } if (transitionInput.Fields != null && transitionInput.Fields.Any()) { var list = transitionInput.Fields.Where(f => f.Value != null).ToDictionary(f => f.Id, f => ComplexIssueInputFieldValueJsonGenerator.GenerateFieldValueForJson(f.Value)); jsonObject.Add("fields", list.ToJson()); } return jsonObject; }
public override IProfiler LoadProfilingSession(Guid sessionId) { var jsonArray = new JsonArrayObjects(); // parse json array of specified session for (var i = _logFileLines.Length - 1; i >= 0; --i) { var json = JsonObject.Parse(_logFileLines[i]); if (Guid.Parse(json["sessionId"]) == sessionId) { jsonArray.Add(json); } } // parse session var sessionJson = jsonArray.First(json => json["type"] == "session"); var session = ParseSessionFields(sessionJson); session.StepTimings = new List<SerializableStepTiming>(); session.CustomTimings = new List<SerializableCustomTiming>(); // parse step timings var stepJsons = jsonArray.Where(json => json["type"] == "step"); foreach (var stepJson in stepJsons) { var step = ParseStepFields(stepJson); session.StepTimings.Add(step); } // parse custom timings var customJsons = jsonArray.Where(json => json["type"] != "session" && json["type"] != "step"); foreach (var customJson in customJsons) { var custom = ParseCustomFields(customJson); session.CustomTimings.Add(custom); } // sort session step & custom timings SortSessionTimings(session); return session; }
private static IEnumerable<TLCombinator> CreateMethodsFromJsonArrayObjects(JsonArrayObjects objects, TLTypesBox typesBox) { return CreateCombinatorsFromJsonArrayObjects(objects, "method", typesBox); }
private static IEnumerable<TLCombinator> CreateConstructorsFromJsonArrayObjects(JsonArrayObjects objects, TLTypesBox typesBox) { return CreateCombinatorsFromJsonArrayObjects(objects, "predicate", typesBox); }
public void Can_parse_array_with_nulls() { Assert.That(JsonArrayObjects.Parse("[null,null]"), Is.EqualTo(new string[] { null, null })); }
public void Can_parse_empty_array_with_whitespaces() { Assert.That(JsonArrayObjects.Parse("[ ]"), Is.Empty); Assert.That(JsonArrayObjects.Parse("[\n\n]"), Is.Empty); Assert.That(JsonArrayObjects.Parse("[\t\t]"), Is.Empty); }
public void Can_parse_empty_array() { Assert.That(JsonArrayObjects.Parse("[]"), Is.Empty); }
public void Can_parse_empty_array_with_tab() { Assert.That(JsonArrayObjects.Parse("[\t]"), Is.Empty); }
public string GetShaValue(string content) { Guard.Protect(content); return(JsonArrayObjects.Parse(content).ConvertAll((c) => c["sha"]).First()); }
public static JsonArrayObjects ArrayObjects(this string json) { return(JsonArrayObjects.Parse(json)); }
// async Task<ViewQueryResponse<string>> GetPersonListAsync () async Task GetPersonListAsync(Container container) { //List<MyPerson> database = new List<MyPerson>(); //List<MyPerson> database = FilesService.Database; //string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; //AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting FingerprintDatabase: " + date1); // WebClient client = new WebClient (); //string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); ViewQueryResponse <string> result = null; try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); result = await myCouchClient.Views.QueryAsync <string>(queryView); var rows = result.Rows; // foreach (ViewQueryResponse<SimpleFingerprint> row in rows) foreach (ViewQueryResponse <string, string> .Row row in rows) { Console.WriteLine("Lookin' at " + row); string doc = row.IncludedDoc; var person = new MyPerson(); // SimpleFingerprint print = TypeSerializer.DeserializeFromString<SimpleFingerprint>(doc); var jsonObj = JsonSerializer.DeserializeFromString <JsonObject>(doc); person._id = jsonObj["_id"]; var jsonFingerprints = jsonObj["simpleFingerprint"]; //var Filename = jsonObj["Filename"]; // var serialFingerprints = JsonSerializer.DeserializeFromString<List<JsonObject>>(jsonFingerprints); var serialFingerprints = JsonArrayObjects.Parse(jsonFingerprints); //var fps = JsonSerializer.DeserializeFromString<Dictionary<string, string>>(jsonFingerprints); //var fp = JsonSerializer.DeserializeFromString<JsonObject>(jsonObj["simpleFingerprint"]); //SimpleFingerprint sf = JsonSerializer.DeserializeFromString<SimpleFingerprint>(jsonObj["simpleFingerprint"]); List <Fingerprint> fingerprints = new List <Fingerprint> (); foreach (KeyValuePair <string, string> pair in serialFingerprints[0]) { Fingerprint simpleFingerprint = new Fingerprint(); String value = pair.Value; if (value != null) { char[] delimiterChars = { ':' }; string[] printPair = value.Split(delimiterChars); if (printPair[0] == "Base64Template") { byte[] printArray = System.Convert.FromBase64String(printPair[1]); simpleFingerprint.Template = printArray; fingerprints.Add(simpleFingerprint); } } //var print = printPair[1]; //byte[] printArray = System.Convert.FromBase64String(print); //simpleFingerprint.Template = printArray; // simpleFingerprint.Filename = Filename; //fingerprints.Add(simpleFingerprint); // foreach (KeyValuePair<string,string> pair in fprint) { // SimpleFingerprint simpleFingerprint = new SimpleFingerprint (); // var strBase64Template = JsonSerializer.DeserializeFromString<string>(pair.Key); //// simpleFingerprint.Base64Template = strBase64Template["Base64Template"]; // fingerprints.Add(simpleFingerprint); // } } // foreach (KeyValuePair<string,string> pair in serialFingerprints) // { // var prints = JsonSerializer.DeserializeFromString<JsonObject>(pair.Key); // foreach (KeyValuePair<string,string> print in prints) // { // SimpleFingerprint simpleFingerprint = new SimpleFingerprint (); // var strBase64Template = JsonSerializer.DeserializeFromString<string>(print.Key); //// simpleFingerprint.Base64Template = print["Base64Template"]; // fingerprints.Add(simpleFingerprint); // } // } person.Fingerprints = fingerprints; //person.Filename = jsonObj["Filename"]; person.Uuid = jsonObj["Uuid"]; //database.Add(person); FingerprintDatabase.AddData(person); Console.WriteLine("Added person to FingerprintDatabase."); } //container.Register(database); } catch (Exception e) { Console.WriteLine("Error: " + e); } // return result; }
public static IDictionary <string, object>[] GetAllocations(JsonArrayObjects jsonInvoiceBudgetItems) { List <dynamic> res = new List <dynamic>(); var invoiceBudgetItems = jsonInvoiceBudgetItems != null ? (new DictionaryToDynamicMapper("InvoiceBudgetItem")).Map(jsonInvoiceBudgetItems.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))).ToList() : new List <dynamic>(); if (invoiceBudgetItems.Count > 0) { var budgetItemIds = invoiceBudgetItems.Select(c => (Guid)c.BudgetItemId).ToList(); var budgetItems = DynamicRepository.GetByView("BudgetItem", FilterCriteriaSet.And.In(budgetItemIds, "Id")); var budgetItemAllocations = DynamicRepository.GetByView("BudgetItemAllocation", FilterCriteriaSet.And.In(budgetItemIds, "BudgetItemId")); var sum = invoiceBudgetItems.Sum(c => (double)c.Amount); foreach (dynamic bi in budgetItems) { var ibiSum = invoiceBudgetItems.Where(c => c.BudgetItemId == bi.Id).Sum(c => (double)c.Amount); var k = sum != 0 ? (double)ibiSum / sum : 0; foreach (dynamic bia in budgetItemAllocations.Where(c => c.BudgetItemId == bi.Id)) { var invoiceAllocation = DynamicRepository.NewByView("InvoiceAllocation"); invoiceAllocation.CostCenterId = bia.CostCenterId; invoiceAllocation.CostCenterId_Code = bia.CostCenterId_Code; invoiceAllocation.LegalEntityId = bia.LegalEntityId; invoiceAllocation.LegalEntityId_Name = bia.LegalEntityId_Name; invoiceAllocation.Weight = (double)bia.Weight * k; invoiceAllocation.AccountCodeId = bi.AccountCodeId; invoiceAllocation.AccountCodeId_Name = bi.AccountCodeId_Name; invoiceAllocation.DetailedProjectCode = bi.DetailedProjectCode; invoiceAllocation.ProjectId = bi.ProjectId; invoiceAllocation.ProjectId_Code = bi.ProjectId_Code; invoiceAllocation.ProjectId_Name = bi.ProjectId_Name; invoiceAllocation.CAPEXOPEX = bi.CAPEXOPEX; res.Add(invoiceAllocation); } } for (int i = 0; i < res.Count - 1; i++) { var item = res[i]; for (int j = i + 1; j < res.Count; j++) { var item2 = res[j]; if (item.CostCenterId == item2.CostCenterId && item.LegalEntityId == item2.LegalEntityId && item.AccountCodeId == item2.AccountCodeId && item.ProjectId == item2.ProjectId && item.DetailedProjectCode == item2.DetailedProjectCode && item.CAPEXOPEX == item2.CAPEXOPEX) { item.Weight += item2.Weight; res.RemoveAt(j); j--; } } } } foreach (var item in res) { item.Weight = Math.Round((double)item.Weight, 2); } var firstItem = res.OrderByDescending(c => (double)c.Weight).FirstOrDefault(); if (firstItem != null) { var w = res.Sum(c => (double)c.Weight); firstItem.Weight += 100 - Math.Round(w, 2); } return(res.Select(c => (c as DynamicEntity).Dictionary).ToArray()); }
public static IDictionary<string, object>[] GetAllocations(JsonArrayObjects jsonInvoiceBudgetItems) { List<dynamic> res = new List<dynamic>(); var invoiceBudgetItems = jsonInvoiceBudgetItems != null ? (new DictionaryToDynamicMapper("InvoiceBudgetItem")).Map(jsonInvoiceBudgetItems.Select(c => c.ToDictionary(k => k.Key, k => (object)k.Value))).ToList() : new List<dynamic>(); if (invoiceBudgetItems.Count > 0) { var budgetItemIds = invoiceBudgetItems.Select(c=> (Guid)c.BudgetItemId).ToList(); var budgetItems = DynamicRepository.GetByView("BudgetItem", FilterCriteriaSet.And.In(budgetItemIds, "Id")); var budgetItemAllocations = DynamicRepository.GetByView("BudgetItemAllocation", FilterCriteriaSet.And.In(budgetItemIds, "BudgetItemId")); var sum = invoiceBudgetItems.Sum(c => (double)c.Amount); foreach (dynamic bi in budgetItems) { var ibiSum = invoiceBudgetItems.Where(c=>c.BudgetItemId == bi.Id).Sum(c => (double)c.Amount); var k = sum != 0 ? (double)ibiSum / sum : 0; foreach (dynamic bia in budgetItemAllocations.Where(c => c.BudgetItemId == bi.Id)) { var invoiceAllocation = DynamicRepository.NewByView("InvoiceAllocation"); invoiceAllocation.CostCenterId = bia.CostCenterId; invoiceAllocation.CostCenterId_Code = bia.CostCenterId_Code; invoiceAllocation.LegalEntityId = bia.LegalEntityId; invoiceAllocation.LegalEntityId_Name = bia.LegalEntityId_Name; invoiceAllocation.Weight = (double)bia.Weight * k; invoiceAllocation.AccountCodeId = bi.AccountCodeId; invoiceAllocation.AccountCodeId_Name = bi.AccountCodeId_Name; invoiceAllocation.DetailedProjectCode = bi.DetailedProjectCode; invoiceAllocation.ProjectId = bi.ProjectId; invoiceAllocation.ProjectId_Code = bi.ProjectId_Code; invoiceAllocation.ProjectId_Name = bi.ProjectId_Name; invoiceAllocation.CAPEXOPEX = bi.CAPEXOPEX; res.Add(invoiceAllocation); } } for (int i = 0; i < res.Count - 1; i++) { var item = res[i]; for (int j = i + 1; j < res.Count; j++) { var item2 = res[j]; if (item.CostCenterId == item2.CostCenterId && item.LegalEntityId == item2.LegalEntityId && item.AccountCodeId == item2.AccountCodeId && item.ProjectId == item2.ProjectId && item.DetailedProjectCode == item2.DetailedProjectCode && item.CAPEXOPEX == item2.CAPEXOPEX) { item.Weight += item2.Weight; res.RemoveAt(j); j--; } } } } foreach (var item in res) item.Weight = Math.Round((double)item.Weight, 2); var firstItem = res.OrderByDescending(c => (double)c.Weight).FirstOrDefault(); if (firstItem != null) { var w = res.Sum(c => (double)c.Weight); firstItem.Weight += 100 - Math.Round(w, 2); } return res.Select(c => (c as DynamicEntity).Dictionary).ToArray(); }