Exemple #1
0
        private async Task UploadFile()
        {
            string serverDirPath = AppEnvironment.dataService.ServerUserDataDirPath + "/";

            await Task.Delay(10);

            try
            {
                UploadButton.IsEnabled = false;
                UploadButton.Text      = AppResources.Uploading;

                if (!FTPService.CheckDirExist(serverDirPath))
                {
                    FTPService.CreateDir(serverDirPath);
                }

                isUploaded = FTPService.UploadFile(recordFilePath, Path.Combine(serverDirPath, Path.GetFileName(recordFilePath)));

                if (!isUploaded)
                {
                    throw new Exception("Cannot upload file");
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                DependencyService.Get <IToast>().Show(ex.ToString());
#endif
                DependencyService.Get <IToast>().Show(AppResources.UploadFail_ReUpload);

                UploadButton.IsEnabled = true;
            }
            finally
            {
                UploadButton.Text      = AppResources.Upload;
                RecordButton.IsEnabled = true;
                RecordButton.Text      = File.Exists(recordFilePath) ? AppResources.Re_Record : AppResources.Record;
            }

            try
            {
                (BindingContext as VoiceRecordDetailViewModel).UpdateItemInfo(isRecorded, isUploaded);

                DependencyService.Get <IToast>().Show(AppResources.Upload_Success);
            }
            catch (Exception)
            {
                DependencyService.Get <IToast>().Show("Cannot update info");
            }
            finally
            {
                UploadButton.IsEnabled = true;
                UploadButton.Text      = isUploaded ? AppResources.ReUpload : AppResources.Upload;

                UpdateButtonStatus();

                recorder = null;
            }
        }
Exemple #2
0
        public bool UploadTable()
        {
            if (!FTPService.CheckDirExist(ServerUserDataDirPath))
            {
                FTPService.CreateDir(ServerUserDataDirPath);
            }

            return(FTPService.UploadFile(LocalDataFilePath, Path.Combine(ServerUserDataDirPath, serverFile)));
        }
Exemple #3
0
        public bool UploadFirstVoiceStatus()
        {
            string filePath   = Path.Combine(LocalDataPath, firstVoiceSetStatusFile);
            string serverPath = Path.Combine(ServerUserDataDirPath, firstVoiceSetStatusFile);

            if (!FTPService.CheckDirExist(ServerUserDataDirPath))
            {
                FTPService.CreateDir(ServerUserDataDirPath);
            }

            return(FTPService.UploadFile(filePath, serverPath));
        }
Exemple #4
0
        public async Task <ActionResult> EditarToque(ToqueModel toque)
        {
            if (VerificarLogin())
            {
                if ((toque.IsSegunda) ||
                    (toque.IsTerca) ||
                    (toque.IsQuarta) ||
                    (toque.IsQuinta) ||
                    (toque.IsSexta) ||
                    (toque.IsSabado) ||
                    (toque.IsDomingo))
                {
                    List <ToqueModel>       toques  = LerToquesCSV();
                    List <ToqueExportModel> toquesE = new List <ToqueExportModel>();

                    int i = 0;

                    foreach (var item in toques)
                    {
                        ToqueExportModel it = new ToqueExportModel();
                        it.Arquivo = item.Arquivo;
                        it.Nome    = item.Nome;
                        it.Hora    = item.Hora;
                        it.Canal   = item.Canal;
                        if (item.IsDomingo)
                        {
                            it.DiasSemana += ",0";
                        }
                        if (item.IsSegunda)
                        {
                            it.DiasSemana += ",1";
                        }
                        if (item.IsTerca)
                        {
                            it.DiasSemana += ",2";
                        }
                        if (item.IsQuarta)
                        {
                            it.DiasSemana += ",3";
                        }
                        if (item.IsQuinta)
                        {
                            it.DiasSemana += ",4";
                        }
                        if (item.IsSexta)
                        {
                            it.DiasSemana += ",5";
                        }
                        if (item.IsSabado)
                        {
                            it.DiasSemana += ",6";
                        }
                        it.DiasSemana  = it.DiasSemana.Substring(1);
                        it.IsAtivo     = item.IsAtivo;
                        it.NivelEnsino = item.NivelEnsino;
                        it.UltimoToque = item.UltimoToque;

                        toquesE.Add(it);
                    }
                    string arquivoId = "";
                    foreach (var item in toques)
                    {
                        if (item.Arquivo == toque.Arquivo)
                        {
                            toquesE[i].DiasSemana = "";
                            toquesE[i].Arquivo    = toque.Arquivo;
                            toquesE[i].Nome       = toque.Nome;
                            toquesE[i].Hora       = toque.Hora;
                            if (toque.IsDomingo)
                            {
                                toquesE[i].DiasSemana += ",0";
                            }
                            if (toque.IsSegunda)
                            {
                                toquesE[i].DiasSemana += ",1";
                            }
                            if (toque.IsTerca)
                            {
                                toquesE[i].DiasSemana += ",2";
                            }
                            if (toque.IsQuarta)
                            {
                                toquesE[i].DiasSemana += ",3";
                            }
                            if (toque.IsQuinta)
                            {
                                toquesE[i].DiasSemana += ",4";
                            }
                            if (toque.IsSexta)
                            {
                                toquesE[i].DiasSemana += ",5";
                            }
                            if (toque.IsSabado)
                            {
                                toquesE[i].DiasSemana += ",6";
                            }
                            toquesE[i].DiasSemana  = toquesE[i].DiasSemana.Substring(1);
                            toquesE[i].IsAtivo     = toque.IsAtivo;
                            toquesE[i].NivelEnsino = toque.NivelEnsino;
                            toquesE[i].UltimoToque = toquesE[i].UltimoToque;

                            arquivoId = toque.Arquivo;

                            if (toque.NivelEnsino == 2 || toque.NivelEnsino == 3)
                            {
                                toquesE[i].Canal = 1;
                            }
                            else
                            {
                                toquesE[i].Canal = 2;
                            }

                            break;
                        }
                        i++;
                    }

                    string pathMusica = "";

                    foreach (var file in toque.fileupload)
                    {
                        if (file != null && file.ContentLength > 0)
                        {
                            var nameType = file.FileName.ToString().Split('.');
                            pathMusica = Path.Combine(Server.MapPath("~/Musicas"), (arquivoId.ToString() + "." + nameType[1]));

                            file.SaveAs(pathMusica);
                        }
                    }

                    string dir = Path.Combine(Server.MapPath("~/CSV/toque.csv"));
                    ServiceCSV.WriteCSVFileToque(dir, toquesE);

                    await FTPService.UploadFile(dir);

                    await FTPService.UploadFile(pathMusica);

                    return(RedirectToAction("Toques", true));
                }
                else
                {
                    return(RedirectToAction("EditarToque", toque));
                }
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Exemple #5
0
        public async Task <ActionResult> PararToques()
        {
            if (VerificarLogin())
            {
                List <ToqueModel>       toques  = LerToquesCSV();
                List <ToqueExportModel> toquesE = new List <ToqueExportModel>();

                bool ativo = VerificarAtivo();

                foreach (var item in toques)
                {
                    ToqueExportModel it = new ToqueExportModel();
                    if (ativo)
                    {
                        it.IsAtivo = false;
                    }
                    else
                    {
                        it.IsAtivo = true;
                    }
                    it.Arquivo = item.Arquivo;
                    it.Nome    = item.Nome;
                    it.Hora    = item.Hora;
                    it.Canal   = item.Canal;
                    //it.IsSegunda = item.IsSegunda;
                    //it.IsTerca = item.IsTerca;
                    //it.IsQuarta = item.IsQuarta;
                    //it.IsQuinta = item.IsQuinta;
                    //it.IsSexta = item.IsSexta;
                    //it.IsSabado = item.IsSabado;
                    //it.IsDomingo = item.IsDomingo;
                    if (item.IsDomingo)
                    {
                        it.DiasSemana += ",0";
                    }
                    if (item.IsSegunda)
                    {
                        it.DiasSemana += ",1";
                    }
                    if (item.IsTerca)
                    {
                        it.DiasSemana += ",2";
                    }
                    if (item.IsQuarta)
                    {
                        it.DiasSemana += ",3";
                    }
                    if (item.IsQuinta)
                    {
                        it.DiasSemana += ",4";
                    }
                    if (item.IsSexta)
                    {
                        it.DiasSemana += ",5";
                    }
                    if (item.IsSabado)
                    {
                        it.DiasSemana += ",6";
                    }
                    it.DiasSemana  = it.DiasSemana.Substring(1);
                    it.NivelEnsino = item.NivelEnsino;
                    it.UltimoToque = item.UltimoToque;

                    toquesE.Add(it);
                }

                string dir = Path.Combine(Server.MapPath("~/CSV/toque.csv"));
                ServiceCSV.WriteCSVFileToque(dir, toquesE);

                await FTPService.UploadFile(dir);

                return(RedirectToAction("Toques", true));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }