Beispiel #1
0
        public void SetAudioLevelValue(AudioLevels type, double newValue)
        {
            float value = (float)(newValue / 100.0);

            if (type == AudioLevels.Headphone)
            {
                ResultCodes result = AccessoryHeadsetDriverHelper.SetSpeakerVolumeValue(currentHeadset, new VolumeChannel()
                {
                    ChannelIndex = OMENVolumeChannels.Master,
                    ChannelValue = value
                });
                checkErrors(result);
            }
            else if (type == AudioLevels.Mic)
            {
                ResultCodes result = AccessoryHeadsetDriverHelper.SetMicrophoneVolumeValue(currentHeadset, new VolumeChannel()
                {
                    ChannelIndex = OMENVolumeChannels.Master,
                    ChannelValue = value
                });
                checkErrors(result);
            }
            else
            {
                if (type != AudioLevels.SideTone)
                {
                    return;
                }

                VolumeChannel volumeChannel = new VolumeChannel();
                volumeChannel.ChannelIndex = OMENVolumeChannels.FrontLeft;
                volumeChannel.ChannelValue = value;
                VolumeChannel sideToneChannel1 = volumeChannel;
                ResultCodes   result           = AccessoryHeadsetDriverHelper.SetSideToneVolumeValue(currentHeadset, sideToneChannel1);
                checkErrors(result);
                volumeChannel = new VolumeChannel();
                volumeChannel.ChannelIndex = OMENVolumeChannels.FrontRight;
                volumeChannel.ChannelValue = value;
                VolumeChannel sideToneChannel2 = volumeChannel;
                ResultCodes   result2          = AccessoryHeadsetDriverHelper.SetSideToneVolumeValue(currentHeadset, sideToneChannel2);
                checkErrors(result2);
            }
        }
        public ScriptManager(LoggingProvider logger, SoftwareConfiguration configuration)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }


            for (int i = 0; i < 8; i++)
            {
                channels.Add(new VolumeChannel("XXX", "XXX", logger));
            }


            try
            {
                // TODO: consider using the advice in https://github.com/Microsoft/ClearScript/issues/65 instead of using WeakReferences.

                WeakReference <List <Channel> > weakChannelList = new WeakReference <List <Channel> >(channels);

                _engine.AddHostObject("host", new ExtendedHostFunctions());

                _engine.AddHostObject("AddVolumeChannel", (Func <int, String, String, int>)((int c, String displayName, String exeSuffix) => {
                    List <Channel> localChannels;
                    if (weakChannelList.TryGetTarget(out localChannels))
                    {
                        localChannels[c] = new VolumeChannel(displayName, exeSuffix, logger);
                    }
                    return(0);
                }));

                _engine.AddHostType("ScriptChannelCallback", typeof(ScriptChannelCallback));
                _engine.AddHostObject("AddScriptChannelInternal", (Func <int, ScriptChannelCallback, ScriptChannel>)((int c, ScriptChannelCallback config) => {
                    ScriptChannel nc;
                    ScriptChannel dv = ScriptChannel.ConstructForScript(config, out nc);
                    List <Channel> localChannels;
                    if (weakChannelList.TryGetTarget(out localChannels))
                    {
                        localChannels[c] = nc;
                    }
                    return(dv);
                }));

                _engine.Execute("builtin.js", Software.Properties.Resources.BuiltInScript);

                if (!File.Exists(configuration.ConfigFilePath))
                {
                    File.WriteAllText(configuration.ConfigFilePath, Software.Properties.Resources.DefaultConfigScript);
                }

                _engine.Execute(configuration.ConfigFilePath, File.ReadAllText(configuration.ConfigFilePath));
            }
            catch (ScriptEngineException e)
            {
                MessageBox.Show(e.ErrorDetails, "Error executing config.js", MessageBoxButtons.OK);
                throw e;
            }
        }
