Ejemplo n.º 1
0
        public static bool SetServiceStatus(string serviceName, AdapterStatus status)
        {
            try
            {
                ServiceController sc = new ServiceController(serviceName);

                switch (status)
                {
                case AdapterStatus.Running:
                    sc.Start(new string[] { AdapterConfigArgument.InIM });
                    sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 0, 0, TimeOut));
                    break;

                case AdapterStatus.Stopped:
                    sc.Stop();
                    sc.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 0, 0, TimeOut));
                    break;
                }

                return(true);
            }
            catch (Exception err)
            {
                GCError.SetLastError("Set service status failed. service name: " + serviceName + " status: " + status.ToString());
                GCError.SetLastError(err);
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enables logging of device status on change.
        /// </summary>
        public static void StartListeningForAdapterChanges()
        {
            bool startListening = false;

            _adapterReadyDisposable?.Dispose();
            _adapterReadyDisposable = CrossBleAdapter.Current.WhenStatusChanged().Subscribe(async status =>
            {
                if (status != AdapterStatus)
                {
                    AdapterStatus = status;
                    if (status == AdapterStatus.PoweredOff && Windesheart.PairedDevice != null)
                    {
                        Windesheart.PairedDevice?.Disconnect();
                    }

                    if (status == AdapterStatus.PoweredOn && Windesheart.PairedDevice != null && startListening)
                    {
                        var tempConnectCallback = Windesheart.PairedDevice.ConnectionCallback;
                        var DisconnectCallback  = Windesheart.PairedDevice.DisconnectCallback;
                        var secretKey           = Windesheart.PairedDevice.SecretKey;
                        var device = await GetKnownDevice(Windesheart.PairedDevice.IDevice.Uuid);

                        if (DisconnectCallback != null)
                        {
                            device?.SubscribeToDisconnect(DisconnectCallback);
                        }
                        device?.Connect(tempConnectCallback, secretKey);
                    }
                    startListening = true;
                }
            });
        }
Ejemplo n.º 3
0
    void Start()
    {
        MobileAds.Initialize((initStatus) =>
        {
            Dictionary <string, AdapterStatus> map = initStatus.getAdapterStatusMap();
            foreach (KeyValuePair <string, AdapterStatus> keyValuePair in map)
            {
                string className     = keyValuePair.Key;
                AdapterStatus status = keyValuePair.Value;
                switch (status.InitializationState)
                {
                case AdapterState.NotReady:
                    // The adapter initialization did not complete.
                    MonoBehaviour.print("Adapter: " + className + " not ready.");
                    break;

                case AdapterState.Ready:
                    // The adapter was successfully initialized.
                    MonoBehaviour.print("Adapter: " + className + " is initialized.");
                    break;
                }
            }
            OnAdapterReady();
        });
    }
Ejemplo n.º 4
0
    void Start()
    {
        MobileAds.Initialize((initStatus) =>
        {
            Dictionary <string, AdapterStatus> map = initStatus.getAdapterStatusMap();
            foreach (KeyValuePair <string, AdapterStatus> keyValuePair in map)
            {
                string className     = keyValuePair.Key;
                AdapterStatus status = keyValuePair.Value;
                switch (status.InitializationState)
                {
                case AdapterState.NotReady:
                    // The adapter initialization did not complete.
                    MonoBehaviour.print("Adapter: " + className + " not ready.");
                    break;

                case AdapterState.Ready:
                    // The adapter was successfully initialized.
                    MonoBehaviour.print("Adapter: " + className + " is initialized.");
                    break;
                }
            }
        });

        m_RewardAdPlacement = gameObject.GetComponent <RewardedAdsGoogle>();
        m_RewardAdPlacement.Init();
    }
Ejemplo n.º 5
0
        /// <summary>Converts from Native Phone Bluetooth status to Project Breathe status.</summary>
        /// <param name="status">The status.</param>
        /// <returns>The <see cref="AdapterStatus"/>.</returns>
        public static AdapterStatus ToBluetoothAdapterStatus(this Plugin.BluetoothLE.AdapterStatus status)
        {
            AdapterStatus newStatus = AdapterStatus.Unknown;

            switch (status)
            {
            case Plugin.BluetoothLE.AdapterStatus.Resetting:
                newStatus = AdapterStatus.Resetting;
                break;

            case Plugin.BluetoothLE.AdapterStatus.Unsupported:
                newStatus = AdapterStatus.Unsupported;
                break;

            case Plugin.BluetoothLE.AdapterStatus.Unauthorized:
                newStatus = AdapterStatus.Unauthorized;
                break;

            case Plugin.BluetoothLE.AdapterStatus.PoweredOff:
                newStatus = AdapterStatus.PoweredOff;
                break;

            case Plugin.BluetoothLE.AdapterStatus.PoweredOn:
                newStatus = AdapterStatus.PoweredOn;
                break;
            }

            return(newStatus);
        }
Ejemplo n.º 6
0
        private void OnMainPageLoaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("主窗口开始加载");

            AdapterStatus Astatus = CrossBleAdapter.Current.Status;

            CrossBleAdapter.Current.WhenStatusChanged().Subscribe(status =>
            {
                Debug.WriteLine("状态更新:" + status.ToString());
            });
            Debug.WriteLine("主窗口加载完成");
        }
