Пример #1
0
        public IList <ContentFileInfo> GetList()
        {
            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select Id,AppCode,UserId,ContentId,FileName,FileSize,FileExt,FileUrl,ViewUrl,LastUpdatedDate 
			            from ContentFile
					    order by LastUpdatedDate desc "                    );

            IList <ContentFileInfo> list = new List <ContentFileInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString()))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ContentFileInfo model = new ContentFileInfo();
                        model.Id              = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                        model.AppCode         = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        model.UserId          = reader.IsDBNull(2) ? Guid.Empty : reader.GetGuid(2);
                        model.ContentId       = reader.IsDBNull(3) ? Guid.Empty : reader.GetGuid(3);
                        model.FileName        = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                        model.FileSize        = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
                        model.FileExt         = reader.IsDBNull(6) ? string.Empty : reader.GetString(6);
                        model.FileUrl         = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                        model.ViewUrl         = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                        model.LastUpdatedDate = reader.IsDBNull(9) ? DateTime.Parse("1754-01-01") : reader.GetDateTime(9);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #2
0
        protected async Task <IReadOnlyList <KeyValuePair <ContentHash, ContentFileInfo> > > PopulateRandomInfo(
            IContentDirectory contentDirectory, Func <int, bool> shouldPopulateIteration = null)
        {
            var list = new List <KeyValuePair <ContentHash, ContentFileInfo> >();

            for (var i = 0; i < DefaultInfoCount; i++)
            {
                byte[] content = ThreadSafeRandom.GetBytes(DefaultFileSize);
                using (var stream = new MemoryStream(content))
                {
                    ContentHash contentHash = await _hasher.GetContentHashAsync(stream);

                    var newInfo = new ContentFileInfo(MemoryClock, content.Length);

                    if (shouldPopulateIteration == null || shouldPopulateIteration(i))
                    {
                        await contentDirectory.UpdateAsync(contentHash, false, MemoryClock, fileInfo =>
                        {
                            Assert.Null(fileInfo);
                            return(Task.FromResult(newInfo));
                        });
                    }

                    list.Add(new KeyValuePair <ContentHash, ContentFileInfo>(contentHash, newInfo));
                }
            }

            return(list);
        }
Пример #3
0
        public int Update(ContentFileInfo model)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append(@"update ContentFile set AppCode = @AppCode,UserId = @UserId,ContentId = @ContentId,FileName = @FileName,FileSize = @FileSize,FileExt = @FileExt,FileUrl = @FileUrl,ViewUrl = @ViewUrl,LastUpdatedDate = @LastUpdatedDate 
			            where Id = @Id
					    "                    );

            SqlParameter[] parms =
            {
                new SqlParameter("@Id",              SqlDbType.UniqueIdentifier),
                new SqlParameter("@AppCode",         SqlDbType.Char,                6),
                new SqlParameter("@UserId",          SqlDbType.UniqueIdentifier),
                new SqlParameter("@ContentId",       SqlDbType.UniqueIdentifier),
                new SqlParameter("@FileName",        SqlDbType.NVarChar,          256),
                new SqlParameter("@FileSize",        SqlDbType.Int),
                new SqlParameter("@FileExt",         SqlDbType.VarChar,            50),
                new SqlParameter("@FileUrl",         SqlDbType.NVarChar,          256),
                new SqlParameter("@ViewUrl",         SqlDbType.NVarChar,          256),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.AppCode;
            parms[2].Value = model.UserId;
            parms[3].Value = model.ContentId;
            parms[4].Value = model.FileName;
            parms[5].Value = model.FileSize;
            parms[6].Value = model.FileExt;
            parms[7].Value = model.FileUrl;
            parms[8].Value = model.ViewUrl;
            parms[9].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString(), parms));
        }
Пример #4
0
        public IList <ContentFileInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append(@"select count(*) from ContentFile ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString(), cmdParms);

            if (totalRecords == 0)
            {
                return(new List <ContentFileInfo>());
            }

            sb.Clear();
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber,
			          Id,AppCode,UserId,ContentId,FileName,FileSize,FileExt,FileUrl,ViewUrl,LastUpdatedDate
					  from ContentFile "                    );
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex);

            IList <ContentFileInfo> list = new List <ContentFileInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ContentFileInfo model = new ContentFileInfo();
                        model.Id              = reader.IsDBNull(1) ? Guid.Empty : reader.GetGuid(1);
                        model.AppCode         = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
                        model.UserId          = reader.IsDBNull(3) ? Guid.Empty : reader.GetGuid(3);
                        model.ContentId       = reader.IsDBNull(4) ? Guid.Empty : reader.GetGuid(4);
                        model.FileName        = reader.IsDBNull(5) ? string.Empty : reader.GetString(5);
                        model.FileSize        = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        model.FileExt         = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                        model.FileUrl         = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                        model.ViewUrl         = reader.IsDBNull(9) ? string.Empty : reader.GetString(9);
                        model.LastUpdatedDate = reader.IsDBNull(10) ? DateTime.Parse("1754-01-01") : reader.GetDateTime(10);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #5
