/// <summary> /// Get all of the dependencies from a workspace /// </summary> /// <param name="workspace">The workspace to read the dependencies from</param> /// <param name="customNodeManager">A custom node manager to look up dependencies</param> /// <returns>A WorkspaceDependencies object containing the workspace and its CustomNodeWorkspaceModel dependencies</returns> public static WorkspaceDependencies Collect(HomeWorkspaceModel workspace, ICustomNodeManager customNodeManager) { if (workspace == null) throw new ArgumentNullException("workspace"); if (customNodeManager == null) throw new ArgumentNullException("customNodeManager"); // collect all dependencies var dependencies = new HashSet<CustomNodeDefinition>(); foreach (var node in workspace.Nodes.OfType<Function>()) { dependencies.Add(node.Definition); foreach (var dep in node.Definition.Dependencies) { dependencies.Add(dep); } } var customNodeWorkspaces = new List<ICustomNodeWorkspaceModel>(); foreach (var dependency in dependencies) { ICustomNodeWorkspaceModel customNodeWs; var workspaceExists = customNodeManager.TryGetFunctionWorkspace(dependency.FunctionId, false, out customNodeWs); if (!workspaceExists) { throw new InvalidOperationException(String.Format(Resources.CustomNodeDefinitionNotFoundErrorMessage, dependency.FunctionName)); } if (!customNodeWorkspaces.Contains(customNodeWs)) { customNodeWorkspaces.Add(customNodeWs); } } return new WorkspaceDependencies(workspace, customNodeWorkspaces); }
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; 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(); // Use the inputs to 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(); // Use the outputs to 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; } } } #region 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; } } } } } } #endregion // 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); IEnumerable <INodeLibraryDependencyInfo> nodeLibraryDependencies; if (obj[NodeLibraryDependenciesPropString] != null) { nodeLibraryDependencies = obj[NodeLibraryDependenciesPropString].ToObject <IEnumerable <INodeLibraryDependencyInfo> >(serializer); } else { nodeLibraryDependencies = new List <PackageDependencyInfo>(); } var info = new WorkspaceInfo(guid.ToString(), name, description, Dynamo.Models.RunType.Automatic); // IsVisibleInDynamoLibrary and Category should be set explicitly for custom node workspace if (obj["View"] != null && obj["View"]["Dynamo"] != null && obj["View"]["Dynamo"]["IsVisibleInDynamoLibrary"] != null) { info.IsVisibleInDynamoLibrary = obj["View"]["Dynamo"]["IsVisibleInDynamoLibrary"].Value <bool>(); } 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>(); #region Restore trace data // 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); } } #endregion 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); } ws.NodeLibraryDependencies = nodeLibraryDependencies.ToList(); 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); // 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); }
private WorkspaceDependencies(HomeWorkspaceModel homeWorkspace, IEnumerable<ICustomNodeWorkspaceModel> customNodeWorkspaces) { this.HomeWorkspace = homeWorkspace; this.CustomNodeWorkspaces = customNodeWorkspaces.OfType<CustomNodeWorkspaceModel>(); }
/// <summary> /// Sends workspace and its' dependencies to Flood. /// </summary> /// <returns>String which is response from server.</returns> private IReachHttpResponse Send(HomeWorkspaceModel workspace, WorkspaceProperties workspaceProperties = null) { if (reachClient == null) { reachClient = new WorkspaceStorageClient(authenticationProvider, serverUrl); } var dependencies = WorkspaceDependencies.Collect(workspace, customNodeManager); InvalidNodeNames = null; return reachClient.Send( workspace, dependencies.CustomNodeWorkspaces, workspaceProperties); }
internal async void SendAsync(HomeWorkspaceModel workspace, WorkspaceProperties workspaceProperties = null) { if (String.IsNullOrWhiteSpace(serverUrl)) { Error = UploadErrorType.ServerNotFound; return; } if (String.IsNullOrWhiteSpace(authenticationProvider.Username)) { Error = UploadErrorType.AuthenticationFailed; return; } if (workspace.Nodes.Count() == 0) { Error = UploadErrorType.EmptyWorkspace; return; } if (authenticationProvider == null) { Error = UploadErrorType.AuthProviderNotFound; return; } State = UploadState.Uploading; IReachHttpResponse result; try { result = await Task.Run(() => this.Send(workspace, workspaceProperties)); } catch (InvalidNodesException ex) { InvalidNodeNames = ex.InvalidNodeNames; Error = UploadErrorType.InvalidNodes; return; } if (result.StatusCode == HttpStatusCode.Unauthorized) { Error = UploadErrorType.Unauthorized; return; } var serverResponce = serverResponceRegex.Match(result.Content); if (serverResponce.Success) { State = UploadState.Succeeded; Error = UploadErrorType.None; CustomizerURL = String.Concat(serverUrl, serverResponce.Value); } else { // If there wasn't any error during uploading, // that means it's some error on the server side. Error = UploadErrorType.UnknownServerError; } }
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 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; }