/// <summary> /// Is a slot name valid. /// </summary> /// <param name="slotName">the name of the slot</param> /// <returns>whether a slot name is present in the object</returns> public bool HasSlot(string slotName) { using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(slotName))) { return(this.GetFunction <R_has_slot>()(this.DangerousGetHandle(), s)); } }
/// <summary> /// 以异步方式执行给定请求的绑定。 /// </summary> /// <param name="metadataProvider">要用于验证的元数据提供程序。</param> /// <param name="actionContext">绑定的操作上下文。操作上下文包含将使用参数填充的参数字典。</param> /// <param name="cancellationToken">用于取消绑定操作的取消标记。</param> /// <returns>一个表示异步操作的任务对象。</returns> public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) { string content = actionContext.Request.Content.ReadAsStringAsync().Result; try { var value = GetFunction()(content); SetValue(actionContext, value); } catch (Exception ex) { var e = ex; while (e.InnerException != null) { e = e.InnerException; } _errorMessage = e.Message; } var tcs = new TaskCompletionSource <AsyncVoid>(); tcs.SetResult(default(AsyncVoid)); return(tcs.Task); }
/// <summary> /// Sets the command line arguments. /// </summary> /// <param name="args">The arguments.</param> public void SetCommandLineArguments(string[] args) { CheckEngineIsRunning(); var newArgs = ArrayConverter.Prepend(ID, args); GetFunction <R_set_command_line_arguments>()(newArgs.Length, newArgs); }
/// <summary> Gets alternate rep array.</summary> /// /// <exception cref="NotSupportedException"> Thrown when the requested operation is not supported.</exception> /// /// <returns> An array of t.</returns> public override double[] GetAltRepArray() { // by inference from `static SEXP compact_intseq_Duplicate(SEXP x, Rboolean deep)` in altrep.c var res = new double[this.Length]; GetFunction <REAL_GET_REGION>()(this.DangerousGetHandle(), (IntPtr)0, (IntPtr)this.Length, res); return(res); }
/// <summary> Gets alternate rep array.</summary> /// /// <exception cref="NotSupportedException"> Thrown when the requested operation is not supported.</exception> /// /// <returns> An array of t.</returns> public override int[] GetAltRepArray() { // by inference from `static SEXP compact_intseq_Duplicate(SEXP x, Rboolean deep)` in altrep.c var res = new int[this.Length]; GetFunction <INTEGER_GET_REGION>()(this.DangerousGetHandle(), (ulong)0, (ulong)this.Length, res); return(res); }
public int StartupApp() { var startup = AppInfo.Events.FirstOrDefault(v => v.Type == AppEventType.Startup); if (startup == default) { return(0); } return(GetFunction <Events.StartupFunc>(startup.Function)()); }
// ---- 初始化 ---- public int InitializeApp(int authCode) { var code = GetFunction <Events.InitializeFunc>("Initialize")(authCode); if (code == 0) { Initialized = true; } AuthCode = authCode; return(code); }
private SymbolicExpression Parse(string statement, StringBuilder incompleteStatement, REnvironment environment = null) { incompleteStatement.Append(statement); var s = GetFunction <Rf_mkString>()(InternalString.NativeUtf8FromString(incompleteStatement.ToString())); string errorStatement; using (new ProtectedPointer(this, s)) { ParseStatus status; var vector = new ExpressionVector(this, GetFunction <R_ParseVector>()(s, -1, out status, NilValue.DangerousGetHandle())); switch (status) { case ParseStatus.OK: incompleteStatement.Clear(); if (vector.Length == 0) { return(null); } using (new ProtectedPointer(vector)) { SymbolicExpression result; if (!vector.First().TryEvaluate((environment == null) ? GlobalEnvironment : environment, out result)) { throw new EvaluationException(LastErrorMessage); } if (AutoPrint && !result.IsInvalid && GetVisible()) { GetFunction <Rf_PrintValue>()(result.DangerousGetHandle()); } return(result); } case ParseStatus.Incomplete: return(null); case ParseStatus.Error: // TODO: use LastErrorMessage if below is just a subset var parseErrorMsg = this.GetAnsiString("R_ParseErrorMsg"); errorStatement = incompleteStatement.ToString(); incompleteStatement.Clear(); throw new ParseException(status, errorStatement, parseErrorMsg); default: errorStatement = incompleteStatement.ToString(); incompleteStatement.Clear(); throw new ParseException(status, errorStatement, ""); } } }
private string ReadString(IntPtr pointer, int offset) { pointer = Marshal.ReadIntPtr(pointer, offset); if (Engine.Compatibility == REngine.CompatibilityMode.ALTREP) { pointer = GetFunction <DATAPTR_OR_NULL>()(pointer); } else { pointer = IntPtr.Add(pointer, Marshal.SizeOf(Engine.GetVectorSexprecType())); } return(InternalString.StringFromNativeUtf8(pointer)); }
/// <summary> /// Gets a point on this segment defined by relative position. /// This method doesn't checks, if relative position is in range (0, 1). /// </summary> /// <param name="start">The start point of the segment.</param> /// <param name="relPosition">The relative position on the segment.</param> /// <returns>A point on the segment.</returns> public override Point GetPointOnSegment(ref Point start, double relPosition) { Refresh(ref start); if (a == 0) { Vector v = Point.Subtract(EndPoint, start); return(Point.Add(start, v * relPosition)); } double resX = GetPositionX(ref start, relPosition); double resY = GetFunction(ref start)(resX); return(new Point(resX, resY)); }
public ExternalProperty(PropertyInfo externalProperty) { MethodInfo getMethod = externalProperty.GetGetMethod(); GetFunction getter = (GetFunction)Delegate.CreateDelegate(typeof(GetFunction), getMethod); MethodInfo setMethod = externalProperty.GetSetMethod(); SetFunction setter = (SetFunction)Delegate.CreateDelegate(typeof(SetFunction), setMethod); }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <remarks>Used for R 3.5 and higher, to account for ALTREP objects</remarks> /// <param name="index">The zero-based index of the element to get.</param> /// <returns>The element at the specified index.</returns> protected override string GetValueAltRep(int index) { // To work with ALTREP (introduced in R 3.5.0) and non-ALTREP objects, we will get strings // via STRING_ELT, instead of offseting the DataPointer. This lets R manage the details of // ALTREP conversion for us. IntPtr objPointer = GetFunction <STRING_ELT>()(this.DangerousGetHandle(), (IntPtr)index); if (objPointer == Engine.NaStringPointer) { return(null); } IntPtr stringData = GetFunction <DATAPTR_OR_NULL>()(objPointer); return(InternalString.StringFromNativeUtf8(stringData)); }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <remarks>Used for R 3.5 and higher, to account for ALTREP objects</remarks> /// <param name="index">The zero-based index of the element to get.</param> /// <returns>The element at the specified index.</returns> protected override string GetValueAltRep(int index) { // To work with ALTREP (introduced in R 3.5.0) and non-ALTREP objects, we will get strings // via STRING_ELT, instead of offseting the DataPointer. This lets R manage the details of // ALTREP conversion for us. IntPtr objPointer = GetFunction <STRING_ELT>()(this.DangerousGetHandle(), (ulong)index); if (objPointer == Engine.NaStringPointer) { return(null); } IntPtr stringData = IntPtr.Add(objPointer, Marshal.SizeOf(typeof(Internals.ALTREP.VECTOR_SEXPREC))); return(InternalString.StringFromNativeUtf8(stringData)); }
public int EnableApp() { var enable = AppInfo.Events.FirstOrDefault(v => v.Type == AppEventType.AppEnable); if (enable == default) { throw new MissingMethodException("启用函数不存在."); } var code = GetFunction <Events.AppEnableEvent>(enable.Function)(); if (code == 0) { Enabled = true; } return(code); }
public void InvokeMenu(string name) { try { var menu = AppInfo.Menus.FirstOrDefault(v => v.Name == name); if (menu == default) { return; } GetFunction <Events.MenuFunc>(menu.Function)(); } catch (Exception ex) { Console.WriteLine(ex); } }
public ExternalPropertyHelper(PropertyInfo externalProperty) { MethodInfo getMethod = externalProperty.GetGetMethod(); GetFunction getter = (GetFunction)Delegate.CreateDelegate(typeof(GetFunction), getMethod); GetValue = getter; }
public static TValue Return <TValue>(ParquetHandle handle, GetFunction <TValue> getter) { var value = Return(handle.IntPtr, getter); GC.KeepAlive(handle); return(value); }
public Task <ulong> GetQueryAsync(BigInteger code, BlockParameter blockParameter = null) { var getFunction = new GetFunction(); getFunction.Code = code; return(ContractHandler.QueryAsync <GetFunction, ulong>(getFunction, blockParameter)); }
public static void Iterate <T>(GetFunction <T> next, Action <T, uint> fnc) { uint i = 0; for (next(out var val); val != null; next(out val)) { fnc(val, i++); } }
public static string ReturnString(ParquetHandle handle, GetFunction <IntPtr> getter, Action <IntPtr> deleter = null) { Check(getter(handle.IntPtr, out var value)); var str = Marshal.PtrToStringAnsi(value); deleter?.Invoke(value); GC.KeepAlive(handle); return(str); }
public void CheckForTables(int tablesCount, GetFunction function, string msg) { if (tablesCount == 0) { Console.WriteLine("No table has been created."); } else { function(Util.Console.GetInfo(msg)); } }
public static List <T> ToList <T>(GetFunction <T> next) { var res = new List <T>(); for (next(out var val); val != null; next(out val)) { res.Add(val); } return(res); }
public static List <Tuple <Ts, Tv> > GetFlagsValues <Ts, Tv>(GetFunction <Ts> fcn, IReadOnlyDictionary <Tv, Ts> map) where Ts : Enum { fcn(out Ts supportedValues); List <Ts> components = supportedValues.FindFlagComponents(); if (components.Count == 0) { throw new Exception("No Flag Values"); } return(components.Select(v => Tuple.Create(v, map.FindByValue(v))).ToList()); }
public static List <Tv> IterateList <T, Tv>(GetFunction <T> next, Func <T, uint, Tv> fnc) { var res = new List <Tv>(); uint i = 0; for (next(out var val); val != null; next(out val)) { res.Add(fnc(val, i++)); } return(res); }
/// <summary> /// Gets/sets the value of a slot /// </summary> /// <param name="name"></param> /// <returns></returns> public SymbolicExpression this[string name] { get { checkSlotName(name); IntPtr slotValue; using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(name))) { slotValue = this.GetFunction <R_do_slot>()(this.DangerousGetHandle(), s); } return(new SymbolicExpression(Engine, slotValue)); } set { checkSlotName(name); using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(name))) { using (new ProtectedPointer(this)) { this.GetFunction <R_do_slot_assign>()(this.DangerousGetHandle(), s, value.DangerousGetHandle()); } } } }
/// <summary> /// Dispose of this REngine, including using the native R API to clean up, if the parameter is true /// </summary> /// <param name="disposing">if true, release native resources, using the native R API to clean up.</param> protected override void Dispose(bool disposing) { this.isRunning = false; OnDisposing(EventArgs.Empty); if (disposing && !Disposed) { GetFunction <R_RunExitFinalizers>()(); GetFunction <Rf_CleanEd>()(); GetFunction <R_CleanTempDir>()(); Disposed = true; } if (disposing && this.adapter != null) { this.adapter.Dispose(); this.adapter = null; } if (Disposed) { return; } GC.KeepAlive(this.parameter); base.Dispose(disposing); }
/// <summary> /// Sets the element at the specified index. /// </summary> /// <remarks>Used for R 3.5 and higher, to account for ALTREP objects</remarks> /// <param name="index">The zero-based index of the element to set.</param> /// <param name="value">The value to set</param> protected override void SetValueAltRep(int index, Complex value) { GetFunction <SET_COMPLEX_ELT>()(this.DangerousGetHandle(), (IntPtr)index, RTypesUtil.SerializeComplexToRComplex(value)); }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <remarks>Used for R 3.5 and higher, to account for ALTREP objects</remarks> /// <param name="index">The zero-based index of the element to get.</param> /// <returns>The element at the specified index.</returns> protected override Complex GetValueAltRep(int index) { var data = GetFunction <COMPLEX_ELT>()(this.DangerousGetHandle(), (IntPtr)index); return(new Complex(data.r, data.i)); }
public static float CallFunction(Functions function, float value) { return(GetFunction(function)(value)); }
public static string ReturnString(ParquetHandle handle, GetFunction <IntPtr> getter, Action <IntPtr>?deleter = null) { Check(getter(handle.IntPtr, out var value)); return(ConvertPtrToString(handle, deleter, value)); }