private async void Client_MessageEdit(object sender, MessageResult e) { if (this.GetSetting(eSettings.SkipAllMessages, false)) { return; } try { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); e.Device = ds; if (this.GetSetting(eSettings.LogAllMessages, false)) { OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); } //Call same, to handle received liked edited ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); await Client_TryMessageEdit(sender, e); } catch (Telegram.Bot.Exceptions.ApiRequestException ex) { } catch (Exception ex) { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); } }
public ChannelConfiguration(DeviceType deviceType, DeviceSession session) { if (deviceType == DeviceType.PowerMeter) { ChannelId = session.PowerMeterChannelId; DeviceId = session.PowerMeterId; // ANT+ Bike Power Device Type spec DeviceTypeId = 0x0B; ChannelPeriod = 8182; ChannelType = 0x10; // bidirectional master ChannelDescription = "bi-directional master"; } else if (deviceType == DeviceType.FeC) { ChannelId = session.FecChannelId; DeviceId = session.FecId; // ANT+ FE-C Device Type spec DeviceTypeId = 0x11; ChannelPeriod = 8192; ChannelType = 0x00; // slave ChannelDescription = "slave"; } }
public static Generator Create(DeviceSession session, ExecutionOptions options) { Generator generator = null; if (options.Operation == OperationType.Ants) { generator = new AutoAntsScriptGenerator(session, options.Device); } else if (options.Operation == OperationType.Json) { generator = new JsonGenerator(session); } else if (options.Operation == OperationType.Hz) { generator = new WaveGenerator(session); } else if (options.Operation == OperationType.CArray) { generator = new CArrayGenerator(session, options.Device); } else if (options.Operation == OperationType.HumanReadable) { generator = new HumanReadableGenerator(session, options); } return(generator); }
private async void Client_Message(object sender, MessageResult e) { if (this.SkipAllMessages) { return; } try { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); e.Device = ds; if (LogAllMessages) { OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); } ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message)); await Client_TryMessage(sender, e); } catch (Telegram.Bot.Exceptions.ApiRequestException ex) { } catch (Exception ex) { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); } }
public SystemExceptionEventArgs(String Command, long DeviceId, DeviceSession Device, Exception error) { this.Command = Command; this.DeviceId = DeviceId; this.Device = Device; this.Error = error; }
private void PomaMobile_Load(object sender, EventArgs e) { //Internet.Init(); session = new DeviceSession(); //txtURL.Text = Operation<object>.SERVICE_URL = "http://localhost:8080/api/mobile"; gps = new Gps(); gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged); gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged); UpdateGpsDataHandler = new EventHandler(UpdateGpsData); }
public PomaTest() { InitializeComponent(); long id = 0L; try { id = long.Parse(txtUsername.Text); } catch { }; session = new DeviceSession(); txtServiceURL.Text = Operation <object> .SERVICE_URL; txtServiceURL.Text = "http://localhost:8080/api/mobile"; geocodeQueue = new Queue <Geocode>(); }
/////////////////////////////////////////////////////////////////////////////// // Public Methods... /////////////////////////////////////////////////////////////////////////////// #region Public Methods... /// <summary> /// Handle TWAIN Cloud... /// </summary> /// <param name="a_devicesessionCloud"></param> public HttpListenerResponseBase(DeviceSession a_devicesessionCloud) { // This is how we know we're a TWAIN Cloud response... m_devicesessionCloud = a_devicesessionCloud; m_httplistenerresponseLocal = null; // Init all the other stuff... m_webheadercollection = new WebHeaderCollection(); m_szStastusDescription = null; m_iStatusCode = 200; m_streamOutput = new ReactiveMemoryStream(); m_lContentLength64 = 0; m_webheadercollection.Add(HttpResponseHeader.ContentType, "application/json; charset=UTF-8"); }
/// <summary> /// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised. /// </summary> /// <param name="DeviceId">Contains the device/chat id of the device to update.</param> /// <param name="e"></param> public async Task InvokeMessageLoop(long DeviceId, MessageResult e) { try { DeviceSession ds = this.Sessions.GetSession(DeviceId); e.Device = ds; await Client_Loop(this, e); } catch (Exception ex) { DeviceSession ds = this.Sessions.GetSession(DeviceId); OnException(new SystemExceptionEventArgs(e.Message.Text, DeviceId, ds, ex)); } }
/// <summary> /// Start polling for tasks... /// </summary> /// <returns>true on success</returns> public async Task <bool> MonitorTasksStart() { DeviceSession devicesession = null; string szCloudApiRoot = ""; string szCloudScannerId = ""; var cloudScanner = GetCurrentCloudScanner(); // If cloud fails, we should keep going so that the // user can still run TWAIN Local... if (cloudScanner != null) { try { szCloudApiRoot = CloudManager.GetCloudApiRoot(); var twaincloudtokens = new TwainCloudTokens(cloudScanner.AuthorizationToken, cloudScanner.RefreshToken); var twaincloudclient = new TwainCloudClient(szCloudApiRoot, twaincloudtokens); twaincloudclient.TokensRefreshed += (sender, args) => { cloudScanner.AuthorizationToken = args.Tokens.AuthorizationToken; cloudScanner.RefreshToken = args.Tokens.RefreshToken; SaveScannerRegistration(cloudScanner); }; devicesession = new DeviceSession(twaincloudclient, cloudScanner.Id); szCloudScannerId = cloudScanner.Id; } catch (Exception exception) { Log.Error("MonitorTasksStart: failed to initialize cloud, has it been registered? - " + exception.Message); devicesession = null; } } // Start monitoring for commands... var blSuccess = await m_twainlocalscannerdevice.DeviceHttpServerStart(devicesession, szCloudApiRoot, szCloudScannerId); if (!blSuccess) { Log.Error("MonitorTasksStart: DeviceHttpServerStart failed..."); return(false); } // All done... return(true); }
private void Client_Action(object sender, MessageResult e) { try { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); e.Device = ds; if (this.GetSetting(eSettings.LogAllMessages, false)) { OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e)); } Client_TryAction(sender, e); } catch (Exception ex) { DeviceSession ds = this.Sessions.GetSession(e.DeviceId); OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex)); } }
public async Task CloseModal(ModalDialog modalForm, FormBase oldForm) { DeviceSession ds = this.Device; if (ds == null) { return; } if (modalForm == null) { throw new Exception("No modal form"); } ds.FormSwitched = true; ds.PreviousForm = ds.ActiveForm; ds.ActiveForm = oldForm; }
public static void Create(DEVICE_INFO_TYPE deviceinfo, MFP_WEBSERVICE_TYPE[] mfpwebservices, ACL_DOC_TYPE xmldocacl, CREDENTIALS_TYPE Credentials, LIMITS_TYPE[] xmldoclimits) { DeviceSession s = new DeviceSession(); s.deviceinfo = deviceinfo; s.mfpwebservices = mfpwebservices; s.xmldocacl = xmldocacl; s.Credentials = Credentials; s.xmldoclimits = xmldoclimits; location = deviceinfo.location; serialNumber = deviceinfo.serialnumber;; modelName = deviceinfo.modelname; ipAddress = deviceinfo.network_address; deviceId = deviceinfo.uuid; localIP = Gethostip(); url = "http://" + localIP + "/PrintReleaseMfp/Default.aspx"; sessionData[deviceinfo.uuid] = s; }
/// <summary> /// Opens this form modal, but don't closes the original ones /// </summary> /// <param name="newForm"></param> /// <returns></returns> public virtual async Task OpenModal(ModalDialog newForm, params object[] args) { DeviceSession ds = this.Device; if (ds == null) { return; } var parentForm = this; ds.FormSwitched = true; ds.PreviousForm = ds.ActiveForm; ds.ActiveForm = newForm; newForm.Client = parentForm.Client; newForm.Device = ds; newForm.ParentForm = parentForm; newForm.Closed += async(s, en) => { await CloseModal(newForm, parentForm); }; foreach (var b in this.Controls) { if (!b.Enabled) { continue; } await b.Hidden(false); } await newForm.OnInit(new InitEventArgs(args)); await newForm.OnOpened(new EventArgs()); }
private async Task Client_TryMessageEdit(object sender, MessageResult e) { DeviceSession ds = e.Device; if (ds == null) { ds = await this.Sessions.StartSession <T>(e.DeviceId); e.Device = ds; } ds.LastAction = DateTime.Now; ds.LastMessage = e.Message; //Pre Loading Event await ds.ActiveForm.Edited(e); //When form has been switched due navigation within the edit method, reopen Client_Message if (ds.FormSwitched) { await Client_TryMessage(sender, e); } }
/// <summary> /// Navigates to a new form /// </summary> /// <param name="newForm"></param> /// <returns></returns> public virtual async Task NavigateTo(FormBase newForm, params object[] args) { DeviceSession ds = this.Device; if (ds == null) { return; } ds.FormSwitched = true; ds.PreviousForm = ds.ActiveForm; ds.ActiveForm = newForm; newForm.Client = this.Client; newForm.Device = ds; //Notify prior to close foreach (var b in this.Controls) { if (!b.Enabled) { continue; } await b.Hidden(true); } this.CloseControls().Wait(); await this.OnClosed(new EventArgs()); await newForm.OnInit(new InitEventArgs(args)); await newForm.OnOpened(new EventArgs()); }
private async void connectButton_Click_1(object sender, EventArgs e) { var scanner = registeredDevicesComboBox.SelectedItem as CloudScanner; var tokens = new TwainCloudTokens(scanner.AuthorizationToken, scanner.RefreshToken); var client = new TwainCloudClient(Constants.ApiRoot, tokens); client.TokensRefreshed += (o, args) => { scanner.AuthorizationToken = args.Tokens.AuthorizationToken; scanner.RefreshToken = args.Tokens.RefreshToken; SaveScannerRegistration(scanner); }; var deviceSession = new DeviceSession(client, scanner.Id); deviceSession.Received += async(o, message) => { Debug.WriteLine("cloud message received: " + message); await deviceSession.Send("message received"); }; await deviceSession.Connect(scanner.Id); }
/// <summary> /// Loads the previously saved states from the machine. /// </summary> public async void LoadSessionStates(IStateMachine statemachine) { if (statemachine == null) { throw new ArgumentNullException("StateMachine", "No StateMachine defined. Please set one to property BotBase.StateMachine"); } var container = statemachine.LoadFormStates(); foreach (var s in container.States) { Type t = Type.GetType(s.QualifiedName); if (t == null || !t.IsSubclassOf(typeof(FormBase))) { continue; } var form = t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; //No default constructor, fallback if (form == null) { if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase))) { continue; } form = statemachine.FallbackStateForm.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; //Fallback failed, due missing default constructor if (form == null) { continue; } } if (s.Values != null && s.Values.Count > 0) { var properties = s.Values.Where(a => a.Key.StartsWith("$")); var fields = form.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic).Where(a => a.GetCustomAttributes(typeof(SaveState), true).Length != 0).ToList(); foreach (var p in properties) { var f = fields.FirstOrDefault(a => a.Name == p.Key.Substring(1)); if (f == null) { continue; } try { if (f.PropertyType.IsEnum) { var ent = Enum.Parse(f.PropertyType, p.Value.ToString()); f.SetValue(form, ent); continue; } f.SetValue(form, p.Value); } catch (ArgumentException ex) { } catch { } } } //Is Subclass of IStateForm var iform = form as IStateForm; if (iform != null) { var ls = new LoadStateEventArgs(); ls.Values = s.Values; iform.LoadState(ls); } form.Client = Client; var device = new DeviceSession(s.DeviceId, form); device.ChatTitle = s.ChatTitle; this.SessionList.Add(s.DeviceId, device); try { await form.OnInit(new InitEventArgs()); await form.OnOpened(new EventArgs()); } catch { //Skip on exception this.SessionList.Remove(s.DeviceId); } } }
public MessageIncomeEventArgs(long DeviceId, DeviceSession Device, MessageResult message) { this.DeviceId = DeviceId; this.Device = Device; this.Message = message; }
public SessionBeginEventArgs(long DeviceId, DeviceSession Device) { this.DeviceId = DeviceId; this.Device = Device; }
static IntPtr n_GetWriteHandler(IntPtr jnienv, IntPtr native__this) { DeviceSession __this = Java.Lang.Object.GetObject <DeviceSession> (native__this, JniHandleOwnership.DoNotTransfer); return(JNIEnv.ToLocalJniHandle(__this.WriteHandler)); }
/// <summary> /// Get device session from Device/ChatId /// </summary> /// <param name="deviceId"></param> /// <returns></returns> public DeviceSession GetSession(long deviceId) { DeviceSession ds = this.SessionList.FirstOrDefault(a => a.Key == deviceId).Value ?? null; return(ds); }
static void n_Start(IntPtr jnienv, IntPtr native__this) { DeviceSession __this = Java.Lang.Object.GetObject <DeviceSession> (native__this, JniHandleOwnership.DoNotTransfer); __this.Start(); }
public void Setup() { session = TestSetup.GetSessions()[3]; }
private async void Client_TryAction(object sender, MessageResult e) { DeviceSession ds = e.Device; if (ds == null) { ds = await this.Sessions.StartSession <T>(e.DeviceId); e.Device = ds; } ds.LastAction = DateTime.Now; ds.LastMessage = e.Message; FormBase activeForm = null; int i = 0; //Should formulars get navigated (allow maximum of 10, to dont get loops) do { i++; //Reset navigation ds.FormSwitched = false; activeForm = ds.ActiveForm; //Pre Loading Event await activeForm.PreLoad(e); //Send Load event to controls await activeForm.LoadControls(e); //Loading Event await activeForm.Load(e); //Action Event if (!ds.FormSwitched) { //Send Action event to controls await activeForm.ActionControls(e); //Send Action event to form itself await activeForm.Action(e); if (!e.Handled) { var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); OnUnhandledCall(uhc); if (uhc.Handled) { e.Handled = true; if (!ds.FormSwitched) { break; } } } } //Render Event if (!ds.FormSwitched) { await activeForm.RenderControls(e); await activeForm.Render(e); } e.IsFirstHandler = false; } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); }
static long n_GetActiveTimeStamp(IntPtr jnienv, IntPtr native__this) { DeviceSession __this = Java.Lang.Object.GetObject <DeviceSession> (native__this, JniHandleOwnership.DoNotTransfer); return(__this.ActiveTimeStamp); }
public BotCommandEventArgs(String Command, List <String> Parameters, Message Message, long DeviceId, DeviceSession Device) { this.Command = Command; this.Parameters = Parameters; this.OriginalMessage = Message; this.DeviceId = DeviceId; this.Device = Device; }
public UnhandledCallEventArgs(String Command, String RawData, long DeviceId, int MessageId, Message message, DeviceSession Device) : this() { this.Command = Command; this.RawData = RawData; this.DeviceId = DeviceId; this.MessageId = MessageId; this.Message = message; this.Device = Device; }
private async Task Client_TryMessage(object sender, MessageResult e) { DeviceSession ds = e.Device; if (ds == null) { ds = await this.Sessions.StartSession <T>(e.DeviceId); e.Device = ds; ds.LastMessage = e.Message; OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); } ds.LastAction = DateTime.Now; ds.LastMessage = e.Message; //Is this a bot command ? if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0) { var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds); await OnBotCommand(sce); if (sce.Handled) { return; } } FormBase activeForm = null; int i = 0; //Should formulars get navigated (allow maximum of 10, to dont get loops) do { i++; //Reset navigation ds.FormSwitched = false; activeForm = ds.ActiveForm; //Pre Loading Event await activeForm.PreLoad(e); //Send Load event to controls await activeForm.LoadControls(e); //Loading Event await activeForm.Load(e); //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document) if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Photo | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Audio) { await activeForm.SentData(new DataResult(e)); } //Render Event if (!ds.FormSwitched) { await activeForm.RenderControls(e); await activeForm.Render(e); } e.IsFirstHandler = false; } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10)); }