/// <summary>
        /// 播放给定的曲谱
        /// </summary>
        /// <param name="pianoScore">需要播放的曲谱</param>
        public void PlaySelected(PianoScore pianoScore)
        {
            string flashPath = Environment.CurrentDirectory;

            flashPath += @"\Assets\flash\fuckTan8\Main.swf?id=" + pianoScore.id;
            //axShockwaveFlash.Movie = flashPath;
        }
Beispiel #2
0
 public AddSinglePianoScoreDialog(PianoScore pianoScore)
 {
     InitializeComponent();
     if (null != pianoScore)
     {
         TextBoxMsuicId.Text = Convert.ToString(pianoScore.id);
         //ID不能修改, 禁用输入框
         TextBoxMsuicId.IsEnabled = false;
         //禁用复选框
         AutoDownloadCheckBox.IsEnabled = false;
         TextBoxName.Text = pianoScore.Name;
     }
     DataContext = this;
 }
 /// <summary>
 /// 弹8曲谱下载完成事件
 /// </summary>
 /// <param name="pianoScore"></param>
 public void OnTan8SheetDownloadFinish(PianoScore pianoScore)
 {
     Dispatcher.Invoke(() =>
     {
         var dataRow      = SQLite.SqlRow(string.Format("SELECT id, ypid, name, strftime('%Y-%m-%d %H:%M:%S', create_time) create_time, result  FROM tan8_music_down_record WHERE ypid = {0} ORDER BY create_time DESC LIMIT 1", pianoScore.id));
         var context      = DataContext as PianoScoreDownloadRecordViewModel;
         var downloadList = context.DownloadRecordList;
         downloadList.Insert(0, new Tan8SheetDownloadRecord()
         {
             Id          = Convert.ToInt32(dataRow[0]),
             Ypid        = Convert.ToInt32(dataRow[1]),
             Name        = Convert.ToString(dataRow[2]),
             Create_time = Convert.ToString(dataRow[3]),
             Result      = Convert.ToString(dataRow[4])
         });
     });
 }
        /// <summary>
        /// 以递增方式复制ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCopyIncrIdContextMenuClick(object sender, RoutedEventArgs e)
        {
            //XamlUtil.SelectRow(DownloadRecordDataGrid, e);
            var record = DownloadRecordDataGrid.SelectedItem as Tan8SheetDownloadRecord;

            if (null == record)
            {
                return;
            }
            var pianoScore = new PianoScore()
            {
                autoDownload = true,
                id           = record.Ypid + 1
            };

            editConfirmHnadler?.Invoke(pianoScore);
        }
Beispiel #5
0
        /// <summary>
        /// 检查并将数据库所有曲目生成去水印封面
        /// </summary>
        /// <param name="dbPath">数据库路径</param>
        /// <param name="threadCount">最大线程数</param>
        private static void CheckWhiteBlackPreview(string dbPath, bool overwrite, int threadCount)
        {
            Console.WriteLine("执行水印任务, dbPath=" + dbPath + ", 线程数 = " + threadCount);
            InitDB(dbPath);
            var ypHomePath = ConfigUtil.Instance.Load().PianoScorePath;

            if (string.IsNullOrEmpty(ypHomePath))
            {
                Console.WriteLine("无法获取乐谱路径, 先检查一下配置文件");
                return;
            }
            ConcurrentQueue <PianoScore> sheetDirQueue = new ConcurrentQueue <PianoScore>();
            var dataSet = SQLite.SqlTable("SELECT ypid, name, yp_count FROM tan8_music", null);
            var total   = dataSet.Rows.Count;

            foreach (DataRow dataRow in dataSet.Rows)
            {
                if (Directory.Exists(Path.Combine(ypHomePath, Convert.ToString(dataRow["ypid"]))))
                {
                    Console.WriteLine(string.Format("正在添加 {0} 到任务队列...", dataRow["name"]));
                    sheetDirQueue.Enqueue(new PianoScore()
                    {
                        id      = Convert.ToInt32(dataRow["ypid"]),
                        Name    = dataRow["name"].ToString(),
                        YpCount = Convert.ToByte(dataRow["yp_count"])
                    });
                }
            }

            for (int i = 0; i < threadCount; i++)
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        PianoScore pianoScore = new PianoScore();
                        var isOk = sheetDirQueue.TryDequeue(out pianoScore);
                        if (isOk)
                        {
                            var sheetDir       = Path.Combine(ypHomePath, pianoScore.id.GetValueOrDefault().ToString());
                            var previewPicName = "public.png";
                            bool doProcess     = true;
                            //检查目标文件夹是否已经存在已处理的图片
                            if (File.Exists(Path.Combine(ypHomePath, sheetDir, previewPicName)))
                            {
                                doProcess = overwrite ? true : false;
                            }
                            if (!doProcess)
                            {
                                continue;
                            }
                            var sheetFiles = Directory.GetFiles(sheetDir);
                            foreach (var sheetFile in sheetFiles)
                            {
                                if (Path.GetFileName(sheetFile).Equals("page.0.png"))
                                {
                                    Console.WriteLine("剩余 : " + sheetDirQueue.Count + ", 当前 : " + Path.GetFileName(sheetDir));
                                    var sufId     = "(" + pianoScore.id.GetValueOrDefault() + ")";
                                    var titleName = pianoScore.Name.EndsWith(sufId) ? pianoScore.Name.Substring(0, pianoScore.Name.Length - sufId.Length) : pianoScore.Name;
                                    Bitmap rawImg = (Bitmap)Bitmap.FromFile(sheetFile);
                                    Bitmap bmp    = ImageUtil.CreateIegalTan8Sheet(rawImg, titleName, 1, pianoScore.YpCount, true);
                                    bmp.Save(Path.Combine(ypHomePath, sheetDir, previewPicName), ImageFormat.Png);
                                    bmp.Dispose();
                                }
                            }
                        }
                    }
                });
            }
            while (sheetDirQueue.Count > 0)
            {
                Thread.Sleep(1000);
            }
            //转换完毕打开目标文件夹
            Console.WriteLine("水印图片生成完毕");
        }
