Exemplo n.º 1
0
        public void Should_create_SQL_Server_tables_for_each_TableInfo_entity_in_Assembly()
        {
            //Initialize logging
            var simpleContainer = new SimpleContainer(new Dictionary <Type, IContainerItemResolver>());

            simpleContainer.AddResolverFor <ILogFactory>(new SimpleContainerItemResolver(CreateLog4NetFactory));

            Container.InitializeWith(simpleContainer);
            string targetAssemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "KataTestAssembly.dll");

            targetAssemblyPath = targetAssemblyPath.Replace("KataOrm.Test", "KataTestAssembly");

            Assembly assembly      = Assembly.LoadFrom(targetAssemblyPath);
            var      metaInfoStore = new MetaInfoStore();

            Log.BoundTo(metaInfoStore).Log("Initial binding to test MetaInfoStore");

            metaInfoStore.BuildMetaInfoForAssembly(assembly);

            var kataSchemaManager = new KataSchemaManager(assembly, new HardCodedTestConfigurationSettings());

            kataSchemaManager.CreateSchema();

            Assert.IsTrue(kataSchemaManager.AffectedTables.Count == metaInfoStore.TableInfos.Count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="stream"></param>
        /// <param name="extraArgs"></param>
        /// <returns></returns>
        public override async Task <FileMetaInfo> SaveAsync(FileMetaInfo fileInfo, Stream stream, IDictionary <string, object> extraArgs)
        {
            if (extraArgs == null || !extraArgs.ContainsKey("context"))
            {
                throw new ArgumentException("extraArgs 参数需要context键值");
            }

            var context = extraArgs["context"].ToString();
            var rule    = FileStoreRuleManager.GetRuleByName(context) as ImageStoreRule;

            if (rule == null)
            {
                throw new Exception("未找到指定规则或默认规则:" + context);
            }

            fileInfo.Id = Guid.NewGuid().ToString();
            var name = GetInnerFileName(fileInfo);
            var dir  = rule.GetSaveDir();

            await SaveFileAsync(dir, name, stream);

            fileInfo.Path = Path.Combine(rule.GetSaveDir(), name).Replace("\\", "/");

            //保存文件信息
            await MetaInfoStore.SaveAsync(fileInfo, rule.Id);

            return(fileInfo);
        }
Exemplo n.º 3
0
 public KataSchemaManager(Assembly assembly, IConfigurationSettings configurationSettings)
 {
     AffectedTables         = new List <string>();
     _assembly              = assembly;
     _metaInfoStore         = new MetaInfoStore();
     _configurationSettings = configurationSettings;
 }
Exemplo n.º 4
0
        public TEntity Insert <TEntity>(TEntity entity)
        {
            using (var command = CreateSqlCommand())
            {
                var tableInfo = MetaInfoStore.GetTableInfoFor <TEntity>();
                command.CommandText = tableInfo.GetInsertStatement();

                foreach (var VARIABLE in tableInfo.GetParametersForInsert(entity))
                {
                }
            }
            throw new MethodAccessException();
        }
Exemplo n.º 5
0
        public void Should_load_column_info_items_for_TableInfo_when_asked_to_build_metainfo_for_Assembly()
        {
            //Arrange
            var metaInfoStore = new MetaInfoStore();

            //Act
            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());

            //Assert
            int result = metaInfoStore.TableInfos.Where(x => x.Key.Name == "TableInfoTestsOne").Sum(x => x.Value.ColumnInfos.Count());

            Assert.AreEqual(2, result);
        }
Exemplo n.º 6
0
        public void Should_load_the_PrimaryKey_column_for_TableInfo_when_asked_to_build_MetaInfo_for_Assembly()
        {
            //Arrange
            var metaInfoStore = new MetaInfoStore();

            //Act
            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());

            //Assert
            var primaryKey =
                metaInfoStore.TableInfos.Where(x => x.Key.Name == "TableInfoTestsOne").First().Value.PrimaryKey;

            Assert.AreEqual("TableKey", primaryKey.Name);
        }