Ejemplo n.º 7
0
        protected void AdapterStateReport(AdapterStatus state, object extrainfo)
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.TK_CommandType = Constants.TK_CommandType.ADAPTER_STATE_REPORT;

            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_STATE, state);
            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_EXTRAINFO, extrainfo);

            try
            {
                m_CommClient.PostCommand(cm);
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
            }
        }
Ejemplo n.º 8
0
        public void StopInterface()
        {
            base.SetStatus("Stopping interface.");

            GCInterface gcInterface = _interfaceView.GetSelectedInterface();

            if (gcInterface == null)
            {
                return;
            }

            if (_interfaceManager.StopInterface(gcInterface))
            {
                Program.Log.Write("{Interface} stop interface (" + gcInterface.ToString() + ") succeed");

                _interfaceView.RefreshView();
                _interfaceView.SelectInterface(gcInterface);
            }
            else
            {
                Program.Log.Write(LogType.Warning, "{Interface} stop interface (" + gcInterface.ToString() + ") failed");
                Program.Log.Write(LogType.Error, GCError.LastErrorInfor);
                Program.Log.Write(GCError.LastError);

                //Stop some NT service may meets error (System.ComponentModel.Win32Exception: The service cannot accept control messages at this time),
                //especaily after these NT services are started together at the same time by bat files. 2007/07/17

                AdapterStatus status = ServiceControl.GetServiceStatus(gcInterface.InterfaceName);
                if (status != AdapterStatus.Stopped)
                {
                    MessageBox.Show(frmMain, "Stop interface failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    _interfaceView.RefreshView();
                    _interfaceView.SelectInterface(gcInterface);
                }
            }

            base.ClearStatus();
        }
Ejemplo n.º 9
0
    static public void Initialize(Action onInited)
    {
        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            Dictionary <string, AdapterStatus> map = initStatus.getAdapterStatusMap();
            foreach (KeyValuePair <string, AdapterStatus> keyValuePair in map)
            {
                string className     = keyValuePair.Key;
                AdapterStatus status = keyValuePair.Value;
                switch (status.InitializationState)
                {
                case AdapterState.NotReady:
                    Debug.LogWarning("Adapter: " + className + " not ready.");
                    break;

                case AdapterState.Ready:
                    Debug.Log("Adapter: " + className + " is initialized.");
                    break;
                }
            }
            onInited?.Invoke();
        });
    }
Ejemplo n.º 10
0
 public AdapterMessage(int interfaceID, AdapterStatus status)
 {
     _interfaceID = interfaceID;
     _status      = status;
 }