protected override bool UpdateValueCore(UpdateValueParams updateValueParams) { string name = updateValueParams.PropertyName; string value = updateValueParams.PropertyValue; ElementResolver workspaceElementResolver = updateValueParams.ElementResolver; if (name != "Code") { return(base.UpdateValueCore(updateValueParams)); } value = CodeBlockUtils.FormatUserText(value); //Since an empty Code Block Node should not exist, this checks for such instances. // If an empty Code Block Node is found, it is deleted. Since the creation and deletion of // an empty Code Block Node should not be recorded, this method also checks and removes // any unwanted recordings if (value == "") { Code = ""; } else { if (!value.Equals(Code)) { SetCodeContent(value, workspaceElementResolver); } } return(true); }
private void ProcessCode(ref string errorMessage, ref string warningMessage, ElementResolver workspaceElementResolver = null) { code = CodeBlockUtils.FormatUserText(code); codeStatements.Clear(); if (string.IsNullOrEmpty(Code)) { previewVariable = null; } try { // During loading of CBN from file, the elementResolver from the workspace is unavailable // in which case, a local copy of the ER obtained from the CBN is used var resolver = workspaceElementResolver ?? this.ElementResolver; var parseParam = new ParseParam(GUID, code, resolver); if (CompilerUtils.PreCompileCodeBlock(libraryServices.LibraryManagementCore, ref parseParam)) { if (parseParam.ParsedNodes != null) { // Create an instance of statement for each code statement written by the user foreach (var parsedNode in parseParam.ParsedNodes) { // Create a statement variable from the generated nodes codeStatements.Add(Statement.CreateInstance(parsedNode)); } SetPreviewVariable(parseParam.ParsedNodes); } } if (parseParam.Errors.Any()) { errorMessage = string.Join("\n", parseParam.Errors.Select(m => m.Message)); ProcessError(); CreateInputOutputPorts(); return; } if (parseParam.Warnings != null) { // Unbound identifiers in CBN will have input slots. // // To check function redefinition, we need to check other // CBN to find out if it has been defined yet. Now just // skip this warning. var warnings = parseParam.Warnings.Where( w => w.ID != WarningID.kIdUnboundIdentifier && w.ID != WarningID.kFunctionAlreadyDefined); if (warnings.Any()) { warningMessage = string.Join("\n", warnings.Select(m => m.Message)); } } if (parseParam.UnboundIdentifiers != null) { inputIdentifiers = new List <string>(); inputPortNames = new List <string>(); foreach (var kvp in parseParam.UnboundIdentifiers) { inputIdentifiers.Add(kvp.Value); inputPortNames.Add(kvp.Key); } } else { inputIdentifiers.Clear(); inputPortNames.Clear(); } } catch (Exception e) { errorMessage = e.Message; previewVariable = null; ProcessError(); return; } // Set the input and output ports based on the statements CreateInputOutputPorts(); }