Esempio n. 1
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);
                    }
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
        }