public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var isCustomNode = obj["IsCustomNode"].Value <bool>(); var description = obj["Description"].Value <string>(); var guidStr = obj["Uuid"].Value <string>(); var guid = Guid.Parse(guidStr); var name = obj["Name"].Value <string>(); var elementResolver = obj["ElementResolver"].ToObject <ElementResolver>(serializer); var nmc = (NodeReadConverter)serializer.Converters.First(c => c is NodeReadConverter); nmc.ElementResolver = elementResolver; // nodes var nodes = obj["Nodes"].ToObject <IEnumerable <NodeModel> >(serializer); // nodes var inputsToken = obj["Inputs"]; if (inputsToken != null) { var inputs = inputsToken.ToArray().Select(x => x.ToObject <NodeInputData>()).ToList(); //using the inputs lets set the correct properties on the nodes. foreach (var inputData in inputs) { var matchingNode = nodes.Where(x => x.GUID == inputData.Id).FirstOrDefault(); if (matchingNode != null) { matchingNode.IsSetAsInput = true; } } } var outputsToken = obj["Outputs"]; if (outputsToken != null) { var outputs = outputsToken.ToArray().Select(x => x.ToObject <NodeOutputData>()).ToList(); //using the inputs lets set the correct properties on the nodes. foreach (var outputData in outputs) { var matchingNode = nodes.Where(x => x.GUID == outputData.Id).FirstOrDefault(); if (matchingNode != null) { matchingNode.IsSetAsOutput = true; } } } // notes //TODO: Check this when implementing ReadJSON in ViewModel. //var notes = obj["Notes"].ToObject<IEnumerable<NoteModel>>(serializer); //if (notes.Any()) //{ // foreach(var n in notes) // { // serializer.ReferenceResolver.AddReference(serializer.Context, n.GUID.ToString(), n); // } //} // connectors // Although connectors are not used in the construction of the workspace // we need to deserialize this collection, so that they connect to their // relevant ports. var connectors = obj["Connectors"].ToObject <IEnumerable <ConnectorModel> >(serializer); var info = new WorkspaceInfo(guid.ToString(), name, description, Dynamo.Models.RunType.Automatic); //Build an empty annotations. Annotations are defined in the view block. If the file has View block //serialize view block first and build the annotations. var annotations = new List <AnnotationModel>(); //Build an empty notes. Notes are defined in the view block. If the file has View block //serialize view block first and build the notes. var notes = new List <NoteModel>(); // Trace Data Dictionary <Guid, List <CallSite.RawTraceData> > loadedTraceData = new Dictionary <Guid, List <CallSite.RawTraceData> >(); // Restore trace data if bindings are present in json if (obj["Bindings"] != null && obj["Bindings"].Children().Count() > 0) { JEnumerable <JToken> bindings = obj["Bindings"].Children(); // Iterate through bindings to extract nodeID's and bindingData (callsiteId & traceData) foreach (JToken entity in bindings) { Guid nodeId = Guid.Parse(entity["NodeId"].ToString()); string bindingString = entity["Binding"].ToString(); // Key(callsiteId) : Value(traceData) Dictionary <string, string> bindingData = JsonConvert.DeserializeObject <Dictionary <string, string> >(bindingString); List <CallSite.RawTraceData> callsiteTraceData = new List <CallSite.RawTraceData>(); foreach (KeyValuePair <string, string> pair in bindingData) { callsiteTraceData.Add(new CallSite.RawTraceData(pair.Key, pair.Value)); } loadedTraceData.Add(nodeId, callsiteTraceData); } } WorkspaceModel ws; if (isCustomNode) { ws = new CustomNodeWorkspaceModel(factory, nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info); } else { ws = new HomeWorkspaceModel(guid, engine, scheduler, factory, loadedTraceData, nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info, verboseLogging, isTestMode); } return(ws); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var isCustomNode = obj["IsCustomNode"].Value <bool>(); var description = obj["Description"].Value <string>(); var guidStr = obj["Uuid"].Value <string>(); var guid = Guid.Parse(guidStr); var name = obj["Name"].Value <string>(); var elementResolver = obj["ElementResolver"].ToObject <ElementResolver>(serializer); var nmc = (NodeReadConverter)serializer.Converters.First(c => c is NodeReadConverter); nmc.ElementResolver = elementResolver; // nodes var nodes = obj["Nodes"].ToObject <IEnumerable <NodeModel> >(serializer); // notes //TODO: Check this when implementing ReadJSON in ViewModel. //var notes = obj["Notes"].ToObject<IEnumerable<NoteModel>>(serializer); //if (notes.Any()) //{ // foreach(var n in notes) // { // serializer.ReferenceResolver.AddReference(serializer.Context, n.GUID.ToString(), n); // } //} // connectors // Although connectors are not used in the construction of the workspace // we need to deserialize this collection, so that they connect to their // relevant ports. var connectors = obj["Connectors"].ToObject <IEnumerable <ConnectorModel> >(serializer); var info = new WorkspaceInfo(guid.ToString(), name, description, Dynamo.Models.RunType.Automatic); //Build an empty annotations. Annotations are defined in the view block. If the file has View block //serialize view block first and build the annotations. var annotations = new List <AnnotationModel>(); //Build an empty notes. Notes are defined in the view block. If the file has View block //serialize view block first and build the notes. var notes = new List <NoteModel>(); WorkspaceModel ws; if (isCustomNode) { ws = new CustomNodeWorkspaceModel(factory, nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info); } else { ws = new HomeWorkspaceModel(guid, engine, scheduler, factory, Enumerable.Empty <KeyValuePair <Guid, List <CallSite.RawTraceData> > >(), nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info, verboseLogging, isTestMode); } return(ws); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var isCustomNode = obj["IsCustomNode"].Value <bool>(); var description = obj["Description"].Value <string>(); var guidStr = obj["Uuid"].Value <string>(); var guid = Guid.Parse(guidStr); var name = obj["Name"].Value <string>(); var elementResolver = obj["ElementResolver"].ToObject <ElementResolver>(serializer); var nmc = (NodeReadConverter)serializer.Converters.First(c => c is NodeReadConverter); nmc.ElementResolver = elementResolver; // nodes var nodes = obj["Nodes"].ToObject <IEnumerable <NodeModel> >(serializer); // Setting Inputs // Required in headless mode by Dynamo Player that NodeModel.Name and NodeModel.IsSetAsInput are set var inputsToken = obj["Inputs"]; if (inputsToken != null) { var inputs = inputsToken.ToArray().Select(x => x.ToObject <NodeInputData>()).ToList(); //using the inputs lets set the correct properties on the nodes. foreach (var inputData in inputs) { var matchingNode = nodes.Where(x => x.GUID == inputData.Id).FirstOrDefault(); if (matchingNode != null) { matchingNode.IsSetAsInput = true; matchingNode.Name = inputData.Name; } } } // Setting Outputs var outputsToken = obj["Outputs"]; if (outputsToken != null) { var outputs = outputsToken.ToArray().Select(x => x.ToObject <NodeOutputData>()).ToList(); //using the inputs lets set the correct properties on the nodes. foreach (var outputData in outputs) { var matchingNode = nodes.Where(x => x.GUID == outputData.Id).FirstOrDefault(); if (matchingNode != null) { matchingNode.IsSetAsOutput = true; matchingNode.Name = outputData.Name; } } } // Setting Inputs based on view layer info // TODO: It is currently duplicating the effort with Input Block parsing which should be cleaned up once // Dynamo supports both selection and drop down nodes in Inputs block var view = obj["View"]; if (view != null) { var nodesView = view["NodeViews"]; if (nodesView != null) { var inputsView = nodesView.ToArray().Select(x => x.ToObject <Dictionary <string, string> >()).ToList(); foreach (var inputViewData in inputsView) { string isSetAsInput = ""; if (!inputViewData.TryGetValue("IsSetAsInput", out isSetAsInput) || isSetAsInput == bool.FalseString) { continue; } string inputId = ""; if (inputViewData.TryGetValue("Id", out inputId)) { Guid inputGuid; try { inputGuid = Guid.Parse(inputId); } catch { continue; } var matchingNode = nodes.Where(x => x.GUID == inputGuid).FirstOrDefault(); if (matchingNode != null) { matchingNode.IsSetAsInput = true; string inputName = ""; if (inputViewData.TryGetValue("Name", out inputName)) { matchingNode.Name = inputName; } } } } } } // notes //TODO: Check this when implementing ReadJSON in ViewModel. //var notes = obj["Notes"].ToObject<IEnumerable<NoteModel>>(serializer); //if (notes.Any()) //{ // foreach(var n in notes) // { // serializer.ReferenceResolver.AddReference(serializer.Context, n.GUID.ToString(), n); // } //} // connectors // Although connectors are not used in the construction of the workspace // we need to deserialize this collection, so that they connect to their // relevant ports. var connectors = obj["Connectors"].ToObject <IEnumerable <ConnectorModel> >(serializer); var info = new WorkspaceInfo(guid.ToString(), name, description, Dynamo.Models.RunType.Automatic); //https://jira.autodesk.com/browse/QNTM-3872 //Category should be set explicitly from custom node workspace. if (obj["Category"] != null) { info.Category = obj["Category"].Value <string>(); } //Build an empty annotations. Annotations are defined in the view block. If the file has View block //serialize view block first and build the annotations. var annotations = new List <AnnotationModel>(); //Build an empty notes. Notes are defined in the view block. If the file has View block //serialize view block first and build the notes. var notes = new List <NoteModel>(); // Trace Data Dictionary <Guid, List <CallSite.RawTraceData> > loadedTraceData = new Dictionary <Guid, List <CallSite.RawTraceData> >(); // Restore trace data if bindings are present in json if (obj["Bindings"] != null && obj["Bindings"].Children().Count() > 0) { JEnumerable <JToken> bindings = obj["Bindings"].Children(); // Iterate through bindings to extract nodeID's and bindingData (callsiteId & traceData) foreach (JToken entity in bindings) { Guid nodeId = Guid.Parse(entity["NodeId"].ToString()); string bindingString = entity["Binding"].ToString(); // Key(callsiteId) : Value(traceData) Dictionary <string, string> bindingData = JsonConvert.DeserializeObject <Dictionary <string, string> >(bindingString); List <CallSite.RawTraceData> callsiteTraceData = new List <CallSite.RawTraceData>(); foreach (KeyValuePair <string, string> pair in bindingData) { callsiteTraceData.Add(new CallSite.RawTraceData(pair.Key, pair.Value)); } loadedTraceData.Add(nodeId, callsiteTraceData); } } WorkspaceModel ws; if (isCustomNode) { ws = new CustomNodeWorkspaceModel(factory, nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info); } else { ws = new HomeWorkspaceModel(guid, engine, scheduler, factory, loadedTraceData, nodes, notes, annotations, Enumerable.Empty <PresetModel>(), elementResolver, info, verboseLogging); } return(ws); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var isCustomNode = obj["IsCustomNode"].Value<bool>(); var lastModifiedStr = obj["LastModified"].Value<string>(); var lastModified = DateTime.ParseExact(lastModifiedStr,"yyyy-MM-dd",CultureInfo.InvariantCulture); var author = obj["LastModifiedBy"].Value<string>(); var description = obj["Description"].Value<string>(); var guidStr = obj["Uuid"].Value<string>(); var guid = Guid.Parse(guidStr); var name = obj["Name"].Value<string>(); var elementResolver = obj["ElementResolver"].ToObject<ElementResolver>(serializer); var nmc = (NodeModelConverter)serializer.Converters.First(c => c is NodeModelConverter); nmc.ElementResolver = elementResolver; // nodes var nodes = obj["Nodes"].ToObject<IEnumerable<NodeModel>>(serializer); // notes var notes = obj["Notes"].ToObject<IEnumerable<NoteModel>>(serializer); if (notes.Any()) { foreach(var n in notes) { serializer.ReferenceResolver.AddReference(serializer.Context, n.GUID.ToString(), n); } } // connectors // Although connectors are not used in the construction of the workspace // we need to deserialize this collection, so that they connect to their // relevant ports. var connectors = obj["Connectors"].ToObject<IEnumerable<ConnectorModel>>(serializer); // annotations var annotations = obj["Annotations"].ToObject<IEnumerable<AnnotationModel>>(serializer); var info = new WorkspaceInfo(guid.ToString(), name, description, Dynamo.Models.RunType.Automatic); WorkspaceModel ws; if (isCustomNode) { ws = new CustomNodeWorkspaceModel(factory, nodes, notes, annotations, Enumerable.Empty<PresetModel>(), elementResolver, info); } else { ws = new HomeWorkspaceModel(guid, engine, scheduler, factory, Enumerable.Empty<KeyValuePair<Guid, List<CallSite.RawTraceData>>>(), nodes, notes, annotations, Enumerable.Empty<PresetModel>(), elementResolver, info, verboseLogging, isTestMode); } return ws; }