public override JObject classToJson(AbstractNodeClass nodeClass) { CombinedNodeClass combinedClass = nodeClass as CombinedNodeClass; if (combinedClass == null) { return(null); } JObject root = new JObject(); AddOwnType(root); AddName(root, nodeClass.Name); AddDescription(root, nodeClass.Description); AddDisplayName(root, nodeClass.DisplayName); AddOutput(root, nodeClass.OutputType); AddInputs(root, nodeClass.InputTypes); AddProxyProperties(root, combinedClass.ProxyProperties); AddUserCreated(root, nodeClass.UserCreated); AddCreator(root, nodeClass.Creator); AddConnections(root, combinedClass.Connections); AddSubNodes(root, combinedClass.SubElements); AddOutputNodeID(root, combinedClass.OutputNodeUuid); return(root); }
public override JObject classToJson(AbstractNodeClass nodeClass) { DataSourceNodeClass sourceClass = nodeClass as DataSourceNodeClass; JObject root = new JObject(); AddOwnType(root); AddName(root, nodeClass.Name); AddDescription(root, nodeClass.Description); AddDisplayName(root, nodeClass.DisplayName); AddOutput(root, nodeClass.OutputType); AddMainClass(root, nodeClass.MainClass); AddNeededClasses(root, nodeClass.NeedsOtherClasses); AddExtras(root, nodeClass.NeededExtras); AddConfig(root, nodeClass.Configuration); AddProxyProperties(root, nodeClass.ProxyProperties); AddUserCreated(root, nodeClass.UserCreated); AddCreator(root, nodeClass.Creator); AddDataMethod(root, sourceClass.DataMethod); AddStartMethod(root, sourceClass.StartMethod); AddStopMethod(root, sourceClass.StopMethod); return(root); }
private AbstractNodeClass AddClass(AbstractNodeClass nodeClass, bool updateGUI) { if (nodeClass == null) { return(null); } //If already present -> Do not add! AbstractNodeClass result; if (this._classes.TryGetValue(nodeClass.Name, out result)) { return(result); } this._classes.Add(nodeClass.Name, nodeClass); //Always update the filtered nodes. this._filteredNodeClasses = null; _allNodeViewers = null; if (updateGUI) { this.OnPropertyChanged("FilteredNodeClasses"); this.OnPropertyChanged("FilteredNodeViewers"); } return(nodeClass); }
public override JObject classToJson(AbstractNodeClass nodeClass) { var transClass = nodeClass as TransformationNodeClass; var root = new JObject(); AddOwnType(root); AddName(root, nodeClass.Name); AddDescription(root, nodeClass.Description); AddDisplayName(root, nodeClass.DisplayName); AddCreator(root, nodeClass.Creator); AddOutput(root, nodeClass.OutputType); AddMainClass(root, nodeClass.MainClass); AddNeededClasses(root, nodeClass.NeedsOtherClasses); AddExtras(root, nodeClass.NeededExtras); AddConfig(root, nodeClass.Configuration); AddInputs(root, nodeClass.InputTypes); AddProxyProperties(root, nodeClass.ProxyProperties); AddUserCreated(root, nodeClass.UserCreated); AddMethodName(root, transClass.Method); AddStatic(root, transClass.IsStatic); return(root); }
/// <summary> /// Starts a call for all elements on the web-server. /// Calls the callback when done. /// </summary> /// <param name="clazz">The class to upload</param> /// <param name="callback">to call when done.</param> public void UploadElement(AbstractNodeClass clazz, Action <string, UploadResponse> callback) { if (clazz == null || callback == null) { return; } if (!CheckOnlineSync()) { callback.Invoke(null, UploadResponse.FAILED_SERVER_NOT_REACHABLE); return; } var folder = Path.Combine(WorkSpace.DIR, (clazz.UserCreated ? WorkSpace.CREATED_DIR : WorkSpace.BASE_DIR), clazz.Name); var tmpName = Path.Combine(WorkSpace.DIR, TmpPath, "upload_" + clazz.Name + ".zip"); ZipFile.CreateFromDirectory(folder, tmpName, CompressionLevel.NoCompression, false); var t = new Task(() => UploadFile(clazz.Name, File.ReadAllBytes(tmpName), (n, b) => { File.Delete(tmpName); callback.Invoke(n, b); })); t.Start(); }
public override string GenerateClassFromSnippet(AbstractNodeClass nodeClass, string methodCode) { var package = GetPackageFromMainclass(nodeClass.MainClass); var imports = nodeClass.InputTypes .ToArray() .Concat(new[] { nodeClass.OutputType }) .Distinct() .Select(i => i.MinimizedName) .Where(i => !CodeExtension.importBlacklist.Contains(i)) .Select(i => "import " + i + ";") .StringJoin("\n"); var methodArgs = ""; for (var i = 0; i < nodeClass.InputTypes.Count(); i++) { if (i > 0) { methodArgs += ", "; } methodArgs += nodeClass.InputTypes[i].MinimizedName + " arg" + i; } return(string.Format(ClassTemplates.TRANSFORMATION_TEMPLATE, package, imports, nodeClass.Name, nodeClass.OutputType.MinimizedName, methodArgs, methodCode)); }
private void uploadDropZone_Drop(object sender, DragEventArgs e) { AbstractNodeClass uploadClass = ((Tuple <Node>)e.Data.GetData(typeof(Tuple <Node>))).Item1.Class as AbstractNodeClass; if (uploadClass != null) { onlineServer.UploadElement(uploadClass, callbackUploadElement); } }
/// <summary> /// Saves the Node passed to the path passed. /// The passed path is taken AS IS. No fiddeling with names afterwards. /// </summary> /// <param name="nodeClass">To Save</param> /// <param name="path">To save to</param> /// <param name="methodCode">To save, can be null.</param> public void saveToFolder(AbstractNodeClass nodeClass, string path, string methodCode = null) { if (path == null) { throw new ArgumentException("Path may not be null!"); } if (nodeClass == null) { throw new ArgumentException("NodeClass may not be null!"); } string metadataPath = Path.Combine(path, METADATA_FILENAME); string newClassPath = Path.Combine(path, Path.Combine(nodeClass.MainClass.Split('.').ToArray()).RemoveAll(" ", "_") + ".java"); if (Directory.Exists(path)) { throw new FileAlreadyPresentException("Folder: " + path + " already exists."); } AbstractNodeLoader loader = loaders[nodeClass.NodeType]; if (loader == null) { throw new MissingTypeException("Did not recognize Type for serialization: " + nodeClass.NodeType); } JObject metadata = loader.classToJson(nodeClass); string generatedClass = methodCode == null ? null : loader.GenerateClassFromSnippet(nodeClass, methodCode); if (metadata == null) { throw new Exception("Ehhh, Something gone wrong, doc!"); } //Write the Metadata + New class if exists: Directory.CreateDirectory(path); File.WriteAllText(metadataPath, metadata.ToBeautifulJson()); if (generatedClass != null) { Directory.CreateDirectory(Path.Combine(path, newClassPath)); Directory.Delete(newClassPath); File.WriteAllText(newClassPath, generatedClass); } //TODO add other stuff to add, like dependencies, etc. }
// moved to Ctrl+N private void CreateCustomElement_Executed(object sender, ExecutedRoutedEventArgs e) { DialogCreateCustomElement dialogNewElement = new DialogCreateCustomElement(); if (dialogNewElement.ShowDialog() == true) { string newElementName = dialogNewElement.ElementName; List <DataType> inputTypes = dialogNewElement.InputTypes; DataType outputType = dialogNewElement.OutputType; string methodCode = dialogNewElement.MethodCode; AbstractNodeClass generatedClass = dialogNewElement.GenerateClassFromInputs(); Singleton <NodeLoader> .Instance.saveToFolder(generatedClass, Path.Combine(WorkSpace.DIR, "created", generatedClass.Name), dialogNewElement.MethodCode); Singleton <ClassManager> .Instance.AddClass(generatedClass); } }
public override string GenerateClassFromSnippet(AbstractNodeClass nodeClass, string methodCode) { string package = GetPackageFromMainclass(nodeClass.MainClass); string imports = nodeClass.InputTypes .ToArray() .Concat(new[] { nodeClass.OutputType }) .Distinct() .Select(i => "import " + i.MinimizedName + ";") .StringJoin("\n"); return(string.Format( ClassTemplates.SENSOR_TEMPLATE, package, imports, nodeClass.Name.RemoveAll(" ", "_"), nodeClass.OutputType.Name, methodCode)); }
/// <summary> /// Called when the Class property changed its value. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnClassChanged(AbstractNodeClass oldValue, AbstractNodeClass newValue) { //Create new Input-IOData, to force new Bindings. InputIOData = newValue.InputTypes .Select(t => new IOData(t, "")) .ToObservableCollection(); //Create new Output-IOData, to force new Bindings. OutputIOData = new IOData(newValue.OutputType, null); //Create new Configuration to force new Bindings. this.Configuration = clazz .Configuration.Select(c => c.GenerateDataElement()) .ToObservableCollection(); //Set a new UUID for the node: this.NodeUUID = Guid.NewGuid().ToString(); //Set the Input data: this.InputNodes = new Node[newValue.InputTypes.Count()]; }
public override JObject classToJson(AbstractNodeClass nodeClass) { BufferNodeClass bufferClass = nodeClass as BufferNodeClass; JObject root = new JObject(); AddOwnType(root); AddName(root, nodeClass.Name); AddDescription(root, nodeClass.Description); AddDisplayName(root, nodeClass.DisplayName); AddOutput(root, nodeClass.OutputType); AddMainClass(root, nodeClass.MainClass); AddNeededClasses(root, nodeClass.NeedsOtherClasses); AddExtras(root, nodeClass.NeededExtras); AddConfig(root, nodeClass.Configuration); AddProxyProperties(root, nodeClass.ProxyProperties); AddUserCreated(root, nodeClass.UserCreated); AddCreator(root, nodeClass.Creator); AddBufferAdd(root, bufferClass.BufferAddMethod); AddBufferGet(root, bufferClass.BufferGetMethod); return(root); }
/// <summary> /// Adds the Node-Class passed. /// </summary> /// <param name="nodeClass"> to add. </param> /// <returns></returns> public AbstractNodeClass AddClass(AbstractNodeClass nodeClass) { return(AddClass(nodeClass, true)); }
/// <summary> /// Starts a downlaod for a specific element. /// </summary> /// <param name="name">To get</param> /// <param name="callback">to call when done</param> private async void StartDownloadOfElement(string name, Action <AbstractNodeClass, DownloadSingleResponse> callback) { byte[] data = null; var resp = DownloadSingleResponse.FAILED_EXCEPTION; var address = GetBaseAddress() + "get?name=" + name; try { using (var client = new HttpClient()) using (var response = await client.GetAsync(address)) using (var content = response.Content) { //Did work! if (response.StatusCode == HttpStatusCode.OK) { data = await content.ReadAsByteArrayAsync(); resp = DownloadSingleResponse.SUCCESS; } if (response.StatusCode == HttpStatusCode.BadRequest) { resp = DownloadSingleResponse.FAILED_NO_NAME; } if (response.StatusCode == HttpStatusCode.NotFound) { resp = DownloadSingleResponse.FAILED_NAME_NOT_FOUND; } } } catch (HttpRequestException exp) { Debug.Print("Server not reachable?! Check your config!"); Debug.Print(exp.ToString()); resp = DownloadSingleResponse.FAILED_SERVER_NOT_REACHABLE; } catch (Exception exp) { Debug.Print("Exception while Downloading Element :" + name); Debug.Print(exp.ToString()); resp = DownloadSingleResponse.FAILED_EXCEPTION; } //If download failed -> break! if (resp != DownloadSingleResponse.SUCCESS) { callback?.Invoke(null, resp); return; } var workSpace = WorkSpace.DIR; var tmpPath = Path.Combine(workSpace, TmpPath, name + "_download"); var tmpZipPath = Path.Combine(tmpPath, "data.zip"); var destDir = Path.Combine(workSpace, "created", name); //Just to be sure we do not have some old remainings. if (Directory.Exists(tmpPath)) { Directory.Delete(tmpPath, true); } //Now create new stuff: Directory.CreateDirectory(tmpPath); Directory.CreateDirectory(destDir); //Write and do your stuff: if (data != null) { File.WriteAllBytes(tmpZipPath, data); } try { ZipFile.ExtractToDirectory(tmpZipPath, destDir); } catch (Exception exp) { Debug.Print(exp.ToString()); resp = DownloadSingleResponse.FAILED_WHILE_EXTRACTING; } //Cleanup: Directory.Delete(tmpPath, true); if (resp != DownloadSingleResponse.SUCCESS) { Directory.Delete(destDir, true); } //Now try to load the new element: AbstractNodeClass newElement = null; if (resp == DownloadSingleResponse.SUCCESS) { try { newElement = Singleton <NodeLoader> .Instance.loadFromFolder(destDir); } catch (Exception exp) { Debug.Print(exp.ToString()); resp = DownloadSingleResponse.FAILED_WHILE_LOADING; } } callback?.Invoke(newElement, resp); }
/// <summary> /// Returns true if is on Blacklist. /// </summary> /// <param name="clazz">To to search for.</param> /// <returns>true if is on Blacklist</returns> public bool IsOnBlackList(AbstractNodeClass clazz) { return(IsOnBlackList(clazz.Name)); }
/// <summary> /// Removes the Node from the Blacklist. /// </summary> /// <param name="clazz"></param> public void Remove(AbstractNodeClass clazz) { Remove(clazz.Name); }
/// <summary> /// Generates a new Class from a snippet. /// </summary> /// <param name="methodCode">to use.</param> /// <param name="nodeClass">to use.</param> /// <returns>the generated Java class</returns> public abstract string GenerateClassFromSnippet(AbstractNodeClass nodeClass, string methodCode);
public override string GenerateClassFromSnippet(AbstractNodeClass nodeClass, string methodCode) { //TODO IMPLEMENT ME! return(""); }
public override string GenerateClassFromSnippet(AbstractNodeClass nodeClass, string methodCode) { //Combined node have nothing to generate on classes. return(null); }
private void uploadElement(AbstractNodeClass clazz, Action <string, UploadResponse> callback) { onlineServer.UploadElement(clazz, callbackUploadElement); }
/// <summary> /// Called when the Class property changed its value. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected override void OnClassChanged(AbstractNodeClass oldValue, AbstractNodeClass newValue) { //Do not forget to call super to set DATA. base.OnClassChanged(oldValue, newValue); if (newValue != null && oldValue != newValue) { //First update the Input nodes as Size: this.inputNodes = new Node[newValue.InputTypes.Count()]; CombinedNodeClass ownClass = newValue as CombinedNodeClass; if (ownClass != null) { //This means we are called from the Constructor of the Node class. We get a call with our data later on! if (ownClass.Connections == null || ownClass.SubElements == null) { return; } ClassManager classManager = Singleton <ClassManager> .Instance; this.includedNodes = new Node[ownClass.SubElements.Count]; this.inputConnections = new Dictionary <int, Tuple <Node, int> >(); int i = 0; //Generate the Nodes: foreach (SimpleSubNode simpleNode in ownClass.SubElements) { Node subNode = simpleNode.GetAsRealNode(classManager); if (subNode == null) { //We have some types that are not registered?!? throw new Exception("Could not load Node: " + simpleNode.Type); } //We have our output node: if (subNode != null && subNode.NodeUUID == ownClass.OutputNodeUuid) { this.outputNode = subNode; } this.includedNodes[i] = subNode; i++; } //Generate the Connections: foreach (SimpleConnection connection in ownClass.Connections) { string first = connection.FirstNode; string second = connection.SecondNode; int index = connection.Position; //Search for the 2 nodes: Node firstNode = this.includedNodes.FirstOrDefault(n => n.NodeUUID == first); Node secondNode = this.includedNodes.FirstOrDefault(n => n.NodeUUID == second); //We have an Input node: if (second.StartsWith("input")) { this.inputConnections.Add(Int32.Parse(second.Substring("input".Count())), new Tuple <Node, int>(firstNode, index)); continue; } //We have an internal connection: if (secondNode != null && firstNode != null) { Transformation transformation = firstNode as Transformation; CombinedNode combined = firstNode as CombinedNode; //We connect a Transformation: if (transformation != null) { transformation.SetInput(index, secondNode); continue; } //We connect a CombinedNode: if (combined != null) { combined.SetInput(index, secondNode); continue; } } } //Now we apply the Node-IO-Options: for (i = 0; i < inputConnections.Count(); i++) { Tuple <Node, int> tuple = inputConnections[i]; this.inputIOData[i] = tuple.Item1.InputIOData[tuple.Item2]; } //After building from base -> We unify the UUIDs, so they are now unique again! includedNodes.ForEach(n => n.ForceUUID(Guid.NewGuid().ToString())); } } }
private void callbackGetOnlineElement(AbstractNodeClass downloadedClass, DownloadSingleResponse downloadSingleResponse) { this.downloadedClass = downloadedClass; this.downloadSingleResponse = downloadSingleResponse; Dispatcher.Invoke(new Action(responseGetOnlineElement)); }
/// <summary> /// Serializes the Nodeclass to a Json respective for the Meta-Data. /// </summary> /// <param name="nodeClass">to generate for.</param> /// <returns>The generated root object</returns> public abstract JObject classToJson(AbstractNodeClass nodeClass);