Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// اضافه کردن فایل صوتی جدید
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog())
     {
         openFileDialog.Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             string strDesc = "فایل صوتی " + _DbBrowser.GetPoem(_PoemId)._Title;
             if (grdList.Rows.Count > 0)
             {
                 strDesc += (" (" + (grdList.Rows.Count + 1).ToString() + ")");
             }
             using (ItemEditor itemEditor = new ItemEditor(EditItemType.General, "شرح فایل", "شرح فایل"))
             {
                 itemEditor.ItemName = strDesc;
                 if (itemEditor.ShowDialog(this) == DialogResult.Cancel)
                 {
                     return;
                 }
                 strDesc = itemEditor.ItemName;
             }
             PoemAudio newAudio = _DbBrowser.AddAudio(_PoemId, openFileDialog.FileName, strDesc);
             if (newAudio != null)
             {
                 grdList.Rows[AddAudioInfoToGrid(newAudio)].Selected = true;
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void btnSync_Click(object sender, EventArgs e)
        {
            if (grdList.SelectedRows.Count == 0)
            {
                MessageBox.Show("لطفاً ردیفی را انتخاب کنید.");
                return;
            }

            if (_PoemAudioPlayer != null)
            {
                _PoemAudioPlayer.CleanUp();
            }
            PoemAudio poemAudio = grdList.SelectedRows[0].Tag as PoemAudio;

            using (SyncPoemAudio dlg = new SyncPoemAudio(_DbBrowser, poemAudio))
            {
                dlg.ShowDialog(this);
                if (dlg.Saved)
                {
                    poemAudio.SyncArray = _DbBrowser.GetPoemSync(poemAudio);
                    _DbBrowser.ReadPoemAudioGuid(ref poemAudio);
                    grdList.SelectedRows[0].Cells[GRDCOLUMN_IDX_SYNCED].Value = poemAudio.IsSynced;
                }
            }
        }
Ejemplo n.º 4
0
        private void Export(bool bFix)
        {
            if (grdList.SelectedRows.Count == 0)
            {
                MessageBox.Show("لطفاً ردیفی را انتخاب کنید.");
                return;
            }
            PoemAudio poemAudio = grdList.SelectedRows[0].Tag as PoemAudio;

            if (!poemAudio.IsSynced)
            {
                MessageBox.Show("ردیف جاری همگام نشده است.");
                return;
            }
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter   = "XML Files (*.xml)|*.xml";
                dlg.FileName = System.IO.Path.GetFileNameWithoutExtension(poemAudio.FilePath);

                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    List <PoemAudio> lst = new List <PoemAudio>();
                    lst.Add(poemAudio);
                    if (PoemAudioListProcessor.Save(dlg.FileName, lst, bFix))
                    {
                        MessageBox.Show("فایل به درستی در مسیر انتخاب شده ذخیره شد.", "اعلان", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                    }
                    else
                    {
                        MessageBox.Show("خطایی در ذخیرۀ فایل رخ داد.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                    }
                }
            }
        }
        /// <summary>
        /// ذخیره در فایل
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="poemAudio"></param>
        /// <param name="oldVersion"></param>
        /// <returns></returns>
        public static bool Save(string FileName, PoemAudio poemAudio, bool oldVersion)
        {
            List <PoemAudio> lst = new List <PoemAudio>();

            lst.Add(poemAudio);
            return(Save(FileName, lst, oldVersion));
        }
Ejemplo n.º 6
0
        public SyncPoemAudio(DbBrowser dbBrowser, PoemAudio poemAudio)
        {
            InitializeComponent();

            _DbBrowser = dbBrowser;
            _PoemAudio = poemAudio;

            _PoemAudioPlayer = new PoemAudioPlayer();
            _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted);
            _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped);

            _Modified       = false;
            _Saved          = false;
            _SyncOrder      = -1;
            _LastSearchText = "";
            if (poemAudio.SyncArray != null)
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(poemAudio.SyncArray);
            }
            else
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>();
            }

            _PoemVerses = _DbBrowser.GetVerses(poemAudio.PoemId).ToArray();

            EnableButtons();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// اضافه کردن اطلاعات یک ردیف به گرید
        /// </summary>
        /// <param name="Audio"></param>
        private int AddAudioInfoToGrid(PoemAudio Audio)
        {
            int nRowIdx = grdList.Rows.Add();

            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_POET].Value  = Audio.PoetName;
            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_TITLE].Value = Audio.PoemTitle;
            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_DESC].Value  = Audio.Description;
            grdList.Rows[nRowIdx].Tag = Audio;
            return(nRowIdx);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// اضافه کردن اطلاعات یک ردیف به گرید
        /// </summary>
        /// <param name="Audio"></param>
        private int AddAudioInfoToGrid(PoemAudio Audio)
        {
            int nRowIdx = grdList.Rows.Add();

            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_DESC].Value     = Audio.Description;
            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_FILEPATH].Value = Audio.FilePath;
            grdList.Rows[nRowIdx].Cells[GRDCOLUMN_IDX_SYNCED].Value   = Audio.IsSynced;
            grdList.Rows[nRowIdx].Tag = Audio;
            return(nRowIdx);
        }
