public void LoadByBusinessID(string businessID)
        {
            string regScript = @"ID: '{0}',
                    FileName: '{1}',
                    FileSize:'{2}',
                    Url: '{3}',
                    CreatorName: '{4}',
                    CreateTime: '{5}'";

            AttachmentFilter filter = new AttachmentFilter();

            filter.BusinessID = businessID;
            if (string.IsNullOrEmpty(AttachmentType) == false)
            {
                filter.BusinessType = AttachmentType;
            }

            IList <B_Attachment> attachments = B_AttachmentOperator.Instance.GetAttachmentList(Guid.Parse(businessID), "月报上传");

            StringBuilder sScript = new StringBuilder("");

            for (int i = 0; i < attachments.Count; i++)
            {
                sScript.Append(this.ClientID + "_Attachments[" + i.ToString() + "] = {");
                sScript.Append(string.Format(regScript, new string[] { attachments[i].ID.ToString(),
                                                                       attachments[i].FileName,
                                                                       attachments[i].Size,
                                                                       HttpUtility.UrlEncode(attachments[i].Url),
                                                                       attachments[i].CreatorName,
                                                                       attachments[i].CreateTime.ToShortDateString() }));
                sScript.Append("};");
            }
            sScript.Append(this.ClientID + "_Show();");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Initial", sScript.ToString(), true);
        }
Beispiel #2
0
 /// <summary>
 /// A collection attachments that belong to this base asset filtered by the passed in filter
 /// </summary>
 public ICollection <Attachment> GetAttachments(AttachmentFilter filter)
 {
     filter = filter ?? new AttachmentFilter();
     filter.Asset.Clear();
     filter.Asset.Add(this);
     return(Instance.Get.Attachments(filter));
 }
Beispiel #3
0
        public override bool StepExecute(int operatorUserID, string param, ref long offset, ref int totalCount, ref int finishedCount, out string title, out bool isLastStep)
        {
            AttachmentFilter filter = AttachmentFilter.Parse(param);

            AuthUser operatorUser = UserBO.Instance.GetAuthUser(operatorUserID);

            int stepCount;

            if (PostBOV5.Instance.DeleteSearchAttachments(operatorUser, filter, stepDeleteCount, out stepCount)) // .DeleteDoingsBySearch(filter, 200);
            {
                finishedCount += stepCount;

                isLastStep = stepCount < stepDeleteCount;

                title = "正在删除附件,总数 " + totalCount + ",已删 " + finishedCount;

                return(true);
            }
            else
            {
                isLastStep = false;

                title = "发生错误";

                return(false);
            }
        }
        //get a list of valid extensions for the given file category
        private static string[] GetValidExtensions(AttachmentFilter filter)
        {
            string[] validExtensions;

            switch (filter)
            {
            case AttachmentFilter.Audio:
                validExtensions = _validAudioExtensions;
                break;

            case AttachmentFilter.Media:
                validExtensions = _validMediaExtensions;
                break;

            case AttachmentFilter.Images:
                validExtensions = _validImageExtensions;
                break;

            case AttachmentFilter.Plaintext:
                validExtensions = _validPlaintextExtensions;
                break;

            case AttachmentFilter.All:
                validExtensions = _wildcardExtension;
                break;

            default:
                validExtensions = new string[] { };
                break;
            }

            return(validExtensions);
        }
        private void DeletedSearchResult()
        {
            AttachmentFilter filter = AttachmentFilter.GetFromFilter("filter");

            if (TaskManager.BeginTask(MyUserID, new DeleteAttachmentTask(), filter.ToString()))
            {
            }
        }
Beispiel #6
0
        public override void AfterExecute(int operatorUserID, string param, bool success, int totalCount, int finishedCount, out string title)
        {
            if (success)
            {
                title = "删除附件成功,共删除 " + finishedCount + " 个附件";

                AttachmentFilter filter = AttachmentFilter.Parse(param);

                AuthUser operatorUser = UserBO.Instance.GetAuthUser(operatorUserID);

                Logs.LogManager.LogOperation(
                    new Topic_DeleteAttachmentBySearch(operatorUserID, operatorUser.Name, operatorUser.LastVisitIP, filter, finishedCount)
                    );
            }
            else
            {
                title = "删除附件失败";
            }
        }
