Ejemplo n.º 1
0
        internal Dictionary <string, myPropInfo> Getproperties(Type type, string typename)
        {
            Dictionary <string, myPropInfo> sd = null;

            if (_propertycache.TryGetValue(typename, out sd))
            {
                return(sd);
            }
            else
            {
                sd = new SafeValueType <string, myPropInfo>();
                var pr = DeepCloner.GetFastDeepClonerProperties(type);
                foreach (var p in pr)
                {
                    if (p.PropertyGetValue == null)// Property is an indexer
                    {
                        continue;
                    }

                    myPropInfo d = CreateMyProp(p.PropertyType, p.Name);
                    d.Property = p;
                    d.CanWrite = p.CanWrite;

                    foreach (var at in p.Attributes)
                    {
                        if (at is DataMemberAttribute)
                        {
                            var dm = (DataMemberAttribute)at;
                            if (dm.Name != "")
                            {
                                d.memberName = dm.Name;
                            }
                        }
                    }
                    if (d.memberName != null)
                    {
                        sd.Add(d.memberName, d);
                    }
                    else
                    {
                        sd.Add(p.Name.ToLowerInvariant(), d);
                    }
                }

                _propertycache.Add(typename, sd);
            }
            return(sd);
        }
Ejemplo n.º 2
0
        private void Play(VideoData video = null)
        {
            try
            {
                if (video == null || !video.Playable)
                {
                    video = _videos.FirstOrDefault(x => x.Playable);
                }


                if (video != null && video.Playable)
                {
                    var index = _videos.FindIndex(x => x == video);
                    var vd    = new SafeValueType <string, MediaItem>();

                    foreach (var item in _videos)
                    {
                        if (item.Playable)
                        {
                            vd.Add(item.LocalPath, new MediaItem(item.LocalPath)
                            {
                                Title = item.Title,
                            });
                        }
                    }

                    CurrentVideo = video;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (!(lVideo.VideoSource?.Any(x => x.Url == video.LocalPath) ?? false))
                        {
                            lVideo.PlayVideos(vd.Values.ToArray());
                        }
                        else
                        {
                            lVideo.PlayQueueItem(index);
                        }
                    });
                }
            }
            catch (Exception e)
            {
                Methods.AppSettings.Logger?.Error(e);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Get the ColumnSchema
 /// </summary>
 /// <param name="datatype"></param>
 /// <returns></returns>
 public SafeValueType <string, ColumnSchema> GetColumnSchema(Type datatype)
 {
     try
     {
         var key = datatype.FullName + _transaction.DataBaseTypes.ToString();
         if (CachedColumnSchema.ContainsKey(key))
         {
             return(CachedColumnSchema[key]);
         }
         datatype = datatype.GetActualType();
         var tableName = datatype.TableName();
         var sql       = $"SELECT COLUMN_NAME as columnname, data_type as datatype ,TABLE_CATALOG as db,TABLE_NAME as tb , IS_NULLABLE as isnullable FROM INFORMATION_SCHEMA.COLUMNS WHERE LOWER(TABLE_NAME) = LOWER(String[{tableName.Name}])";
         if (_transaction.DataBaseTypes == DataBaseTypes.Sqllight)
         {
             sql = $"SELECT name  as columnname, type as datatype FROM pragma_table_info(String[{tableName.Name}])";
         }
         var columns = (List <ColumnSchema>)_transaction.DataReaderConverter(_transaction.GetSqlCommand(sql), typeof(ColumnSchema));
         var dic     = new SafeValueType <string, ColumnSchema>();
         if (columns != null)
         {
             columns.ForEach(x => dic.Add(x.ColumnName, x));
         }
         _transaction.CounterException = 0;
         return(CachedColumnSchema.GetOrAdd(key, dic));
     }
     catch (Exception e)
     {
         if (_transaction.DataBaseTypes == DataBaseTypes.PostgreSql && _transaction.CounterException <= 3)
         {
             _transaction.CounterException++;
             _transaction.Renew();
             return(GetColumnSchema(datatype));
         }
         else
         {
             throw new EntityException(e.Message);
         }
     }
 }
Ejemplo n.º 4
0
        private List <string> DeleteAbstract(object o, bool save)
        {
            object dbTrigger = null;

            GlobalConfiguration.Log?.Info("Delete", o);
            var type            = o.GetType().GetActualType();
            var props           = DeepCloner.GetFastDeepClonerProperties(type);
            var table           = type.TableName().GetName(_repository.DataBaseTypes);
            var primaryKey      = o.GetType().GetPrimaryKey();
            var primaryKeyValue = o.GetPrimaryKeyValue();
            var objectRules     = type.GetCustomAttribute <Rule>();

            if (primaryKeyValue.ObjectIsNew())
            {
                return(new List <string>());
            }
            var sql = new List <string>()
            {
                "DELETE " + (_repository.DataBaseTypes == DataBaseTypes.Sqllight || _repository.DataBaseTypes == DataBaseTypes.PostgreSql ? "From " : "") +
                table +
                Querys.Where(_repository.DataBaseTypes).Column(primaryKey.GetPropertyName()).Equal(primaryKeyValue).Execute()
            };

            if (objectRules != null && !CachedIDbRuleTrigger.ContainsKey(type))
            {
                dbTrigger = objectRules.RuleType.CreateInstance();
                CachedIDbRuleTrigger.Add(o.GetType(), dbTrigger);
            }
            else if (objectRules != null || CachedIDbRuleTrigger.ContainsKey(type))
            {
                dbTrigger = CachedIDbRuleTrigger[type];
            }

            try
            {
                _repository.CreateTransaction();
                if (objectRules != null)
                {
                    dbTrigger?.GetType().GetMethod("Delete").Invoke(dbTrigger, new List <object>()
                    {
                        _repository, o
                    }.ToArray());                                                                                                // Check the Rule before save
                }
            }
            catch
            {
                _repository.Rollback();
                throw;
            }



            foreach (var prop in props.Where(x => x.CanRead && !x.IsInternalType && x.GetCustomAttribute <IndependentData>() == null && !x.ContainAttribute <JsonDocument>() && !x.ContainAttribute <XmlDocument>() && x.GetCustomAttribute <ExcludeFromAbstract>() == null))
            {
                var value = prop.GetValue(o);

                if (value == null)
                {
                    continue;
                }
                var subSql       = new List <string>();
                var propType     = prop.PropertyType.GetActualType();
                var insertBefore = props.Any(x => x.GetCustomAttribute <ForeignKey>()?.Type == propType);
                if (DeepCloner.GetFastDeepClonerProperties(propType).All(x => x.GetCustomAttribute <ForeignKey>()?.Type != type))
                {
                    if (!insertBefore)
                    {
                        continue;
                    }
                }
                if (value is IList)
                {
                    foreach (var item in value as IList)
                    {
                        subSql.AddRange(DeleteAbstract(item, false));
                    }
                }
                else
                {
                    subSql.AddRange(DeleteAbstract(value, false));
                }

                if (insertBefore)
                {
                    sql.InsertRange(sql.Count - 1, subSql);
                }
                else
                {
                    sql.AddRange(subSql);
                }
            }

            if (!save)
            {
                return(sql);
            }
            try
            {
                _repository.CreateTransaction();

                var       i = sql.Count - 1;
                var       exceptionCount      = 0;
                Exception firstChanceExcepion = null;

                while (sql.Count > 0 && exceptionCount <= 10)
                {
                    try
                    {
                        if (i < 0)
                        {
                            i = sql.Count - 1;
                        }
                        var s   = sql[i];
                        var cmd = _repository.GetSqlCommand(s);
                        cmd.Command.ExecuteNonQuery();
                        sql.RemoveAt(i);
                        i--;
                    }
                    catch (Exception e)
                    {
                        firstChanceExcepion = e;
                        exceptionCount++;
                        i--;
                    }
                }

                if (exceptionCount >= 10)
                {
                    throw firstChanceExcepion;
                }
            }
            catch
            {
                _repository.Rollback();
                throw;
            }
            return(sql);
        }