private ModuleSchema(ModuleJson json) { // Note: we populate everything other than the fields first, so that field // construction can rely on it. json.Validate(); Identifier = json.Identifier !.ToModuleIdentifier(); Kits = json.Counts !["kits"];
private static ModuleJson ToJson(WebModuleMeta module) { var mJson = new ModuleJson { keyLabel = module.KeyLabel }; if (module.HasUI) { if (module.IsCustomUI) { mJson.url = module.Url; } else { mJson.model = ClientEntities.GetClientName(module.EntityType); mJson.clientRuntime = module.ClientRuntime; mJson.viewName = module.AggtBlocksName; } } foreach (WebModuleMeta child in module.Children) { var childJson = ToJson(child); mJson.children.Add(childJson); } return mJson; }
private static ModuleJson ToJson(WebModuleMeta module) { var mJson = new ModuleJson { keyLabel = module.KeyLabel }; if (module.HasUI) { if (module.IsCustomUI) { mJson.url = module.Url; } else { mJson.model = ClientEntities.GetClientName(module.EntityType); mJson.clientRuntime = module.ClientRuntime; mJson.viewName = module.AggtBlocksName; } } foreach (WebModuleMeta child in module.Children) { var childJson = ToJson(child); mJson.children.Add(childJson); } return(mJson); }
private ModuleSchema(ModuleJson json) { // Note: we populate everything other than the fields first, so that field // construction can rely on it. json.Validate(); Identifier = json.Identifier !.ToModuleIdentifier(); InstrumentGroups = json.InstrumentGroups .Select((igj, index) => igj.ToInstrumentGroup(index)) .Concat(new[] { InstrumentGroup.ForUserSamples(json.InstrumentGroups !.Count, json.Counts !["userSamples"]) })
public void should_Read_Module_Json() { var modules = new ModuleJson().Read(); Assert.IsTrue(modules.Count > 0); foreach (var module in modules) { Console.WriteLine(module); } }
private void WriteModules(StringBuilder js) { var result = new ModuleJson(); var roots = CommonModel.Modules.Roots; foreach (WebModuleMeta root in roots) { var rootJson = ToJson(root); result.children.Add(rootJson); } js.AppendFormat(@" Rafy.App.getModules()._setRoot({0}); ", result.ToJsonString()); }
// Note: this used to be in ModuleJson.ToModuleSchema(), but it turns out it's really useful for // a field to have access to the schema it's part of... which is tricky when everything is immutable // and the schema also has to have references to the fields. So this code is ugly - and makes field testing // trickier - but at least it's pleasant to use elsewhere. internal ModuleSchema(ModuleJson json) { // Note: we populate everything other than the fields first, so that field // construction can rely on it. json.Validate(); Identifier = new ModuleIdentifier(json.Name !, json.ModelId !.Value, json.FamilyCode !.Value, json.FamilyNumberCode !.Value); InstrumentGroups = json.BuildInstrumentGroups(); PresetInstruments = InstrumentGroups.SelectMany(ig => ig.Instruments) .OrderBy(i => i.Id) .ToList() .AsReadOnly(); // Just validate that our list is consistent. for (int i = 0; i < PresetInstruments.Count; i++) { if (PresetInstruments[i].Id != i) { throw new InvalidOperationException($"Instrument {PresetInstruments[i]} is in index {i}"); } } UserSampleInstruments = Enumerable.Range(0, json.UserSamples !.Value) .Select(id => Instrument.FromUserSample(id)) .ToList() .AsReadOnly(); // Now do everything with the fields. Root = new FixedContainer(json.BuildRootContainer(this), new ModuleAddress(0)); LogicalRoot = json.BuildLogicalRoot(Root); PhysicalRoot = VisualTreeNode.FromFixedContainer(null, Root); KitRoots = LogicalRoot.DescendantNodesAndSelf() .Where(node => node.KitNumber != null) .ToDictionary(node => node.KitNumber !.Value) .AsReadOnly(); LoadableContainersByAddress = Root .DescendantsAndSelf() .Where(context => context.Container.Loadable) .ToDictionary(context => context.Address, context => context.Container) .AsReadOnly(); }
private static ModuleSchema FromJson(JObject json) => new ModuleSchema(ModuleJson.FromJson(json));
public async Task <IActionResult> Sort(ModuleJson obj) { var result = await _moduRepo.SortAsync(obj.Json); return(Ok(result)); }