예제 #1
0
파일: Form1.cs 프로젝트: yyan/winform
        private void btnPlayMp3_Click(object sender, EventArgs e)
        {
            if (!isPlay)
            {
                string mp3File = Path.Combine(Application.StartupPath, "Music\\小酒窝.mp3");
                //string waveFile = Path.Combine(Application.StartupPath, "ringin.wav");
                //string midFile = @"C:\Windows\Media\onestop.mid";

                SoundPlayerHelper.Play(mp3File, false);    //播放MP3格式文件
                //SoundPlayerHelper.Play(waveFile, true); //播放WAV格式文件
                //SoundPlayerHelper.Play(midFile, false);  //播放Midi格式文件
                this.btnPlayMp3.Text = "停止播放";
            }
            else
            {
                SoundPlayerHelper.Stop();//停止播放
                //SoundPlayerHelper.Pause();//暂停播放
                this.btnPlayMp3.Text = "播放声音";
            }

            string statu = SoundPlayerHelper.Status;

            this.Text = statu;
            isPlay    = !isPlay;
        }
예제 #2
0
        public AboutWindow()
        {
            InitializeComponent();
            SoundPlayerHelper.PlaySound(SoundPlayerHelper.Sound.About);

            infoBlock.Text = $"Happy counting!{Environment.NewLine}{Environment.NewLine}Build date: "
                             + $"{File.GetLastWriteTime("CashManager.exe"):dd-MM-yyyy}";
        }
예제 #3
0
        public MainWindow(ApplicationViewModel viewModel)
        {
            DataContext = viewModel;

            using (new MeasureTimeWrapper(InitializeComponent, "MainWindow.Init")) { }

            SoundPlayerHelper.PlaySound(SoundPlayerHelper.Sound.AppStart);
        }
예제 #4
0
        public static void LoadSoundsAndCache()
        {
            PluginViewModel.Instance.SoundFiles.Clear();

            // do your gui stuff here
            List <FileInfo> legacyFiles = new List <FileInfo>();
            List <string>   filters     = new List <string> {
                "*.wav",
                "*.mp3",
            };

            foreach (var filter in filters)
            {
                IEnumerable <FileInfo> files = Directory.GetFiles(Constants.BaseDirectory, filter, SearchOption.AllDirectories).Select(file => new FileInfo(file));
                legacyFiles.AddRange(files);
            }

            foreach (FileInfo legacyFile in legacyFiles)
            {
                if (legacyFile.DirectoryName == null)
                {
                    continue;
                }

                var baseKey = legacyFile.DirectoryName.Replace(Constants.BaseDirectory, string.Empty);
                var key     = string.IsNullOrWhiteSpace(baseKey)
                              ? legacyFile.Name
                              : $"{baseKey.Substring(1)}\\{legacyFile.Name}";
                if (File.Exists(Path.Combine(Common.Constants.SoundsPath, key)))
                {
                    continue;
                }

                try {
                    var directoryKey = string.IsNullOrWhiteSpace(baseKey)
                                           ? string.Empty
                                           : baseKey.Substring(1);
                    var directory = Path.Combine(Common.Constants.SoundsPath, directoryKey);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    File.Copy(legacyFile.FullName, Path.Combine(Common.Constants.SoundsPath, key));
                    SoundPlayerHelper.TryGetSetSoundFile(key);
                }
                catch (Exception ex) {
                    Logging.Log(Logger, new LogItem(ex, true));
                }
            }

            foreach (var cachedSoundFile in SoundPlayerHelper.SoundFileKeys())
            {
                PluginViewModel.Instance.SoundFiles.Add(cachedSoundFile);
            }

            PluginViewModel.Instance.SoundFiles.Insert(0, " ");
        }
예제 #5
0
        public static bool PlayCached(string soundFile, int volume = 100)
        {
            var retval = SoundPlayerHelper.PlayCached(soundFile, volume);

            //LogHelper.Log(Logger, "Sound Playback with " + FFXIVAPP.Common.Constants.AudioMode + ":" + soundFile + " at volume:" + volume, LogLevel.Debug);
            LogHelper.Log(Logger, "Sound Playback:" + soundFile + " at volume:" + volume, LogLevel.Debug);

            return(retval);
        }
예제 #6
0
        private static void TestSound()
        {
            if (SettingsView.View.TSound.Text.Trim() == "")
            {
                return;
            }
            var volume = Settings.Default.AlarmVolume * 100;

            SoundPlayerHelper.PlayCached(SettingsView.View.TSound.Text, (int)volume);
        }
예제 #7
0
        private static Action PlaySound(LogEvent logEvent, int volume)
        {
            var soundFile = logEvent.Sound;

            if (String.IsNullOrWhiteSpace(soundFile))
            {
                return(null);
            }

            return(() => SoundPlayerHelper.PlayCached(soundFile, volume));
        }