Beispiel #7
0
        public override bool BeforeExecute(int operatorUserID, string param, ref long offset, ref int totalCount, out string title)
        {
            AttachmentFilter filter = AttachmentFilter.Parse(param);

            AuthUser operatorUser = UserBO.Instance.GetAuthUser(operatorUserID);

            int tempTotalCount;
            AttachmentCollection attachments = PostBOV5.Instance.GetAttachments(operatorUser, filter, 1, out tempTotalCount);

            if (attachments == null || attachments.Count == 0)
            {
                title = "没有数据可以删除";
                return(false);
            }

            totalCount = tempTotalCount;

            title = "将删除 " + totalCount + " 个附件";

            return(true);
        }
        public static List <string> GetTempAssets(AttachmentFilter filter)
        {
            string[] validExtensions = GetValidExtensions(filter);

            DirectoryInfo d = new DirectoryInfo(Path.Combine("assets", "temp"));

            //Filter files by regex
            FileInfo[] Files = d.GetFiles();

            List <string> filePaths = new List <string>();

            foreach (FileInfo file in Files)
            {
                if (FileIsValid(file.FullName, validExtensions))
                {
                    filePaths.Add(file.FullName);
                }
            }

            return(filePaths);
        }
        public virtual IEnumerable <Server.Model.Attachment.Attachment> Get(AttachmentFilter <int?> filter)
        {
            try
            {
                var res = (from attachment in Db.Set <Server.Model.Attachment.Attachment>()
                           join attachmentType in Db.Set <Server.Model.Attachment.AttachmentType>() on attachment.AttachmentTypeId equals attachmentType.Id
                           where (!filter.AttachmentTypeId.HasValue || attachment.AttachmentTypeId == filter.AttachmentTypeId) &&
                           (!filter.ExtensionId.HasValue || attachment.ExtensionId == filter.ExtensionId)
                           select attachment);


                return(res);
                //        Db.Set<Server.Model.Attachment.Attachment>()
                //            .Include(it => it.AttachmentType)
                //            .Where(it => !filter.AttachmentTypeId.HasValue || it.AttachmentTypeId == filter.AttachmentTypeId)
                //            .Where(attach => !filter.ExtensionId.HasValue || attach.ExtensionId == filter.ExtensionId);
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }
Beispiel #10
0
 public override IEnumerable <Server.Model.Attachment.Attachment> Get(AttachmentFilter <int?> filter)
 {
     try
     {
         var realFilter = filter as SecuredAttachmentFilter <int?, int?, int?>;
         if (realFilter == null)
         {
             return(base.Get(filter));
         }
         return((from attach in base.Get(filter)
                 join attachmentTypePermission in Db.Set <AttachmentTypePermission>() on attach.AttachmentTypeId equals
                 attachmentTypePermission.AttachmentTypeId
                 where
                 (realFilter.RoleIds == null || !realFilter.RoleIds.Any() || realFilter.RoleIds.Contains(attachmentTypePermission.RoleId)) &&
                 (realFilter.PermissionIds == null || !realFilter.PermissionIds.Any() || realFilter.PermissionIds.Contains(attachmentTypePermission.PermissionId))
                 select attach).Distinct());
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex.Message, ex);
         throw;
     }
 }
        public async Task <ResultList> GetAllFilesAsync(AttachmentFilter filterDto)
        {
            IQueryable <Attachment> files = Context.Attachments.Include(x => x.AttachmentType);

            files = files.Where(x => filterDto.CustomerID == 0 || x.CustomerHeadID == filterDto.CustomerID)
                    .Where(x => filterDto.UserID == 0 || x.UserID == filterDto.UserID)
                    .Where(x => filterDto.SessionID == 0 || x.SessionID == filterDto.SessionID);


            ResultList resultList = new ResultList()
            {
                TotalRows   = files.Count(),
                MaxPageRows = _take
            };

            if (filterDto.WithPaging)
            {
                files = files.Skip((filterDto.PageNumber - 1) * _take).Take(_take);
            }

            resultList.Results = await files.ToListAsync();

            return(resultList);
        }
Beispiel #12
0
 /// <summary>
 /// Get attachments filtered by the criteria specified in the passed in filter.
 /// </summary>
 /// <param name="filter">Limit the items returned. If null, then all items returned.</param>
 /// <returns>ICollection of items as specified in the filter.</returns>
 public ICollection <Attachment> Attachments(AttachmentFilter filter)
 {
     return(Get <Attachment>(filter ?? new AttachmentFilter()));
 }
