Ejemplo n.º 1
0
        /// <summary>
        /// Async Process
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override Task <HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken)
        {
            using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_OBT_AutenticarUsuario"))
            {
                svc.Parameters.Add("USUA_NombreUsuario", Model.username);
                svc.Parameters.Add("USUA_Contrasena", Gale.Security.Cryptography.MD5.GenerateHash(Model.password));
                Gale.Db.EntityRepository rep = this.ExecuteQuery(svc);

                Models.User user = rep.GetModel <Models.User>(0).FirstOrDefault();
                Gale.Db.EntityTable <Models.Profile> profiles = rep.GetModel <Models.Profile>(1);

                //------------------------------------------------------------------------------------------------------------------------
                //GUARD EXCEPTION
                Gale.Exception.RestException.Guard(() => user == null, "USERNAME_OR_PASSWORD_INCORRECT", Resources.Security.ResourceManager);
                //------------------------------------------------------------------------------------------------------------------------

                List <System.Security.Claims.Claim> claims = new List <System.Security.Claims.Claim>();

                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.email));
                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.PrimarySid, user.token.ToString()));
                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, user.fullname));
                claims.Add(new System.Security.Claims.Claim("photo", user.photo.ToString()));
                profiles.ForEach((perfil) =>
                {
                    claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, perfil.identifier));
                });

                int expiration = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Gale:Security:TokenTmeout"]);

                //RETURN TOKEN
                return(Task.FromResult(_request.CreateResponse <Gale.Security.Oauth.Jwt.Wrapper>(
                                           Gale.Security.Oauth.Jwt.Manager.CreateToken(claims, DateTime.Now.AddMinutes(expiration))
                                           )));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Async Process
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(System.Threading.CancellationToken cancellationToken)
        {
            //Check the Debug Access Token (Future Implementation)
            //http://stackoverflow.com/questions/8605703/how-to-verify-facebook-access-token

            //---------------------------------------------
            //Get Stream Image from the User
            byte[] imageBytes = null;
            if (Model.image != null)
            {
                try
                {
                    //Try to download the image
                    var webClient = new WebClient();
                    imageBytes = webClient.DownloadData(Model.image);
                }
                catch
                {
                }
            }

            using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MOT_OBT_AutenticarUsuarioExterno"))
            {
                svc.Parameters.Add("USUA_NombreCompleto", Model.name);
                svc.Parameters.Add("USUA_Email", Model.email);
                svc.Parameters.Add("AEXT_Identificador", Model.id);
                svc.Parameters.Add("ARCH_Binario", imageBytes);
                svc.Parameters.Add("ARCH_Tamano", imageBytes.Length);
                svc.Parameters.Add("TIAU_Identificador", "gmail");  //Facebook

                Gale.Db.EntityRepository rep = this.ExecuteQuery(svc);

                Models.User user = rep.GetModel <Models.User>(0).FirstOrDefault();
                Gale.Db.EntityTable <Models.Profile> profiles = rep.GetModel <Models.Profile>(1);

                //------------------------------------------------------------------------------------------------------------------------
                //GUARD EXCEPTION
                Gale.Exception.RestException.Guard(() => user == null, "USERNAME_OR_PASSWORD_INCORRECT", Resources.Security.ResourceManager);
                //------------------------------------------------------------------------------------------------------------------------

                List <System.Security.Claims.Claim> claims = new List <System.Security.Claims.Claim>();

                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.email));
                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.PrimarySid, user.token.ToString()));
                claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, user.fullname));
                claims.Add(new System.Security.Claims.Claim("photo", user.photo.ToString()));
                profiles.ForEach((perfil) =>
                {
                    claims.Add(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, perfil.identifier));
                });

                int expiration = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Gale:Security:TokenTmeout"]);

                //RETURN TOKEN
                return(Task.FromResult(_request.CreateResponse <Gale.Security.Oauth.Jwt.Wrapper>(
                                           Gale.Security.Oauth.Jwt.Manager.CreateToken(claims, DateTime.Now.AddMinutes(expiration))
                                           )));
            }
        }