예제 #8
0
        public static void LoadAndCacheSounds()
        {
            //PluginViewModel.Instance.SoundFiles.Clear();
            //do your gui stuff here
            var legacyFiles = new List <FileInfo>();
            var filters     = new List <string>
            {
                "*.wav",
                "*.mp3"
            };

            foreach (var filter in filters)
            {
                var files = Directory.GetFiles(Constants.BaseDirectory, filter, SearchOption.AllDirectories)
                            .Select(file => new FileInfo(file));
                legacyFiles.AddRange(files);
            }
            foreach (var legacyFile in legacyFiles)
            {
                if (legacyFile.DirectoryName == null)
                {
                    continue;
                }
                var baseKey = legacyFile.DirectoryName.Replace(Constants.BaseDirectory, "");
                var key     = String.IsNullOrWhiteSpace(baseKey) ? legacyFile.Name : String.Format("{0}\\{1}", baseKey.Substring(1), legacyFile.Name);
                if (File.Exists(Path.Combine(FFXIVAPP.Common.Constants.SoundsPath, key)))
                {
                    continue;
                }
                try
                {
                    var directoryKey = String.IsNullOrWhiteSpace(baseKey) ? "" : baseKey.Substring(1);
                    var directory    = Path.Combine(FFXIVAPP.Common.Constants.SoundsPath, directoryKey);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    File.Copy(legacyFile.FullName, Path.Combine(FFXIVAPP.Common.Constants.SoundsPath, key));
                    SoundPlayerHelper.TryGetSetSoundFile(key);
                }
                catch (Exception)
                {
                }
            }

            var cachedSoundFiles = SoundPlayerHelper.SoundFileKeys()
                                   .Except(PluginViewModel.Instance.SoundFiles);

            foreach (var cachedSoundFile in cachedSoundFiles)
            {
                PluginViewModel.Instance.SoundFiles.Add(cachedSoundFile);
            }
        }
 public static void Process(ChatLogEntry chatLogEntry)
 {
     try
     {
         var line = chatLogEntry.Line.Replace("  ", " ");
         foreach (var item in PluginViewModel.Instance.Events)
         {
             if (!item.Enabled)
             {
                 continue;
             }
             var resuccess = false;
             var check     = new Regex(item.RegEx);
             if (SharedRegEx.IsValidRegex(item.RegEx))
             {
                 var reg = check.Match(line);
                 if (reg.Success)
                 {
                     resuccess = true;
                 }
             }
             else
             {
                 resuccess = (item.RegEx == line);
             }
             if (!resuccess)
             {
                 continue;
             }
             var         soundEvent = item;
             Func <bool> playSound  = delegate
             {
                 var delay = soundEvent.Delay;
                 var timer = new Timer(delay > 0 ? delay * 1000 : 1);
                 ElapsedEventHandler timerEventHandler = null;
                 timerEventHandler = delegate
                 {
                     DispatcherHelper.Invoke(() => SoundPlayerHelper.Play(Constants.BaseDirectory, soundEvent.Sound));
                     timer.Elapsed -= timerEventHandler;
                 };
                 timer.Elapsed += timerEventHandler;
                 timer.Start();
                 return(true);
             };
             playSound.BeginInvoke(null, null);
         }
     }
     catch (Exception ex)
     {
         Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
     }
 }
예제 #10
0
        private static void TestSound()
        {
            var volume = Convert.ToInt32((MainView.View.TVolume.Value * 100) * Settings.Default.GlobalVolume);

            if (!string.IsNullOrWhiteSpace(MainView.View.TSound.Text))
            {
                SoundPlayerHelper.PlayCached(MainView.View.TSound.Text, volume);
            }
            if (!string.IsNullOrWhiteSpace(MainView.View.TTTS.Text))
            {
                TTSPlayer.Speak(MainView.View.TTTS.Text, volume, (int)MainView.View.TRate.Value);
            }
        }
