Beispiel #1
0
        /// <summary>
        /// init the static instance of the DiscordHandler
        /// </summary>
        public static async void Initialize()
        {
            if (DiscordHandler.Instance == null)
            {
                Instance = new DiscordHandler();

                // setup the client
                bool   installKeyPresent = false;
                string ik;

                ik = MednaNetSettings.GetInstallKey();
                if (ik != null && ik.Trim() != "")
                {
                    installKeyPresent   = true;
                    Instance.InstallKey = ik;
                }

                // Instantiate client
                if (installKeyPresent == true)
                {
                    Instance.Client = new Client(Instance.EndPointAddress, Instance.EndPointPort, ik);
                }
                else
                {
                    Instance.Client = new Client(Instance.EndPointAddress, Instance.EndPointPort);
                }

                // get the current install object from the API
                if (installKeyPresent == true)
                {
                    try { Instance.CurrentInstall = await Instance.Client.Install.GetCurrentInstall(Instance.InstallKey); }
                    catch (Exception ex) { Instance.APIDisconnected(ex); return; }
                }

                if (installKeyPresent == false)
                {
                    try { Instance.CurrentInstall = await Instance.Client.Install.GetCurrentInstall(""); }
                    catch (Exception ex) { Instance.APIDisconnected(ex); return; }

                    Instance.InstallKey = Instance.CurrentInstall.code;
                    MednaNetSettings.SetInstallKey(Instance.InstallKey);
                }

                Instance.IsConnected = true;
            }

            Instance.HistoryInMinutes = MednaNetSettings.GetChatHistoryInMinutes();

            Timer.Interval = new TimeSpan(0, 0, Instance.TimerIntervalInSeconds);

            DiscordHandler.Timer.Start();
            Instance.IsConnected = true;
        }
Beispiel #2
0
        private async void LoadClient()
        {
            bool   installKeyPresent = false;
            string ik;

            ik = MednaNetSettings.GetInstallKey();
            if (ik != null && ik.Trim() != "")
            {
                installKeyPresent = true;
                InstallKey        = ik;
            }

            // Instantiate client
            if (installKeyPresent == true)
            {
                Client = new Client(EndPointAddress, EndPointPort, ik);
            }
            else
            {
                Client = new Client(EndPointAddress, EndPointPort);
            }


            // get the current install object from the API
            if (installKeyPresent == true)
            {
                try { CurrentInstall = await Client.Install.GetCurrentInstall(InstallKey); }
                catch (Exception ex) { APIDisconnected(ex); return; }
            }


            if (installKeyPresent == false)
            {
                try { CurrentInstall = await Client.Install.GetCurrentInstall(""); }
                catch (Exception ex) { APIDisconnected(ex); return; }


                InstallKey = CurrentInstall.code;
                MednaNetSettings.SetInstallKey(InstallKey);
            }

            isConnected = true;

            DoPoll();

            // start the timer
            Timer.Start();
        }