Exemple #1
0
 private string[] GetFields(PropertyInfo prop, eCrmName crmName)
 {
     return
         (prop.GetCustomAttributes(true).OfType <CrmAttribute>()
          .Where(x => x.CrmName.Equals(crmName))
          .Select(x => x.Mappings).ToList().FirstOrDefault());
 }
Exemple #2
0
        public string GetEntityNameByAttribute(eCrmName crmName)
        {
            var crmEntity = typeof(T).GetTypeInfo().GetCustomAttributes <CrmAttribute>()
                            .Where(x => x.CrmName.Equals(crmName)).FirstOrDefault();

            return(crmEntity == null ? "" : crmEntity.Mappings[0]);
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="crmName"></param>
 /// <param name="entity"></param>
 /// <param name="mappings"></param>
 public CrmAttribute(eCrmName crmName, string entity, string[] mappings)
 {
     this.HasEntity = !string.IsNullOrEmpty(entity);
     this.Entity    = entity;
     this.Mappings  = mappings;
     this.CrmName   = crmName;
 }
Exemple #4
0
        public List <MapeamentoCampos> GetFieldsByAttribute(int id, eCrmName crmName)
        {
            List <MapeamentoCampos> fields = new List <MapeamentoCampos>();
            string entityCrm = this.GetEntityNameByAttribute(crmName);

            List <Map> mapping = new List <Map>();

            typeof(T).GetProperties().ToList().ForEach(x =>
            {
                x.GetCustomAttributes(true).OfType <CrmAttribute>().ToList().ForEach(a =>
                {
                    Map map            = new Map();
                    map.Name           = x.Name;
                    map.PropertieValue = x.GetValue(this);
                    map.Entity         = a.HasEntity ? a.Entity : entityCrm;
                    map.Fields         = a.Mappings;
                    map.Format         = a.Format;
                    mapping.Add(map);
                });
            });

            foreach (var map in mapping)
            {
                if (map.Fields is IList)
                {
                    string fieldValue = string.Empty;
                    if (map.PropertieValue is IList)
                    {
                        var propertieValue = map.PropertieValue as IList;
                        var maxLoop        = Math.Min(propertieValue.Count, map.Fields.Length);
                        for (int index = 0; index < maxLoop; index++)
                        {
                            fields.Add(new MapeamentoCampos()
                            {
                                Id = id,
                                TipoEntidadeCRM = map.Entity,
                                CampoCRM        = map.Fields[index],
                                Valor           = ConvertToString(propertieValue[index], map.Format)
                            });
                        }
                        continue;
                    }
                }

                fields.Add(new MapeamentoCampos()
                {
                    Id = id,
                    TipoEntidadeCRM = map.Entity,
                    CampoCRM        = map.Fields[0],
                    Valor           = ConvertToString(map.PropertieValue, map.Format)
                });
            }

            return(fields);
        }
Exemple #5
0
 private bool Exec(eCrmName crm, Func <BaseIntegration, bool> function)
 {
     try
     {
         return(function(CrmController(crm)));
     }
     catch (KeyNotFoundException e)
     {
         _messageController.AddErrorMessage(e.Message);
     }
     return(false);
 }
Exemple #6
0
 private BaseIntegration CrmController(eCrmName value) => (BaseIntegration)Activator.CreateInstance(_crmHub[value], HttpMessageSender, MessageController);
Exemple #7
0
 public Crm(eCrmName name)
 {
     this.Name = name;
 }
Exemple #8
0
 /// <summary>
 /// Apply format in value field
 /// </summary>
 /// <param name="crmName"></param>
 /// <param name="mapping"></param>
 /// <param name="format"></param>
 public CrmAttribute(eCrmName crmName, string mapping, string format = null)
 {
     this.Mappings = new string[] { mapping };
     this.CrmName  = crmName;
     this.Format   = format;
 }
Exemple #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="crmName"></param>
 /// <param name="mappings"></param>
 public CrmAttribute(eCrmName crmName, string[] mappings)
 {
     this.Mappings = mappings;
     this.CrmName  = crmName;
 }
Exemple #10
0
        public Crm GetByName(eCrmName name, string environment)
        {
            var crm = _repository.List(x => x.Name.Equals(name.ToString()) && x.Environment.Equals(environment)).SingleOrDefault();

            return(crm);
        }