/// <summary> /// Cargar datos en interfaz. /// </summary> private void loadData() { mainController = new MainController(); //Datos del servidor. textBoxServer.Text = mainController.getAutomaticRingSystem().domainHost; textBoxPort.Text = mainController.getAutomaticRingSystem().domainPort.ToString(); //Horarios. mainController.getAutomaticRingSystem().horaryList.ForEach(h => { if (tabControlHorary.TabPages.Count < configurationParametersModel.numberschedules) { HoraryUserControl horaryUserControl = new HoraryUserControl(h); horaryUserControl.mainController = mainController; horaryUserControl.Dock = DockStyle.Fill; TabPage horaryTabPage = new TabPage(h.name); tabControlHorary.TabPages.Add(horaryTabPage); horaryTabPage.ImageIndex = 0; horaryTabPage.Controls.Add(horaryUserControl); } }); //Sonidos generales. generalRingUserControl.mainController = mainController; if (mainController.getAutomaticRingSystem().generalRingList.Any()) { HoraryModel horary = mainController.getAutomaticRingSystem().generalRingList[0]; generalRingUserControl.horary = horary; generalRingUserControl.loadData(); } }
/// <summary> /// Iniciar trabajo ahora. /// </summary> /// <param name="horary"></param> /// <param name="callServer"></param> public void startJobNow(HoraryModel horary, CallServerModel callServer) { String idJob = horary.randomId + callServer.randomId + "now"; getCallsRunningUtils(); if (!callsRunningUtils.idsList.Contains(idJob)) { startJobs(horary, callServer, true); } }
/// <summary> /// Colgar llamada ahora. /// </summary> public void hangUpNow(HoraryModel horary, CallServerModel callServer) { String idJob = horary.randomId + callServer.randomId + "now"; if (callsRunningUtils.idsList.Contains(idJob)) { if (playerUtilsMap.ContainsKey(idJob)) { playerUtilsMap[idJob].hangUpNow(); playerUtilsMap.Remove(idJob); } callsRunningUtils.idsList.Remove(idJob); } }
private void buttonAddHorary_Click(object sender, EventArgs e) { string tabPageName = "Horario"; if (tabControlHorary.TabPages.Count < configurationParametersModel.numberschedules) { if (Dialog.Prompt("Crear nuevo Horario", "Ingrese el nombre del horario:", ref tabPageName) == DialogResult.OK) { TabPage horaryTabPage = new TabPage(tabPageName); HoraryModel horary = new HoraryModel(tabPageName); HoraryUserControl horaryUserControl = new HoraryUserControl(horary); horaryUserControl.Dock = DockStyle.Fill; horaryUserControl.mainController = mainController; tabControlHorary.TabPages.Add(horaryTabPage); horaryTabPage.ImageIndex = 0; horaryTabPage.Controls.Add(horaryUserControl); tabControlHorary.SelectTab(tabControlHorary.TabPages[tabControlHorary.TabCount - 1]); } } else { MessageBox.Show("No se puede crear más horarios, ya exedio el límite licenciado. Por favor póngase en contacto con el proveedor del sistema.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// Inicializar datos de la aplicación. /// </summary> public void init() { //callsRunningJsonFileFullPath = validateEntriesUtils.getProgramDataPath() + "\\" + Properties.Settings.Default.callsRunning + Properties.Settings.Default.jsonExtension; jsonFileFullPath = validateEntriesUtils.getProgramDataPath() + "\\" + Properties.Settings.Default.jsonFileName + Properties.Settings.Default.jsonExtension; jsonFileFullPathEncrypted = jsonFileFullPath + Properties.Settings.Default.encryptedExtension; if (System.IO.File.Exists(jsonFileFullPathEncrypted)) { cypherUtils.FileDecrypt(jsonFileFullPathEncrypted, jsonFileFullPath, Properties.Settings.Default.cypherPassword); jsonHandlerUtils = new JsonHandlerUtils(jsonFileFullPath, "STA.Model.AutomaticRingSystemModel"); automaticRingSystem = (AutomaticRingSystemModel)jsonHandlerUtils.deserialize(); try { System.IO.File.Delete(jsonFileFullPath); } catch (Exception e) { log.Error("Intentando eliminar archivo json", e); } } else { log.Info("El archivo JSON encriptado no existe."); automaticRingSystem = new AutomaticRingSystemModel(); } //Asignar objeto para validar. automaticRingSystemToMatchSerialized = JsonConvert.SerializeObject(automaticRingSystem); //Fueron asignados los parámetros de conexión al servidor. if (hasServerParams()) { //Hay horarios configurados?. if (automaticRingSystem.horaryList.Any()) { automaticRingSystem.horaryList.ForEach(h => { //Tiene el horario definidos los parámetros para llamar al servidor?. if (hasHoraryConnectionCallServerParams(h)) { //Crear lista con llamadas al servidor habilitadas. List <CallServerModel> callServerList = h.callServerList.Where(cs => { //Tiene llamadas habilitadas?. if (cs.enabled) { //Existe archivo de sonido. Boolean existSoundFile = System.IO.File.Exists(cs.soundFile.targetPath); //Deshabilitar horario en caso de no existir archivo de sonido. if (!existSoundFile) { cs.enabled = false; } return(existSoundFile); } return(false); }).ToList(); //Tiene llamadas al servidor habilitadas y existe el archivo de sonido?. if (callServerList.Any()) { //Agregar horario. HoraryModel horary = new HoraryModel(h.name, h.randomId, callServerList, h.connectionCallServer); automaticRingSystemToExecute.horaryList.Add(horary); } } }); } } }
/// <summary> /// Tiene el horario definidos los parámetros para llamar al servidor?. /// </summary> /// <param name="horary"></param> /// <returns></returns> private bool hasHoraryConnectionCallServerParams(HoraryModel horary) { return(!horary.connectionCallServer.registerName.Equals("") && !horary.connectionCallServer.registerPassword.Equals("")); }
/// <summary> /// Iniciar trabajo ahora. /// </summary> /// <param name="horary"> /// Horario. /// </param> /// <param name="callServer"> /// Llamada al servidor. /// </param> /// <param name="startNow"> /// Iniciar ahora. Por defecto falso. /// </param> private async void startJobs(HoraryModel horary, CallServerModel callServer, Boolean startNow = false) { if (startNow) { if (scheduler == null || scheduler.IsShutdown) { initScheduler(); startScheduler(); } } MediaBaseUtils mediaBase = null; if (callServer.mode.value.Equals("softphone")) { mediaBase = new SoftPhoneUtils(); } else { mediaBase = new JackCableUtils(); } String idJob = horary.randomId + callServer.randomId + (startNow ? "now" : ""); String hour = callServer.startAt == null || callServer.startAt.Length < 2 ? "00" : callServer.startAt.Substring(0, 2);//start:"12:30:10" String min = callServer.startAt == null || callServer.startAt.Length < 5 ? "00" : callServer.startAt.Substring(3, 2); String sec = callServer.startAt == null || callServer.startAt.Length < 8 ? "00" : callServer.startAt.Substring(6); if (playerUtilsMap.ContainsKey(idJob)) { playerUtilsMap[idJob] = mediaBase; } else { playerUtilsMap.Add(idJob, mediaBase); } if (startNow) { getCallsRunningUtils(); if (!callsRunningUtils.idsList.Contains(idJob)) { callsRunningUtils.idsList.Add(idJob); } setCallsRunningUtils(); } JobDataMap jobDataMap = new JobDataMap(); //softPhoneUtils.jobDataCommon = new JobDataCommon(automaticRingSystem.registrationRequired, automaticRingSystem.domainHost, automaticRingSystem.domainPort, horary.connectionCallServer, callServer, idJob); //jobDataMap.Put("softPhone", JsonConvert.SerializeObject(softPhoneUtils)); if (callServer.mode.value.Equals("softphone")) { ((SoftPhoneUtils)mediaBase).jobDataCommon = new JobDataCommon(automaticRingSystem.registrationRequired, automaticRingSystem.domainHost, automaticRingSystem.domainPort, horary.connectionCallServer, callServer, idJob); jobDataMap.Put("softPhone", JsonConvert.SerializeObject((SoftPhoneUtils)mediaBase)); } else { ((JackCableUtils)mediaBase).jobDataCommon = new JobDataCommon(automaticRingSystem.registrationRequired, automaticRingSystem.domainHost, automaticRingSystem.domainPort, horary.connectionCallServer, callServer, idJob); jobDataMap.Put("jackCable", JsonConvert.SerializeObject((JackCableUtils)mediaBase)); } //Definir job. IJobDetail job = JobBuilder.Create <RingJobUtils>() .WithIdentity(idJob, groupJobs) .SetJobData(jobDataMap) .Build(); //Disparador de trabajos. ITrigger trigger; if (startNow) { //Disparador de trabajos ahora. trigger = TriggerBuilder.Create() .WithIdentity(idJob, groupJobs) .StartNow() .ForJob(idJob, groupJobs) .Build(); } else { //Disparador de trabajos a hora y minuto de lunes a viernes: "0 30 10 ? * WED,FRI" trigger = TriggerBuilder.Create() .WithIdentity(idJob, groupJobs) .WithCronSchedule(sec + " " + min + " " + hour + " ? * MON-FRI") .ForJob(idJob, groupJobs) .Build(); } //Eliminar trabajo si existe if (await scheduler.CheckExists(new JobKey(idJob, groupJobs))) { await scheduler.DeleteJob(new JobKey(idJob, groupJobs)); } //Asignar trigger a job en el programador de llamadas(scheduler) await scheduler.ScheduleJob(job, trigger); //Sintaxis para asignarle varios triggers a un treabajo. //await scheduler.ScheduleJob(objJob, new[] { trigger, trigger1, trigger2, trigger3 }, true); }
/// <summary> /// Constructor. Para cargar datos en interfaz. /// </summary> /// <param name="horary"></param> public HoraryUserControl(HoraryModel horary) { this.horary = horary; InitializeComponent(); }
/// <summary> /// Constructor por defecto. /// </summary> public GeneralRingUserControl() { horary = new HoraryModel("gs"); InitializeComponent(); callServerModelBindingSource.DataSource = new List <CallServerModel>(); }
static void Main() { MainController.log.Info("App started!"); Boolean run = true; if (!run) { //crear archivo JSON ValidateEntriesUtils validateEntriesUtils = new ValidateEntriesUtils(); AutomaticRingSystemModel automaticRingSystem = new AutomaticRingSystemModel(); automaticRingSystem.registrationRequired = true; automaticRingSystem.domainHost = "100.50.40.3"; automaticRingSystem.domainPort = 5060; for (int i = 0; i < 1; i++) { ConnectionCallServerModel connectionCallServer = new ConnectionCallServerModel(); connectionCallServer.displayName = "1230"; connectionCallServer.userName = "******"; connectionCallServer.registerName = "1230"; connectionCallServer.registerPassword = "******"; HoraryModel horary = new HoraryModel("h" + i, connectionCallServer); for (int a = 0; a < 2; a++) { int s = i + a; String sec = s < 10 ? "0" : "" + s; SoundFileModel soundFile = new SoundFileModel(); String filename = "helloworld" + a + ".mp3"; soundFile.name = filename; soundFile.targetPath = validateEntriesUtils.getMyDocumentsPath() + "\\" + Properties.Settings.Default.soundFolderName + "\\" + Properties.Settings.Default.horarySounds + "\\" + filename; CallServerModel callServer = new CallServerModel(a + 1, "23:54:" + sec, 5, soundFile, true, "1300", "llamada " + a); horary.callServerList.Add(callServer); } automaticRingSystem.horaryList.Add(horary); } string outputJSON = JsonConvert.SerializeObject(automaticRingSystem); String jsonFileFullPath = validateEntriesUtils.getProgramDataPath() + "\\" + Properties.Settings.Default.jsonFileName + Properties.Settings.Default.jsonExtension; File.WriteAllText(jsonFileFullPath, outputJSON); try { MainController.cypherUtils.FileEncrypt(jsonFileFullPath, Properties.Settings.Default.cypherPassword); System.IO.File.Delete(jsonFileFullPath); } catch (Exception e) { MainController.log.Error("Intentando guardar archivo json", e); } //crear archivo JSON FIN } if (run) { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } catch (Exception e) { BaseUtils.log.Error(e); } } }