//!!!!rename public static T GetVariableFromCurrentFlow_Generic <T>(string name) { object value = null; if (CurrentFlow != null) { CurrentFlow.variables.TryGetValue(name, out value); } var expectedType = typeof(T); //auto convert types if (value != null && !expectedType.IsAssignableFrom(value.GetType())) { var newValue = MetadataManager.AutoConvertValue(value, expectedType); if (newValue == null) { newValue = MetadataManager.AutoConvertValue(ReferenceUtility.GetUnreferencedValue(value), expectedType); } value = newValue; } //default for value types if (value == null && expectedType.IsValueType) { value = Activator.CreateInstance(expectedType); } return((T)value); }
public override object GetValue(object obj, object[] index) { //always obj == Owner var c = (Component_ConvertTo)obj; object result = c.Source.Value; //!!!!Metadata.TypeInfo support //auto convert types if (result != null && !Type.GetNetType().IsAssignableFrom(result.GetType())) { var newValue = MetadataManager.AutoConvertValue(result, Type.GetNetType()); if (newValue == null) { newValue = MetadataManager.AutoConvertValue(ReferenceUtility.GetUnreferencedValue(result), Type.GetNetType()); } result = newValue; } //check the type. result can contains value with another type after change the type of property. if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result))) { result = null; } if (result == null && Type.GetNetType().IsValueType) { result = Type.InvokeInstance(null); } return(result); }
public object Invoke(object obj, object[] parameters) { object returnValue = null; var invokeItem = new InvokeStackItem(); invokeItem.obj = obj; invokeItem.parameters = parameters; if (invokeStack == null) { invokeStack = new Stack <InvokeStackItem>(); } invokeStack.Push(invokeItem); //execute flow Flow flow = null; if (Flow.Value != null) { flow = NeoAxis.Flow.ExecuteWithoutRemoveFromStack(Flow, null); } //get ref, out, return value parameters var bodyEnd = BodyEnd.Value; if (bodyEnd != null) { foreach (var p in bodyEnd.properties) { switch (p.parameterType) { case Component_MethodBodyEnd.PropertyImpl.ParameterType.Parameter: if (p.invokeParameterIndex < parameters.Length) { parameters[p.invokeParameterIndex] = ReferenceUtility.GetUnreferencedValue(p.GetValue(bodyEnd, null)); } break; case Component_MethodBodyEnd.PropertyImpl.ParameterType.ReturnValue: returnValue = ReferenceUtility.GetUnreferencedValue(p.GetValue(bodyEnd, null)); break; } } } if (flow != null) { NeoAxis.Flow.RemoveFromStack(flow); } invokeStack.Pop(); //returnValue = EngineApp.EngineTime % 4.0 > 2.0; return(returnValue); }
public override void SetValue(object obj, object value, object[] index) { var c = (Component_DeclareVariable)obj; c.valuePropertyValue = value; //set variable to current flow var currentFlow = Flow.CurrentFlow; currentFlow?.SetVariable(c.GetVariableName(), ReferenceUtility.GetUnreferencedValue(value)); }
void UpdateDefaultValue(PropertyImpl property) { property.DefaultValueSpecified = DefaultValueSpecified.Value; if (property.DefaultValueSpecified && defaultValueProperty != null) { //!!!!need check type? property.DefaultValue = ReferenceUtility.GetUnreferencedValue(defaultValueProperty.GetValue(this, null)); } else { property.DefaultValue = null; } }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { var variable = Variable.Value; if (variable != null && valueProperty != null) { var value = ReferenceUtility.GetUnreferencedValue(valueProperty.GetValue(this, null)); flow.SetVariable(variable.GetVariableName(), value); } FlowInput next = Exit; if (next != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(next)); } }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { var selection = Selection.Value; if (selection != null) { //!!!!always compare via strings? var selectionStr = selection.ToString(); for (int nCase = 0; nCase < Cases.Count; nCase++) { if (selectionStr == Cases[nCase]) { var p = GetProperty(nCase); if (p != null) { var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v)); return; } } } } } //Default { var p = GetProperty(-1); if (p != null) { var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v)); } } } }
void IFlowExecutionComponent.FlowExecution(Flow flow, Flow.ExecutionStackItem entryItem) { bool isEntry = entryItem.FlowInput != null && entryItem.FlowInput.PropertyName == nameof(Entry); int number = -1; if (!isEntry) { if (flow.InternalVariables.TryGetValue(this, out var value)) { number = (int)value; } } number++; var p = GetProperty(number); if (p != null) { flow.InternalVariables[this] = number; //reply after Body flow.ExecutionStack.Push(new Flow.ExecutionStackItem(this)); //go to Body var v = (FlowInput)ReferenceUtility.GetUnreferencedValue(p.GetValue(this, null)); if (v != null) { flow.ExecutionStack.Push(new Flow.ExecutionStackItem(v.Owner)); return; } } else { //end flow.InternalVariables.Remove(this); } }
public override void RenderNodeReferences(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node, Dictionary <Component, List <Component_FlowGraphNode> > objectToNodes, Dictionary <Component_FlowGraphNode.Representation.Item, EditorRenderSelectionState> referenceSelectionStates, out Component_FlowGraphNode.Representation.Item outMouseOverReference) { outMouseOverReference = null; var representation = node.GetRepresentation(); var renderer = window.ViewportControl.Viewport.CanvasRenderer; for (int nItem = 0; nItem < representation.Items.Count; nItem++) { var item = representation.Items[nItem]; //references from input if (item.Input != null) { var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty; if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) && !MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced)) { Component obj = itemProperty.Owner.Owner.ControlledObject; if (obj != null) { var v = itemProperty.Property.GetValue(obj, null); IReference iReference = v as IReference; if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference)) { iReference.GetMember(obj, out object destObject, out Metadata.Member destMember); var destProperty = destMember as Metadata.Property; if (destProperty != null) { //reference to property //!!!!только компоненты? статичные свойства тоже нельзя? var destComponent = destObject as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); Component_FlowGraphNode.Representation.ItemProperty destSocket; if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket)) { if (destSocket.Output != null) { var from = GetSocketPositionInUnits(item, true); var to = GetSocketPositionInUnits(destSocket, false); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.5, 0.5, 0.5); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } } } else { //reference to Component var unrefValue = ReferenceUtility.GetUnreferencedValue(iReference.GetValue(obj)); var destComponent = unrefValue as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); var destSocket = destRep.ItemObject; if (destSocket != null) { var from = GetSocketPositionInUnits(item, true); var to = GetSocketPositionInUnits(destSocket, false); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.5, 0.5, 0.5); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } //!!!!invalid reference } } } } } //references from output (FlowInput) if (item.Output != null) { var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty; if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) && MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced)) { Component obj = itemProperty.Owner.Owner.ControlledObject; if (obj != null) { var v = itemProperty.Property.GetValue(obj, null); IReference iReference = v as IReference; if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference)) { iReference.GetMember(obj, out object destObject, out Metadata.Member destMember); var destProperty = destMember as Metadata.Property; if (destProperty != null) { //!!!!только компоненты? статичные свойства тоже нельзя? var destComponent = destObject as Component; if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes)) { foreach (var destNode in destNodes) { var destRep = destNode.GetRepresentation(); Component_FlowGraphNode.Representation.ItemProperty destSocket; if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket)) { if (destSocket.Input != null) { var from = GetSocketPositionInUnits(item, false); var to = GetSocketPositionInUnits(destSocket, true); if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state)) { state = EditorRenderSelectionState.None; } ColorValue color; if (state != EditorRenderSelectionState.None) { color = GetColorMultiplierSelectionState(state); } else { color = new ColorValue(0.3, 0.3, 1); } //ColorValue color = GetColorMultiplierSelectionState( state ); window.GetFlowGraphStyle().RenderReference(window, from, false, to, color, out bool mouseOver); if (mouseOver && outMouseOverReference == null) { outMouseOverReference = item; } } } } } } else { //!!!!invalid reference } } } } } } }
void Invoke() { //!!!! //!!!!try catch if (MemberObject != null) { //method { var method = MemberObject as Metadata.Method; if (method != null) { ////!!!! //if( method.Name == "Factorial" ) // Log.Info( "dgdg" ); object obj = null; if (!method.Static && propertyThis != null) { obj = ReferenceUtility.GetUnreferencedValue(propertyThis.GetValue(this, null)); //if( obj == null && !( method.Owner is Metadata.TypeInfo ) ) //{ // obj = method.Owner; // //Metadata.TypeInfo creatorType = method.Creator as Metadata.TypeInfo; // //if( creatorType == null ) // // creatorType = MetadataManager.MetadataGetType( method.Creator ); //} } object[] parameters = new object[propertyMethodParameters.Count]; for (int n = 0; n < parameters.Length; n++) { var value = ReferenceUtility.GetUnreferencedValue(propertyMethodParameters[n].GetValue(this, null)); //подвисает только в дебаггере. ////!!!!чтобы не подвисало. даже с try, catch. на int.Parse //{ // var type = propertyMethodParameters[ n ].TypeUnreferenced; // if( value != null && !type.IsAssignableFrom( MetadataManager.MetadataGetType( value ) ) ) // value = null; // if( value == null && type.GetNetType().IsValueType ) // value = type.InvokeInstance( null ); //} parameters[n] = value; } if (method.Static || method.Constructor || obj != null) { //!!!!пока так try { var result = method.Invoke(obj, parameters); //ref, out for (int n = 0; n < parameters.Length; n++) { var p = propertyMethodParameters[n]; if ((p.Parameter.ByReference || p.Parameter.Output) && !p.Parameter.ReturnValue) { p.SetValue(this, parameters[n], null); } } //return propertyMethodReturnParameter?.SetValue(this, result, null); //if( propertyMethodReturnParameter != null ) //{ // var key = propertyMethodReturnParameter.GetKey(); // if( result != null ) // propertyValues[ key ] = result; // else // propertyValues.Remove( key ); //} } catch { //!!!! } } } } //property { var property = MemberObject as Metadata.Property; if (property != null) { //!!!!indexers object obj = null; if (!property.Static && propertyThis != null) { obj = ReferenceUtility.GetUnreferencedValue(propertyThis.GetValue(this, null)); } if (property.Static || obj != null) { object[] indexers = new object[0]; //object[] parameters = new object[ propertyParameters.Length ]; //for( int n = 0; n < parameters.Length; n++ ) // parameters[ n ] = propertyParameters[ n ].GetValue( this ); var result = property.GetValue(obj, indexers); propertyPropertyValue?.SetValue(this, result, null); //propertyValues[ propertyPropertyValue.GetKey() ] = result; } } } } else { //!!!! } }
void Invoke() { //!!!! //!!!!try catch //One method if (compiledOneMethod != null) { object obj = null; //if( !method.Static && propertyThis != null ) //{ // obj = ReferenceUtils.GetUnreferencedValue( propertyThis.GetValue( this, null ) ); // //if( obj == null && !( method.Owner is Metadata.TypeInfo ) ) // //{ // // obj = method.Owner; // // //Metadata.TypeInfo creatorType = method.Creator as Metadata.TypeInfo; // // //if( creatorType == null ) // // // creatorType = MetadataManager.MetadataGetType( method.Creator ); // //} //} object[] parameters = new object[propertyMethodParameters.Count]; for (int n = 0; n < parameters.Length; n++) { var value = ReferenceUtility.GetUnreferencedValue(propertyMethodParameters[n].GetValue(this, null, false)); //подвисает только в дебаггере. ////!!!!чтобы не подвисало. даже с try, catch. на int.Parse //{ // var type = propertyMethodParameters[ n ].TypeUnreferenced; // if( value != null && !type.IsAssignableFrom( MetadataManager.MetadataGetType( value ) ) ) // value = null; // if( value == null && type.GetNetType().IsValueType ) // value = type.InvokeInstance( null ); //} parameters[n] = value; } //if( compiledOneMethod.Static )//|| method.Constructor || obj != null ) { //!!!!пока так try { var result = compiledOneMethod.Invoke(obj, parameters); //ref, out for (int n = 0; n < parameters.Length; n++) { var p = propertyMethodParameters[n]; if ((p.Parameter.ByReference || p.Parameter.Output) && !p.Parameter.ReturnValue) { p.SetValue(this, parameters[n], null); } } //return propertyMethodReturnParameter?.SetValue(this, result, null); } catch { //!!!! } } } }