コード例 #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (grdList.SelectedRows.Count == 0)
            {
                MessageBox.Show("لطفاً ابتدا فایل معادل اطلاعات همگام‌سازی را اضافه کرده، آن را انتخاب کنید.");
                return;
            }

            PoemAudio poemAudio = grdList.SelectedRows[0].Tag as PoemAudio;

            if (poemAudio.IsSynced)
            {
                if (MessageBox.Show(
                        String.Format("فایل انتخاب شده با شرح «{0}» و مسیر '{1}' در حال حاضر دارای اطلاعات همگام‌سازی است.\n" +
                                      "از جایگزینی این اطلاعات اطمینان دارید؟", poemAudio.Description, poemAudio.FilePath),
                        "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                        MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "XML Files (*.xml)|*.xml";
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    List <PoemAudio> lstPoemAudio = PoemAudioListProcessor.Load(dlg.FileName);
                    if (lstPoemAudio.Count == 0)
                    {
                        MessageBox.Show("فایل انتخاب شده حاوی اطلاعات همگام‌سازی شعرها نیست.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                        return;
                    }

                    foreach (PoemAudio xmlAudio in lstPoemAudio)
                    {
                        if (xmlAudio.PoemId == poemAudio.PoemId)
                        {
                            if (xmlAudio.FileCheckSum != PoemAudio.ComputeCheckSum(poemAudio.FilePath))
                            {
                                if (MessageBox.Show(
                                        "اطلاعات فایل همگام شده با فایل انتخاب شده همسانی ندارد. از استفاده از این اطلاعات اطمینان دارید؟",
                                        "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                                        MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == System.Windows.Forms.DialogResult.No)
                                {
                                    return;
                                }
                            }
                            _DbBrowser.SavePoemSync(poemAudio, xmlAudio.SyncArray, false);
                            poemAudio.SyncArray = xmlAudio.SyncArray;
                            poemAudio.SyncGuid  = xmlAudio.SyncGuid;
                            grdList.SelectedRows[0].Cells[GRDCOLUMN_IDX_SYNCED].Value = poemAudio.IsSynced;
                            return;
                        }
                    }

                    MessageBox.Show("فایل انتخاب شده حاوی اطلاعات همگام‌سازی شعر جاری نیست.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                }
            }
        }
コード例 #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());
            }
        }
コード例 #3
0
        /// <summary>
        /// بازگشت پشتیبان
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImport_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dlg = new FolderBrowserDialog())
            {
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string strInDir = dlg.SelectedPath;



                    string[] xmlFiles = Directory.GetFiles(strInDir, "*.xml");

                    if (xmlFiles.Length == 0)
                    {
                        MessageBox.Show("در مسیر انتخابی فایل XML وجود ندارد.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                        return;
                    }


                    prgss.Maximum = xmlFiles.Length;
                    prgss.Value   = 0;

                    this.Enabled = false;

                    int nErr = 0;
                    foreach (string xmlFile in xmlFiles)
                    {
                        prgss.Value++;
                        Application.DoEvents();

                        List <PoemAudio> lstPoemAudio = PoemAudioListProcessor.Load(xmlFile);

                        if (lstPoemAudio.Count == 1)
                        {
                            foreach (PoemAudio xmlAudio in lstPoemAudio)
                            {
                                string mp3FilePath = Path.Combine(strInDir, Path.GetFileNameWithoutExtension(xmlFile)) + Path.GetExtension(xmlAudio.FilePath);
                                if (!File.Exists(mp3FilePath))
                                {
                                    nErr++;
                                    break;
                                }

                                if (_DbBrowser.AddAudio(
                                        mp3FilePath,
                                        xmlAudio
                                        )
                                    == null)
                                {
                                    nErr++;
                                }
                            }
                        }
                        else
                        {
                            nErr++;
                        }
                    }//foreach

                    this.Enabled = true;

                    FillGrid();

                    if (nErr > 0)
                    {
                        MessageBox.Show(String.Format("خطا در اضافه کردن {0} مورد", nErr), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                    }
                    else
                    {
                        MessageBox.Show("فرایند بازگشت پشتیبان خوانشها بدون خطا انجام شد.", "اعلان", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                    }
                } //if
            }     //using
        }