Example #1
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     CurrentDevice?.Dispose();
     CurrentDevice = null;
     MessAgeLog(MsgType.NotifyTxt, "主动断开连接");
 }
Example #2
0
        public void StartCapturing()
        {
            using (PacketCommunicator communicator = CurrentDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
            {
                Packet packet;
                do
                {
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:
                        // Timeout elapsed
                        continue;

                    case PacketCommunicatorReceiveResult.Ok:
                        PacketBuffer.Enqueue(packet);
                        break;

                    default:
                        throw new InvalidOperationException("The result " + result + " shoudl never be reached here");
                    }

                    if (PacketBuffer.Count == 1000)
                    {
                        if (queueIsFull != null)
                        {
                            queueIsFull();
                        }
                    }
                } while (true);
            }
        }
Example #3
0
        /// <summary>
        /// 按GUID 查找主服务
        /// </summary>
        /// <param name="characteristic">GUID 字符串</param>
        /// <returns></returns>
        public async Task SelectDeviceService()
        {
            Guid guid = new Guid(ServiceGuid);

            CurrentDevice.GetGattServicesForUuidAsync(guid).Completed = (asyncInfo, asyncStatus) =>
            {
                if (asyncStatus == AsyncStatus.Completed)
                {
                    try
                    {
                        GattDeviceServicesResult result = asyncInfo.GetResults();

                        if (result.Services.Count > 0)
                        {
                            CurrentService = result.Services[CHARACTERISTIC_INDEX];
                            if (CurrentService != null)
                            {
                                asyncLock = true;
                                GetCurrentWriteCharacteristic();
                                GetCurrentNotifyCharacteristic();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log4netHelper.Error(ex);
                    }
                }
            };
        }
Example #4
0
        /// <summary>
        /// Initialize application global variables
        /// </summary>
        public static void Init(ISettingRepository setttingRepository)
        {
            CurrentFolders folder = new CurrentFolders(setttingRepository);

            Folders = folder;
            Folders.Init();

            CurrentDevice device = new CurrentDevice(setttingRepository, Folders.DevicesGuid);

            Device = device;
            Device.Init();

            CurrentUser userSystem = new CurrentUser(setttingRepository, Folders.UsersGuid);

            UserSystem = userSystem;
            UserSystem.Init();

            CurrentUser user = new CurrentUser(setttingRepository, Folders.UsersGuid);

            User = user;
            User.Init();

            SettingLog log = new SettingLog(setttingRepository);

            Log = log;
            Log.Init();
        }
        private async void FetchDevicesList()
        {
            var devices = (await CloudClipboardService.GetDevices(accountId))?.OrderBy(x => x.Name ?? "");

            if (devices == null)
            {
                return;
            }

            foreach (var item in devices)
            {
                if ((item.Name ?? "").ToLower() == CurrentDevice.GetDeviceName().ToLower())
                {
                    currentDeviceId = item.DeviceID;

                    //Don't set the property directly, so we don't send a request with the same value.
                    receiveCloudClipboardOnThisDeviceChecked = item.CloudClipboardEnabled;
                    OnPropertyChanged("ReceiveCloudClipboardOnThisDeviceChecked");

                    ReceiveCloudClipboardOnThisDeviceEnabled = true;
                    continue;
                }

                Devices.Add(new DeviceItem(item.CloudClipboardEnabled)
                {
                    AccountID = item.AccountID,
                    DeviceID  = item.DeviceID,
                    Name      = item.Name,
                    Type      = (item.FormFactor == null) ? DeviceType.Unknown :
                                (item.FormFactor.ToLower() == "phone") ? DeviceType.Phone : DeviceType.PC,
                });
            }
        }
Example #6
0
        public void Update()
        {
            if (CurrentDevice != null)
            {
                CurrentDevice.Update(this);
                if (!CurrentDevice.IsConnected)
                {
                    SendTargetData(new TargetData(0, 0, 0, 0));

                    if (drone.Data.State.AreMotorsRunning())
                    {
                        Log.Warning("Stopping because input device is disconnceted");
                        StopDrone();
                    }
                }

                // schauen ob sich Informationen vom Gerät geändert haben
                bool dirty = CurrentDevice.IsConnected != lastConnected || !CurrentDevice.Battery.Equals(lastBattery);
                if (dirty)
                {
                    OnDeviceInfoChanged?.Invoke(this, EventArgs.Empty);

                    lastConnected = CurrentDevice.IsConnected;
                    lastBattery   = CurrentDevice.Battery;
                }
            }
        }
        public async Task <LoginResponse> Login(Uri loginUri, string username, string password, Guid operatorId,
                                                CurrentDevice device)
        {
            try
            {
                _httpClient.DefaultRequestHeaders["Origin"]  = "https://gateway.hbogo.eu";
                _httpClient.DefaultRequestHeaders["Referer"] = "https://gateway.hbogo.eu/signin/form";

                Login lg = new Login();

                lg.Action   = "L";
                lg.Language = "CES";

                lg.CurrentDevice = device;

                EasClientDeviceInformation eas = new EasClientDeviceInformation();

                //TEST
                lg.BirthYear = 1;
                if (lg.CurrentDevice == null)
                {
                    lg.CurrentDevice = new CurrentDevice();
                }
                lg.CurrentDevice.Brand     = eas.SystemManufacturer;
                lg.CurrentDevice.Modell    = eas.SystemProductName;
                lg.CurrentDevice.OsName    = "Windows";
                lg.CurrentDevice.OsVersion = eas.SystemFirmwareVersion;
                lg.CurrentDevice.Platform  = "XONE";
                lg.CurrentDevice.SwVersion = "3.3.9.6418.2100";
                //

                lg.EmailAddress = username;
                lg.Password     = password;
                lg.OperatorId   = operatorId;

                var jsonRequest    = JsonConvert.SerializeObject(lg);
                var requestContent = new HttpStringContent(jsonRequest, UnicodeEncoding.Utf8, "application/json");
                var response       = await _httpClient.PostAsync(loginUri, requestContent);

                var login = !response.IsSuccessStatusCode
                    ? null
                    : JsonConvert.DeserializeObject <LoginResponse>(await response.Content.ReadAsStringAsync());

                if (login != null && login.Error == null)
                {
                    _httpClient.DefaultRequestHeaders["GO-SessionId"]  = login.SessionId.ToString();
                    _httpClient.DefaultRequestHeaders["GO-Token"]      = login.Token;
                    _httpClient.DefaultRequestHeaders["GO-CustomerId"] = login.Customer.Id.ToString();
                }

                return(login);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(null);
            }
        }
Example #8
0
 public void Stop()
 {
     if (CurrentDevice != null)
     {
         CurrentDevice.SignalToStop();
         CurrentDevice.WaitForStop();
         CurrentDevice.NewFrame -= new NewFrameEventHandler(CameraNewFrameEventHandler);
         IsStarted = false;
     }
 }
Example #9
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     CurrentService?.Dispose();
     CurrentDevice?.Dispose();
     CurrentDevice               = null;
     CurrentService              = null;
     CurrentWriteCharacteristic  = null;
     CurrentNotifyCharacteristic = null;
     ValueChanged(MsgType.NotifyTxt, "主动断开连接");
 }
Example #10
0
        private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var isVisible = (bool)e.NewValue;

            if (isVisible)
            {
                CurrentDevice?.Start();
            }
            else
            {
                CurrentDevice?.SignalToStop();
            }
        }
