/// <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); } } }); } } }
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); } } }