Ejemplo n.º 1
0
        /// <summary>
        /// Metodo que se ejecuta toda vez que se manda a llamar a la clase ClsDemonio
        /// Este inicia el servicio
        /// </summary>
        /// <param name="intent"></param>
        /// <param name="startId"></param>
        public override void OnStart(Android.Content.Intent intent, int startId)
        {
            base.OnStart(intent, startId);
            tva.AuthHeader Credentials  = new tva.AuthHeader();
            string         settings     = "";
            string         userpassword = "";

            try
            {
                using (StreamReader sr = new StreamReader(Assets.Open("Validator.archive")))
                {
                    settings = sr.ReadToEnd();
                }
            }
            catch (Exception exep)
            {
            }
            Servicio.ClsRijndaels _encript = new Servicio.ClsRijndaels();
            userpassword           = _encript.Transmute(settings, Servicio.ClsRijndaels.enmTransformType.intDecrypt);
            Credentials.UserName   = userpassword;
            asmxEM.PreAuthenticate = true;
            Credentials.Password   = userpassword;
            asmxEM.SoapVersion     = System.Web.Services.Protocols.SoapProtocolVersion.Soap11;
            asmxEM.UnsafeAuthenticatedConnectionSharing = true;
            asmxEM.AuthHeaderValue = Credentials;

            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
            System.Net.ServicePointManager.SecurityProtocol  = SecurityProtocolType.Ssl3;

            System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
            {
                return(true);
            };

            DoStuff();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inicia el renderizado de la aplicación para pintarlo en pantalla
        /// </summary>
        /// <param name="intent"></param>
        /// <param name="startId"></param>
        public override void OnStart(Android.Content.Intent intent, int startId)
        {
            base.OnStart(intent, startId);
            try
            {
                asmxEM = new tva.WSEncuestaMovil();

                tva.AuthHeader Credentials  = new tva.AuthHeader();
                string         settings     = "";
                string         userpassword = "";
                try
                {
                    using (StreamReader sr = new StreamReader(Assets.Open("Validator.archive")))
                    {
                        settings = sr.ReadToEnd();
                        sr.Close();
                    }
                }
                catch (Exception exep)
                {
                }
                Servicio.ClsRijndaels _encript = new Servicio.ClsRijndaels();
                userpassword           = _encript.Transmute(settings, Servicio.ClsRijndaels.enmTransformType.intDecrypt);
                Credentials.UserName   = userpassword;
                asmxEM.PreAuthenticate = true;
                Credentials.Password   = userpassword;
                asmxEM.SoapVersion     = System.Web.Services.Protocols.SoapProtocolVersion.Soap11;
                asmxEM.UnsafeAuthenticatedConnectionSharing = true;
                asmxEM.AuthHeaderValue = Credentials;

                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                System.Net.ServicePointManager.SecurityProtocol  = SecurityProtocolType.Ssl3;

                System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
                {
                    return(true);
                };
            }
            catch (WebException error)
            { }
            //Buscamos el directorio personal en el dispositivo
            var personalFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            //Buscamos el directorio database en la carpeta personal
            var databaseFolderPath = string.Format(@"{0}/database", personalFolderPath.Substring(0, personalFolderPath.LastIndexOf('/')));

            if (!Directory.Exists(databaseFolderPath))
            {
                Directory.CreateDirectory(databaseFolderPath);//Si no existe la creamos
            }

            if (!Directory.Exists(databaseFolderPath))
            {
                throw new Exception(string.Format("{0} no existe!", databaseFolderPath));//Si no existe quiere decir que en el paso anterior no se creo correctamente el dir
            }
            //var paths = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).ToString() + "/Encuestas.db3";
            //Agrega el nombre de la base de datos al path de la carpeta local y subcarpeta database
            string dbPath = Path.Combine(databaseFolderPath, "Encuestadb.db3");

            //Verifica si existe el archivo mencionado en la parte de arriba

            exists = System.IO.File.Exists(dbPath);
            if (!exists)
            {
                SqliteConnection.CreateFile(dbPath); //Si no existe crea la base de datos
                bandera = 0;                         //Configura;
            }

            connection = new SqliteConnection("Data Source=" + dbPath); //Abre la cadena de conexion con la base de datos creado anteriormente

            if (connection.State == System.Data.ConnectionState.Open)
            {
                connection.Close();
            }

            connection.Open();//Abre la conexion a la base de datos creado con anterioridad
            DoStuff();
        }