Example #11
0
        private void StartCapturing()
        {
            using (PacketCommunicator communicator = CurrentDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
            {
                Packet packet;
                do
                {
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);

                    if (Filter != null)
                    {
                        communicator.SetFilter(Filter);
                    }

                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:
                        // Timeout elapsed
                        continue;

                    case PacketCommunicatorReceiveResult.Ok:
                        PacketBuffer.Enqueue((new CustomPacket(packet)).ToString());
                        //PacketBuffer.Enqueue(SuspiciousPacketGenerator.GenerateSample(36, "0", rand, false));

                        int randomNumber = rand.Next(10);

                        if (randomNumber % 5 == 0)
                        {
                            PacketBuffer.Enqueue(SuspiciousPacketGenerator.GenerateSample(36, "0", rand, false));
                        }
                        break;

                    default:
                        throw new InvalidOperationException("The result " + result + " should never be reached here");
                    }

                    lock (PacketBuffer)
                    {
                        if (PacketBuffer.Count >= PACKETS_COUNT_CONSTRAINT && !Pause)
                        {
                            string[] data = GetLastPackets();

                            if (queueIsFull != null)
                            {
                                queueIsFull(data);
                            }
                        }
                    }
                } while (true);
            }
        }
Example #12
0
 public void Start()
 {
     if (CurrentDevice != null)
     {
         try
         {
             CurrentDevice.NewFrame += new NewFrameEventHandler(CameraNewFrameEventHandler);
             CurrentDevice.Start();
             IsStarted = true;
         }
         catch
         {
             MessageBox.Show($"Error opening a device called {CurrentDeviceName}", "Error", MessageBoxButton.OK);
         }
     }
 }