0
        public async Task <ContentFileInfo> GetCacheFileInfo(ContentHash contentHash)
        {
            ContentFileInfo info = null;

            await ContentDirectory.UpdateAsync(contentHash, false, Clock, fileInfo =>
            {
                info = fileInfo;
                return(null);
            });

            return(info);
        }
Пример #6
0
        internal List <ContentFileInfo> GetContentFiles(string contentFolderLocation)
        {
            List <ContentFileInfo> ContentFileInfos = new List <ContentFileInfo>();

            string[] files = Directory.GetFiles(contentFolderLocation, "*.md", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                ContentFileInfos.Add(
                    ContentFileInfo.For(file)
                    );
            }

            return(ContentFileInfos);
        }
Пример #7
0
        public async Task OutOfRangeTimestampsNormalized()
        {
            var context = new Context(Logger);

            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                // Construct a valid directory with some legit entries.
                using (var directory = new MemoryContentDirectory(FileSystem, testDirectory.Path))
                {
                    await directory.StartupAsync(context).ShouldBeSuccess();
                    await PopulateRandomInfo(directory);

                    await directory.ShutdownAsync(context).ShouldBeSuccess();
                }

                // Corrupt it in place with out of range timestamps.
                var i = 0;
                await MemoryContentDirectory.TransformFile(context, FileSystem, testDirectory.Path, pair =>
                {
                    ContentFileInfo fileInfo    = pair.Value;
                    var lastAccessedFileTimeUtc = (i++ % 2) == 0 ? -1 : long.MaxValue;
                    var updatedFileInfo         = new ContentFileInfo(fileInfo.FileSize, lastAccessedFileTimeUtc, fileInfo.ReplicaCount);
                    return(new KeyValuePair <ContentHash, ContentFileInfo>(pair.Key, updatedFileInfo));
                });

                // Load the directory again, fixing the bad timestamps.
                using (var directory = new MemoryContentDirectory(FileSystem, testDirectory.Path))
                {
                    await directory.StartupAsync(context).ShouldBeSuccess();

                    await directory.ShutdownAsync(context).ShouldBeSuccess();
                }

                // Verify timestamps are now in range.
                long nowFileTimeUtc = DateTime.UtcNow.ToFileTimeUtc();
                await MemoryContentDirectory.TransformFile(context, FileSystem, testDirectory.Path, pair =>
                {
                    long fileTimeUtc = pair.Value.LastAccessedFileTimeUtc;
                    fileTimeUtc.Should().BePositive();
                    fileTimeUtc.Should().BeLessOrEqualTo(nowFileTimeUtc);
                    return(pair);
                });
            }
        }
Пример #8
0
        public void ParseNixString_ReturnCorrectFTPFileInfo(string dataListing, bool isDirectory, long fileSize, string fileName, int minute, int hour, int day, int month, int year)
        {
            //Arrange
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }

            var lastModified = new DateTime(year, month, day, hour, minute, 0);
            var expected     = new ContentFileInfo(isDirectory, fileSize, lastModified, fileName);

            //Act
            var actual = ContentFileInfoParser.ParseNixString(dataListing);

            //Assert
            Assert.AreEqual(expected.IsDirectory, actual.IsDirectory);
            Assert.AreEqual(expected.FileSize, actual.FileSize);
            Assert.AreEqual(expected.LastModifiedDate, actual.LastModifiedDate);
            Assert.AreEqual(expected.FileName, actual.FileName);
        }
Пример #9
0
        public Task ModifyWithUpdate()
        {
            var context = new Context(Logger);

            return(TestContentDirectory(context, async contentDirectory =>
            {
                var firstHash = (await PopulateRandomInfo(contentDirectory))[0].Key;
                var newInfo = new ContentFileInfo(MemoryClock, DefaultFileSize * 2, DefaultReplicaCount + 1);

                await contentDirectory.UpdateAsync(firstHash, false, MemoryClock, fileInfo =>
                {
                    Assert.NotNull(fileInfo);
                    return Task.FromResult(newInfo);
                });

                await contentDirectory.UpdateAsync(firstHash, false, MemoryClock, fileInfo =>
                {
                    fileInfo.ReplicaCount.Should().Be(newInfo.ReplicaCount);
                    return Task.FromResult((ContentFileInfo)null);
                });
            }));
        }
