public IValue CallMethod(IRuntimeContextInstance target, string methodName, IRuntimeContextInstance arguments = null) { ArrayImpl argArray; if (arguments != null) { argArray = arguments as ArrayImpl; if (argArray == null) { throw RuntimeException.InvalidArgumentType(); } } else { argArray = new ArrayImpl(); } var methodIdx = target.FindMethod(methodName); var methInfo = target.GetMethodInfo(methodIdx); IValue retValue = ValueFactory.Create(); if (methInfo.IsFunction) { target.CallAsFunction(methodIdx, argArray.ToArray(), out retValue); } else { target.CallAsProcedure(methodIdx, argArray.ToArray()); } return(retValue); }
public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null) { if (arguments == null) { arguments = new ArrayImpl(); } var methodIdx = target.FindMethod(methodName); var methInfo = target.GetMethodInfo(methodIdx); if (methInfo.ArgCount < arguments.Count()) { throw RuntimeException.TooManyArgumentsPassed(); } if (methInfo.ArgCount > arguments.Count()) { throw RuntimeException.TooLittleArgumentsPassed(); } IValue retValue = ValueFactory.Create(); if (methInfo.IsFunction) { target.CallAsFunction(methodIdx, arguments.ToArray(), out retValue); } else { target.CallAsProcedure(methodIdx, arguments.ToArray()); } return(retValue); }
public FormButton(Control parentCntrl) { this._item = new Button(); ((Button)this._item).Click += BtnClick; this._item.MinimumSize = new Size(100, 21); this._item.AutoSize = true; this._parentControl = parentCntrl; this._panel = new Panel(); this._name = ""; this._visible = true; this._enabled = true; this._title = ""; this._parent = null; this._methodName = ""; this._thisScript = null; this._panel.Dock = DockStyle.Top; this._panel.AutoSize = true; this._panel.Controls.Add(this._item); this._parentControl.Controls.Add(_panel); this._panel.BringToFront(); }
public void setAction(IRuntimeContextInstance contex, string eventName, string methodName) { if (eventName == "ПриДвойномКлике") { ((ListView)_item).DoubleClick -= FormFieldDblClick; ((ListView)_item).DoubleClick += FormFieldDblClick; this._scriptDblClick = contex; this._methodNameDblClick = methodName; } else if (eventName == "ПриВыборе") { (_item).KeyPress -= FormFieldOnChoice; (_item).KeyPress += FormFieldOnChoice; this._scriptOnChoice = contex; this._methodOnChoice = methodName; } else if (eventName == "ПриНажатииНаКлавишу") { (_item).KeyDown -= FormFieldOnKeyDown; (_item).KeyDown += FormFieldOnKeyDown; this._scriptOnKeyDown = contex; this._methodOnKeyDown = methodName; } }
public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null) { var methodIdx = target.FindMethod(methodName); var methInfo = target.GetMethodInfo(methodIdx); var argsToPass = GetArgsToPass(arguments, methInfo); IValue retValue = ValueFactory.Create(); if (methInfo.IsFunction) { target.CallAsFunction(methodIdx, argsToPass, out retValue); } else { target.CallAsProcedure(methodIdx, argsToPass); } if (arguments != null) { for (int i = 0; i < argsToPass.Length; i++) { if (i < arguments.Count()) { arguments.Set(i, argsToPass[i]?.GetRawValue()); } } } return(retValue); }
public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, IValue filledProperties = null, IValue ignoredProperties = null) { string strFilled; string strIgnored; if (filledProperties == null || filledProperties.DataType == DataType.Undefined) { strFilled = null; } else if (filledProperties.DataType == DataType.String) { strFilled = filledProperties.AsString(); } else { throw RuntimeException.InvalidArgumentType(3, nameof(filledProperties)); } if (ignoredProperties == null || ignoredProperties.DataType == DataType.Undefined) { strIgnored = null; } else if (ignoredProperties.DataType == DataType.String) { strIgnored = ignoredProperties.AsString(); } else { throw RuntimeException.InvalidArgumentType(4, nameof(ignoredProperties)); } FillPropertyValuesStr(acceptor, source, strFilled, strIgnored); }
public void setAction(IRuntimeContextInstance contex, string eventName, string methodName) { //if (eventName == "ПриСоздании") //{ // this._form.HandleCreated -= OnFormCreated; // this._form.HandleCreated += OnFormCreated; // this._thisScriptOnCreated = contex; // this._methodNameOnCreated = methodName; //} if (eventName == "ПриОткрытии") { this._form.Shown -= OnFormShown; this._form.Shown += OnFormShown; this._thisScriptOnShown = contex; this._methodNameOnShown = methodName; } else if (eventName == "ПриЗакрытии") { this._form.FormClosing -= OnFormClose; this._form.FormClosing += OnFormClose; this._thisScriptOnClose = contex; this._methodNameOnClose = methodName; } }
public void setAction(IRuntimeContextInstance contex, string eventName, string methodName) { if (eventName == "ПриВыбореСтроки") { this._thisScript = contex; this._methodName = methodName; _item.TreeView.AfterSelect -= FormFieldValueChanged; _item.TreeView.AfterSelect += FormFieldValueChanged; } else if (eventName == "ПриДвойномКлике") { _item.TreeView.DoubleClick -= FormFieldDblClick; _item.TreeView.DoubleClick += FormFieldDblClick; this._thisScriptDblClick = contex; this._methodNameDblClick = methodName; } else if (eventName == "ПриВыборе") { _item.TreeView.KeyPress -= FormFieldOnChoice; _item.TreeView.KeyPress += FormFieldOnChoice; this._scriptOnChoice = contex; this._methodOnChoice = methodName; } }
public void setAction(IRuntimeContextInstance contex, string eventName, string methodName) { if (eventName == "ПриПотереФокусаЯчейки") { this._thisScript = contex; this._methodName = methodName; ((DataGridView)_item).CurrentCellChanged -= FormFieldValueChanged; ((DataGridView)_item).CurrentCellChanged += FormFieldValueChanged; } else if (eventName == "ПриДвойномКлике") { ((DataGridView)_item).CellDoubleClick -= FormFieldDblClick; ((DataGridView)_item).CellDoubleClick += FormFieldDblClick; this._thisScriptDblClick = contex; this._methodNameDblClick = methodName; } else if (eventName == "ПриВыборе") { (_item).KeyPress -= FormFieldOnChoice; (_item).KeyPress += FormFieldOnChoice; this._scriptOnChoice = contex; this._methodOnChoice = methodName; } }
public VariableReference(IRuntimeContextInstance context, int propertyNumber, string name) { _refType = ReferenceType.ContextProperty; _context = context; _contextPropertyNumber = propertyNumber; Name = name; }
public VariableReference(IRuntimeContextInstance context, IValue index, string name) { _refType = ReferenceType.IndexedProperty; _context = context; _index = index; Name = name; }
public void CallCommonModuleProcedure(string moduleName, string methodName, IValue[] parameters) { IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName); int methodId = commonModule.FindMethod(methodName); commonModule.CallAsProcedure(methodId, parameters); }
private static void ProduceResponse(HttpContext context, IRuntimeContextInstance runner) { int methodIndex = runner.FindMethod("ОбработкаВызоваHTTPСервиса"); IValue result; IValue[] args = new IValue[1]; args[0] = new OneScript.HTTPService.HTTPServiceRequestImpl(context); runner.CallAsFunction(methodIndex, args, out result); // Обрабатываем результаты var response = (OneScript.HTTPService.HTTPServiceResponseImpl)result; context.Response.StatusCode = response.StatusCode; if (response.Headers != null) { foreach (var ch in response.Headers) { context.Response.AddHeader(ch.Key.AsString(), ch.Value.AsString()); } } if (response.Reason != "") { context.Response.Status = response.Reason; } if (response.BodyStream != null) { response.BodyStream.Seek(0, SeekOrigin.Begin); response.BodyStream.CopyTo(context.Response.OutputStream); } context.Response.Charset = response.ContentCharset; }
public FormTree(Control parentCntrl) { this._name = ""; this._visible = true; this._enabled = true; this._title = ""; this._parent = null; this._parentControl = parentCntrl; this._methodName = ""; this._thisScript = null; this._methodNameDblClick = ""; this._thisScriptDblClick = null; this._methodOnChoice = ""; this._scriptOnChoice = null; _dataTable = new DataTableProvider(); _item = new TreeViewColumns(); _nodesMap = new Dictionary <TreeNode, ValueTreeRow>(); //# Создаем контейнер для элемента формы _panelMainContainer = new Panel(); _panelTitleContainer = new Panel(); _panelControlContainer = new Panel(); _panelMainContainer.Controls.Add(_panelControlContainer); _panelMainContainer.Controls.Add(_panelTitleContainer); _panelMainContainer.Dock = DockStyle.Top; _panelMainContainer.MinimumSize = new Size(150, 22); _panelMainContainer.AutoSize = true; _panelMainContainer.AutoSizeMode = AutoSizeMode.GrowAndShrink; _panelTitleContainer.Dock = DockStyle.Left; _panelTitleContainer.MinimumSize = new Size(50, 21); _panelTitleContainer.AutoSize = true; _panelTitleContainer.AutoSizeMode = AutoSizeMode.GrowAndShrink; _label = new Label(); _panelTitleContainer.Controls.Add(_label); _label.AutoSize = true; _label.Dock = DockStyle.Fill; //# Установка параметров панели для поля с данными _panelControlContainer.Dock = DockStyle.Fill; _panelControlContainer.MinimumSize = new Size(100, 21); _panelControlContainer.AutoSize = true; _panelControlContainer.AutoSizeMode = AutoSizeMode.GrowAndShrink; this._parentControl.Controls.Add(_panelMainContainer); _panelMainContainer.BringToFront(); this.createFormFieldByType(); }
public void OnAttach(MachineInstance machine, out IVariable[] variables, out MethodInfo[] methods, out IRuntimeContextInstance instance) { variables = _state; methods = GetMethods().ToArray(); instance = this; }
public IValue CallCommonModuleFunction(string moduleName, string methodName, IValue[] parameters) { IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName); int methodId = commonModule.FindMethod(methodName); IValue result = ValueFactory.Create(); commonModule.CallAsFunction(methodId, parameters, out result); return(result); }
private int GetDispatchIndex(IRuntimeContextInstance obj) { if (_dispId != -1) { return(obj.FindMethod(Name)); } return(_dispId); }
public static IVariable CreateIndexedPropertyReference(IRuntimeContextInstance context, IValue index) { var newVar = new VariableReference(); newVar._refType = ReferenceType.IndexedProperty; newVar._context = context; newVar._index = index; return(newVar); }
public static IVariable CreateContextPropertyReference(IRuntimeContextInstance context, int propertyNumber) { var newVar = new VariableReference(); newVar._refType = ReferenceType.ContextProperty; newVar._context = context; newVar._contextPropertyNumber = propertyNumber; return(newVar); }
public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null) { IEnumerable <string> sourceProperties; IEnumerable <string> ignoredPropCollection; if (filledProperties == null) { string[] names = new string[source.GetPropCount()]; for (int i = 0; i < names.Length; i++) { names[i] = source.GetPropName(i); } sourceProperties = names; } else { sourceProperties = filledProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0) .ToArray(); // Проверка существования заявленных свойств foreach (var item in sourceProperties) { acceptor.FindProperty(item); } } if (ignoredProperties != null) { ignoredPropCollection = ignoredProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0); } else { ignoredPropCollection = new string[0]; } foreach (var srcProperty in sourceProperties.Where(x => !ignoredPropCollection.Contains(x))) { try { var propIdx = acceptor.FindProperty(srcProperty); var srcPropIdx = source.FindProperty(srcProperty); if (source.IsPropReadable(propIdx) && acceptor.IsPropWritable(propIdx)) { acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx)); } } catch (PropertyAccessException) { } } }
public void DisposeObject(IRuntimeContextInstance obj) { var disposable = obj as IDisposable; if (disposable != null) { disposable.Dispose(); } }
public void FillPropertyValuesStr(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null) { IEnumerable <string> sourceProperties; if (filledProperties == null) { string[] names = new string[source.GetPropCount()]; for (int i = 0; i < names.Length; i++) { names[i] = source.GetPropName(i); } if (ignoredProperties == null) { sourceProperties = names; } else { IEnumerable <string> ignoredPropCollection = ignoredProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0); sourceProperties = names.Where(x => !ignoredPropCollection.Contains(x)); } } else { sourceProperties = filledProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0); // Проверка существования заявленных свойств foreach (var item in sourceProperties) { acceptor.FindProperty(item); // бросает PropertyAccessException если свойства нет } } foreach (var srcProperty in sourceProperties) { try { var srcPropIdx = source.FindProperty(srcProperty); var accPropIdx = acceptor.FindProperty(srcProperty); // бросает PropertyAccessException если свойства нет if (source.IsPropReadable(srcPropIdx) && acceptor.IsPropWritable(accPropIdx)) { acceptor.SetPropValue(accPropIdx, source.GetPropValue(srcPropIdx)); } } catch (PropertyAccessException) { // игнорировать свойства Источника, которых нет в Приемнике } } }
public void WriteXML(XmlWriterImpl xmlWriter, IValue value, string name, XMLTypeAssignment typeAssigment = XMLTypeAssignment.Implicit, XMLForm form = XMLForm.Element) { XMLExpandedName xmlType; switch (value.DataType) { case DataType.Undefined: WriteXMLUndefined(xmlWriter, name, form); break; case DataType.String: xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "string"); WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form); break; case DataType.Number: xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "decimal"); WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form); break; case DataType.Boolean: xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "boolean"); WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form); break; case DataType.Date: xmlType = new XMLExpandedName(XmlSchema.InstanceNamespace, "dateTime"); WriteXMLSimpleData(xmlWriter, name, value, xmlType, typeAssigment, form); break; case DataType.Object: IRuntimeContextInstance valueObject = value.AsObject(); if (valueObject is IXDTOSerializableXML seriazable) { seriazable.WriteXML(xmlWriter, this); } else { throw RuntimeException.InvalidArgumentType(); } break; default: throw RuntimeException.InvalidArgumentType(); } }
public static IEnumerable <MethodInfo> GetMethods(this IRuntimeContextInstance context) { MethodInfo[] methods = new MethodInfo[context.GetMethodsCount()]; for (int i = 0; i < methods.Length; i++) { methods[i] = context.GetMethodInfo(i); } return(methods); }
public void setAction(IRuntimeContextInstance contex, string eventName, string methodName) { if (eventName == "Нажатие") { ((Button)this._item).Click -= BtnClick; ((Button)this._item).Click += BtnClick; this._thisScript = contex; this._methodName = methodName; } }
public static IValue GetPropValue(this IRuntimeContextInstance context, string propName) { int propNum = context.FindProperty(propName); if (propNum == -1) { throw RuntimeException.InvalidArgumentValue(propName); } return(context.GetPropValue(propNum)); }
public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, System.Globalization.CultureInfo culture) { IRuntimeContextInstance inst = obj as IRuntimeContextInstance; if (inst == null) { throw new ArgumentException("Wrong argument type"); } inst.SetPropValue(_dispId, COMWrapperContext.CreateIValue(value)); }
public void OnAttach(MachineInstance machine, out IVariable[] variables, out MethodInfo[] methods, out IRuntimeContextInstance instance) { variables = new IVariable[this.Count]; for (int i = 0; i < variables.Length; i++) { variables[i] = Variable.CreateContextPropertyReference(this, i); } methods = new MethodInfo[0]; instance = this; }
private static bool MethodExistsForObject(IRuntimeContextInstance target, string methodName) { try { var idx = target.FindMethod(methodName); return(idx >= 0); } catch (RuntimeException) { return(false); } }
public void HandleEvent(IRuntimeContextInstance eventSource, string eventName, IValue[] eventArgs) { if (!_registeredHandlers.TryGetValue(eventSource, out var handlers)) { return; } foreach (var handler in handlers[eventName]) { handler.Method(eventArgs); } }
public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, System.Globalization.CultureInfo culture) { IRuntimeContextInstance inst = obj as IRuntimeContextInstance; if (inst == null) { throw new ArgumentException("Wrong argument type"); } IValue retVal = inst.GetPropValue(_dispId); return(COMWrapperContext.MarshalIValue(retVal)); }
public static IVariable CreateContextPropertyReference(IRuntimeContextInstance context, int propertyNumber) { return VariableReference.CreateContextPropertyReference(context, propertyNumber); }
public static IVariable CreateIndexedPropertyReference(IRuntimeContextInstance context, IValue index) { return VariableReference.CreateIndexedPropertyReference(context, index); }
public static IValue Create(IRuntimeContextInstance instance) { return (IValue)instance; }
public void OnAttach(MachineInstance machine, out IVariable[] variables, out MethodInfo[] methods, out IRuntimeContextInstance instance) { variables = new IVariable[0]; methods = (MethodInfo[])GetMethods(); instance = this; }
public void OnAttach(MachineInstance machine, out IVariable[] variables, out MethodInfo[] methods, out IRuntimeContextInstance instance) { UpdateState(); variables = _state; methods = AttachMethods(); instance = this; _machine = machine; }
public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null) { var accReflector = acceptor as IReflectableContext; if (accReflector == null) throw RuntimeException.InvalidArgumentValue(); var srcReflector = source as IReflectableContext; if (srcReflector == null) throw RuntimeException.InvalidArgumentValue(); IEnumerable<string> sourceProperties; IEnumerable<string> ignoredPropCollection; if(filledProperties == null) { sourceProperties = srcReflector.GetProperties().Select(x => x.Identifier); } else { sourceProperties = filledProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0) .ToArray(); // Проверка существования заявленных свойств foreach (var item in sourceProperties) { acceptor.FindProperty(item); } } if(ignoredProperties != null) { ignoredPropCollection = ignoredProperties.Split(',') .Select(x => x.Trim()) .Where(x => x.Length > 0); } else { ignoredPropCollection = new string[0]; } foreach (var srcProperty in sourceProperties.Where(x=>!ignoredPropCollection.Contains(x))) { try { var propIdx = acceptor.FindProperty(srcProperty); var srcPropIdx = source.FindProperty(srcProperty); acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx)); } catch(PropertyAccessException) { } } }
public static IVariable CreateContextPropertyReference(IRuntimeContextInstance context, int propertyNumber) { var newVar = new VariableReference(); newVar._refType = ReferenceType.ContextProperty; newVar._context = context; newVar._contextPropertyNumber = propertyNumber; return newVar; }
public static IVariable CreateIndexedPropertyReference(IRuntimeContextInstance context, IValue index) { var newVar = new VariableReference(); newVar._refType = ReferenceType.IndexedProperty; newVar._context = context; newVar._index = index; return newVar; }