Beispiel #13
0
 public abstract AttachmentCollection GetAttachments(int pageNumber, AttachmentFilter filter, Guid[] excludeRoleIDs, ref int totalCount);
Beispiel #14
0
 public abstract void DeleteSearchAttachments(AttachmentFilter filter, IEnumerable <Guid> excludeRoleIDs, int topCount, out int deletedCount, out List <int> threadIDs);
Beispiel #15
0
        private string BuilderSearchAttachmentCondition(AttachmentFilter filter, IEnumerable<Guid> excludeRoleIDs, SqlQuery query, bool startWithWhere)
        {
            SqlConditionBuilder condition;
            if (startWithWhere)
                condition = new SqlConditionBuilder(SqlConditionStart.Where);
            else
                condition = new SqlConditionBuilder(SqlConditionStart.None);

            condition += (filter.ForumID == null ? "" : ("AND [ForumID] = @ForumID "));
            condition += (filter.UserID == null ? "" : ("AND [UserID] = @UserID "));
            condition += (string.IsNullOrEmpty(filter.FileType) ? "" : ("AND [FileType] = @FileType "));
            condition += (string.IsNullOrEmpty(filter.KeyWord) ? "" : ("AND [FileName] LIKE '%'+@keyword+'%' "));
            condition += (filter.MinFileSize == null ? "" : ("AND [FileSize] >= @MinFileSize "));
            condition += (filter.MaxFileSize == null ? "" : ("AND [FileSize] <= @MaxFileSize "));
            condition += (filter.MinTotalDownload == null ? "" : ("AND [TotalDownloads] >= @MinTotalDownload "));
            condition += (filter.MaxTotalDownload == null ? "" : ("AND [TotalDownloads] <= @MaxTotalDownload "));
            condition += (filter.MinPrice == null ? "" : ("AND [Price] >= @MinPrice "));
            condition += (filter.MaxPrice == null ? "" : ("AND [Price] <= @MaxPrice "));
            condition += (filter.BeginDate == null ? "" : ("AND [CreateDate] > @BeginDate "));
            condition += (filter.EndDate == null ? "" : ("AND [CreateDate] < @EndDate "));

            if (string.IsNullOrEmpty(filter.KeyWord) == false)
            {
                query.CreateParameter<string>("@keyword", filter.KeyWord, SqlDbType.NVarChar, 256);
            }

            if (string.IsNullOrEmpty(filter.FileType) == false)
            {
                query.CreateParameter<string>("@FileType", filter.FileType, SqlDbType.VarChar, 10);
            }

            condition.AppendAnd(DaoUtil.GetExcludeRoleSQL("[UserID]", excludeRoleIDs, query));

            if (filter.ForumID != null)
                query.CreateParameter<int?>("@ForumID", filter.ForumID, SqlDbType.Int);
            if (filter.UserID != null)
                query.CreateParameter<int?>("@UserID", filter.UserID, SqlDbType.Int);

            if (filter.MaxFileSize != null)
            {
                query.CreateParameter<long>("@MaxFileSize", ConvertUtil.GetFileSize(filter.MaxFileSize.Value, filter.MaxFileSizeUnit), SqlDbType.BigInt);
            }
            if (filter.MinFileSize != null)
                query.CreateParameter<long>("@MinFileSize", ConvertUtil.GetFileSize(filter.MinFileSize.Value, filter.MinFileSizeUnit), SqlDbType.BigInt);

            if (filter.MaxTotalDownload != null)
                query.CreateParameter<int?>("@MaxTotalDownload", filter.MaxTotalDownload, SqlDbType.Int);
            if (filter.MinTotalDownload != null)
                query.CreateParameter<int?>("@MinTotalDownload", filter.MinTotalDownload, SqlDbType.Int);

            if (filter.MaxPrice != null)
                query.CreateParameter<int?>("@MaxPrice", filter.MaxPrice, SqlDbType.Int);
            if (filter.MinPrice != null)
                query.CreateParameter<int?>("@MinPrice", filter.MinPrice, SqlDbType.Int);

            if (filter.BeginDate != null)
                query.CreateParameter<DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime);
            if (filter.EndDate != null)
                query.CreateParameter<DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime);

            return condition.ToString();
        }