Example #13
0
 public void RegisterOrLoadCurrentDevice()
 {
     if (string.IsNullOrEmpty(settings.CurrentDeviceId))
     {
         settings.CurrentDeviceId   = Guid.NewGuid().ToString();
         settings.Individualization = Guid.NewGuid().ToString();
     }
     else
     {
         CurrentDevice = new CurrentDevice()
         {
             Id = new Guid(settings.CurrentDeviceId),
             Individualization = settings.Individualization
         };
     }
 }
Example #14
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     if (CurrentService != null)
     {
         CurrentService.Dispose();
     }
     if (CurrentDevice != null)
     {
         CurrentDevice.Dispose();
     }
     CurrentDevice               = null;
     CurrentService              = null;
     CurrentWriteCharacteristic  = null;
     CurrentNotifyCharacteristic = null;
 }
Example #15
0
        /// <summary>
        /// 按GUID 查找主服务
        /// </summary>
        /// <param name="characteristic">GUID 字符串</param>
        /// <returns></returns>
        public async Task SelectDeviceService()
        {
            Guid guid = new Guid(ServiceGuid);



            //foreach (var CurrentService in rr.GetResults().Services)
            //{ Debug.WriteLine(CurrentService.Uuid.ToString()); }

            CurrentDevice.GetGattServicesForUuidAsync(guid).Completed = (asyncInfo, asyncStatus) =>
            {
                if (asyncStatus == AsyncStatus.Completed)
                {
                    try
                    {
                        GattDeviceServicesResult result = asyncInfo.GetResults();
                        string msg = "主服务=" + CurrentDevice.ConnectionStatus;


                        ValueChanged(MsgType.NotifyTxt, msg, CurrentDevice == null ? null : CurrentDevice.DeviceId);
                        if (result.Services.Count > 0)
                        {
                            //Debug.WriteLine(result.Services[0].Uuid.ToString());
                            CurrentService = result.Services[CHARACTERISTIC_INDEX];

                            if (CurrentService != null)
                            {
                                asyncLock = true;
                                //GetCurrentWriteCharacteristic();
                                GetCurrentNotifyCharacteristic();
                            }
                        }
                        else
                        {
                            msg = "没有发现服务,自动重试中";
                            ValueChanged(MsgType.NotifyTxt, msg, CurrentDevice == null ? null : CurrentDevice.DeviceId);
                            SelectDeviceService();
                        }
                    }
                    catch (Exception e)
                    {
                        ValueChanged(MsgType.NotifyTxt, "没有发现服务,自动重试中", CurrentDevice == null ? null : CurrentDevice.DeviceId);
                        SelectDeviceService();
                    }
                }
            };
        }
Example #16
0
        public void RefreshInstalledApps()
        {
            //RemoteApplicationEx

            Collection <IRemoteApplication> installed = CurrentDevice.GetInstalledApplications();

            Collection <RemoteApplicationEx> installedCollection = new Collection <RemoteApplicationEx>();

            foreach (IRemoteApplication app in installed)
            {
                installedCollection.Add(new RemoteApplicationEx(app));
            }

            InstalledApplications = installedCollection;

            RefreshRemoteIsoStores();
        }