Ejemplo n.º 9
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());
            }
        }
Ejemplo n.º 10
0
 private void btnPlayAudio_Click(object sender, EventArgs e)
 {
     if (ganjoorView.IsPlaying)
     {
         ganjoorView.Pause();
         mnuPlayAudio.Text  = btnPlayAudio.Text = "ادامه";
         mnuPlayAudio.Image = btnPlayAudio.Image = Properties.Resources.play;
         return;
     }
     if (ganjoorView.IsInPauseState)
     {
         ganjoorView.Resume();
         mnuPlayAudio.Text  = btnPlayAudio.Text = "توقف";
         mnuPlayAudio.Image = btnPlayAudio.Image = Properties.Resources.pause;
         return;
     }
     PoemAudio[] poemAudioFiles = this.ganjoorView.PoemAudioFiles;
     if (poemAudioFiles.Length == 0)
     {
         ManagePoemAudioFiles();
     }
     else
     {
         PoemAudio poemAudio = poemAudioFiles[0];
         if (poemAudioFiles.Length > 1)
         {
             ItemSelector dlg = new ItemSelector("گزینش خوانش ...", poemAudioFiles, poemAudio);
             if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
             {
                 poemAudio = dlg.SelectedItem as PoemAudio;
             }
             else
             {
                 return;
             }
         }
         ganjoorView.Play(poemAudio);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// پخش و ایست پخش فایل صوتی
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPlayStop_Click(object sender, EventArgs e)
        {
            if (_PoemAudioPlayer != null)
            {
                if (_PoemAudioPlayer.IsPlaying)
                {
                    _PoemAudioPlayer.StopPlayBack();
                    return;
                }
            }
            if (grdList.SelectedRows.Count == 0)
            {
                MessageBox.Show("لطفاً ردیفی را انتخاب کنید.");
                return;
            }

            if (_PoemAudioPlayer == null)
            {
                _PoemAudioPlayer = new PoemAudioPlayer();
                _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted);
                _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped);
            }
            PoemAudio poemAudio = grdList.SelectedRows[0].Tag as PoemAudio;

            if (!_PoemAudioPlayer.BeginPlayback(poemAudio))
            {
                btnPlayStop.Text  = "پخش";
                btnPlayStop.Image = Properties.Resources.play16;

                MessageBox.Show("خطایی در پخش فایل صوتی رخ داد. لطفا چک کنید فایل در مسیر تعیین شده قرار داشته باشد.");
            }

            if (poemAudio != null && poemAudio.SyncArray != null && poemAudio.SyncArray[0].VerseOrder == -1)
            {
                _PoemAudioPlayer.PositionInMiliseconds = poemAudio.SyncArray[0].AudioMiliseconds;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// شروع پخش
        /// </summary>
        /// <param name="poemAudio"></param>
        public bool BeginPlayback(PoemAudio poemAudio)
        {
            if (this.wavePlayer != null)
            {
                Debug.Assert(false);
                return(false);
            }
            if (!File.Exists(poemAudio.FilePath))
            {
                return(false);
            }
            this.PoemAudio  = poemAudio;
            this.wavePlayer = new WaveOut();
            this.file       = new AudioFileReader(poemAudio.FilePath);
            this.wavePlayer.Init(file);
            this.wavePlayer.PlaybackStopped += wavePlayer_PlaybackStopped;
            this.wavePlayer.Play();

            if (PlaybackStarted != null)
            {
                PlaybackStarted(this, new EventArgs());
            }
            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// پشتیبان‌گیری
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExport_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dlg = new FolderBrowserDialog())
            {
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string strOutDir = dlg.SelectedPath;
                    bool   bIsEmpty  = Directory.GetFiles(strOutDir).Length == 0;
                    if (!bIsEmpty)
                    {
                        if (MessageBox.Show("مسیر انتخاب شده خالی نیست. آیا از انتخاب این مسیر اطمینان دارید؟", "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == System.Windows.Forms.DialogResult.No)
                        {
                            return;
                        }
                    }

                    prgss.Maximum = grdList.RowCount;
                    prgss.Value   = 0;
                    this.Enabled  = false;

                    foreach (DataGridViewRow Row in grdList.Rows)
                    {
                        prgss.Value++;
                        bool bRes = true;
                        Row.Selected = true;
                        grdList.FirstDisplayedCell = Row.Cells[0];
                        Application.DoEvents();
                        PoemAudio audio = Row.Tag as PoemAudio;
                        if (audio == null)
                        {
                            bRes = false;
                        }
                        audio.SyncArray = _DbBrowser.GetPoemSync(audio);
                        if (bRes)
                        {
                            string outFileName = Path.Combine(strOutDir, Path.GetFileName(audio.FilePath));
                            if (!File.Exists(audio.FilePath))
                            {
                                bRes = false;
                            }
                            if (bRes)
                            {
                                if (File.Exists(outFileName))
                                {
                                    outFileName = Path.Combine(strOutDir, audio.PoemId.ToString() + ".mp3");
                                }

                                if (File.Exists(outFileName))
                                {
                                    outFileName = Path.Combine(strOutDir, audio.SyncGuid.ToString() + ".mp3");
                                }

                                string xmlFilePath = Path.Combine(strOutDir, Path.GetFileNameWithoutExtension(outFileName) + ".xml");
                                if (bRes)
                                {
                                    if (!PoemAudioListProcessor.Save(xmlFilePath, audio, false))
                                    {
                                        bRes = false;
                                    }
                                }

                                if (bRes)
                                {
                                    try
                                    {
                                        File.Copy(audio.FilePath, outFileName, true);
                                    }
                                    catch
                                    {
                                        bRes = false;
                                        File.Delete(xmlFilePath);
                                    }
                                }
                            }
                        }

                        Row.DefaultCellStyle.BackColor = bRes ? Color.LightGreen : Color.Red;
                    }

                    this.Enabled = true;

                    MessageBox.Show("فرایند پشتیبانگیری انجام شد. ردیفهای قرمزرنگ به دلایلی از قبیل عدم وجود فایل صوتی دارای اشکال بوده‌اند.", "اعلان", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
                }
            }
        }
Ejemplo n.º 14
0
        private async void btnUpload_ClickAsync(object sender, EventArgs e)
        {
            if (grdList.SelectedRows.Count == 0)
            {
                MessageBox.Show("لطفاً ابتدا فایل معادل اطلاعات همگام‌سازی را اضافه کرده، آن را انتخاب کنید.");
                return;
            }

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

            if (!poemAudio.IsSynced)
            {
                MessageBox.Show("لطفا ابتدا خوانش را همگام کنید.");
                return;
            }

            if (Path.GetExtension(poemAudio.FilePath).ToLower() != ".mp3")
            {
                MessageBox.Show("تنها پسوند mp3 برای فایلهای صوتی قابل بارگذاری است.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                return;
            }

            if (!File.Exists(poemAudio.FilePath))
            {
                MessageBox.Show("فایل صوتی متناظر وجود ندارد.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                return;
            }

            bool valid = await TokenIsValid();

            if (!valid)
            {
                using (GLogin gLogin = new GLogin())
                    if (gLogin.ShowDialog(this) != DialogResult.OK)
                    {
                        Cursor = Cursors.Default;
                        Application.DoEvents();
                        return;
                    }
                if (!await TokenIsValid())
                {
                    Cursor = Cursors.Default;
                    Application.DoEvents();
                    return;
                }
            }
            Cursor = Cursors.Default;
            Application.DoEvents();
            if (string.IsNullOrEmpty(Properties.Settings.Default.MuseumToken))
            {
                return;
            }

            if (string.IsNullOrEmpty(Properties.Settings.Default.DefProfile))
            {
                MessageBox.Show("لطفا به پیشخان وارد شوید و در قسمت نمایه‌ها، نمایه‌ای را به عنوان نمایهٔ پیش‌فرض تعریف یا فعال کنید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                Process.Start("https://gaudiopanel.ganjoor.net");
                return;
            }

            bool replaceOldAudio = false;

            using (ConfirmAudioUpload confirmDlg = new ConfirmAudioUpload(Properties.Settings.Default.DefProfile))
            {
                var res = confirmDlg.ShowDialog(this);
                if (res == DialogResult.Cancel)
                {
                    return;
                }
                replaceOldAudio = res == DialogResult.Yes;
            }


            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Properties.Settings.Default.MuseumToken);

                Cursor = Cursors.WaitCursor;
                Application.DoEvents();

                MultipartFormDataContent form = new MultipartFormDataContent();

                string xmlTempPath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

                PoemAudioListProcessor.Save(xmlTempPath, poemAudio, false);
                byte[] xmlFileContent = File.ReadAllBytes(xmlTempPath);
                File.Delete(xmlTempPath);
                form.Add(new ByteArrayContent(xmlFileContent, 0, xmlFileContent.Length), $"{Path.GetFileNameWithoutExtension(poemAudio.FilePath)}.xml", $"{Path.GetFileNameWithoutExtension(poemAudio.FilePath)}.xml");


                byte[] mp3FileContent = File.ReadAllBytes(poemAudio.FilePath);
                form.Add(new ByteArrayContent(mp3FileContent, 0, mp3FileContent.Length), Path.GetFileName(poemAudio.FilePath), Path.GetFileName(poemAudio.FilePath));

                HttpResponseMessage response = await httpClient.PostAsync($"{Properties.Settings.Default.GanjoorServiceUrl}/api/audio?replace={replaceOldAudio}", form);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show(await response.Content.ReadAsStringAsync());
                    return;
                }

                response.EnsureSuccessStatusCode();
            }

            Cursor = Cursors.Default;

            MessageBox.Show("ارسال به سایت به درستی انجام شد.", "اعلان", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
        }
        /// <summary>
        /// بارگذاری از فایل
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public static List <PoemAudio> Load(string FileName)
        {
            List <PoemAudio> lstPoemAudio = new List <PoemAudio>();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(FileName));

            //Collect List:
            XmlNodeList poemAudioNodes = doc.GetElementsByTagName("PoemAudio");

            foreach (XmlNode poemAudioNode in poemAudioNodes)
            {
                PoemAudio poemAudioInfo = new PoemAudio();
                poemAudioInfo.IsDirectlyDownloadable = false;
                poemAudioInfo.IsUploaded             = false;
                foreach (XmlNode Node in poemAudioNode.ChildNodes)
                {
                    switch (Node.Name)
                    {
                    case "PoemId":
                        poemAudioInfo.PoemId = Convert.ToInt32(Node.InnerText);
                        break;

                    case "Id":
                        poemAudioInfo.Id = Convert.ToInt32(Node.InnerText);
                        break;

                    case "DownloadUrl":
                        poemAudioInfo.DownloadUrl = Node.InnerText;
                        break;

                    case "FilePath":
                        poemAudioInfo.FilePath = Node.InnerText;
                        break;

                    case "Description":
                        poemAudioInfo.Description = Node.InnerText;
                        break;

                    case "SyncGuid":
                        poemAudioInfo.SyncGuid = Guid.Parse(Node.InnerText);
                        break;

                    case "FileCheckSum":
                        poemAudioInfo.FileCheckSum = Node.InnerText;
                        break;

                    case "IsDirectlyDownloadable":
                        poemAudioInfo.IsDirectlyDownloadable = Convert.ToBoolean(Node.InnerText);
                        break;

                    case "IsUploaded":
                        poemAudioInfo.IsDirectlyDownloadable = Convert.ToBoolean(Node.InnerText);
                        break;

                    case "SyncArray":
                    {
                        XmlNodeList syncInfoNodeList = Node.SelectNodes("SyncInfo");
                        if (syncInfoNodeList != null)
                        {
                            List <PoemAudio.SyncInfo> lstSyncInfo = new List <PoemAudio.SyncInfo>();

                            foreach (XmlNode nodeSyncIndo in syncInfoNodeList)
                            {
                                lstSyncInfo.Add(
                                    new PoemAudio.SyncInfo()
                                    {
                                        VerseOrder       = Convert.ToInt32(nodeSyncIndo.SelectSingleNode("VerseOrder").InnerText),
                                        AudioMiliseconds = Convert.ToInt32(nodeSyncIndo.SelectSingleNode("AudioMiliseconds").InnerText),
                                    }
                                    );
                            }

                            if (lstSyncInfo.Count > 0)
                            {
                                poemAudioInfo.SyncArray = lstSyncInfo.ToArray();
                            }
                        }
                    }
                    break;
                    }
                }
                lstPoemAudio.Add(poemAudioInfo);
            }


            return(lstPoemAudio);
        }
Ejemplo n.º 16
0
        public SyncPoemAudio(DbBrowser dbBrowser, PoemAudio poemAudio)
        {
            InitializeComponent();

            _DbBrowser = dbBrowser;
            _PoemAudio = poemAudio;

            _PoemAudioPlayer = new PoemAudioPlayer();
            _PoemAudioPlayer.PlaybackStarted += new EventHandler(_PoemAudioPlayer_PlaybackStarted);
            _PoemAudioPlayer.PlaybackStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(_PoemAudioPlayer_PlaybackStopped);

            _Modified       = false;
            _Saved          = false;
            _SyncOrder      = -1;
            _LastSearchText = "";
            _Modifying      = false;
            _PoemVerses     = _DbBrowser.GetVerses(poemAudio.PoemId).ToArray();
            if (poemAudio.SyncArray != null)
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>(poemAudio.SyncArray);

                if (_VerseMilisecPositions.Count > 0 &&
                    _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].VerseOrder != (_PoemVerses[_PoemVerses.Length - 1]._Order - 1)
                    )
                {
                    if (MessageBox.Show("آیا تمایل دارید همگامسازی را از آخرین نقطهٔ همگام شده ادامه دهید؟", "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading) == DialogResult.Yes)
                    {
                        if (!_PoemAudioPlayer.BeginPlayback(_PoemAudio))
                        {
                            MessageBox.Show("خطایی در پخش فایل صوتی رخ داد. لطفا چک کنید فایل در مسیر تعیین شده قرار داشته باشد.");
                        }
                        else
                        {
                            _Modifying = true;

                            btnPlayPause.Text  = "توقف";
                            btnPlayPause.Image = Properties.Resources.pause;
                            timer.Start();
                            trackBar.Maximum = _PoemAudioPlayer.TotalTimeInMiliseconds;


                            _PoemAudioPlayer.PositionInMiliseconds = _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].AudioMiliseconds;
                            _TrackbarValueSetting = true;
                            trackBar.Value        = _PoemAudioPlayer.PositionInMiliseconds;
                            _TrackbarValueSetting = false;
                            trackBar.Enabled      = true;
                            btnPlayPause_Click(null, null);



                            _SyncOrder = _VerseMilisecPositions[_VerseMilisecPositions.Count - 1].VerseOrder;

                            if (_SyncOrder >= 0 && _SyncOrder < _PoemVerses.Length)
                            {
                                if (_SyncOrder < _PoemVerses.Length - 1)
                                {
                                    lblNextVerse.Text = "مصرع بعد: " + _PoemVerses[_SyncOrder + 1]._Text;
                                }
                                else
                                {
                                    lblNextVerse.Text = "این مصرع آخر است.";
                                }

                                lblVerse.Text = _PoemVerses[_VerseMilisecPositions[_SyncOrder].VerseOrder]._Text;
                            }
                        }
                    }
                }
            }
            else
            {
                _VerseMilisecPositions = new List <PoemAudio.SyncInfo>();
            }



            EnableButtons();
        }