Ejemplo n.º 3
0
        public override System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ExecuteAsync(
            System.Threading.CancellationToken cancellationToken)
        {
            using (Gale.Db.DataService svc = new Gale.Db.DataService("PA_MAE_CONTRATOS_NIVEL"))
            {
                svc.Parameters.Add("tokenNivel", this.contratosNivel.tokenNivel);
                svc.Parameters.Add("tokenEmpresa", this.contratosNivel.tokenEmpresa);
                Gale.Db.EntityRepository rep = this.ExecuteQuery(svc);

                Gale.Db.EntityTable <Models.CONTRATOS_NIVEL_LISTA> respuesta = rep.GetModel <Models.CONTRATOS_NIVEL_LISTA>();
Ejemplo n.º 4
0
        /// Envía correos
        public static void Mail(String Subject, Gale.Db.EntityTable <API.Endpoints.BPM.Transition.Models.Mail> to)
        {
            to.ForEach(o =>
            {
                MailMessage message = new MailMessage()
                {
                    IsBodyHtml = true,
                    From       = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["Mail:Account"]),
                    Subject    = Subject,
                    Body       = o.body
                };

                message.To.Add(new MailAddress(o.userMail));

                SmtpClient client = new SmtpClient();
                client.Send(message);
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Obtiene la tabla con registros de modelo especifico
        /// </summary>
        /// <typeparam name="T">Objeto (Modelo) a Extraer</typeparam>
        /// <param name="index">Indice de tabla donde extraer los registros</param>
        /// <returns></returns>
        public Gale.Db.EntityTable <T> GetModel <T>(int index) where T : class
        {
            Type EntityType = typeof(Gale.Db.EntityTable <T>);

            //Responsive Cache Pattern
            if (_caching != null && _caching.SingleOrDefault((obj) => { return(obj.GetType() == typeof(T)); }) != null)
            {
                return((Gale.Db.EntityTable <T>)(from t in Caching
                                                 where t.GetType().GetGenericTypeDefinition() == EntityType
                                                 select t).FirstOrDefault());
            }

            //Create the instance wich set the data
            Gale.Db.EntityTable <T> Model = (Gale.Db.EntityTable <T>)Activator.CreateInstance(EntityType);
            if (_rawData.Tables.Count > 0)
            {
                FillEntity <T>(ref Model, _rawData.Tables[index]);
            }

            //Set into the Cache
            Caching.Add(Model);

            return(Model);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Convierte una Tabla de datos (System.Data.Datatable) a una tabla de entidades del Framework CORFO del tipo T
        /// </summary>
        /// <typeparam name="T">Tipo de Entidad a Convertir</typeparam>
        /// <param name="TableSource">Extension de Datatable</param>
        /// <returns></returns>
        public static Gale.Db.EntityTable <T> ConvertToEntityTable <T>(this System.Data.DataTable TableSource) where T : class, new()
        {
            Type objectToConvertType = typeof(T);

            //Perform Pattern For Huge Data =)
            List <MemoryFieldCaching> MemoryOptimizer = null;

            Gale.Db.EntityTable <T> entityTable = new Gale.Db.EntityTable <T>();

            MemoryOptimizer = (from t in objectToConvertType.GetProperties()
                               where t.CanRead && t.GetIndexParameters().Count() == 0 && (t.PropertyType.IsGenericType == false || (t.PropertyType.IsGenericType == true && t.PropertyType.GetGenericTypeDefinition() != typeof(System.Data.Linq.EntitySet <>)))
                               select new MemoryFieldCaching
            {
                columnName = t.Name,
                property = t,
                columnAttribute = (System.Data.Linq.Mapping.ColumnAttribute)t.GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), false).FirstOrDefault(),
            }).ToList();

            foreach (System.Data.DataRow row in TableSource.Rows)
            {
                T objectMapped = new T();

                foreach (MemoryFieldCaching Caching in MemoryOptimizer)
                {
                    //Perform Pattern For Huge Data =)
                    if (TableSource.Columns.Contains(Caching.columnName))
                    {
                        if (Caching.ordinal == -1)
                        {
                            Caching.ordinal = TableSource.Columns[Caching.columnName].Ordinal;
                        }

                        object value = row[Caching.ordinal];
                        if (row[Caching.ordinal] != System.DBNull.Value)
                        {
                            //Cast To Type
                            if (Caching.property.PropertyType == typeof(char))  //Char
                            {
                                value = System.Char.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(Int16))  //Int16
                            {
                                value = System.Int16.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(Int32))  //Int32
                            {
                                value = System.Int32.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(Int64))  //Int64
                            {
                                value = System.Int64.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(Decimal))  //Decimal
                            {
                                value = System.Decimal.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(string))  //String
                            {
                                value = row[Caching.ordinal].ToString();
                            }
                            else if (Caching.property.PropertyType == typeof(DateTime))  //DateTime
                            {
                                value = System.DateTime.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(Byte))  //Byte
                            {
                                value = System.Byte.Parse(value.ToString());
                            }
                            else if (Caching.property.PropertyType == typeof(System.Guid))  //Byte
                            {
                                value = System.Guid.Parse(value.ToString());
                            }
                            else
                            {
                                value = row[Caching.ordinal];
                            }
                        }
                        else
                        {
                            value = null;
                        }
                        Caching.property.SetValue(objectMapped, value, null);
                    }
                }

                entityTable.Add(objectMapped);
            }

            return(entityTable);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fill a T model with the Database Result Values
        /// </summary>
        /// <typeparam name="T">Type to fill</typeparam>
        /// <param name="model">Entity Table to Fill</param>
        /// <param name="table">DB Result Table</param>
        private void FillEntity <T>(ref Gale.Db.EntityTable <T> model, System.Data.DataTable table)
        {
            Type EntityType = typeof(T);

            //Perform Pattern For Huge Data =)
            List <MemoryFieldCaching> MemoryOptimizer = (from t in EntityType.GetProperties()
                                                         where
                                                         t.CanRead && t.GetIndexParameters().Count() == 0 &&
                                                         (t.PropertyType.IsGenericType == false || (t.PropertyType.IsGenericType == true &&
                                                                                                    t.PropertyType.GetGenericTypeDefinition() != typeof(System.Data.Linq.EntitySet <>)))
                                                         select new MemoryFieldCaching
            {
                columnName = t.Name,
                property = t
            }).ToList();


            foreach (System.Data.DataRow row in table.Rows)
            {
                T Item = Activator.CreateInstance <T>();
                #region Transform Each Row
                foreach (MemoryFieldCaching Caching in MemoryOptimizer)
                {
                    //Perform Pattern For Huge Data =)

                    //Ordinal:
                    //  -1: Significa que tiene que ir a buscarlo
                    string Name = "";
                    if (Caching.ordinal == -1)
                    {
                        try
                        {
                            Name = Caching.columnName;

                            System.Data.Linq.Mapping.ColumnAttribute ColumnAttribute = (System.Data.Linq.Mapping.ColumnAttribute)(Caching.property.GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), true).FirstOrDefault());
                            if (ColumnAttribute != null && ColumnAttribute.Name != null && ColumnAttribute.Name.Length > 0)
                            {
                                Name = ColumnAttribute.Name;
                            }

                            if (ColumnAttribute == null)
                            {
                                Caching.ordinal = -2; //Campo Personalizado (no debe ser llenado por base de datos)
                            }
                            else
                            {
                                if (ColumnAttribute != null)
                                {
                                    //Si existe el atributo de columna y puede ser nulo, verifico que esta columna exista, de no existir esta columna,
                                    //no se debe caer, sino que solo no debe establecerla
                                    if (ColumnAttribute.CanBeNull || ColumnAttribute.DbType == null)
                                    {
                                        if (table.Columns.Contains(Name))
                                        {
                                            Caching.ordinal = table.Columns[Name].Ordinal;
                                        }
                                        else
                                        {
                                            Caching.ordinal = -2;
                                        }
                                    }
                                    else
                                    {
                                        try
                                        {
                                            if (table.Columns.Contains(Name))
                                            {
                                                Caching.ordinal = table.Columns[Name].Ordinal;
                                            }
                                            else
                                            {
                                                Caching.ordinal = -2;
                                            }
                                        }
                                        catch (System.Exception ex)
                                        {
                                            //throw new Gale.Gale.Exception.GaleException("ColumnNameNotFoundInDataServiceAndIsNotNullable", Caching.columnName, Name, EntityType.Name);
                                            throw ex;
                                        }
                                    }
                                }
                                else
                                {
                                    Caching.ordinal = table.Columns[Name].Ordinal;
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            //---[ Guard Exception ]-------------------------------------------------------------------------------------------------------
                            Gale.Exception.GaleException.Guard(() => ex is IndexOutOfRangeException, "ColumnNameNotFoundInDataService", Caching.columnName, Name, EntityType.Name);
                            //-----------------------------------------------------------------------------------------------------------------------------
                            throw ex;
                        }
                    }
                    if (Caching.ordinal != -2)
                    {
                        object data = row[Caching.ordinal];

                        if (data is DateTime)
                        {
                            data = DateTime.SpecifyKind((DateTime)data, DateTimeKind.Local);
                        }

                        if (data is System.Guid && Caching.property.PropertyType == typeof(String))
                        {
                            data = data.ToString();
                        }

                        if (!(data is System.DBNull))
                        {
                            //Parse AnyWay for implicit Casting
                            if (Caching.property.PropertyType.IsGenericType == false && Caching.property.PropertyType != data.GetType())
                            {
                                data = Convert.ChangeType(data, Caching.property.PropertyType);
                            }


                            Caching.property.SetValue(Item, data, null);
                        }
                    }
                }
                #endregion
                model.Add(Item);
            }
        }