Example #17
0
        /// <summary>
        /// Set mock basic test data
        /// </summary>
        /// <returns></returns>
        public void InitializeTestDataBasic()
        {
            Dictionary <string, string> test = new Dictionary <string, string>();

            CurrentFolders folder = new CurrentFolders(this);

            test.Add($"{nameof(CurrentFolders)}{nameof(folder.DevicesGuid)}", "9866738119bc461fb6c2bb14751ffcb0");
            test.Add($"{nameof(CurrentFolders)}{nameof(folder.UsersGuid)}", "f426ad8fd1f44849b61f9e3a486e4fab");

            CurrentDevice device = new CurrentDevice(this, test.GetValueOrDefault($"{ nameof(CurrentFolders)}{folder.DevicesGuid}"));

            test.Add($"{nameof(CurrentDevice)}{nameof(device.DeviceGuid)}", "675f383f708841568e27626889b0344d");

            CurrentUser user = new CurrentUser(this, test.GetValueOrDefault($"{ nameof(CurrentFolders)}{folder.UsersGuid}"));

            test.Add($"{nameof(CurrentUser)}{nameof(user.UserGuid)}", "2ec9e33c41094e8e9b75f7d5a77e7b57");
            persistText = test;
        }
        public void LoadContent(ContentManager Content, Game1 game)
        {
            this.game = game;
            mainMenu  = new MainMenu();
            mainMenu.LoadContent(Content);
            btnPlay          = new cButton(Content.Load <Texture2D>("Menu/Buttons/playButton"));
            backToGameButton = new cButton(Content.Load <Texture2D>("Menu/Buttons/playButton"));
            exitButton       = new cButton(Content.Load <Texture2D>("Menu/Buttons/exitButton"));
            restartButton    = new cButton(Content.Load <Texture2D>("Menu/Buttons/restartButton"));
            font             = Content.Load <SpriteFont>("healthsFont");
            switch (AnalyticsInfo.VersionInfo.DeviceFamily)
            {
            case "Windows.Mobile":
                device = CurrentDevice.Phone;
                break;

            default:
                device = CurrentDevice.Desktop;
                break;
            }
        }
Example #19
0
        /// <summary>
        /// 按GUID 查找主服务
        /// </summary>
        /// <param name="characteristic">GUID 字符串</param>
        /// <returns></returns>
        public async Task SelectDeviceService()
        {
            Guid guid = new Guid(ServiceGuid);

            CurrentDevice.GetGattServicesForUuidAsync(guid).Completed = (asyncInfo, asyncStatus) =>
            {
                if (asyncStatus == AsyncStatus.Completed)
                {
                    try
                    {
                        GattDeviceServicesResult result = asyncInfo.GetResults();
                        string msg = "主服务=" + CurrentDevice.ConnectionStatus;
                        ValueChanged(MsgType.NotifyTxt, msg);
                        if (result.Services.Count > 0)
                        {
                            CurrentService = result.Services[CHARACTERISTIC_INDEX];
                            if (CurrentService != null)
                            {
                                asyncLock = true;
                                GetCurrentWriteCharacteristic();
                                GetCurrentNotifyCharacteristic();
                            }
                        }
                        else
                        {
                            msg = "没有发现服务,自动重试中";
                            ValueChanged(MsgType.NotifyTxt, msg);
                            SelectDeviceService();
                        }
                    }
                    catch (Exception e)
                    {
                        ValueChanged(MsgType.NotifyTxt, "没有发现服务,自动重试中");
                        SelectDeviceService();
                    }
                }
            };
        }
Example #20
0
 /// <summary>
 /// 连接状态改变事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void CurrentDevice_ConnectionStatusChanged(BluetoothLEDevice sender, object args)
 {
     if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected && CurrentDeviceMAC != null)
     {
         string msg = "Disconnected";
         ValueChanged(MsgType.NotifyTxt, msg);
         CurrentDevice.ConnectionStatusChanged -= CurrentDevice_ConnectionStatusChanged;
         if (!asyncLock)
         {
             asyncLock = true;
             CurrentDevice.Dispose();
             CurrentDevice               = null;
             CurrentService              = null;
             CurrentWriteCharacteristic  = null;
             CurrentNotifyCharacteristic = null;
         }
     }
     else
     {
         string msg = "Success";
         ValueChanged(MsgType.NotifyTxt, msg);
     }
 }
Example #21
0
 private void CurrentDevice_ConnectionStatusChanged(BluetoothLEDevice sender, object args)
 {
     if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected && CurrentDeviceMAC != null)
     {
         string msg = "设备已断开,自动重连";
         ValueChanged(MsgType.NotifyTxt, msg);
         if (!asyncLock)
         {
             asyncLock = true;
             CurrentDevice.Dispose();
             CurrentDevice               = null;
             CurrentService              = null;
             CurrentWriteCharacteristic  = null;
             CurrentNotifyCharacteristic = null;
             SelectDeviceFromIdAsync(CurrentDeviceMAC);
         }
     }
     else
     {
         string msg = "设备已连接";
         ValueChanged(MsgType.NotifyTxt, msg);
     }
 }