Beispiel #6
0
        /// <summary>
        /// 检查并上传乐谱图片
        /// </summary>
        /// <param name="dbPath"></param>
        /// <param name="threadCount"></param>
        private static void CheckSheetPreviewImg(string dbPath, int threadCount)
        {
            Console.WriteLine("执行上传乐谱首页任务, dbPath=" + dbPath + ", 线程数 = " + threadCount);
            InitDB(dbPath);
            var ypHomePath = ConfigUtil.Instance.Load().PianoScorePath;

            if (string.IsNullOrEmpty(ypHomePath))
            {
                Console.WriteLine("无法获取乐谱路径, 先检查一下配置文件");
                return;
            }
            ConcurrentQueue <PianoScore> sheetDirQueue = new ConcurrentQueue <PianoScore>();
            var dataSet = SQLite.SqlTable("SELECT ypid, name, yp_count FROM tan8_music WHERE ypid NOT IN (SELECT ypid FROM tan8_music_img)", null);
            var total   = dataSet.Rows.Count;

            Console.WriteLine("正在添加任务队列...");
            foreach (DataRow dataRow in dataSet.Rows)
            {
                if (Directory.Exists(Path.Combine(ypHomePath, Convert.ToString(dataRow["ypid"]))))
                {
                    sheetDirQueue.Enqueue(new PianoScore()
                    {
                        id      = Convert.ToInt32(dataRow["ypid"]),
                        Name    = dataRow["name"].ToString(),
                        YpCount = Convert.ToByte(dataRow["yp_count"])
                    });
                }
            }
            Console.WriteLine("共添加" + total + "项任务");

            List <ManualResetEvent> manualEvents = new List <ManualResetEvent>();

            for (int i = 0; i < threadCount; i++)
            {
                ManualResetEvent mre = new ManualResetEvent(false);
                manualEvents.Add(mre);
                ThreadPool.QueueUserWorkItem((object obj) =>
                {
                    while (sheetDirQueue.Count > 0)
                    {
                        PianoScore pianoScore = new PianoScore();
                        var isOk = sheetDirQueue.TryDequeue(out pianoScore);
                        if (isOk)
                        {
                            var sheetDir       = Path.Combine(ypHomePath, pianoScore.id.GetValueOrDefault().ToString());
                            var previewPicName = "public.png";
                            //检查目标文件夹是否已经存在已处理的图片
                            if (File.Exists(Path.Combine(ypHomePath, sheetDir, previewPicName)))
                            {
                                IImageRepo imageAPI = ImageRepoFactory.GetRandomApi();
                                //IImageRepo imageAPI = new PrntImageRepo();
                                ImageRepoUploadArg uploadArg = new ImageRepoUploadArg()
                                {
                                    FullFilePath = Path.Combine(ypHomePath, sheetDir, previewPicName),
                                    ExtraArgs    = new JObject
                                    {
                                        { "uploadFileFormName", "sheet_" + pianoScore.id + ".png" }
                                    }
                                };
                                InvokeResult <ImageRepoUploadResult> invokeResult;
                                try
                                {
                                    invokeResult = imageAPI.Upload(uploadArg);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("api {0}, 引发异常, {1}", imageAPI.GetApiCode(), e.Message);
                                    continue;
                                }
                                if (!invokeResult.success)
                                {
                                    Console.WriteLine(pianoScore.Name + "上传失败, msg=" + invokeResult.message);
                                    continue;
                                }
                                SQLite.ExecuteNonQuery("INSERT INTO tan8_music_img(ypid, yp_name, img_url, api, api_channel, create_time) VALUES (@ypid, @ypName, @imgUrl, @api, @apiChannel, datetime('now', 'localtime'))",
                                                       new List <SQLiteParameter>()
                                {
                                    new SQLiteParameter("@ypid", pianoScore.id.GetValueOrDefault()),
                                    new SQLiteParameter("@ypName", pianoScore.Name),
                                    new SQLiteParameter("@imgUrl", invokeResult.data.ImgUrl),
                                    new SQLiteParameter("@api", invokeResult.data.Api),
                                    new SQLiteParameter("@apiChannel", invokeResult.data.ApiChannel)
                                });
                                Console.WriteLine("剩余 : " + sheetDirQueue.Count);
                            }
                        }
                    }
                    ManualResetEvent localMre = (ManualResetEvent)obj;
                    localMre.Set();
                }, mre);
            }
            WaitHandle.WaitAll(manualEvents.ToArray());
            Console.WriteLine("乐谱图片上传完毕");
        }