Beispiel #3
0
        public async Task RefreshCoins()
        {
            for (int i = 0; i < Coins.Count; i++)
            {
                try
                {
                    string json = AlertClient.DownloadString(TickerURL + Coins[i].Id);

                    List <Coin> Items     = JsonConvert.DeserializeObject <List <Coin> >(json);
                    Coin        FoundCoin = Items.Find(x => x.Id == Coins[i].Id);
                    FoundCoin.Alert = Coins[i].Alert;
                    Coins[i]        = FoundCoin;
                }
                catch (WebException) { }
            }

            if (PriceChannel != null && VolumeChannel != null && TetherChannel != null && MiscPriceChannel != null && MiscVolChannel != null && BitcoinChannel != null)
            {
                foreach (Coin coin in Coins)
                {
                    string message     = null;
                    bool   NeedsUpdate = !UpdateHistoy.TryGetValue(coin.Id, out DateTime LastUpdate);
                    bool   HasAlerted  = false;
                    var    serverEmote = Emotes.FirstOrDefault(x => x.Name == coin.Symbol);

                    if (NeedsUpdate || TimeSpan.FromHours(1) <= (DateTime.Now - LastUpdate))
                    {
                        if (coin.Alert == "volume" || coin.Alert == "main" || coin.Alert == "main-volume")
                        {
                            message = null;

                            if (VolumeHistory.ContainsKey(coin.Id))
                            {
                                double Percent = ((coin.Day_volume_usd - VolumeHistory[coin.Id]) / VolumeHistory[coin.Id]) * 100;
                                if (Percent >= 4)
                                {
                                    message = (serverEmote == null ? coin.Symbol : "<:" + coin.Symbol + ":" + serverEmote.Id + ">") + " <:UP:361650797802684416> " + Math.Round(Math.Abs(Percent), 2) + "%";
                                }
                                else if (Percent <= -4)
                                {
                                    message = (serverEmote == null ? coin.Symbol : "<:" + coin.Symbol + ":" + serverEmote.Id + ">") + " <:DOWN:361650806409396224> " + Math.Round(Math.Abs(Percent), 2) + "%";
                                }

                                VolumeHistory[coin.Id] = coin.Day_volume_usd;
                            }
                            else
                            {
                                VolumeHistory.Add(coin.Id, coin.Day_volume_usd);
                            }

                            if (message != null)
                            {
                                try
                                {
                                    if (coin.Id == "bitcoin")
                                    {
                                        message += " V";
                                        await BitcoinChannel.SendMessageAsync(message);
                                    }
                                    else if (coin.Id == "tether")
                                    {
                                        await TetherChannel.SendMessageAsync(message);
                                    }
                                    else if (coin.Alert == "main")
                                    {
                                        await VolumeChannel.SendMessageAsync(message);
                                    }
                                    else
                                    {
                                        await MiscVolChannel.SendMessageAsync(message);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }

                                HasAlerted = true;
                            }
                        }

                        if (coin.Alert == "price" || coin.Alert == "main")
                        {
                            message = null;

                            if (coin.Percent_change_hour >= 4)
                            {
                                message = (serverEmote == null ? coin.Symbol : "<:" + coin.Symbol + ":" + serverEmote.Id + ">") + " <:UP:361650797802684416> " + Math.Abs(coin.Percent_change_hour) + "%";
                            }
                            else if (coin.Percent_change_hour <= -4)
                            {
                                message = (serverEmote == null ? coin.Symbol : "<:" + coin.Symbol + ":" + serverEmote.Id + ">") + " <:DOWN:361650806409396224> " + Math.Abs(coin.Percent_change_hour) + "%";
                            }

                            if (message != null)
                            {
                                try
                                {
                                    if (coin.Id == "bitcoin")
                                    {
                                        message += " P";
                                        await BitcoinChannel.SendMessageAsync(message);
                                    }
                                    else if (coin.Alert == "main")
                                    {
                                        await PriceChannel.SendMessageAsync(message);
                                    }
                                    else
                                    {
                                        await MiscPriceChannel.SendMessageAsync(message);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }

                                HasAlerted = true;
                            }
                        }

                        if (HasAlerted)
                        {
                            if (NeedsUpdate)
                            {
                                UpdateHistoy.Add(coin.Id, DateTime.Now);
                            }
                            else
                            {
                                UpdateHistoy[coin.Id] = DateTime.Now;
                            }
                        }
                    }
                }
            }
        }