예제 #11
0
        /// <summary>
        /// alarm
        /// </summary>
        /// <param name="activeAlarmList"></param>
        private static void DoAlarm(List <GathererInfo> activeAlarmList)
        {
            if (!Properties.Settings.Default.IsEnabledAlarm)
            {
                return;
            }
            if (Properties.Settings.Default.AlarmSoundFile.Trim() == "")
            {
                return;
            }
            var volume = Properties.Settings.Default.AlarmVolume * 100;

            SoundPlayerHelper.PlayCached(SettingsView.View.TSound.Text, (int)volume);
        }
        public void ExecutePlaceOrderData(object para)
        {
            try
            {
                DelegationModel rtm = para as DelegationModel;
                //添加持仓集合
                if (!rtm.bLast)
                {
                    VarietyModel vm     = null;
                    string[]     values = rtm.contract_id.Split(' ');
                    if (values.Length == 3)
                    {
                        string varietie = values[1];
                        if (ContractVariety.Varieties.ContainsKey(varietie))
                        {
                            vm = ContractVariety.Varieties[varietie];
                        }
                        if (vm != null)
                        {
                            rtm.precision = vm.precision;
                        }
                    }
                }
                if (OrderCancelViewModel.Instance().Delegations.FirstOrDefault(x => x.OrderId == rtm.order_id) == null)
                {
                    OrderCancelViewModel.Instance().Delegations.Add(new DelegationModelViewModel(rtm));
                    LogHelper.Info("4002 增加" + rtm.contract_code + ":" + rtm.direction + ":" + rtm.open_offset + ":" + rtm.order_status);
                }

                if (CommParameterSetting.MessageAlert.OrderAlert == "窗口提示")
                {
                    MessageBox.Show(rtm.contract_id + " 委托创建成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (CommParameterSetting.MessageAlert.OrderAlert == "声音提示")
                {
                    SoundPlayerHelper.Play();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }
예제 #13
0
 /// <summary>
 /// </summary>
 public static void LoadSoundsIntoCache()
 {
     SoundPlayerHelper.CacheSoundFiles();
 }
        public void ExecuteSendPlaceOrderData(object para)
        {
            try
            {
                DelegationModel rtm    = para as DelegationModel;
                VarietyModel    vm     = null;
                string[]        values = rtm.contract_code.Split(' ');
                if (values.Length == 3)
                {
                    string varietie = values[1];
                    if (ContractVariety.Varieties.ContainsKey(varietie))
                    {
                        vm = ContractVariety.Varieties[varietie];
                    }
                    if (vm != null)
                    {
                        rtm.precision = vm.precision;
                    }
                }

                DelegationModelViewModel dmvm = OrderCancelViewModel.Instance().Delegations.FirstOrDefault(x => x.OrderId == rtm.order_id);
                if (dmvm == null)
                {
                    return;
                    //OrderCancelViewModel.Instance().Delegations.Add(new DelegationModelViewModel(rtm));
                }
                //DelegationModelViewModel dmvmisHave = OrderCancelViewModel.Instance().Delegations.FirstOrDefault(x => x.OrderId == rtm.order_id && x.OrderStatus == (int)DeleteType.CreateSuccess);
                ////if (dmvmisHave != null)
                //{
                //    return;
                //    //OrderCancelViewModel.Instance().Delegations.Add(new DelegationModelViewModel(rtm));
                //}
                if (rtm.order_status == (int)DeleteType.CreateSuccess || rtm.order_status == (int)DeleteType.PortionTakeEffect)
                {
                    DelegationModelViewModel dmvm1 = OrderCancelViewModel.Instance().KCDelegations.FirstOrDefault(x => x.OrderId == rtm.order_id && rtm.user_id == UserInfoHelper.UserId);
                    if (dmvm1 == null)
                    {
                        OrderCancelViewModel.Instance().KCDelegations.Add(new DelegationModelViewModel(rtm));
                        LogHelper.Info("4003  增加 可撤" + rtm.contract_code + ":" + rtm.direction + ":" + rtm.open_offset + ":" + rtm.order_status);
                    }

                    dmvm.OrderStatus = rtm.order_status;
                    //详细状态
                    dmvm.FailMsg = rtm.fail_msg;
                }
                else
                {
                    dmvm.LeftVolume  = dmvm.OrderVolume - rtm.trade_volume;
                    dmvm.TradeVolume = rtm.trade_volume;
                    dmvm.OrderStatus = rtm.order_status;
                    dmvm.LeftVolume  = rtm.left_volume;

                    //详细状态
                    dmvm.FailMsg = rtm.fail_msg;
                    DelegationModelViewModel dmvm1 = OrderCancelViewModel.Instance().KCDelegations.FirstOrDefault(x => x.OrderId == rtm.order_id && rtm.user_id == UserInfoHelper.UserId);

                    if (dmvm1 != null)
                    {
                        OrderCancelViewModel.Instance().KCDelegations.Remove(dmvm1);
                        LogHelper.Info("4003  移除 可撤" + rtm.contract_code + ":" + rtm.direction + ":" + rtm.open_offset + ":" + rtm.order_status);
                    }
                }

                DelegationModelViewModel tem1 = OrderCancelViewModel.Instance().KCDelegations.FirstOrDefault(x => x.OrderId == rtm.order_id && rtm.user_id == UserInfoHelper.UserId);
                if (tem1 != null)
                {
                    tem1.LeftVolume  = tem1.OrderVolume - rtm.trade_volume;
                    tem1.TradeVolume = rtm.trade_volume;
                    tem1.OrderStatus = rtm.order_status;
                    //详细状态
                    dmvm.FailMsg = rtm.fail_msg;
                }
                if (rtm.order_status == (int)DeleteType.UnTakeEffecUserCannel)
                {
                    if (CommParameterSetting.MessageAlert.RevokeAlert == "窗口提示")
                    {
                        MessageBox.Show(rtm.contract_id + " 委托撤单成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (CommParameterSetting.MessageAlert.RevokeAlert == "声音提示")
                    {
                        SoundPlayerHelper.Play();
                    }
                }
                TransactionViewModel.Instance().SelectNumExecuteChanged();
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }
        public void ExecuteTransactionInfoData(object para)
        {
            try
            {
                TransactionInfoModel tim = para as TransactionInfoModel;
                if (tim == null)
                {
                    return;
                }
                if (TodayTraderViewModels.Instance().TodayTraderList.FirstOrDefault(x => x.ShadowTradeID == tim.shadow_tradeID) != null)
                {
                    return;
                }
                TodayTraderModel ttm = new TodayTraderModel();
                ttm.contract_code  = tim.contract_code;
                ttm.direction      = tim.direction;
                ttm.open_offset    = tim.open_offset;
                ttm.order_id       = tim.order_id;
                ttm.price_type     = tim.price_type;
                ttm.shadow_orderID = tim.shadow_orderID;
                ttm.trade_id       = tim.trade_number;
                ttm.contract_id    = tim.contract_id;
                ttm.shadow_tradeID = tim.shadow_tradeID;
                ttm.trade_date     = tim.trade_date;
                ttm.trade_id       = tim.trade_id;
                ttm.trade_price    = tim.trade_price;
                ttm.trade_time     = tim.trade_time;
                ttm.trade_volume   = tim.trade_volume;
                VarietyModel vm     = null;
                string[]     values = ttm.contract_code.Split(' ');
                if (values.Length == 3)
                {
                    string varietie = values[1];
                    if (ContractVariety.Varieties.ContainsKey(varietie))
                    {
                        vm = ContractVariety.Varieties[varietie];
                    }
                    if (vm != null)
                    {
                        ttm.precision = vm.precision;
                    }
                }
                TodayTraderViewModels.Instance().TodayTraderList.Add(new TodayTraderModelViewModel(ttm));
                Dictionary <string, TodayTraderModelViewModel> dicTTVM = new Dictionary <string, TodayTraderModelViewModel>();
                foreach (TodayTraderModelViewModel item in TodayTraderViewModels.Instance().TodayTraderList)
                {
                    if (!dicTTVM.ContainsKey(item.ContractCode + item.Direction + item.OpenOffset))
                    {
                        TodayTraderModelViewModel ttmvm = item.Clone(item);
                        ttmvm.AllPrice = item.TradePrice * item.TradeVolume;
                        dicTTVM.Add(item.ContractCode + item.Direction + item.OpenOffset, ttmvm);
                    }
                    else
                    {
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice    = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice + item.TradePrice * item.TradeVolume;
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume + item.TradeVolume;
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradePrice  = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice / dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume;
                    }
                }
                if (dicTTVM != null && dicTTVM.Values.Count > 0)
                {
                    TodayTraderViewModels.Instance().TodayTraderListALL.Clear();

                    foreach (TodayTraderModelViewModel item in dicTTVM.Values)
                    {
                        TodayTraderViewModels.Instance().TodayTraderListALL.Add(item);
                    }
                }
                if (CommParameterSetting.MessageAlert.TradeAlert == "窗口提示")
                {
                    // string msg = "\t合约已成交\t" + "\n\n" + ttm.contract_id + "\n\t" + "方向:" + (ttm.direction == "B" ? "买" : "卖") + "\n\t开平:" + (ttm.open_offset == 1 ? "开仓" : "平仓") + "\n\t成交数量:" + ttm.trade_volume + "\n\t成交价格" + ttm.trade_price;
                    string msg = "     " + ttm.contract_id + "\t" + "    方向:" + (ttm.direction == "B" ? "买" : "卖") + "\t\n     开平:" + (ttm.open_offset == 1 ? "开仓" : "平仓") + "\t    成交数量:" + ttm.trade_volume + "\t\n     成交价格" + ttm.trade_price + "\t" + "    已成交";
                    MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    LogHelper.Info(msg + "成交时间:");
                }
                else if (CommParameterSetting.MessageAlert.TradeAlert == "声音提示")
                {
                    SoundPlayerHelper.Play();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }
예제 #16
0
 /// <summary>
 /// </summary>
 public static void ChangeAudioMode()
 {
     SoundPlayerHelper.CacheSoundFiles();
 }