Example #22
0
        public void Update()
        {
            if (CurrentDevice != null)
            {
                CurrentDevice.Update(this);
                if (!CurrentDevice.IsConnected)
                {
                    SendTargetData(new TargetData(0, 0, 0, 0));
                }

                // schauen ob sich Informationen vom Gerät geändert haben
                bool dirty = CurrentDevice.IsConnected != lastConnected || !CurrentDevice.Battery.Equals(lastBattery);
                if (dirty)
                {
                    if (OnDeviceInfoChanged != null)
                    {
                        OnDeviceInfoChanged(this, EventArgs.Empty);
                    }

                    lastConnected = CurrentDevice.IsConnected;
                    lastBattery   = CurrentDevice.Battery;
                }
            }
        }
Example #23
0
        private async void SendClipboardItem()
        {
            if (willSendAfterLimit)
            {
                return;
            }

            try
            {
                var elapsed = (DateTime.UtcNow - lastSendTime);
                if (elapsed < TimeSpan.FromSeconds(11))
                {
                    Debug.WriteLine("Waiting...");
                    willSendAfterLimit = true;
                    await Task.Delay(TimeSpan.FromSeconds(11) - elapsed);

                    willSendAfterLimit = false;
                }

                string text = ViewModel.ClipboardActivities[0].Text;
                Debug.WriteLine("Sending...");

                lastSendTime = DateTime.UtcNow;

                await CloudClipboardService.SendCloudClipboard(Settings.Data.AccountId, text, CurrentDevice.GetDeviceName());
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"SendClipboardItem exception: {ex.Message}");
            }
        }
 protected override void update()
 {
     base.update();
     CurrentDevice.UpdateCollection("Name", "_Total");
 }
Example #25
0
        public async void Login(string login, string password, Guid operatorId, CurrentDevice device)
        {
            CurrentUser = await communication.Login(config.HboAccountLoginUri(CurrentlySelectedCountry.CountryCodeLong, CurrentlySelectedCountry.LanguageCode, "XONE"), login, password, operatorId, device);

            // TODO if error logout
        }
 protected override void update()
 {
     base.update();
     CurrentDevice.UpdateCollection(x => x.GetProperty("Name").AsString().Equals((CurrentDevice as DevicePerformance).DeviceRelated));
 }
 static CurrentDevice()
 {
     Instance = new CurrentDevice();
 }
 protected override void update()
 {
     base.update();
     CurrentDevice.UpdateCollection();
 }
Example #29
0
        public bool Connect()
        {
            // do not use CurrentDevice here (rather, use _currentDevice) because CurrentDevice.Get()
            // can call back into Connect

            if (CurrentConnectableDevice != null)
            {
                // we're already connected to this device! :)
                //if (_currentDevice == _connectedDevice/* && _connectedDevice.IsConnected()*/)
                //    return true;

                try
                {
                    // disconnect the existing device
                    if (CurrentDevice != null)
                    {
                        CurrentDevice.Disconnect();
                    }

                    CurrentDevice = CurrentConnectableDevice.Connect();

                    SystemInfo = CurrentDevice.GetSystemInfo();

                    if (SystemInfo.OSBuildNo < MIN_SUPPORTED_BUILD_NUMBER)
                    {
                        throw new Exception("Windows Phone Power Tools only support build " + MIN_SUPPORTED_BUILD_NUMBER + " and above. This device is on " + SystemInfo.OSBuildNo + ".");
                    }

                    StatusMessage = "Currently connected to " + _currentConnectableDevice.Name;

                    Connected = true;
                    IsError   = false;

                    RefreshInstalledApps();
                }
                catch (Exception ex)
                {
                    SmartDeviceException smartDeviceEx = ex as SmartDeviceException;

                    if (smartDeviceEx != null)
                    {
                        if (ex.Message == "0x89731811")
                        {
                            StatusMessage = "Connection Error! Zune is either not running or not connected to the device.";
                        }
                        else if (ex.Message == "0x89731812")
                        {
                            StatusMessage = "Connection Error! Unlock your phone and make sure it is paired with Zune";
                        }
                        else if (ex.Message == "0x89740005")
                        {
                            StatusMessage = "Developer unlock has expired. Lock and re-unlock your phone using the SDK registration tool";
                        }
                        else
                        {
                            StatusMessage = "Connection Error! Message: " + ex.Message;
                        }
                    }
                    else
                    {
                        StatusMessage = ex.Message;
                    }

                    IsError    = true;
                    Connected  = false;
                    SystemInfo = null;
                }
            }

            return(Connected);
        }
Example #30
0
 protected override void update()
 {
     base.update();
     CurrentDevice.UpdateCollection("Name", (CurrentDevice as DevicePerformance).DeviceRelated);
 }