Exemple #1
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string targetDir = DownloadableAudioListProcessor.SoundsPath;

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }
            Dictionary <string, string> audioInfo = (this.pnlList.Controls[_RealDownloadIndex] as SndDownloadInfo).Tag as Dictionary <string, string>;
            string strException;

            if (!DownloadableAudioListProcessor.DownloadAudioXml(audioInfo["audio_xml"], targetDir, true, out strException))
            {
                MessageBox.Show(string.Format("دریافت فایل XML خوانش {0} با خطا مواجه شد.", DownloadableAudioListProcessor.SuggestTitle((this.pnlList.Controls[_RealDownloadIndex] as SndDownloadInfo).Tag as Dictionary <string, string>)), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
            }
            else
            {
                string sFileDownloaded = DownloadUtilityClass.DownloadFileIgnoreFail(
                    ((this.pnlList.Controls[_RealDownloadIndex] as SndDownloadInfo).Tag as Dictionary <string, string>)["audio_mp3"],
                    targetDir,
                    this.backgroundWorker, out string expString);
                if (!string.IsNullOrEmpty(sFileDownloaded))
                {
                    _DownloadedSounds.Add(audioInfo);
                }
                else
                if (_RealDownloadIndex >= 0)
                {
                    MessageBox.Show(string.Format("دریافت فایل صوتی خوانش {0} با خطا مواجه شد.\n{1}", DownloadableAudioListProcessor.SuggestTitle((this.pnlList.Controls[_RealDownloadIndex] as SndDownloadInfo).Tag as Dictionary <string, string>), expString), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                }
            }
        }
Exemple #2
0
        public override void OnActivated()
        {
            if (OnInstallStarted != null)
            {
                OnInstallStarted(this, new EventArgs());
            }
            DbBrowser db = new DbBrowser();

            Application.DoEvents();
            string targetDir = DownloadableAudioListProcessor.SoundsPath;

            if (DownloadedSounds != null)
            {
                foreach (Dictionary <string, string> audioInfo in DownloadedSounds)
                {
                    grdList.Rows[grdList.Rows.Add()].Cells[0].Value = DownloadableAudioListProcessor.SuggestTitle(audioInfo);
                    string    mp3FilePath = Path.Combine(targetDir, Path.GetFileName(new Uri(audioInfo["audio_mp3"]).LocalPath));
                    PoemAudio poemAudio   = db.AddAudio(
                        Int32.Parse(audioInfo["audio_post_ID"]),
                        mp3FilePath,
                        DownloadableAudioListProcessor.SuggestTitle(audioInfo),
                        Int32.Parse(audioInfo["audio_order"])
                        );
                    string           xmlFilePath  = Path.Combine(targetDir, Path.GetFileName(new Uri(audioInfo["audio_xml"]).LocalPath));
                    List <PoemAudio> lstPoemAudio = PoemAudioListProcessor.Load(xmlFilePath);
                    if (lstPoemAudio.Count == 1)
                    {
                        foreach (PoemAudio xmlAudio in lstPoemAudio)
                        {
                            if (xmlAudio.PoemId == poemAudio.PoemId)
                            {
                                poemAudio.SyncArray = xmlAudio.SyncArray;
                                db.SavePoemSync(poemAudio, poemAudio.SyncArray, false);
                                poemAudio.SyncGuid = Guid.Parse(audioInfo["audio_guid"]);
                                db.WritePoemAudioGuid(poemAudio);
                                db.DeleteAudioWithSync(xmlAudio.PoemId, xmlAudio.SyncGuid, poemAudio.Id);
                                File.Delete(xmlFilePath); //not needed any more
                                grdList.Rows[grdList.RowCount - 1].Cells[1].Value = "نصب شد.";
                                InstalledFilesCount++;
                            }
                        }
                    }
                    else
                    {
                        grdList.Rows[grdList.RowCount - 1].Cells[1].Value = "خطا: فایل xml محتوی اطلاعات همگامسازی یک سطر نیست.";
                    }
                    Application.DoEvents();
                }
            }
            db.CloseDb();
            if (OnInstallFinished != null)
            {
                OnInstallFinished(this, new EventArgs());
            }
        }
Exemple #3
0
        //دریافت فهرست
        private async Task <bool> RetrieveList()
        {
            bool reS = true;
            var  r   = await _RetrieveDictionaryListAsync();

            if (!string.IsNullOrEmpty(r.Item2))
            {
                MessageBox.Show(r.Item2, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                reS = false;
            }
            else
            {
                _Lst = r.Item1;

                DbBrowser db = new DbBrowser();

                //در صورتی که تمام خوانشهای موجود را دریافت می‌کنیم برای تعیین وجود فایل صوتی از روش بهینه‌تری استفاده می‌کنیم.
                PoemAudio[] poemAudios = null;
                if (_PoemId == 0)
                {
                    poemAudios = db.GetAllPoemAudioFiles();
                }

                grdList.Columns.Clear();
                DataTable tbl = new DataTable();
                tbl.Columns.Add("عنوان");
                tbl.Columns.Add("اندازه");
                tbl.Columns.Add("دریافت", typeof(bool));

                int firstSuggestableDownload = -1;
                int idx = -1;

                foreach (Dictionary <string, string> audioInfo in _Lst)
                {
                    idx++;
                    int  nPoemId = Convert.ToInt32(audioInfo["audio_post_ID"]);
                    bool haveIt  =
                        _PoemId == 0 ?
                        poemAudios.Where(p => p.SyncGuid.ToString() == audioInfo["audio_guid"]).FirstOrDefault() != null
                        :
                        db.PoemAudioExists(nPoemId, audioInfo["audio_guid"]);

                    if (!haveIt && firstSuggestableDownload == -1)
                    {
                        firstSuggestableDownload = idx;
                    }

                    tbl.Rows.Add(
                        DownloadableAudioListProcessor.SuggestTitle(audioInfo),
                        (int.Parse(audioInfo["audio_mp3bsize"]) / 1024.0 / 1024.0).ToString("0.00") + " مگابایت",
                        !haveIt
                        );
                }
                db.CloseDb();

                grdList.DataSource = tbl;

                grdList.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                grdList.Columns[0].FillWeight   = 50;
                grdList.Columns[1].Width        = 110;
                grdList.Columns[2].Width        = 50;

                foreach (DataGridViewRow row in grdList.Rows)
                {
                    row.Tag = !((bool)row.Cells[GRDCLMN_CHECK].Value);
                }
                if (firstSuggestableDownload != -1)
                {
                    grdList.FirstDisplayedScrollingRowIndex = firstSuggestableDownload;
                }
                EnableDownloadCheckedButton();
            }


            return(reS);
        }
Exemple #4
0
 public SndDownloadInfo(Dictionary <string, string> audioInfo)
 {
     InitializeComponent();
     this.Tag             = audioInfo;
     this.lblSndName.Text = DownloadableAudioListProcessor.SuggestShortTitle(audioInfo);
 }