private FlutnetMessage GetFromBuffer(int requestId) { lock (_responseBufferLock) { FlutnetMessage response = _responseBufferQueue.FirstOrDefault(r => r.MethodInfo.RequestId == requestId); return(response); } }
/// <summary> /// Converts a .NET object to a valid <see cref="NSObject"/> /// that can be sent to Flutter as a successful result of /// a <see cref="Flutnet.Interop.FlutterMethodChannel"/> method invoke. /// </summary> public static NSObject ToMethodChannelResult(FlutnetMessage message) { // FIX ISSUES ABOUT DICTIONARY JObject jsonObject = JObject.FromObject(message, Serializer); CleanObjectFromInvalidTypes(ref jsonObject); return(NSObject.FromObject(jsonObject.ToString(Formatting.None))); }
/// <summary> /// Converts a .NET object to a valid <see cref="Java.Lang.Object"/> /// that can be sent to Flutter as a successful result of /// a <see cref="Flutnet.Interop.Plugin.Common.MethodChannel"/> method invoke. /// </summary> public static Java.Lang.Object ToMethodChannelResult(FlutnetMessage message) { // FIX ISSUES ABOUT DICTIONARY IN FLUTTER JObject jsonObject = JObject.FromObject(message, Serializer); CleanObjectFromInvalidTypes(ref jsonObject); Java.Lang.Object obj = jsonObject.ToString(Formatting.None); return(obj); }
private void SendError(FlutnetMethodInfo methodInfo, PlatformOperationException exception) { FlutnetMessage message = new FlutnetMessage { MethodInfo = methodInfo, // NOTE: Please consider remove ErrorCode and ErrorMessage ErrorCode = FlutnetErrorCode.OperationFailed, ErrorMessage = exception.Message, Exception = exception }; Send(message); }
private void SendResult(FlutnetMethodInfo methodInfo, object result) { Dictionary <string, object> resultValue = new Dictionary <string, object>(); resultValue.Add("ReturnValue", result); FlutnetMessage message = new FlutnetMessage { MethodInfo = methodInfo, Result = resultValue }; Send(message); }
private void AddToBuffer(FlutnetMessage message) { lock (_responseBufferLock) { FlutnetMessage found = _responseBufferQueue.FirstOrDefault(r => r.MethodInfo.RequestId == message.MethodInfo.RequestId); if (found == null) { _responseBufferQueue.Enqueue(message); if (_responseBufferQueue.Count > 20) { _responseBufferQueue.Dequeue(); } } } }
private void SendError(FlutnetMethodInfo methodInfo, PlatformOperationException exception) { FlutnetMessage message = new FlutnetMessage { MethodInfo = methodInfo, // NOTE: Please consider removing ErrorCode and ErrorMessage ErrorCode = FlutnetErrorCode.OperationFailed, ErrorMessage = exception.Message, Exception = exception }; NSObject dartReturnValue = FlutterInterop.ToMethodChannelResult(message); Console.WriteLine("Sending error to Flutter..."); MainThread.BeginInvokeOnMainThread(() => _methodChannelIncoming.InvokeMethod("error", dartReturnValue)); }
private void SendResult(FlutnetMethodInfo methodInfo, object result) { Dictionary <string, object> resultValue = new Dictionary <string, object>(); resultValue.Add("ReturnValue", result); FlutnetMessage message = new FlutnetMessage { MethodInfo = methodInfo, Result = resultValue }; NSObject dartReturnValue = FlutterInterop.ToMethodChannelResult(message); Console.WriteLine("Sending result to Flutter..."); MainThread.BeginInvokeOnMainThread(() => _methodChannelIncoming.InvokeMethod("result", dartReturnValue)); }
private void Send(FlutnetMessage message) { try { // OLD VERSION //string json = JsonConvert.SerializeObject(message, FlutterInterop.JsonSerializerSettings); // NEW - FIX ISSUES ABOUT DICTIONARY IN FLUTTER JObject jsonObject = JObject.FromObject(message, FlutterInterop.Serializer); FlutterInterop.CleanObjectFromInvalidTypes(ref jsonObject); string json = jsonObject.ToString(Formatting.None); Send(json); } catch (Exception) { AddToBuffer(message); } }
private void FlutnetRuntimeOnPlatformEvent(object sender, OnPlatformEventArgs e) { FlutnetEventInfo eventInfo = new FlutnetEventInfo { InstanceId = e.ServiceName, EventName = e.EventName.FirstCharLower(), EventData = e.EventData }; FlutnetMessage message = new FlutnetMessage() { MethodInfo = new FlutnetMethodInfo { RequestId = -1, Instance = e.ServiceName }, Result = null, EventInfo = eventInfo }; Send(message); }