Exemplo n.º 7
0
        protected override void EstablishContext()
        {
            base.EstablishContext();
            var testBase = new TestBase();

            _productToSave = new Product()
            {
                ProductName   = "First Product",
                Description   = "Product Description",
                SellStartDate = DateTime.Now,
                SellEndDate   = DateTime.Now.AddYears(1)
            };
            _metaStore = testBase.GetMetaInfo();
        }
Exemplo n.º 8
0
        public void Should_load_table_info_items_when_asked_to_build_metainfo_for_Assemble()
        {
            //Arrange
            var metaInfoStore = new MetaInfoStore();

            //Act
            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());

            //Assert

            int resultCount = metaInfoStore.TableInfos.Where(x => x.Key.Name.Contains("TableInfoTests")).Count();

            Assert.AreEqual(3, resultCount);
        }
Exemplo n.º 9
0
        public void Should_return_select_statement_with_the_reference_key_columns()
        {
            var metaInfoStore = new MetaInfoStore();

            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());
            var tableInfo = metaInfoStore.TableInfos.Where(x => x.Key.Name == "TableInfoTestsTwo").First();

            var selectStatement = tableInfo.Value.GetSelectTableForAllFields();

            foreach (var referenceColumns in tableInfo.Value.References)
            {
                Assert.IsTrue(selectStatement.Contains(referenceColumns.Name));
            }
        }
Exemplo n.º 10
0
        public void Should_load_the_reference_columns_for_TableInfo_when_asked_to_build_MetaInfo_for_Assembly()
        {
            //Arrange
            var metaInfoStore = new MetaInfoStore();

            //Act
            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());

            //Assert
            int result =
                metaInfoStore.TableInfos.Where(x => x.Key.Name == "TableInfoTestsTwo").Sum(
                    x => x.Value.References.Count());

            Assert.AreEqual(1, result);
        }
Exemplo n.º 11
0
        protected override void EstablishContext()
        {
            base.EstablishContext();
            var testBase = new TestBase();

            _productToSave = new Product()
            {
                ProductName   = "First Product",
                Description   = "Product Description",
                SellStartDate = DateTime.Now,
                SellEndDate   = DateTime.Now.AddYears(1)
            };
            _connection = new SqlConnection(new HardCodedTestConfigurationSettings().ConnectionSettings);
            _metaStore  = testBase.GetMetaInfo();
        }
Exemplo n.º 12
0
        public void Should_return_select_statement_with_all_columns_in_Table_Entity()
        {
            //Arrange
            var metaInfoStore = new MetaInfoStore();

            metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());
            var tablInfo = metaInfoStore.TableInfos.Where(x => x.Key.Name == "TableInfoTestsOne").First();

            var selectStatement = tablInfo.Value.GetSelectTableForAllFields();

            Assert.IsTrue(selectStatement.StartsWith("SELECT", StringComparison.InvariantCultureIgnoreCase));
            foreach (var columnInfo in tablInfo.Value.ColumnInfos)
            {
                Assert.IsTrue(selectStatement.Contains(columnInfo.Name));
            }
        }
Exemplo n.º 13
0
        public TestBase()
        {
            var simpleContainer = new SimpleContainer(new Dictionary <Type, IContainerItemResolver>());

            simpleContainer.AddResolverFor <ILogFactory>(new SimpleContainerItemResolver(CreateLog4NetFactory));

            Container.InitializeWith(simpleContainer);
            string targetAssemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "KataTestAssembly.dll");

            targetAssemblyPath = targetAssemblyPath.Replace("KataOrm.Test", "KataTestAssembly");

            _assembly      = Assembly.LoadFrom(targetAssemblyPath);
            _metaInfoStore = new MetaInfoStore();
            Log.BoundTo(_metaInfoStore).Log("Initial binding to test MetaInfoStore");

            _metaInfoStore.BuildMetaInfoForAssembly(_assembly);
        }