Пример #10
0
        public ContentFileInfo GetModel(Guid id)
        {
            ContentFileInfo model = null;

            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select top 1 Id,AppCode,UserId,ContentId,FileName,FileSize,FileExt,FileUrl,ViewUrl,LastUpdatedDate 
			            from ContentFile
						where Id = @Id "                        );
            SqlParameter[] parms =
            {
                new SqlParameter("@Id", SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = id;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString(), parms))
            {
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        model                 = new ContentFileInfo();
                        model.Id              = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                        model.AppCode         = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        model.UserId          = reader.IsDBNull(2) ? Guid.Empty : reader.GetGuid(2);
                        model.ContentId       = reader.IsDBNull(3) ? Guid.Empty : reader.GetGuid(3);
                        model.FileName        = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                        model.FileSize        = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
                        model.FileExt         = reader.IsDBNull(6) ? string.Empty : reader.GetString(6);
                        model.FileUrl         = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                        model.ViewUrl         = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                        model.LastUpdatedDate = reader.IsDBNull(9) ? DateTime.Parse("1754-01-01") : reader.GetDateTime(9);
                    }
                }
            }

            return(model);
        }
Пример #11
0
        public IList <ContentFileInfo> GetListByJoin(string sqlWhere, params SqlParameter[] cmdParms)
        {
            var sb = new StringBuilder(500);

            sb.Append(@"select Id,AppCode,UserId,ContentId,FileName,FileSize,FileExt,FileUrl,ViewUrl,LastUpdatedDate
                        from ContentFile ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.Append("order by LastUpdatedDate desc ");

            var list = new List <ContentFileInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.TygaSoftDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ContentFileInfo model = new ContentFileInfo();
                        model.Id              = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                        model.ContentId       = reader.IsDBNull(3) ? Guid.Empty : reader.GetGuid(3);
                        model.FileName        = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                        model.FileSize        = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
                        model.FileExt         = reader.IsDBNull(6) ? string.Empty : reader.GetString(6);
                        model.FileUrl         = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                        model.ViewUrl         = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                        model.LastUpdatedDate = reader.IsDBNull(9) ? DateTime.Parse("1754-01-01") : reader.GetDateTime(9);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #12
0
        public Task CannotModifyOutsideUpdate()
        {
            var context = new Context(Logger);

            return(TestContentDirectory(context, async contentDirectory =>
            {
                var firstHash = (await PopulateRandomInfo(contentDirectory))[0].Key;

                ContentFileInfo outsideInfo = null;
                await contentDirectory.UpdateAsync(firstHash, false, MemoryClock, fileInfo =>
                {
                    Assert.NotNull(fileInfo);
                    outsideInfo = fileInfo;
                    return null;
                });

                outsideInfo.ReplicaCount++;
                await contentDirectory.UpdateAsync(firstHash, false, MemoryClock, fileInfo =>
                {
                    fileInfo.ReplicaCount.Should().NotBe(outsideInfo.ReplicaCount);
                    return null;
                });
            }));
        }
Пример #13
0
 public int Update(ContentFileInfo model)
 {
     return(dal.Update(model));
 }
Пример #14
0
 public int InsertByOutput(ContentFileInfo model)
 {
     return(dal.InsertByOutput(model));
 }
Пример #15
0
        /// <summary>
        /// Returns All The Textures In The Textures Directory
        /// </summary>
        /// <param name="BaseDirectory"></param>
        /// <param name="FileTypes"></param>
        /// <param name="LoadedTextures"></param>
        /// <returns></returns>
        public static Dictionary <string, ContentFileInfo> LoadTextures(string BaseDirectory, string[] FileTypes = null, Dictionary <string, ContentFileInfo> LoadedTextures = null)
        {
            Dictionary <string, ContentFileInfo> TmpReturn = new Dictionary <string, ContentFileInfo>();

            if (LoadedTextures != null)
            {
                foreach (var key in LoadedTextures.Keys)
                {
                    TmpReturn.Add(key, LoadedTextures[key]);
                }
            }

            if (FileTypes == null)
            {
                FileTypes = new string[] { "png", "jpg", "bmp" };
            }

            if (BaseDirectory.DirectoryExists() == false)
            {
                throw new InvalidPathException(BaseDirectory);
            }

            // Load Files In Folder
            // Folder Should contain info.txt describing the images
            var _Files    = System.IO.Directory.GetFiles(BaseDirectory);
            var _InfoFile = from f in _Files where f.ToLower().EndsWith("info.txt") select f;

            if (_InfoFile != null && _InfoFile.Count() == 1)
            {
                dynamic _TextureData        = ACT.Core.Dynamic.Encoder.LoadFromFile(BaseDirectory.EnsureDirectoryFormat() + _InfoFile.First().GetFileNameFromFullPath());
                string  _PackageName        = _TextureData.name;
                string  _PackageDescription = _TextureData.description;

                // Loop Through Each Background Definition
                foreach (var ObjectName in _TextureData.backgrounds.GetMemberNames)
                {
                    if (ObjectName == "name")
                    {
                        continue;
                    }
                    var    _FileName    = _TextureData.backgrounds.GetObject(ObjectName).filename;
                    string _Description = _TextureData.backgrounds.GetObject(ObjectName).description;
                    var    img_fs       = from fs in _Files where FileTypes.Contains(fs.ToLower().Right(3)) select fs.ToString();

                    if (TmpReturn.ContainsKey(_FileName) == false)
                    {
                        ContentFileInfo _New = new ContentFileInfo();
                        _New.PackageName     = _PackageName;
                        _New.Directory       = BaseDirectory;
                        _New.FileName        = _FileName;
                        _New.FileDescription = _Description;

                        TmpReturn.Add(_PackageName + "\\" + _FileName, _New);
                    }
                }
            }

            // Loop Through Each Folder
            foreach (var s in System.IO.Directory.GetDirectories(BaseDirectory))
            {
                TmpReturn = LoadTextures(s, FileTypes, TmpReturn);
            }

            return(TmpReturn);
        }
Пример #16
0
 public ThemingFileProvider()
 {
     _viewImportsFileInfo = new ContentFileInfo("_ViewImports" + RazorViewEngine.ViewExtension, "@inherits OrchardCore.DisplayManagement.Razor.RazorPage<TModel>");
 }
Пример #17
0
        private void UploadContentFile(HttpContext context)
        {
            #region 请求参数集

            var contentId = Guid.Empty;
            if (context.Request.Form["ContentId"] != null)
            {
                Guid.TryParse(context.Request.Form["ContentId"], out contentId);
            }
            if (contentId.Equals(Guid.Empty))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            var appCode = context.Request.Form["AppCode"];
            if (string.IsNullOrWhiteSpace(appCode))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            var userId = WebCommon.GetUserId();
            if (userId.Equals(Guid.Empty))
            {
                throw new ArgumentException(MC.L_InvalidError);
            }
            var currTime = DateTime.Now;
            var effect   = 0;

            #endregion

            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                var          ufh = new UploadFilesHelper();
                ImagesHelper ih  = new ImagesHelper();
                foreach (string item in files.AllKeys)
                {
                    HttpPostedFile file = files[item];
                    if (file == null || file.ContentLength == 0)
                    {
                        continue;
                    }
                    var ext = Path.GetExtension(file.FileName);

                    FileValidated(file);

                    string originalUrl  = ufh.UploadOriginalFile(file, "ContentFiles", currTime);
                    var    originalPath = UploadFilesHelper.ToFullPath(originalUrl);
                    var    htmlFullPath = string.Empty;
                    if (ext == ".doc" || ext == ".docx")
                    {
                        htmlFullPath = OoxmlConvert.WordToHtml(originalPath, Path.GetFileNameWithoutExtension(file.FileName));
                    }
                    else if (ext == ".xls" || ext == ".xlsx")
                    {
                        htmlFullPath = AsposeConvert.ExcelToHtml(originalPath, Path.GetFileNameWithoutExtension(file.FileName));
                    }

                    var cfInfo = new ContentFileInfo(Guid.Empty, appCode.Trim(), userId, contentId, file.FileName, file.ContentLength, VirtualPathUtility.GetExtension(file.FileName).ToLower(), originalUrl.Trim('~'), UploadFilesHelper.ToVirtualPath(htmlFullPath), currTime);
                    var cfBll  = new ContentFile();
                    effect += cfBll.Insert(cfInfo);

                    //if (ufh.IsImage(file))
                    //    CreateThumbnailImage(context, ih, context.Server.MapPath(originalUrl));
                }
            }

            if (effect > 0)
            {
                context.Response.Write(ResResult.ResJsonString(true, MC.M_Save_Ok, null));
            }
            else
            {
                context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));
            }
        }