Exemplo n.º 1
0
        public async Task <ActionResult> Detalhes(string arquivo)
        {
            if (VerificarLogin())
            {
                List <ToqueModel> toques = LerToquesCSV();
                ToqueModel        toque  = new ToqueModel();
                foreach (var item in toques)
                {
                    if (arquivo == item.Arquivo)
                    {
                        toque = item;
                        break;
                    }
                }

                string file = arquivo + ".wav";
                string dir  = Path.Combine(Server.MapPath("~/Musicas/"));

                await FTPService.DownloadFileSpec(dir, file);

                return(View(toque));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Exemplo n.º 2
0
        private async Task UploadAllVoices()
        {
            try
            {
                string   localRecordPath = Path.Combine(AppEnvironment.appDataPath, AppEnvironment.authService.AuthenticatedUser.GetUserString());
                string   serverDirPath   = AppEnvironment.dataService.ServerUserDataDirPath + "/";
                string[] recordedFiles   = Directory.GetFiles(localRecordPath);

                if (recordedFiles.Length < 1)
                {
                    DependencyService.Get <IToast>().Show(AppResources.SettingPage_UploadAllVoice_NoRecordedFiles);

                    return;
                }

                Configurations.LoadingConfig = new LoadingConfig
                {
                    IndicatorColor = Color.AliceBlue,
                    OverlayColor   = Color.Gray,
                    Opacity        = 0.6,
                    DefaultMessage = AppResources.Uploading
                };

                await Loading.Instance.StartAsync(async (progress) =>
                {
                    using var wc = new WebClient();

                    int count = 0;

                    wc.UploadFileCompleted += (sender, e) =>
                    {
                        progress.Report((count + 1) / (double)recordedFiles.Length);
                    };

                    for (count = 0; count < recordedFiles.Length; ++count)
                    {
                        string fileName = Path.GetFileName(recordedFiles[count]);

                        //Loading.Instance.SetMessage($"{AppResources.Uploading}({count + 1}/{recordedFiles.Length})");

                        await FTPService.UploadFileAsync(Path.Combine(localRecordPath, fileName), Path.Combine(serverDirPath, fileName), wc);
                        await Task.Delay(100);
                    }

                    await Task.Delay(1000);
                });
            }
            catch (Exception ex)
            {
#if DEBUG
                DependencyService.Get <IToast>().Show(ex.ToString());
#endif
                DependencyService.Get <IToast>().Show(AppResources.UploadFail);
            }
            finally
            {
                Loading.Instance.Hide();
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public bool UploadTable()
        {
            if (!FTPService.CheckDirExist(ServerUserDataDirPath))
            {
                FTPService.CreateDir(ServerUserDataDirPath);
            }

            return(FTPService.UploadFile(LocalDataFilePath, Path.Combine(ServerUserDataDirPath, serverFile)));
        }
Exemplo n.º 5
0
        private void PlayButton_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (audioPlayer == null)
                {
                    audioPlayer = CrossSimpleAudioPlayer.Current;
                }

                if (audioPlayer.IsPlaying)
                {
                    audioPlayer.Stop();

                    RecordButton.IsEnabled = true;
                    UploadButton.IsEnabled = true;

                    PlayButton.Text = AppResources.Play;

                    voiceFileStream?.Close();
                }
                else
                {
                    if (!File.Exists(recordFilePath))
                    {
                        if (!FTPService.DownloadFile(AppEnvironment.dataService.ServerUserDataDirPath, recordFilePath))
                        {
                            throw new Exception("Cannot download record file");
                        }
                    }

                    voiceFileStream?.Close();
                    voiceFileStream = new FileStream(recordFilePath, FileMode.Open, FileAccess.Read);

                    audioPlayer.Load(voiceFileStream);
                    audioPlayer.Play();
                    audioPlayer.PlaybackEnded += delegate
                    {
                        RecordButton.IsEnabled = true;
                        UploadButton.IsEnabled = true;

                        PlayButton.Text = AppResources.Play;

                        voiceFileStream?.Close();
                    };

                    RecordButton.IsEnabled = false;
                    UploadButton.IsEnabled = false;

                    PlayButton.Text = AppResources.Stop;
                }
            }
            catch (Exception ex)
            {
                DependencyService.Get <IToast>().Show(ex.ToString());
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        private async Task <int> SyncRasp()
        {
            string   dir    = Path.Combine(Server.MapPath("~/CSV/"));
            FileInfo dirCSV = new FileInfo(dir + "toque.csv");

            dirCSV.Delete();

            await FTPService.DownloadFile(dir, "csv");

            dir = Path.Combine(Server.MapPath("~/Musicas/"));

            DirectoryInfo di = new DirectoryInfo(dir);

            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }
            return(1);
        }
        public int PutDocument(Stream stream, DocumentRequisite documentRequisite, int?filesListId = null)
        {
            if (dataManager == null)
            {
                return(-1);
            }

            var path = GetPath(documentRequisite);

            if (!FTPService.CreateDirectory(Path.GetDirectoryName(path)))
            {
                return(-2);
            }
            if (!FTPService.Upload(stream, path))
            {
                return(-3);
            }

            return(dataManager.PutDocument(documentRequisite, filesListId));
        }
Exemplo n.º 9
0
        internal async Task UpdateStatus(VoiceListItem item)
        {
            await Task.Delay(100);

            string serverDirPath = AppEnvironment.dataService.ServerUserDataDirPath + "/";

            string serverFilePath = Path.Combine(serverDirPath, $"{item.Section}_{item.Chapter}_{item.Number}.mp3");

            if (FTPService.CheckFileExist(serverFilePath))
            {
                item.IsUploaded      = true;
                item.CompletedText   = AppResources.Successed;
                item.UploadTextColor = Color.Green;
            }
            else
            {
                item.IsUploaded      = false;
                item.CompletedText   = AppResources.NonSuccessed;
                item.UploadTextColor = Color.Red;
            }
        }
Exemplo n.º 10
0
        private void CheckFirstVoiceStatusFile()
        {
            string filePath   = Path.Combine(LocalDataPath, firstVoiceSetStatusFile);
            string serverPath = Path.Combine(ServerUserDataDirPath, firstVoiceSetStatusFile);

            if (!Directory.Exists(LocalDataPath))
            {
                Directory.CreateDirectory(LocalDataPath);
            }

            if (!File.Exists(filePath))
            {
                if (FTPService.CheckFileExist(serverPath))
                {
                    FTPService.DownloadFile(filePath, serverPath);
                }
                else
                {
                    File.WriteAllText(filePath, "");
                }
            }
        }
Exemplo n.º 11
0
        public string GetTemplatePath(string templateFilePath)
        {
            using (var stream = FTPService.Donwload(templateFilePath)) {
                if (stream != null)
                {
                    if (!Directory.Exists(@"C:\temp"))
                    {
                        Directory.CreateDirectory(@"c:\temp");
                    }

                    string targetFileName = "C:\\temp\\" + templateFilePath;

                    using (var targetStream = new FileStream(targetFileName, FileMode.OpenOrCreate)) {
                        if (targetStream == null)
                        {
                            return(null);
                        }
                        var    bufferSize = 1024;
                        byte[] byteBuffer = new byte[bufferSize];
                        int    bytesRead  = stream.Read(byteBuffer, 0, bufferSize);
                        try {
                            while (bytesRead > 0)
                            {
                                targetStream.Write(byteBuffer, 0, bytesRead);
                                bytesRead = stream.Read(byteBuffer, 0, bufferSize);
                            }
                        } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); }
                        targetStream.Seek(0, SeekOrigin.Begin);
                        targetStream.Close();
                    }
                    stream.Close();
                    return(targetFileName);
                }
            }
            return(null);
        }
Exemplo n.º 12
0
 public Stream GetDocument(string filePath)
 {
     return(FTPService.Donwload(filePath));
 }
Exemplo n.º 13
0
        public static async Task Main(string[] args)
        {
            // Make sure only days, source Directory, and targetDirectory are entered into program
            if (args.Length != 4)
            {
                await SystemUtilityService.NotifySystemAdminAsync(Constants.InvalidArgs, Constants.SystemAdminEmailAddress).ConfigureAwait(false);

                return;
            }

            DateTime currentTime = DateTime.Now;
            int      days;
            string   targetDirectory = "";

            try
            {
                days = Convert.ToInt32(args[1]);
            }
            catch
            {
                await SystemUtilityService.NotifySystemAdminAsync(Constants.FirstArgumentNotInt, Constants.SystemAdminEmailAddress).ConfigureAwait(false);

                return;
            }

            string sourceDir;

            if (Directory.Exists(args[2]))
            {
                sourceDir = args[2];
            }
            else
            {
                await SystemUtilityService.NotifySystemAdminAsync(Constants.SourceDirectoryDNE, Constants.SystemAdminEmailAddress).ConfigureAwait(false);

                return;
            }

            if (Directory.Exists(args[3]))
            {
                targetDirectory = args[3];
            }

            targetDirectory += currentTime.ToString(Constants.NamingFormatString);
            bool result = false;

            // FetchLogs will return true if files of the proper age are found in the source directory.
            if (FileFetchingService.FetchLogs(sourceDir, targetDirectory, days))
            {
                if (CompressionService.Compress(Constants.SevenZipPath, sourceDir, targetDirectory))
                {
                    result = await FTPService.SendAsync(Constants.FTPUrl, "", targetDirectory, Constants.FTPUsername, Constants.FTPpassword).ConfigureAwait(false);
                }
            }

            // Notify system admin if Archiving fails to run successfully.
            if (result == false)
            {
                await SystemUtilityService.NotifySystemAdminAsync("Archiving failed on" + currentTime, Constants.SystemAdminEmailAddress).ConfigureAwait(false);
            }
        }
Exemplo n.º 14
0
        //Update Guest Details
        async void saveButton(object sender, EventArgs e)
        {
            string validation = FieldValidation.guestSaveDetailsValidation(IdentificationMethod, IdentificationMethodNumber.Text, GuestFisrtName.Text, GuestLastName.Text, DateOfBirth, GuestContact.Text, GuestEmail.Text, City.Text, Street.Text);

            if (validation != "")
            {
                await DisplayAlert("Warning!", validation, "Ok");
            }
            else
            {
                DateTime date = DateOfBirth.Date;

                DateTime dateOfEx = PassportExpiry.Date;

                //Page loading indicator
                pageLoading();

                //Pass values to payload
                StatusChange statusChange = new StatusChange(Constants._hotel_code, Constants._reservation_id, guestIdentification, IdentificationMethodNumber.Text, guestNumber.Text, guestSalutation, GuestFisrtName.Text, GuestLastName.Text, guestGender, GuestEmail.Text, GuestContact.Text, HouseNumber.Text, Street.Text, City.Text, guestCountry, guestNationality, guestLanguage, date.ToString("s"), dateOfEx.ToString("s"));
                //PPExpiryDate expiryDateChange = new PPExpiryDate(Constants._hotel_code, Constants._reservation_id, guestNumber.Text, guestSalutation, GuestFisrtName.Text, GuestLastName.Text, IdentificationMethodNumber.Text ,dateOfEx.ToString("s"),guestIdentification,guestCountry,guestLanguage);

                //Data Posting source
                //PostServiceManager postServiceManager = new PostServiceManager();
                GuestPostManager guestPostManager = new GuestPostManager();

                string result = await guestPostManager.CreateUpdateGuest(statusChange);

                //String result = await postServiceManager.StatusChangeAsync(statusChange);
                //String result2 = await postServiceManager.SavePPExpiryAsync(expiryDateChange);


                if (result != "Reservation is locked" || result.Contains("Updated Successfully"))
                {
                    //Updateing guest details object
                    var obj = guestdetails.FirstOrDefault(x => x.guestNumber == Int32.Parse(guestNumber.Text));
                    obj.guestNumber          = Int32.Parse(guestNumber.Text);
                    obj.identificationMethod = guestIdentification;
                    obj.passportIdNumber     = IdentificationMethodNumber.Text;
                    obj.salutation           = guestSalutation;
                    obj.guestName            = GuestFisrtName.Text + " " + GuestLastName.Text;
                    obj.guestFirstName       = GuestFisrtName.Text;
                    obj.guestLastName        = GuestLastName.Text;
                    obj.gender          = guestGender;
                    obj.email           = GuestEmail.Text;
                    obj.contactNumber   = GuestContact.Text;
                    obj.houseNumber     = HouseNumber.Text;
                    obj.street          = Street.Text;
                    obj.city            = City.Text;
                    obj.nationality     = guestNationality;
                    obj.country         = guestCountry;
                    obj.language        = guestLanguage;
                    obj.guestCode       = guestCodeFromSearch;
                    obj.dateOfBirth     = date.ToString("s");
                    obj.dateOfExpiry    = dateOfEx.ToString("s");
                    obj.noOfVisitsHotel = Visitperhotel;
                    obj.noOfVisits      = Totalvisit;
                    obj.revenueTotal    = RevenueTotal;
                    obj.revenueRoom     = RevenueRoom;
                    obj.reveneuFB       = RevenueFnb;
                    obj.revenueOther    = RevenueOther;

                    var nameToCountry = CountryDictionary.listOfCountrie();
                    if (guestCountry != "" || guestCountry != "")
                    {
                        //Item Value in dictionary
                        string name = nameToCountry.FirstOrDefault(x => x.Value == guestCountry).Key;
                        obj.countryKeyValue = name;
                    }

                    Constants._guestNumber = "";
                    Constants._guestNumber = guestNumber.Text;


                    if (Constants.PassportCopy != null)
                    {
                        await FTPService.UploadPassportCopy(Constants.PassportCopy, GuestFisrtName.Text);
                    }

                    stopPageLoading();

                    //Guest details updateindicator, Reload content page
                    MessagingCenter.Send <GuestEdit, List <guestDetails> >(this, Constants._guestEdited, guestdetails);
                    await DisplayAlert("Message", result, "OK");

                    ////Logger
                    //new APILogger().Logger("Guest Payload :" + JsonConvert.SerializeObject(statusChange));
                    //new APILogger().Logger("Guest Save Status :" + result);

                    //Close this content page
                    this.Navigation.RemovePage(this);
                }
                else
                {
                    stopPageLoading();
                    await DisplayAlert("Message", result, "OK");
                }
            }
        }
Exemplo n.º 15
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"));
            }
        }
Exemplo n.º 16
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"));
            }
        }
Exemplo n.º 17
0
 public bool GetDocument(string filePath, string saveAs)
 {
     return(FTPService.Donwload(filePath, saveAs));
 }
Exemplo n.º 18
0
 public Stream GetTemplateStream(string templateFilePath)
 {
     return(FTPService.Donwload(templateFilePath));
 }
Exemplo n.º 19
0
        public bool DownloadTable()
        {
            string serverPath = Path.Combine(FTPService.CheckDirExist(ServerUserDataDirPath) ? ServerUserDataDirPath : ServerDefaultDataDirPath, serverFile);

            return(FTPService.DownloadFile(LocalDataFilePath, serverPath));
        }