Exemplo n.º 14
0
 protected DatabaseAction(SqlConnection connection, SqlTransaction sqlTransaction, MetaInfoStore metaInfoStore)
 {
     _connection     = connection;
     _sqlTransaction = sqlTransaction;
     MetaInfoStore   = metaInfoStore;
 }
Exemplo n.º 15
0
 protected MetaInfo(MetaInfoStore metaInfoStore)
 {
     MetaInfoStore = metaInfoStore;
 }
Exemplo n.º 16
0
 public InsertAction(SqlConnection connection, SqlTransaction sqlTransaction, MetaInfoStore metaInfoStore) : base(connection, sqlTransaction, metaInfoStore)
 {
 }
Exemplo n.º 17
0
 public void Setup()
 {
     metaInfoStore = new MetaInfoStore();
     metaInfoStore.BuildMetaInfoForAssembly(Assembly.GetExecutingAssembly());
 }
Exemplo n.º 18
0
        private async Task SaveInternalAsync(FileMetaInfo fileInfo, Stream stream, IDictionary <string, object> extraArgs, ImageStoreRule rule, bool modify = false)
        {
            if (!fileInfo.ContentType.ToLower().StartsWith("image"))
            {
                throw new NotSupportedException("传入文件类型不是有效的图片类型");
            }

            var needSaveFiles = new Dictionary <string, Stream>();

            var name = GetInnerFileName(fileInfo);


            var savedir = modify ? fileInfo.DirPath : rule.GetSaveDir();

            //保存原始图片
            if (rule.SaveOriginalImage)
            {
                var dir        = savedir;
                var svname     = rule.AddWaterMarker ? GetInnerFileName(fileInfo, "OriginalImage") : name;
                var fileStream = stream;
                await SaveFileAsync(dir, svname, fileStream, rule.AddWaterMarker);

                if (!rule.ThumbnailSizes.Any())
                {
                    stream.Position = 0;
                    needSaveFiles.Add(name, stream);
                }
            }

            //生成缩略图
            if (rule.ThumbnailSizes.Any())
            {
                foreach (var thumbConfig in rule.ThumbnailSizes.OrderBy(x => x.Value.Size.Height * x.Value.Size.Width))
                {
                    var key         = thumbConfig.Key;
                    var config      = thumbConfig.Value;
                    var thumbStream = GenThumbnail(stream, config);
                    var thumbName   = GetInnerFileName(fileInfo, key);
                    needSaveFiles.Add(thumbName, thumbStream);
                    stream.Position = 0;
                }

                //org comp
                if (rule.SaveOriginalImage && rule.AddWaterMarker && needSaveFiles.Any())
                {
                    var orgInstead = needSaveFiles.Last();
                    var dir        = savedir;
                    var stm        = await AddWaterMarkAsync(orgInstead.Value);
                    await SaveFileAsync(dir, name, stm);
                }
            }

            //添加水印
            if (rule.AddWaterMarker)
            {
                foreach (var images in needSaveFiles.ToDictionary(x => x.Key, x => x.Value))
                {
                    needSaveFiles[images.Key] = await AddWaterMarkAsync(images.Value);
                }
            }

            //持久化
            foreach (var images in needSaveFiles)
            {
                var dir        = savedir;
                var svname     = images.Key;
                var fileStream = images.Value;
                await SaveFileAsync(dir, svname, fileStream);

                if (fileStream != stream)
                {
                    fileStream.Dispose();
                }
            }
            if (extraArgs.ContainsKey("suffix"))
            {
                fileInfo.Path =
                    Path.Combine(savedir, GetInnerFileName(fileInfo, extraArgs["suffix"].ToString()))
                    .Replace("\\", "/");
            }
            else if (!rule.SaveOriginalImage && rule.ThumbnailSizes.ContainsKey("org"))
            {
                fileInfo.Path = Path.Combine(savedir, GetInnerFileName(fileInfo, "org")).Replace("\\", "/");
            }
            else
            {
                fileInfo.Path = Path.Combine(savedir, name).Replace("\\", "/");
            }


            //保存文件信息
            await MetaInfoStore.SaveAsync(fileInfo, rule.Id);
        }