Beispiel #16
0
        public override void DeleteSearchAttachments(AttachmentFilter filter, IEnumerable<Guid> excludeRoleIDs, int topCount, out int deletedCount, out List<int> threadIDs)
        {

            using (SqlQuery query = new SqlQuery())
            {

                string conditon = BuilderSearchAttachmentCondition(filter, excludeRoleIDs, query, false);

                query.CommandText = @"
DECLARE @Table table(AttachmentID int,FileID varchar(50),ThreadID int);
INSERT INTO @Table SELECT TOP (@TopCount) [AttachmentID],[FileID],[ThreadID] FROM [bx_AttacmentsWithForumID] WHERE " + conditon + @";
DELETE [bx_Attachments] WHERE AttachmentID IN(SELECT AttachmentID FROM @Table);
SELECT @@ROWCOUNT;
SELECT DISTINCT ThreadID FROM @Table;
";


                query.CreateTopParameter("@TopCount", topCount);

                threadIDs = new List<int>();
                //fileIDs = new List<string>();
                deletedCount = 0;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        deletedCount = reader.Get<int>(0);
                    }
                    if (reader.NextResult())
                    {
                        while (reader.Read())
                        {
                            threadIDs.Add(reader.Get<int>(0));
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public override AttachmentCollection GetAttachments(int pageNumber, AttachmentFilter filter, Guid[] excludeRoleIDs, ref int totalCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.IsDesc = filter.IsDesc;

                switch (filter.Order)
                {
                    case AttachmentFilter.OrderBy.AttachmentID:
                        query.Pager.SortField = "AttachmentID";
                        break;
                    case AttachmentFilter.OrderBy.FileSize:
                        query.Pager.SortField = "FileSize";
                        break;
                    case AttachmentFilter.OrderBy.Price:
                        query.Pager.SortField = "Price";
                        break;
                    default:
                        query.Pager.SortField = "TotalDownloads";
                        break;
                }

                query.Pager.PageNumber = pageNumber;
                query.Pager.PageSize = filter.PageSize;
                query.Pager.TotalRecords = totalCount;
                query.Pager.SelectCount = true;
                query.Pager.TableName = "[bx_AttacmentsWithForumID]";

                query.Pager.Condition = BuilderSearchAttachmentCondition(filter, excludeRoleIDs, query, false);



                AttachmentCollection attachments;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    attachments = new AttachmentCollection(reader);

                    if (reader.NextResult())
                    {
                        while (reader.Read())
                        {
                            totalCount = reader.GetInt32(0);
                        }
                    }
                    return attachments;
                }
            }
        }
        //get the most recently posted attachments for the given context, or null if none exist
        public async static Task <IReadOnlyCollection <Attachment> > GetMostRecentAttachmentsAsync(SocketCommandContext context, AttachmentFilter filter, int priorMsgCount = 20)
        {
            //filter attachments by file category
            string[] validExtensions = GetValidExtensions(filter);
            var      attachments     = context.Message.Attachments;

            if (attachments == null || attachments.Count == 0)
            {
                //look backwords by priorMsgCount messages for the most recent attachments
                var messages = await context.Channel.GetMessagesAsync(priorMsgCount).FlattenAsync();

                foreach (var message in messages)
                {
                    if (message.Attachments.Count > 0)
                    {
                        //if we've found valid attachments
                        if (AttachmentsAreValid(message.Attachments, validExtensions))
                        {
                            return((IReadOnlyCollection <Attachment>)message.Attachments);
                        }
                    }
                }

                //if none of the previous messages had any filtered attachments
                return(null);
            }
            //if there are valid attachments in the current message
            else
            {
                if (AttachmentsAreValid(attachments, validExtensions))
                {
                    return(attachments);
                }
                else
                {
                    return(null);
                }
            }
        }
        private void Search()
        {
            AttachmentFilter filter = AttachmentFilter.GetFromForm();

            filter.Apply("filter", "page");
        }
 //for use outside the class
 public static bool AttachmentsAreValid(IReadOnlyCollection <IAttachment> attachments, AttachmentFilter filter)
 {
     string[] validExtensions = GetValidExtensions(filter);
     return(AttachmentsAreValid(attachments, validExtensions));
 }