public MailMessage()
        {
            this.To = new MailAddressCollection();

            AlternateViews = new AlternateViewCollection();
            Attachments = new AttachmentCollection();
            Bcc = new MailAddressCollection();
            CC = new MailAddressCollection();
            ReplyToList = new MailAddressCollection();
            Headers = new Dictionary<string, string> {{"MIME-Version", "1.0"}};
        }
Esempio n. 2
0
    public static AttachmentCollection GetAttachmentsInfo(IDbConnection cn,string[] fileIds)
    {
        AttachmentCollection rv = new AttachmentCollection();

        using (IDataReader reader = YZDBProviderManager.CurrentProvider.GetAttachmentsInfo(cn,fileIds))
        {
            while (reader.Read())
                rv.Add(new Attachment(reader, YZAttachmentHelper.AttachmentRootPath));
        }

        return rv;
    }
        public void TestAddStream()
        {
            var      fileName    = Path.Combine("..", "..", "TestData", "images", "girl.jpg");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            using (var stream = File.OpenRead(fileName))
                attachment = (MimePart)attachments.Add(fileName, stream);

            Assert.AreEqual("image/jpeg", attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
        // Token: 0x0600003E RID: 62 RVA: 0x00004434 File Offset: 0x00002634
        private void AttachOriginalMessageToNotification(MessageItem initiationMessage, MessageItem notificationMessage, out string originalSenderDisplayname)
        {
            originalSenderDisplayname = string.Empty;
            if (string.IsNullOrEmpty(this.defaultAcceptedDomain))
            {
                ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Cannot attach original message to notification without domain for content conversion.");
                return;
            }
            AttachmentCollection attachmentCollection = initiationMessage.AttachmentCollection;

            foreach (AttachmentHandle handle in attachmentCollection)
            {
                using (Attachment attachment = attachmentCollection.Open(handle))
                {
                    if ("OriginalMessage".Equals(attachment.FileName, StringComparison.OrdinalIgnoreCase))
                    {
                        StreamAttachment streamAttachment = attachment as StreamAttachment;
                        if (streamAttachment != null)
                        {
                            using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                            {
                                using (ItemAttachment itemAttachment = (ItemAttachment)notificationMessage.AttachmentCollection.Create(AttachmentType.EmbeddedMessage))
                                {
                                    using (Item item = itemAttachment.GetItem())
                                    {
                                        InboundConversionOptions options = new InboundConversionOptions(this.defaultAcceptedDomain);
                                        ItemConversion.ConvertAnyMimeToItem(item, contentStream, options);
                                        item[MessageItemSchema.Flags] = MessageFlags.None;
                                        originalSenderDisplayname     = (item.TryGetProperty(MessageItemSchema.SenderDisplayName) as string);
                                        item.Save(SaveMode.NoConflictResolution);
                                        itemAttachment[AttachmentSchema.DisplayName] = initiationMessage.Subject;
                                        itemAttachment.Save();
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 5
0
        protected void SyncChangedAttachmentFolders()
        {
            string sel, hostpath, remotepath;

            //SFTPInterface sftpi = new SFTPInterface();
            //sel = @"select LogX, ERefNo = null from _Attachments where changed = 1 union select LogX = null, ERefNo from _Attachments where changed = 1";
            sel = @"select LogX, ERefNo from _Attachments where changed = 1";
            AttachmentCollection changed = Attachments.GetCollection(sel);

            foreach (Attachment a in changed)
            {
                hostpath   = GetHostPathToThisAttachment(a.Logx, a.ERefNo);
                remotepath = GetRemotePathToThisAttachment(a.Logx, a.ERefNo);
                int xxx = 0;
                xxx = SFTPInterface.SynchronizeAttachmentFolder(remotepath, hostpath);
                if (xxx == 0)
                {
                    Attachment.ClearAttachmentChangedFlag(a);
                }
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        AttachmentCollection MergeData(AttachmentCollection attachments, AttachmentCollection additionalAttachments)
        {
            try {
                if (attachments == null || attachments.Count <= 0)
                {
                    return(additionalAttachments);
                }
                if (additionalAttachments == null || additionalAttachments.Count <= 0)
                {
                    return(attachments);
                }

                AttachmentCollection result = new AttachmentCollection();
                result.AddRange(attachments);
                result.AddRange(additionalAttachments);
                return(result);
            }
            catch {
                return(attachments);
            }
        }
Esempio n. 8
0
        public async Task SendAsync(EmailTypes from,
                                    string to,
                                    string subject,
                                    string body,
                                    bool isBodyHtml = true,
                                    string cc       = null,
                                    string bcc      = null,
                                    AttachmentCollection attachments = null)
        {
            //1- Set Email Message
            var mailMessage = new MailMessage();

            mailMessage.From = EmailSettings.GetMailAddress(from);
            mailMessage.To.Add(to);
            mailMessage.Subject    = subject;
            mailMessage.IsBodyHtml = isBodyHtml;
            mailMessage.Body       = body;
            if (cc != null)
            {
                mailMessage.CC.Add(cc);
            }
            if (bcc != null)
            {
                mailMessage.Bcc.Add(bcc);
            }
            if (attachments != null)
            {
                foreach (var attachment in attachments)
                {
                    mailMessage.Attachments.Add(attachment);
                }
            }


            //2- Set SmtpClient
            var smtp = EmailSettings.GetSmtpClient(from);

            //3- Send Email
            await smtp.SendMailAsync(mailMessage);
        }
Esempio n. 9
0
        public virtual void testGetURLCidStream()
        {
            new MimeUtilTest().testBuildMimePackageDocJMF();
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");
            Attachment           bp = MimeUtil.GetPartByCID(mp, "jdf.JDF");
            JDFDoc  d = MimeUtil.getJDFDoc(bp);
            JDFNode n = d.getJDFRoot();
            JDFColorSpaceConversionParams cscp = (JDFColorSpaceConversionParams)n.getMatchingResource(ElementName.COLORSPACECONVERSIONPARAMS, null, null, 0);

            Assert.IsNotNull(cscp);
            JDFFileSpec fs  = cscp.getFinalTargetDevice();
            Stream      @is = fs.getURLInputStream();

            Assert.IsNotNull(@is);
            byte[] b = new byte[100];
            int    i = @is.Read(b, 0, 100);

            Assert.IsTrue(i > 0);
            string s = System.Text.Encoding.Default.GetString(b);

            Assert.IsTrue(s.IndexOf("I C C") >= 0);
        }
        public string AddAttachmentWithName(string files, string fileNames)
        {
            string str;

            try
            {
                char[]   chrArray  = new char[] { ';' };
                string[] strArrays = files.Split(chrArray);
                chrArray = new char[] { ';' };
                string[] strArrays1 = fileNames.Split(chrArray);
                bool     length     = (int)strArrays.Length == (int)strArrays1.Length;
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string str1 = strArrays[i].Trim();
                    if (!string.IsNullOrEmpty(str1))
                    {
                        if ((!length ? true : string.IsNullOrWhiteSpace(strArrays1[i])))
                        {
                            this.message.Attachments.Add(new Attachment(str1));
                        }
                        else
                        {
                            AttachmentCollection attachments = this.message.Attachments;
                            Attachment           attachment  = new Attachment(str1)
                            {
                                Name = strArrays1[i].Trim()
                            };
                            attachments.Add(attachment);
                        }
                    }
                }
                str = "";
            }
            catch (Exception exception)
            {
                str = SmtpMessage.ErrorMessage(exception);
            }
            return(str);
        }
Esempio n. 11
0
        public static void FillList(AttachmentCollection coll, OdbcDataReader reader, int totalRows, int firstRow)
        {
            int  index    = 0;
            bool readMore = true;

            while (reader.Read())
            {
                if (index >= firstRow && readMore)
                {
                    if (coll.Count >= totalRows && totalRows > 0)
                    {
                        readMore = false;
                    }
                    else
                    {
                        Attachment attachmentitem = Attachment.AttachmentItem(reader);
                        coll.Add(attachmentitem);
                    }
                }
                index++;
            }
        }
Esempio n. 12
0
        private IAttachment CreateAttachment(IItem parentItem, IAttachment entity, AttachmentType attachmentType)
        {
            ItemIdAttachment     itemIdAttachment     = entity as ItemIdAttachment;
            AttachmentCollection attachmentCollection = this.GetAttachmentCollection(parentItem);
            IAttachment          attachment;
            StorageTranslator <IAttachment, IAttachment> storageTranslator;

            if (itemIdAttachment != null)
            {
                using (IItem item = this.BindToItem(base.IdConverter.ToStoreObjectId(itemIdAttachment.ItemToAttachId)))
                {
                    attachment        = attachmentCollection.AddExistingItem(item);
                    storageTranslator = AttachmentTranslator <ItemIdAttachment, ItemIdAttachmentSchema> .MetadataInstance;
                    goto IL_5E;
                }
            }
            attachment        = attachmentCollection.CreateIAttachment(attachmentType);
            storageTranslator = this.GetAttachmentTranslator(attachment.AttachmentType, false);
IL_5E:
            storageTranslator.SetPropertiesFromEntityOnStorageObject(entity, attachment);
            return(attachment);
        }
        private static AttachmentCollection GetAttachmentCollection(Item item, UserContext userContext)
        {
            AttachmentCollection attachmentCollection = null;

            if (Utilities.IsSMimeButNotSecureSign(item))
            {
                Item item2 = Utilities.OpenSMimeContent(item);
                if (item2 != null)
                {
                    attachmentCollection = item2.AttachmentCollection;
                }
            }
            else if (userContext.IsIrmEnabled && !userContext.IsBasicExperience && Utilities.IsIrmDecrypted(item))
            {
                attachmentCollection = ((RightsManagedMessageItem)item).ProtectedAttachmentCollection;
            }
            if (attachmentCollection != null)
            {
                return(attachmentCollection);
            }
            return(item.AttachmentCollection);
        }
Esempio n. 14
0
        /// <summary>
        /// Handles the remove attachment button's Click event.
        /// </summary>
        /// <param name="sender">The button object.</param>
        /// <param name="e">The event arguments.</param>
        private void btnRemoveAttachment_Click(object sender, EventArgs e)
        {
            bool b = _changed;

            // Removes an attachment from the collection.
            _attachments.RemoveAt(cbxAttachment.SelectedIndex);

            // and the combo box.
            if (_attachments.Count > 0)
            {
                // and the combo box.
                cbxAttachment.Items.RemoveAt(cbxAttachment.SelectedIndex);
            }
            else
            {
                cbxAttachment.SelectedItem = null;
                cbxAttachment.Items.Clear();
            }

            if (cbxAttachment.Items.Count == 0)
            {
                // Disables the "Remove" button.
                btnRemoveAttachment.Enabled = false;
                _attachments = null;
                saveAttachmentsButton.Enabled = false;
            }
            else if (cbxAttachment.SelectedIndex == -1)
            {
                cbxAttachment.SelectedIndex = cbxAttachment.Items.Count - 1;
            }

            _changed           = true;
            saveButton.Enabled = true;
            if (b == false)
            {
                SetTitle();
            }
        }
        public virtual void RefreshAttachmentClassifications()
        {
            List <string>        list = new List <string>();
            AttachmentCollection attachmentCollection = this.StoreItem.AttachmentCollection;

            if (attachmentCollection != null && attachmentCollection.Count > 0)
            {
                foreach (AttachmentHandle handle in attachmentCollection)
                {
                    using (Attachment attachment = this.StoreItem.AttachmentCollection.Open(handle))
                    {
                        if (!ScanResultStorageProvider.IsExcludedFromDlp(attachment))
                        {
                            list.Add(string.Format(ScanResultStorageProvider.UniqueIdFormat, attachment.FileName, attachment.Id.ToBase64String()));
                        }
                    }
                }
            }
            list.Add(ScanResultStorageProvider.MessageBodyName);
            IEnumerable <DiscoveredDataClassification> dlpDetectedClassificationObjects = FipsResultParser.DeleteClassifications(this.GetDlpDetectedClassificationObjects(), list, true);

            this.SetDlpDetectedClassificationObjects(dlpDetectedClassificationObjects);
        }
            private string GenerateBody(string content, AttachmentCollection fs)
            {
                var body   = content ?? string.Empty;
                var images = _imagesRegex.Matches(body);

                if (images.Count > 0)
                {
                    var sb           = new StringBuilder();
                    var currentIndex = 0;
                    foreach (Match match in images)
                    {
                        var  fileid = match.Groups[_FILEID_REGEX_GROUP];
                        var  src    = match.Groups[_SRC_REGEX_GROUP];
                        Guid imgId;
                        if (GUID.TryParse(fileid.Value, out imgId))
                        {
                            fs.Add(imgId);
                            sb.Append(body.Substring(currentIndex, src.Index - currentIndex));
                            sb.Append(AttachmentCollection.CreateLink(imgId));
                            sb.Append(_SRC_ATT_POSTFIX);
                            currentIndex = body.IndexOf(_SRC_ATT_POSTFIX, fileid.Index + fileid.Length) + _SRC_ATT_POSTFIX.Length;
                        }
                        else
                        {
                            var newIndex = src.Index + src.Length + _SRC_ATT_POSTFIX.Length;
                            sb.Append(body.Substring(currentIndex, newIndex - currentIndex));
                            currentIndex = newIndex;
                        }
                    }
                    if (currentIndex < body.Length - 1)
                    {
                        sb.Append(body.Substring(currentIndex));
                    }
                    body = sb.ToString();
                }
                return(body);
            }
Esempio n. 17
0
 private static void FillAttachmentCollection(AttachmentCollection attachmentCollection, List <string> attachmentList, List <string> attachNameList)
 {
     if (attachmentList == null || attachmentList.Count <= 0)
     {
         return;
     }
     attachmentList.ForEach(
         delegate(string fileName)
     {
         Attachment attachment = new Attachment(fileName);
         attachmentCollection.Add(attachment);
     }
         );
     if (attachNameList != null)
     {
         for (int i = 0; i < attachmentList.Count; i++)
         {
             if (attachmentCollection.Count > i)
             {
                 attachmentCollection[i].Name = attachNameList[i];
             }
         }
     }
 }
            private AttachmentCollection ReadAttachments(EPActivity message)
            {
                var fs = new AttachmentCollection(_graph);

                foreach (NoteDoc notes in
                         PXSelect <NoteDoc,
                                   Where <NoteDoc.fileID, IsNotNull,
                                          And <NoteDoc.noteID, Equal <Required <NoteDoc.noteID> > > > > .
                         Select(_graph, message.NoteID))
                {
                    fs.Add((Guid)notes.FileID);
                }

                var addFiles = PXSelect <DynamicAttachment,
                                         Where <DynamicAttachment.refNoteID, Equal <Required <DynamicAttachment.refNoteID> > > > .
                               Select(_graph, message.NoteID);

                foreach (Guid fileId in DynamicAttachmentManager.Process(_graph, addFiles.Extract()))
                {
                    fs.Add(fileId);
                }

                return(fs);
            }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            AttachmentCollection collection = (AttachmentCollection)value;

            writer.WriteStartArray();

            foreach (Attachment a in collection)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("name");
                writer.WriteValue(a.Name);

                writer.WritePropertyName("comment");
                writer.WriteValue(a.Comment);

                writer.WritePropertyName("uri");
                writer.WriteValue(a.Uri);

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
        }
        public virtual bool NeedsClassificationForBodyOrAnyAttachments()
        {
            if (this.NeedsClassificationScan())
            {
                return(true);
            }
            AttachmentCollection attachmentCollection = this.StoreItem.AttachmentCollection;

            if (attachmentCollection != null && attachmentCollection.Count > 0)
            {
                foreach (AttachmentHandle handle in attachmentCollection)
                {
                    using (Attachment attachment = this.StoreItem.AttachmentCollection.Open(handle))
                    {
                        if (attachment != null && !ScanResultStorageProvider.IsExcludedFromDlp(attachment) && this.NeedsClassificationScan(attachment))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            return(false);
        }
Esempio n. 21
0
    public EmailSender(string subject, Queue <SubscriberInfo> subscribers, string fromEmail, string plainTextBody, string htmlBody, AttachmentCollection attachments)
    {
        if (fromEmail == "")
        {
            throw new InvalidEmailConfigurationException("From Email can't be an empty string");
        }

        if (htmlBody == "" && plainTextBody == "")
        {
            throw new InvalidEmailConfigurationException("The body of the email can't be an empty string");
        }

        if (subscribers.Count == 0)
        {
            throw new InvalidEmailConfigurationException("There are no subscribers to send this email to");
        }

        m_subject       = subject;
        m_subscribers   = subscribers;
        m_plainTextBody = plainTextBody;
        m_htmlBody      = htmlBody;
        m_fromEmail     = fromEmail;
        m_attachments   = attachments;
    }
Esempio n. 22
0
		/// <summary>
		/// Deletes the messages matching the messagefilter passed in
		/// </summary>
		/// <param name="messageFilter">The message filter.</param>
		/// <param name="trans">The transaction to use.</param>
		private static void DeleteMessages(IPredicate messageFilter, Transaction trans)
		{
			// first delete all audit info for these message. This isn't done by a batch call directly on the db, as this is a targetperentity hierarchy
			// which can't be deleted directly into the database in all cases, so we first fetch the entities to delete. 
			AuditDataMessageRelatedCollection messageAudits = new AuditDataMessageRelatedCollection();
			trans.Add(messageAudits);
			// use a fieldcompareset predicate to get the auditdata related to this message and then delete all of them using the collection.
			messageAudits.GetMulti(new FieldCompareSetPredicate(AuditDataMessageRelatedFields.MessageID, MessageFields.MessageID, SetOperator.In, messageFilter));
			messageAudits.DeleteMulti();

			// delete all attachments for this message. This can be done directly onto the db.
			AttachmentCollection attachments = new AttachmentCollection();
			trans.Add(attachments);
			// delete these directly from the db, using a fieldcompareset predicate
			attachments.DeleteMulti(new FieldCompareSetPredicate(AttachmentFields.MessageID, MessageFields.MessageID, SetOperator.In, messageFilter));

			// delete the message/messages
			MessageCollection messages = new MessageCollection();
			trans.Add(messages);
			// use the passed in filter to remove the messages
			messages.DeleteMulti(messageFilter);

			// don't commit the transaction, leave that to the caller.
		}
Esempio n. 23
0
        public static AttachmentCollection GetCollection(string selection)
        {
            AttachmentCollection ac          = new AttachmentCollection();
            OdbcConnection       conn        = new OdbcConnection(ConfigurationManager.AppSettings["adbmdsn"]);
            OdbcCommand          cmdSalesman = new OdbcCommand(selection, conn);

            try
            {
                conn.Open();
                OdbcDataReader dr;
                dr = cmdSalesman.ExecuteReader();
                FillList(ac, dr);
                dr.Close();
            }
            catch (Exception eODBC)
            {
                string xxx = eODBC.Message;
            }
            finally
            {
                conn.Close();
            }
            return(ac);
        }
Esempio n. 24
0
         /// <summary>
        ///处理 [local] (帖子发完后 临时附件转为真的附件 再处理帖子内容的[local] )
        /// </summary>
        /// <param name="content"></param>
        /// <param name="attachments">附件 </param>
        /// <param name="realAttachmentIDs">真实附件ID 与 attachments 一一对应</param>
        /// <returns></returns>
        public static string ParseLocalAttachTag(string content, AttachmentCollection attachments, List<int> realAttachmentIDs, Dictionary<string, int> fileIDs)
        {
            if (attachments != null && attachments.Count > 0)
            {
                content = regex_LocalAttach.Replace(content, delegate(Match match)
                {
                    return OnMatchLocalFile(match, null, null, attachments, realAttachmentIDs, fileIDs, false);
                });
            }

            return content;
        }
Esempio n. 25
0
        //public static Regex regex_allAttach = new Regex(@"\[attach[imgeda=\d+,]*\](?<id>\d+)\[/attach[imgeda]*\]", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline);

        /// <summary>
        /// 保存的时候 处理UBB 处理表情 不处理[local]标签
        /// </summary>
        /// <param name="posterUserID"></param>
        /// <param name="userEmoticon"></param>
        /// <param name="forumID"></param>
        /// <param name="content"></param>
        /// <param name="allowHtml"></param>
        /// <param name="allowMaxcode3"></param>
        /// <returns></returns>
        public static string ParseWhenSave(int posterUserID, bool useEmoticon, int forumID, string content, bool allowHtml, bool allowMaxcode3, AttachmentCollection attachments)
        {
            User currentUser = User.Current;

            content = content.Replace("[/quote]\r", "[/quote]");
            content = content.Replace("[/quote]\n", "[/quote]");

            content = new PostUbbParserV5(UserBO.Instance.GetUser(posterUserID,GetUserOption.WithAll), forumID, allowHtml, allowMaxcode3, true).UbbToHtml(content);

            bool allowEmoticon = AllSettings.Current.ForumSettings.Items.GetForumSettingItem(forumID).CreatePostAllowEmoticon.GetValue(currentUser);

            if (useEmoticon && allowEmoticon)
            {
                content = EmoticonParser.ParseToHtml(posterUserID, content);
            }

            //attachments  同一个附件出现多次 只显示一个?

            return content;
        }
Esempio n. 26
0
        public static string ParseWhenDisplay(int posterUserID, int forumID, int postID, string content, bool allowHtmlForV2, bool allowMaxcodeForV2, bool isV5_0, AttachmentCollection attachmemts)
        {
            content = StringUtil.EncodeInnerUrl(content);

            User postUser = UserBO.Instance.GetUser(posterUserID, GetUserOption.WithAll);

            if (attachmemts != null && attachmemts.Count > 0)
            {
                ForumSettingItem forumSetting = AllSettings.Current.ForumSettings.Items.GetForumSettingItem(forumID);
                AuthUser my = User.Current;

                bool? hasViewAttachPermission = null, canAlwaysViewContents = null, allowImageTag = null
                    , allowAudioTag = null, allowVideoTag = null, allowFlashTag = null;
                content = regex_allAttach.Replace(content, delegate(Match match)
                {
                    return OnMatchAllAttach(match, my, postUser, forumID, attachmemts, forumSetting, ref hasViewAttachPermission
                        , ref canAlwaysViewContents, ref allowImageTag, ref allowAudioTag, ref allowVideoTag, ref allowFlashTag);
                });

                if (isV5_0 == false)
                {
                    content = ReplaceV30AttachTag(content, postID);

                    content = regex_fileInfo.Replace(content, string.Empty);
                }

            }

            if (isV5_0 == false)
                content = new PostUbbParserV5(postUser, forumID, true, allowMaxcodeForV2, false).UbbToHtml(content);

            return UrlUtil.ReplaceRootVar(content);
        }
Esempio n. 27
0
        private static string OnMatchAllAttach(Match match, AuthUser operatorUser, User postUser, int forumID, AttachmentCollection attachments, ForumSettingItem forumSetting
            , ref bool? hasViewAttachPermission, ref bool? canAlwaysViewContents, ref bool? allowImageTag, ref bool? allowAudioTag, ref bool? allowVideoTag, ref bool? allowFlashTag)
        {
            if (match.Success == false)
                return match.Value;

            string type = match.Groups["type"].Value;

            if (hasViewAttachPermission == null)
                hasViewAttachPermission = AllSettings.Current.ForumPermissionSet.Nodes.GetPermission(forumID).Can(operatorUser, ForumPermissionSetNode.Action.ViewAttachment);

            if (!hasViewAttachPermission.Value)
            {
                string message;
                if (operatorUser.UserID == 0)
                {
                    message = "您是游客";
                }
                else
                {
                    message = string.Empty;
                }

                if (StringUtil.EqualsIgnoreCase(type, "img"))
                    return GetNopermissionStyle(string.Concat(message, "您没有权限查看该图片"));
                else if (StringUtil.EqualsIgnoreCase(type, "media"))
                    return GetNopermissionStyle(string.Concat(message, "您没有权限查看该多媒体"));
                else
                {
                    int attachID = int.Parse(match.Groups["id"].Value);
                    Attachment attachment = attachments.GetValue(attachID);
                    if (attachment != null)
                        return GetNoPermissonfileStyle(attachment.FileName, operatorUser.UserID == 0);
                    else
                        return match.Value;
                }
            }
            else
            {
                int attachID = int.Parse(match.Groups["id"].Value);
                Attachment attachment = attachments.GetValue(attachID);

                if (attachment == null)
                    return match.Value;

                if (canAlwaysViewContents == null)
                {
                    ForumPermissionSetNode forumPermission = AllSettings.Current.ForumPermissionSet.Nodes.GetPermission(forumID);
                    canAlwaysViewContents = forumPermission.Can(operatorUser, ForumPermissionSetNode.Action.AlwaysViewContents);
                }

                if (StringUtil.EqualsIgnoreCase(type, "img"))
                {
                    if (allowImageTag == null)
                    {
                        allowImageTag = forumSetting.CreatePostAllowImageTag.GetValue(postUser);
                    }
                    if (allowImageTag.Value)
                    {
                        if (attachment.Price == 0 || attachment.UserID == operatorUser.UserID || canAlwaysViewContents.Value || attachment.IsBuyed(operatorUser) || attachment.IsOverSellDays(forumSetting))
                        {
                            //string info = string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" /><a href=\"", BbsUrlHelper.GetAttachmentUrl(attachment.AttachmentID), "\">", attachment.FileName, "</a>  <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:", attachment.TotalDownloads.ToString(), ")</span><br />");

                            string[] param = StringUtil.Split(match.Groups["param"].Value);
                            string width, height;
                            if (param.Length > 1)
                            {
                                width = param[0];
                                height = param[1];
                            }
                            else
                            {
                                width = string.Empty;
                                height = string.Empty;
                            }
                            return GetImageUrl(attachment.AttachmentID, false, width, height);
                        }
                        else
                        {
                            return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", attachment.FileName, " <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:" + attachment.TotalDownloads.ToString(), ")</span><br />", GetNopermissionStyle("您需要购买后才能查看该图片"));
                        }
                    }
                    else
                        return ProcessAttach(attachment, operatorUser, forumSetting, canAlwaysViewContents.Value);
                }
                else if (StringUtil.EqualsIgnoreCase(type, "media"))
                {
                    if (attachment.Price == 0 || canAlwaysViewContents.Value || attachment.UserID == operatorUser.UserID || attachment.IsBuyed(operatorUser)
                        || attachment.IsOverSellDays(forumSetting))
                    {
                        string[] param = StringUtil.Split(match.Groups["param"].Value);
                        string width, height;
                        bool auto = false;
                        if (param.Length > 1)
                        {
                            width = param[0];
                            height = param[1];
                            if (param.Length > 2)
                            {
                                if (string.Compare(param[2], "1") == 0)
                                {
                                    auto = true;
                                }
                            }
                        }
                        else
                        {
                            width = string.Empty;
                            height = string.Empty;
                        }

                        //return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", "<a href=\"", BbsUrlHelper.GetAttachmentUrl(attachment.AttachmentID), "\">", attachment.FileName
                        //    , "</a>  <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:", attachment.TotalDownloads, ")</span><br />"
                        //    , GetMediaContent(attachment, false, width, height, auto, forumSetting, user, ref allowAudioTag, ref allowVideoTag, ref allowFlashTag));

                        return GetMediaContent(attachment, false, width, height, auto, forumSetting, operatorUser, ref allowAudioTag, ref allowVideoTag, ref allowFlashTag);

                    }
                    else
                    {
                        return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", attachment.FileName, "<span class=\"filesize gray\">(大小:", attachment.FileSizeFormat
                            , "    下载次数:", attachment.TotalDownloads, ")</span><br />", GetNopermissionStyle("您需要购买后才能查看该多媒体"));
                    }
                }
                else
                {
                    return ProcessAttach(attachment, operatorUser, forumSetting, canAlwaysViewContents.Value);
                }
            }
        }
Esempio n. 28
0
        public override bool CreatePolemize(string agreeViewPoint, string againstViewPoint, DateTime polemizeExpiresDate
           , int forumID, int threadCatalogID, ThreadStatus threadStatus, int iconID
           , string subject, string subjectStyle, int postUserID, string postNickName, bool isLocked, bool isValued, string content, bool enableHtml
           , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, string ipAddress, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
           ,ThreadAttachType attachType, string words, out BasicThread thread, out PostV5 post, out int totalThreads, out int totalPosts, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
        {

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_CreatePolemize";

                string extendData = PolemizeThreadV5.GetExtendData(againstViewPoint, againstViewPoint, 0, 0, 0, polemizeExpiresDate, null);

                SetCreateThreadParams(query, forumID, threadCatalogID, threadStatus, iconID, subject, subjectStyle, postUserID, postNickName, isLocked
                    , isValued, content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress, attachments, historyAttachmentIDs, extendData, attachType, words);

                query.CreateParameter<string>("@AgreeViewPoint", agreeViewPoint, SqlDbType.NText);
                query.CreateParameter<string>("@AgainstViewPoint", againstViewPoint, SqlDbType.NText);
                query.CreateParameter<DateTime>("@ExpiresDate", polemizeExpiresDate, SqlDbType.DateTime);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    GetThread(reader, attachments, polemizeExpiresDate, out thread, out post, out attachmentIDs, out fileIDs);
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;

                if (returnValue != -1)
                {
                    totalThreads = (query.Parameters["@UserTotalThreads"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalThreads"].Value));
                    totalPosts = (query.Parameters["@UserTotalPosts"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalPosts"].Value));
                }
                else
                {
                    totalThreads = 0;
                    totalPosts = 0;
                    return false;
                }

                return true;


            }

        }
Esempio n. 29
0
        /// <summary>
        /// Deletes the messages matching the messagefilter passed in
        /// </summary>
        /// <param name="messageFilter">The message filter.</param>
        /// <param name="trans">The transaction to use.</param>
        private static void DeleteMessages(IPredicate messageFilter, Transaction trans)
        {
            // first delete all audit info for these message. This isn't done by a batch call directly on the db, as this is a targetperentity hierarchy
            // which can't be deleted directly into the database in all cases, so we first fetch the entities to delete.
            AuditDataMessageRelatedCollection messageAudits = new AuditDataMessageRelatedCollection();
            trans.Add(messageAudits);
            // use a fieldcompareset predicate to get the auditdata related to this message and then delete all of them using the collection.
            messageAudits.GetMulti(new FieldCompareSetPredicate(AuditDataMessageRelatedFields.MessageID, MessageFields.MessageID, SetOperator.In, messageFilter));
            messageAudits.DeleteMulti();

            // delete all attachments for this message. This can be done directly onto the db.
            AttachmentCollection attachments = new AttachmentCollection();
            trans.Add(attachments);
            // delete these directly from the db, using a fieldcompareset predicate
            attachments.DeleteMulti(new FieldCompareSetPredicate(AttachmentFields.MessageID, MessageFields.MessageID, SetOperator.In, messageFilter));

            // delete the message/messages
            MessageCollection messages = new MessageCollection();
            trans.Add(messages);
            // use the passed in filter to remove the messages
            messages.DeleteMulti(messageFilter);

            // don't commit the transaction, leave that to the caller.
        }
Esempio n. 30
0
        private void SetCreateThreadParams(SqlQuery query, int forumID, int threadCatalogID, ThreadStatus threadStatus, int iconID
            , string subject, string subjectStyle, int postUserID, string postNickName, bool isLocked, bool isValued, string content, bool enableHtml
            , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, string ipAddress, AttachmentCollection attachments
            , IEnumerable<int> historyAttachmentIDs, string extendData, ThreadAttachType attachType, string words)
        {
            query.CreateParameter("@ThreadCatalogID", threadCatalogID, SqlDbType.Int);
            query.CreateParameter("@ThreadStatus", (int)threadStatus, SqlDbType.TinyInt);
            //query.CreateParameter("@ThreadType", (int)threadType, SqlDbType.TinyInt);

            query.CreateParameter("@SubjectStyle", subjectStyle, SqlDbType.NVarChar, 300);

            //query.CreateParameter("@Price", price, SqlDbType.Int);

            query.CreateParameter("@IsLocked", isLocked, SqlDbType.Bit);
            query.CreateParameter("@IsValued", isValued, SqlDbType.Bit);

            query.CreateParameter("@ExtendData", extendData, SqlDbType.NText);

            query.CreateParameter<int>("@ThreadRandNumber", GetSortNumber("thread"), SqlDbType.Int);


            query.CreateParameter<int>("@UserTotalThreads", SqlDbType.Int, ParameterDirection.Output);

            query.CreateParameter<int>("@TempPostID", GetTempPostID(), SqlDbType.Int);

            query.CreateParameter<int>("@AttachmentType", (int)attachType, SqlDbType.TinyInt);

            query.CreateParameter<string>("@Words", words, SqlDbType.NVarChar, 400);

            SetCreatePostParams(query, forumID, iconID, subject, postUserID, postNickName, content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice
                , ipAddress, attachments, historyAttachmentIDs);

        }
Esempio n. 31
0
 /// <summary>
 /// Deletes the attachment with the id specified.
 /// </summary>
 /// <param name="attachmentID">The attachment ID.</param>
 public static void DeleteAttachment(int attachmentID)
 {
     // delete the attachment directly from the db, without loading it first into memory, so the attachment won't eat up memory unnecessary.
     AttachmentCollection attachments = new AttachmentCollection();
     attachments.DeleteMulti((AttachmentFields.AttachmentID == attachmentID));
 }
Esempio n. 32
0
        /// <summary>
        /// 预览的时候 处理[local]标签
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="postUserID"></param>
        /// <param name="content"></param>
        /// <param name="attachments"></param>
        /// <returns></returns>
        public static string ParsePreviewLocalAttachTag(int forumID, User postUser, string content, AttachmentCollection attachments)
        {
            if (attachments != null && attachments.Count > 0)
            {
                ForumSettingItem forumSetting = AllSettings.Current.ForumSettings.Items.GetForumSettingItem(forumID);
                content = regex_LocalAttach.Replace(content, delegate(Match match)
                {
                    return OnMatchLocalFile(match, forumSetting, postUser, attachments, null, null, true);
                });
            }

            return content;
        }
Esempio n. 33
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;
                }
            }
        }
Esempio n. 34
0
        public override bool UpdatePost(int postID, bool getExtendedInfo, bool isApproved, int iconID
           , string subject, int lastEditorID, string lastEditorName, string content, bool enableHtml
           , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
           , out PostV5 post, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
        {
            post = null;
            attachmentIDs = new List<int>();
            fileIDs = new Dictionary<string, int>();
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_UpdatePost";

                SetUpdatePostParams(query, postID, iconID, subject, lastEditorID, lastEditorName
                    , content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice, isApproved, attachments, historyAttachmentIDs);

                query.CreateParameter("@GetExtendedInfo", getExtendedInfo, SqlDbType.Bit);
                //SetTopMarkCountParam(query);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    if (attachments.Count > 0)
                    {
                        while (reader.Read())
                        {
                            attachmentIDs.Add(reader.Get<int>(0));
                        }
                        if (reader.NextResult())
                        {
                            while (reader.Read())
                            {
                                string fileID = reader.Get<string>("fileID");
                                if (fileIDs.ContainsKey(fileID) == false)
                                    fileIDs.Add(fileID, reader.Get<int>("attachmentID"));
                            }
                        }
                    }

                    PostCollectionV5 posts = GetPosts(reader, attachments.Count == 0);

                    if (posts.Count > 0)
                        post = posts[0];
                    else
                        post = null;
                }
            }

            return true;
        }
Esempio n. 35
0
        public void ProcessPost()
        {
            m_Action = _Request.Get("postaction",Method.Post,string.Empty);

            string validateCodeAction;
            MessageDisplay msgDisplay = CreateMessageDisplay();
            if (IsReply || IsEditPost)
                validateCodeAction = "ReplyTopic";
            else
                validateCodeAction = "CreateTopic";

            if (CheckValidateCode(validateCodeAction, msgDisplay))
            {
                string subject = _Request.Get("subject", Method.Post, string.Empty);
                string content = _Request.Get("editor_content", Method.Post, string.Empty, false);

                int iconID = _Request.Get<int>("posticon", Method.Post, 0);
                string ipAddress = _Request.IpAddress;

                string idString = _Request.Get("enableitem", Method.Post, string.Empty).ToLower();

                //---------如果是以新的UBB方式提交----------
                string formatMode = _Request.Get("editorallowtype", Method.Post, "ubb").ToLower();
                bool enableHTML = false;
                bool enableMaxCode3 = false;
                if (AllowHtml && AllowMaxcode)
                {
                    enableHTML = StringUtil.EqualsIgnoreCase(_Request.Get("contentformat", Method.Post, string.Empty), "enablehtml");
                    if (enableHTML == false)
                        enableMaxCode3 = true;
                }
                else if (AllowHtml)
                    enableHTML = true;
                else if (AllowMaxcode)
                    enableMaxCode3 = true;

                bool enableEmoticons = (idString.IndexOf("enableemoticons") > -1);
                bool enableSignature = (idString.IndexOf("enablesignature") > -1);
                bool enableReplyNotice = (idString.IndexOf("enablereplynotice") > -1);


                AttachmentCollection attachments = new AttachmentCollection();
                List<int> tempUploadFileIds = new List<int>();

                string postUsername = null;
                int postUserID;
                if (IsEditPost || IsEditThread)
                {
                    postUserID = 0;
                }
                else
                {
                    postUserID = MyUserID;
                    if(IsLogin)
                        postUsername = My.Name;
                    else
                    {
                        if (EnableGuestNickName)
                            postUsername = _Request.Get("guestnickname", Method.Post, string.Empty);
                        else
                            postUsername = "";
                    }
                }

                //string attachIdsText = _Request.Get("attachIds", Method.Post, string.Empty, false);
                //if (string.IsNullOrEmpty(attachIdsText) == false)
                //{
                //    int[] attachIds = StringUtil.Split<int>(attachIdsText, ',');

                //    GetAttachments(attachIds, "0", postUserID, msgDisplay, ref attachments);
                //}

                //string diskIdsText = _Request.Get("diskFileIDs", Method.Post, string.Empty, false);
                //if (string.IsNullOrEmpty(diskIdsText) == false)
                //{
                //    int[] diskFileIDs = StringUtil.Split<int>(diskIdsText, ',');

                //}

                GetAttachments(postUserID, msgDisplay, ref attachments);

                if (msgDisplay.HasAnyError())
                    return;

                bool success = false;

                try
                {
                    int threadID = ThreadID, postID = PostID;
                    if (IsCreateThread)
                    {
                        #region
                        bool isLocked = _Request.Get<bool>("cbLockThread", Method.Post, false);
                        int threadCatalogID = _Request.Get<int>("threadCatalogs", Method.Post, 0);
                        if (Action == "thread")
                        {
                            int price = _Request.Get<int>("price", Method.Post, 0);
                            success = PostBOV5.Instance.CreateThread(My, false, enableEmoticons, ForumID, threadCatalogID, iconID, subject, string.Empty, price
                                , postUsername, isLocked, false, content, enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress
                                , attachments, out threadID, out postID);
                        }
                        else if (Action == "poll")
                        {
                            bool alwaysEyeable = !_Request.IsChecked("cbNoEyeable", Method.Post, false);
                            int multiple = _Request.Get<int>("voteMultiple", Method.Post, 0);
                            TimeSpan expiresDate = GetExpiresDate(ThreadType.Poll);
                            string pollItemString = _Request.Get("vote", Method.Post, string.Empty).Trim();

                            success = PostBOV5.Instance.CreatePoll(pollItemString, multiple, alwaysEyeable, expiresDate
                                , My, false, enableEmoticons, ForumID, threadCatalogID, iconID, subject, string.Empty
                                , postUsername, isLocked, false, content, enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress
                                , attachments, out threadID, out postID);
                        }
                        else if (Action == "question")
                        {
                            int reward = _Request.Get<int>("reward", Method.Post, 0);
                            int rewardCount = _Request.Get<int>("rewardCount", Method.Post, 0);
                            bool alwaysEyeable = !_Request.IsChecked("notEyeable", Method.Post, true);

                            TimeSpan expiresDate = GetExpiresDate(ThreadType.Question);

                            success = PostBOV5.Instance.CreateQuestion(reward, rewardCount, alwaysEyeable, expiresDate
                                , My, false, enableEmoticons, ForumID, threadCatalogID, iconID, subject, string.Empty
                                , postUsername, isLocked, false, content, enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress
                                , attachments, out threadID, out postID);
                        }
                        else if (Action == "polemize")
                        {
                            string agreeViewPoint = _Request.Get("AgreeViewPoint", Method.Post, string.Empty);
                            string againstViewPoint = _Request.Get("AgainstViewPoint", Method.Post, string.Empty);

                            TimeSpan expiresDate = GetExpiresDate(ThreadType.Polemize);

                            success = PostBOV5.Instance.CreatePolemize(agreeViewPoint, againstViewPoint, expiresDate
                                , My, false, enableEmoticons, ForumID, threadCatalogID, iconID, subject, string.Empty
                                , postUsername, isLocked, false, content, enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress
                                , attachments, out threadID, out postID);
                        }

                        if (success)
                        {
                            bool sticky = _Request.Get<bool>("cbStickyThread", Method.Post, false);
                            bool globalStickyThread = _Request.Get<bool>("cbGlobalStickyThread", Method.Post, false);

                            int[] threadIDs = new int[] { threadID };
                            if (globalStickyThread)
                            {
                                PostBOV5.Instance.SetThreadsStickyStatus(My, ForumID, null, threadIDs, ThreadStatus.GlobalSticky, null, false, false, true, "");
                            }
                            else if (sticky)
                            {
                                PostBOV5.Instance.SetThreadsStickyStatus(My, ForumID, null, threadIDs, ThreadStatus.Sticky, null, false, false, true, "");
                            }

                            if (isLocked)//记录日志
                            {
                                string threadLog;
                                PostBOV5.Instance.CreateThreadManageLog(My, _Request.IpAddress, ModeratorCenterAction.LockThread, new int[] { MyUserID }, ForumID
                                    , new int[] { threadID }, new string[] { subject }, string.Empty, true, out threadLog);

                                BasicThread thread = ThreadCachePool.GetThread(threadID);
                                if (string.IsNullOrEmpty(threadLog) == false && thread!=null)
                                {
                                    thread.ThreadLog = threadLog;
                                }
                            }
                        }
                        #endregion
                    }
                    else if (IsEditThread || IsEditPost)
                    {
                        int lastEditorID = MyUserID;
                        string lastEditor = My.Username;

                        #region
                        bool recodeEditLog = _Request.Get("recodeEditLog", Method.Post, "true").ToLower() == "true";

                        if (!recodeEditLog && HasEditPermission)
                        {
                            lastEditorID = 0;
                            lastEditor = string.Empty;
                        }

                        if (IsEditThread)
                        {
                            int threadCatalogID = _Request.Get<int>("threadCatalogs", Method.Post, 0);
                            int price = _Request.Get<int>("price", Method.Post, 0);
                            success = PostBOV5.Instance.UpdateThread(My, ThreadID, threadCatalogID, iconID, subject, price, lastEditorID, lastEditor
                                , content, enableEmoticons, enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, attachments, false
                                );
                        }
                        else
                        {
                            success = PostBOV5.Instance.UpdatePost(My, PostID, iconID, subject, lastEditorID, lastEditor, content, enableEmoticons, enableHTML
                                , enableMaxCode3, enableSignature, enableReplyNotice, attachments, false);
                        }
                        #endregion
                    }
                    else //回复
                    {
                        PostType postType = (PostType)_Request.Get<int>("viewPointType", Method.Post, 0);

                        int parentID = PostID;

                        success = PostBOV5.Instance.ReplyThread(My, ThreadID, postType, iconID, subject, content, enableEmoticons
                            , enableHTML, enableMaxCode3, enableSignature, enableReplyNotice, ForumID, postUsername, ipAddress, parentID
                            , attachments, false, out postID);
                    }


                    if (success == false)
                    {
                        CatchError<ErrorInfo>(delegate(ErrorInfo error)
                        {
                            if (error is UnapprovedError)
                            {
                                //AlertWarning("");
                                //ShowWarning(error.Message, BbsUrlHelper.GetForumUrl(Forum.CodeName));

                                if (IsAjaxRequest)
                                {
                                    m_Message = error.Message;
                                    m_JumpLinks.Add("返回列表页", BbsUrlHelper.GetForumUrl(Forum.CodeName));
                                    m_IsPostAlert = true;
                                    PostReturnUrl = BbsUrlHelper.GetForumUrl(Forum.CodeName);
                                }
                                else
                                {
                                    ShowWarning(error.Message, BbsUrlHelper.GetForumUrl(Forum.CodeName));
                                }

                                //NameObjectCollection paramList = new NameObjectCollection();
                                //paramList.Add("IsPostSuccess", false);
                                //paramList.Add("IsPostAlert", true);
                                //paramList.Add("PostMessage", m_Message);
                                //paramList.Add("JumpLinks", new JumpLinkCollection());
                                //paramList.Add("PostReturnUrl", PostReturnUrl);
                                //Display("~/max-templates/default/_part/post_success.aspx?_max_ajaxids_=post_success", true, paramList);
                            }
                            else
                                msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        if (IsEditPost == false && IsEditThread == false)//编辑的时候 不记录
                            ValidateCodeManager.CreateValidateCodeActionRecode(validateCodeAction);

                        string returnUrl = null;
                        if (Type != "")
                        {
                            SystemForum sf;
                            if (string.Compare(Type, SystemForum.RecycleBin.ToString(), true) == 0)
                                returnUrl = UrlHelper.GetRecycledThreadsUrl(CodeName);
                            else if (string.Compare(Type, SystemForum.UnapprovePosts.ToString(), true) == 0)
                                returnUrl = UrlHelper.GetUnapprovedPostsUrl(CodeName);
                            else if (string.Compare(Type, SystemForum.UnapproveThreads.ToString(), true) == 0)
                                returnUrl = UrlHelper.GetUnapprovedThreadsUrl(CodeName);
                            else
                            {
                                returnUrl = BbsUrlHelper.GetThreadUrl(CodeName, ThreadID, 1);
                            }
                        }

                        BasicThread thread = PostBOV5.Instance.GetThread(threadID);
                        int threadPages = thread.TotalPages;
                        if (IsReply)
                        {
                            bool returnLastUrl = _Request.Get<int>("tolastpage", Method.Post, 0) == 1;

                            int returnPage = _Request.Get<int>("page", Method.Get, 1);

                            string lastUrl = BbsUrlHelper.GetLastThreadUrl(Forum.CodeName, threadID, thread.ThreadTypeString, postID, threadPages, true);
                            returnUrl = BbsUrlHelper.GetThreadUrl(Forum.CodeName, threadID, thread.ThreadTypeString, returnPage);

                            if (returnLastUrl)
                            {
                                m_Message = "回复成功,现在将转入该主题的最后一页";
                                m_JumpLinks.Add("如果没有自动跳转,请点此处", lastUrl);
                                m_JumpLinks.Add("如果要转入该主题的第" + returnPage + "页,请点此处", returnUrl);

                                returnUrl = lastUrl;
                            }
                            else
                            {
                                m_Message = "回复成功,现在将转入该主题的第" + returnPage + "页";
                                m_JumpLinks.Add("如果没有自动跳转,请点此处", returnUrl);
                                m_JumpLinks.Add("如果要转入该主题的最后一页,请点此处", lastUrl);
                            }
                        }
                        else if (IsCreateThread)
                        {
                            returnUrl = BbsUrlHelper.GetThreadUrl(Forum.CodeName, threadID, thread.ThreadTypeString, 1);
                        }
                        else
                        {
                            if (Type == "")
                                returnUrl = BbsUrlHelper.GetThreadUrl(Forum.CodeName, threadID, thread.ThreadTypeString, 1);
                        }




                        JsonBuilder json = new JsonBuilder();
                        json.Set("issuccess", true);
 
                        
                        PostReturnUrl = returnUrl;




                        if (IsReply == false)
                        {
                            m_JumpLinks.Add("如果没有自动跳转,请点此处", returnUrl);
                            m_Message = "操作成功,现在将转入查看主题页";
                        }
                        m_JumpLinks.Add("如果要返回主题列表,请点击此处", BbsUrlHelper.GetForumUrl(Forum.CodeName));
                        m_IsPostSuccess = true;
                        //ShowSuccess("操作成功,现在将转入查看主题页", links);

                        if (IsAjaxRequest == false)
                        {
                            ShowSuccess(m_Message, m_JumpLinks);
                        }
                        else
                        {
                            AjaxPanelContext.SetAjaxResult(json);
                        }
                    }
                }
                catch (Exception ex)
                {
                    msgDisplay.AddException(ex);
                }

            }

        }
Esempio n. 36
0
        private void SetUpdatePostParams(SqlQuery query, int postID, int iconID, string subject, int lastEditorID
            , string lastEditor, string content, bool enableHtml, bool enableMaxCode3, bool enableSignature, bool enableReplyNotice
            , bool isApproved, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs)
        {

            query.CreateParameter("@PostID", postID, SqlDbType.Int);
            query.CreateParameter("@IconID", iconID, SqlDbType.Int);
            query.CreateParameter("@Subject", subject, SqlDbType.NVarChar, 256);
            query.CreateParameter("@Content", content, SqlDbType.NText);


            int contentFormat = 0;
            if (enableHtml)
                contentFormat = contentFormat | (int)ContentFormat.EnableHTML;
            if (enableMaxCode3)
                contentFormat = contentFormat | (int)ContentFormat.EnableMaxCode3;

            contentFormat = contentFormat | (int)ContentFormat.IsV5_0;

            query.CreateParameter("@ContentFormat", contentFormat, SqlDbType.TinyInt);


            query.CreateParameter("@EnableSignature", enableSignature, SqlDbType.Bit);
            query.CreateParameter("@EnableReplyNotice", enableReplyNotice, SqlDbType.Bit);
            query.CreateParameter("@IsApproved", isApproved, SqlDbType.Bit);

            query.CreateParameter("@LastEditorID", lastEditorID, SqlDbType.Int);
            query.CreateParameter("@LastEditor", lastEditor, SqlDbType.NVarChar, 64);

            //query.CreateParameter("@GetExtendedInfo", getExtendedInfo, SqlDbType.Bit);

            SetAttachmentParams(query, attachments, historyAttachmentIDs);
            SetTopMarkCountParam(query);

        }
Esempio n. 37
0
        private void SetCreatePostParams(SqlQuery query, int forumID, int iconID, string subject, int postUserID
            , string postNickName, string content, bool enableHtml, bool enableMaxCode3, bool enableSignature, bool enableReplyNotice
            , string ipAddress, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs)
        {

            query.CreateParameter("@IconID", iconID, SqlDbType.Int);
            query.CreateParameter("@Subject", subject, SqlDbType.NVarChar, 256);
            query.CreateParameter("@Content", content, SqlDbType.NText);


            int contentFormat = 0;
            if (enableHtml)
                contentFormat = contentFormat | (int)ContentFormat.EnableHTML;
            if (enableMaxCode3)
                contentFormat = contentFormat | (int)ContentFormat.EnableMaxCode3;

            contentFormat = contentFormat | (int)ContentFormat.IsV5_0;

            query.CreateParameter("@ContentFormat", contentFormat, SqlDbType.TinyInt);


            query.CreateParameter("@EnableSignature", enableSignature, SqlDbType.Bit);
            query.CreateParameter("@EnableReplyNotice", enableReplyNotice, SqlDbType.Bit);
            query.CreateParameter("@ForumID", forumID, SqlDbType.Int);

            query.CreateParameter("@UserID", postUserID, SqlDbType.Int);
            query.CreateParameter("@NickName", postNickName, SqlDbType.NVarChar, 64);

            query.CreateParameter("@IPAddress", ipAddress, SqlDbType.NVarChar, 64);

            query.CreateParameter<int>("@UserTotalPosts", SqlDbType.Int, ParameterDirection.Output);

            query.CreateParameter<int>("@ErrorCode", SqlDbType.Int, ParameterDirection.ReturnValue);

            SetAttachmentParams(query, attachments, historyAttachmentIDs);
            SetTopMarkCountParam(query);



        }
Esempio n. 38
0
        private static string OnMatchLocalFile(Match match, ForumSettingItem forumSetting, User postUser, AttachmentCollection attachments, List<int> realAttachmentIDs, Dictionary<string, int> fileIDs, bool isReview)
        {
            if (match.Success == false)
                return match.Value;

            string atype = match.Groups["atype"].Value;
            string type = match.Groups["type"].Value;
            string param = match.Groups["param"].Value;

            bool isLocal = StringUtil.EqualsIgnoreCase(atype, "local");

            int id = int.Parse(match.Groups["id"].Value);

            if (type == string.Empty || StringUtil.EqualsIgnoreCase(type, "file"))//[local]12[/local] [diskfile]12[/diskfile]
            {
                int j = 0;
                for (int i = 0; i < attachments.Count; i++)
                {

                    if (isLocal&& attachments[i].AttachType == AttachType.TempAttach)
                    {
                        if (attachments[i].AttachmentID > 0)
                            continue;

                        if (realAttachmentIDs != null && j == realAttachmentIDs.Count)
                            return match.Value;

                        if (attachments[i].AttachmentID == -id)
                        {
                            if (isReview)
                                return GetAttachUrl(attachments[i]);
                            else
                                return GetAttachTag(realAttachmentIDs[j]);
                        }

                        j++;
                    }
                    else if(attachments[i].AttachType == AttachType.DiskFile)
                    {
                        if (attachments[i].DiskFileID == id)
                        {
                            if (isReview)
                                return GetAttachUrl(attachments[i]);
                            else
                            {
                                int attachmentID;
                                if (fileIDs.TryGetValue(attachments[i].FileID, out attachmentID))
                                {
                                    return GetAttachTag(attachmentID);
                                }
                                else
                                    return match.Value;
                            }
                        }
                    }

                }
            }
            else if (StringUtil.EqualsIgnoreCase(type, "img"))//[localimg]12[/localimg]
            {
                string[] p = StringUtil.Split(param);
                string width, height;
                if (p.Length > 1)
                {
                    width = p[0];
                    height = p[1];
                }
                else
                {
                    width = string.Empty;
                    height = string.Empty;
                }

                int j = 0;
                for (int i = 0; i < attachments.Count; i++)
                {

                    Attachment attachment = attachments[i];

                    if (isLocal && attachment.AttachType == AttachType.TempAttach)
                    {
                        if (attachment.AttachmentID > 0)
                            continue;
                        if (realAttachmentIDs != null && j == realAttachmentIDs.Count)
                            return match.Value;

                        if (attachment.AttachmentID == -id)
                        {
                            if (isImage(attachment.FileType))
                            {
                                if (isReview)
                                {
                                    if (forumSetting.CreatePostAllowImageTag.GetValue(postUser))
                                    {
                                        return GetImageUrl(attachment.AttachmentID, false, width, height, false);
                                    }
                                    else
                                    {
                                        return GetAttachUrl(attachment, false);
                                    } 
                                }
                                else
                                    return GetAttachImgTag(realAttachmentIDs[j], width, height);
                            }
                            else
                                return match.Value;
                        }

                        j++;
                    }
                    else if(attachment.AttachType == AttachType.DiskFile)
                    {
                        if (attachment.DiskFileID == id)
                        {
                            if (isImage(attachment.FileType))//确实是图片才处理
                            {
                                if (isReview)
                                {
                                    if (forumSetting.CreatePostAllowImageTag.GetValue(postUser))
                                    {
                                        return GetImageUrl(attachment.DiskFileID, false, width, height, true);
                                    }
                                    else
                                    {
                                        return GetAttachUrl(attachment, true);
                                    }
                                }
                                else
                                {
                                    int attachmentID;
                                    if (fileIDs.TryGetValue(attachment.FileID, out attachmentID))
                                    {

                                        return GetAttachImgTag(attachmentID, width, height);
                                    }
                                    else
                                        return match.Value;
                                }
                            }
                            else
                                return match.Value;
                        }
                    }
                }
            }
            else if (StringUtil.EqualsIgnoreCase(type, "media"))//[localmedia]12[/localmedia]
            {
                string[] p = StringUtil.Split(param);
                string width, height;
                bool auto = false;
                if (p.Length > 1)
                {
                    width = p[0];
                    height = p[1];
                    if (p.Length > 2)
                    {
                        if (string.Compare(p[2], "1") == 0)
                        {
                            auto = true;
                        }
                    }
                }
                else
                {
                    width = string.Empty;
                    height = string.Empty;
                }

                int j = 0;
                for (int i = 0; i < attachments.Count; i++)
                {

                    Attachment attachment = attachments[i];

                    if (isLocal && attachment.AttachType == AttachType.TempAttach)
                    {
                        if (attachment.AttachmentID > 0)
                            continue;

                        if (realAttachmentIDs != null && j == realAttachmentIDs.Count)
                            return match.Value;

                        if (attachment.AttachmentID == -id)
                        {
                            if (isMediaFile(attachment.FileType))
                            {
                                if (isReview)
                                    return GetMediaContent(attachment, false, width, height, auto, forumSetting, postUser);
                                else
                                    return GetAttachMediaTag(realAttachmentIDs[j], width, height, auto);
                            }
                            else
                                return match.Value;
                        }

                        j++;
                    }
                    else if(attachment.AttachType == AttachType.DiskFile)
                    {
                        if (attachment.DiskFileID == id)
                        {
                            if (isMediaFile(attachment.FileType))
                            {
                                if (isReview)
                                    return GetMediaContent(attachment, true, width, height, auto, forumSetting, postUser);
                                else
                                {
                                    int attachmentID;
                                    if (fileIDs.TryGetValue(attachment.FileID, out attachmentID))
                                    {
                                        return GetAttachMediaTag(attachmentID, width, height, auto);
                                    }
                                    else
                                        return match.Value;
                                }
                            }
                            else
                                return match.Value;
                        }
                    }
                }
            }

            return match.Value;
        }
Esempio n. 39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MailDialog"/> class.
 /// </summary>
 public MailDialog()
 {
     _manualResetEvent = new ManualResetEvent(false);
     Attachments = new AttachmentCollection();
     Recipients = new RecipientCollection();
 }
Esempio n. 40
0
        /// <summary>
        /// Convert "CID: object" references to Base-64 encoded versions.
        /// </summary>
        /// <remarks>Useful for displaying text/html messages with image references.</remarks>
        /// <param name="html">HTML block to process.</param>
        /// <param name="attachments">Collection of attachments available to be embedded.</param>
        /// <returns>The HTML block with any CID: object references replaced by their Base-64 encoded bytes.</returns>
        public static string EmbedAttachments(string html, AttachmentCollection attachments)
        {
            // Build a new string using the following buffer.
            StringBuilder htmlBuilder = new StringBuilder(Constants.MEDIUMSBSIZE);

            int srcStartPos = 0, lastPos = 0;
            while (srcStartPos > -1)
            {
                // Find the next SRC= attribute and handle either single or double quotes.
                int srcStartQuotePos = html.IndexOf("src=\"cid:", srcStartPos, StringComparison.Ordinal);
                int srcStartApostrophePos = html.IndexOf("src='cid:", srcStartPos, StringComparison.Ordinal);

                if (srcStartQuotePos > -1)
                {
                    if (srcStartApostrophePos > -1)
                        srcStartPos = srcStartQuotePos < srcStartApostrophePos ? srcStartQuotePos : srcStartApostrophePos;
                    else
                        srcStartPos = srcStartQuotePos;
                }
                else if (srcStartApostrophePos > -1)
                    srcStartPos = srcStartApostrophePos;
                else
                    srcStartPos = -1;

                string srcEndDelimiter = (srcStartQuotePos == srcStartPos) ? "\"" : "'";

                if (srcStartPos > -1)
                {
                    int srcEndPos = html.IndexOf(srcEndDelimiter, srcStartPos + 9, StringComparison.Ordinal);
                    if (srcEndPos > 0)
                    {
                        htmlBuilder.Append(html.Substring(lastPos, srcStartPos + 5 - lastPos));

                        string cid = html.Substring(srcStartPos + 9, srcEndPos - srcStartPos - 9);

                        // Check for attachments with matching Content-IDs.
                        bool matchingAttachmentFound = false;
                        foreach (Attachment attachment in attachments)
                        {
                            if (attachment.ContentId == cid)
                            {
                                htmlBuilder.Append("data:" + attachment.MediaType + ";base64,");

                                matchingAttachmentFound = true;
                                byte[] contentStreamBytes = ((MemoryStream)attachment.ContentStream).ToArray();

                                htmlBuilder.Append(ToBase64String(contentStreamBytes, 0, contentStreamBytes.Length));
                            }
                        }

                        // If the current object hasn't been matched, look for a matching file name.
                        if (!matchingAttachmentFound)
                        {
                            // Ignore the non-file name portion of this Content-ID.
                            int cidAtPos = cid.IndexOf("@", StringComparison.Ordinal);
                            if (cidAtPos > -1)
                                cid = cid.Substring(0, cidAtPos);

                            foreach (Attachment attachment in attachments)
                            {
                                if (attachment.Name == cid)
                                {
                                    htmlBuilder.Append("data:" + attachment.MediaType + ";base64,");

                                    matchingAttachmentFound = true;
                                    byte[] contentStreamBytes = ((MemoryStream)attachment.ContentStream).ToArray();

                                    htmlBuilder.Append(ToBase64String(contentStreamBytes, 0, contentStreamBytes.Length));
                                }
                            }

                            if (!matchingAttachmentFound)
                                htmlBuilder.Append(cid);
                        }

                        srcStartPos = srcEndPos;
                        lastPos = srcStartPos;
                    }
                    else
                        srcStartPos = -1;
                }
                else
                    srcStartPos = -1;
            }

            htmlBuilder.Append(html.Substring(lastPos));

            return htmlBuilder.ToString();
        }
Esempio n. 41
0
        public override bool UpdateThread(int threadID, int postID, bool isApproved, int threadCatalogID, int iconID
            , string subject, int price, int lastEditorID, string lastEditorName, string content, bool enableHtml
            , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
            , ThreadAttachType attachType, string words, out BasicThread thread, out PostV5 post, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_UpdateThread";

                SetUpdatePostParams(query, postID, iconID, subject, lastEditorID, lastEditorName
                    , content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice, isApproved, attachments, historyAttachmentIDs);

                query.CreateParameter<int>("@ThreadID", threadID, SqlDbType.Int);
                query.CreateParameter<int>("@ThreadCatalogID", threadCatalogID, SqlDbType.Int);
                query.CreateParameter<int>("@Price", price, SqlDbType.Int);
                query.CreateParameter<int>("@AttachmentType", (int)attachType, SqlDbType.TinyInt);
                query.CreateParameter<string>("@Words", words, SqlDbType.NVarChar, 400);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    GetThread(reader, attachments, null, out thread, out post, out attachmentIDs, out fileIDs);
                }
            }

            return true;
        }
Esempio n. 42
0
        public void ProcessReview()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();
            int postUserID;

            bool isV50 = true;
            if (IsEditPost || IsEditThread)
            {
                PostV5 post = PostBOV5.Instance.GetPost(PostID, false); //PostManager.GetPost(PostID).UserID;
                postUserID = post.UserID;
                isV50 = post.IsV5_0;
            }
            else
            {
                postUserID = MyUserID;
            }


            m_Review = true;
            reviewContent = _Request.Get("editor_content", Method.Post, string.Empty, false);

            reviewSubject = ClearHTML(_Request.Get("subject", Method.Post, string.Empty));

            if ((IsEditThread || IsCreateThread) && reviewSubject.Trim() == "")
            {
                msgDisplay.AddError("标题不能为空");
                //ShowAlert("标题不能为空!");
            }

            bool enableHTML = false, enableMaxCode3 = false;
            if (AllowHtml && AllowMaxcode)
            {
                enableHTML = _Request.Get("contentFormat", Method.Post, "").ToLower() == "enablehtml";
                if (enableHTML == false)
                    enableMaxCode3 = true;
            }
            else if (AllowHtml)
                enableHTML = true;
            else if (AllowMaxcode)
                enableMaxCode3 = true;

            bool enableEmoticon = AllowEmoticon && _Request.Get("enableItem", Method.Post, "").ToLower().IndexOf("enableemoticons") > -1;

            AttachmentCollection attachments = new AttachmentCollection();


            //string attachIdsText = _Request.Get("attachIds", Method.Post, string.Empty, false);
            //if (string.IsNullOrEmpty(attachIdsText) == false)
            //{
            //    int[] attachIds = StringUtil.Split<int>(attachIdsText, ',');


            //    GetAttachments(attachIds, "0", postUserID, msgDisplay, ref attachments);
            //}

            //string diskIdsText = _Request.Get("diskFileIDs", Method.Post, string.Empty, false);
            //if (string.IsNullOrEmpty(diskIdsText) == false)
            //{
            //    int[] diskFileIDs = StringUtil.Split<int>(diskIdsText, ',');

            //    GetAttachments(diskFileIDs, "1", postUserID, msgDisplay, ref attachments);
            //}

            GetAttachments(postUserID, msgDisplay, ref attachments);

            reviewContent = PostUbbParserV5.ParseWhenSave(postUserID, enableEmoticon, Forum.ForumID, reviewContent, enableHTML, enableMaxCode3, attachments);
            reviewContent = PostUbbParserV5.ParsePreviewLocalAttachTag(Forum.ForumID, UserBO.Instance.GetUser(postUserID,GetUserOption.WithAll), reviewContent, attachments);

            MatchCollection ms = PostUbbParserV5.regex_AllAttach.Matches(reviewContent);
            List<int> historyAttachmentIDs = new List<int>();

            foreach (Match m in ms)
            {
                bool isHistoryAttach = true;
                int attachID = int.Parse(m.Groups["id"].Value);
                foreach (Attachment attach in attachments)
                {
                    if (attachID == attach.AttachmentID)
                    {
                        isHistoryAttach = false;
                        break;
                    }
                }
                if (isHistoryAttach)
                    historyAttachmentIDs.Add(attachID);
            }

            AttachmentCollection historyAttachs = PostBOV5.Instance.GetAttachments(MyUserID, historyAttachmentIDs);

            foreach (Attachment attach in historyAttachs)
            {
                attachments.Add(attach);
            }

            reviewContent = PostUbbParserV5.ParseWhenDisplay(postUserID, Forum.ForumID, PostID, reviewContent, enableHTML, false, isV50, attachments);


            if (reviewContent.Trim() == "")
            {
                msgDisplay.AddError("内容不能为空");
            }

            if (msgDisplay.HasAnyError())
            {
                m_Review = false;
            }
        }
Esempio n. 43
0
 /// <summary>
 /// Approves / revokes the approval of the attachment with ID passed in.
 /// </summary>
 /// <param name="attachmentID">The attachment ID.</param>
 /// <param name="approved">the new flag value for Approved</param>
 public static void ModifyAttachmentApproval(int attachmentID, bool approved)
 {
     // we'll update the approved flag directly in the db, so we don't load the whole attachment into memory.
     AttachmentEntity updater = new AttachmentEntity();
     AttachmentCollection attachments = new AttachmentCollection();
     updater.Approved = approved;
     attachments.UpdateMulti(updater, (AttachmentFields.AttachmentID == attachmentID));
 }
Esempio n. 44
0
 private void GetThread(XSqlDataReader reader, AttachmentCollection attachments, DateTime? expiresDate, out BasicThread thread, out PostV5 post, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
 {
     attachmentIDs = new List<int>();
     fileIDs = new Dictionary<string, int>();
     thread = null;
     post = null;
     while (reader.Read())
     {
         thread = GetThread(reader, expiresDate);
     }
     if (attachments.Count > 0)
     {
         //本地刚上传的附件 ID
         if (reader.NextResult())
         {
             while (reader.Read())
             {
                 attachmentIDs.Add(reader.Get<int>(0));
             }
         }
         //所有附件
         if (reader.NextResult())
         {
             while (reader.Read())
             {
                 string fileID = reader.Get<string>("fileID");
                 if (fileIDs.ContainsKey(fileID) == false)
                     fileIDs.Add(fileID, reader.Get<int>("attachmentID"));
             }
         }
     }
     if (reader.NextResult())
     {
         while (reader.Read())
         {
             post = new PostV5(reader);
         }
     }
 }
Esempio n. 45
0
        public override AttachmentCollection GetAttachments(int operatorUserID, DateTime? beginDate, DateTime? endDate, string keyword, int pageNumber, int pageSize, ExtensionList fileTypes)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.IsDesc = true;

                query.Pager.PageNumber = pageNumber;
                query.Pager.PageSize = pageSize;
                query.Pager.SelectCount = true;
                query.Pager.TableName = "[bx_Attachments]";
                query.Pager.SortField = "[AttachmentID]";


                StringBuilder condition = new StringBuilder();
                condition.Append(" [UserID] = @UserID");

                query.CreateParameter<int>("@UserID", operatorUserID, SqlDbType.Int);

                if (beginDate != null)
                {
                    condition.Append(" AND [CreateDate] >= @BeginDate");
                    query.CreateParameter<DateTime>("@BeginDate", beginDate.Value, SqlDbType.DateTime);
                }
                if (endDate != null)
                {
                    condition.Append(" AND [CreateDate] <= @EndDate");
                    query.CreateParameter<DateTime>("@EndDate", endDate.Value, SqlDbType.DateTime);
                }

                if (false == string.IsNullOrEmpty(keyword))
                {
                    condition.Append(" AND [FileName] LIKE '%'+@Keyword+'%'");
                    query.CreateParameter<string>("@Keyword", keyword, SqlDbType.NVarChar, 100);
                }
                if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains("*"))
                {
                    condition.Append(" And (");
                    int i = 0;
                    string ft;
                    foreach (string s in fileTypes)
                    {
                        ft = "@f_" + i++;
                        condition.Append(" FileType=" + ft);
                        query.CreateParameter<string>(ft, s, SqlDbType.VarChar, 10);

                        if (fileTypes.Count > i)
                            condition.Append(" OR ");
                    }

                    condition.Append(")");
                }

                query.Pager.Condition = condition.ToString();


                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    AttachmentCollection attachments = new AttachmentCollection(reader);
                    if (reader.NextResult())
                    {
                        while (reader.Read())
                        {
                            attachments.TotalRecords = reader.GetInt32(0);
                        }
                    }
                    return attachments;
                }
            }
        }
Esempio n. 46
0
        public override bool CreateThread(int forumID, int threadCatalogID, ThreadStatus threadStatus, int iconID
            , string subject, string subjectStyle, int price, int postUserID, string postNickName, bool isLocked, bool isValued, string content, bool enableHtml
            , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, string ipAddress, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
            , ThreadAttachType attachType, string words, out BasicThread thread, out PostV5 post, out int totalThreads, out int totalPosts, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_CreateThread";

                SetCreateThreadParams(query, forumID, threadCatalogID, threadStatus, iconID, subject, subjectStyle, postUserID, postNickName, isLocked
                    , isValued, content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress, attachments, historyAttachmentIDs, null, attachType, words);

                query.CreateParameter<int>("@ThreadID", SqlDbType.Int, ParameterDirection.Output);
                query.CreateParameter<int>("@PostID", SqlDbType.Int, ParameterDirection.Output);
                query.CreateParameter("@ThreadType", (int)ThreadType.Normal, SqlDbType.TinyInt);
                query.CreateParameter("@Price", price, SqlDbType.Int);


                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    GetThread(reader, attachments, null, out thread, out post, out attachmentIDs, out fileIDs);
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;

                if (returnValue != -1)
                {
                    //threadID = Convert.ToInt32(query.Parameters["@ThreadID"].Value);
                    //postID = Convert.ToInt32(query.Parameters["@PostID"].Value);
                    totalThreads = (query.Parameters["@UserTotalThreads"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalThreads"].Value));
                    totalPosts = (query.Parameters["@UserTotalPosts"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalPosts"].Value));

                    return true;
                }
                else
                {
                    //threadID = 0;
                    //postID = 0;
                    totalPosts = 0;
                    totalThreads = 0;

                    return false;
                }
            }

        }
Esempio n. 47
0
        public override bool CreatePoll(string pollItems, int pollMultiple, bool pollIsAlwaysEyeable, DateTime pollExpiresDate
            , int forumID, int threadCatalogID, ThreadStatus threadStatus, int iconID
            , string subject, string subjectStyle, int postUserID, string postNickName, bool isLocked, bool isValued, string content, bool enableHtml
            , bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, string ipAddress, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
            , ThreadAttachType attachType, string words, out BasicThread thread, out PostV5 post, out int totalThreads, out int totalPosts, out List<int> attachmentIDs, out Dictionary<string, int> fileIDs)
        {

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_CreatePoll";

                SetCreateThreadParams(query, forumID, threadCatalogID, threadStatus, iconID, subject, subjectStyle, postUserID, postNickName, isLocked
                    , isValued, content, enableHtml, enableMaxCode3, enableSignature, enableReplyNotice, ipAddress, attachments, historyAttachmentIDs, null, attachType, words);

                query.CreateParameter("@PollItems", pollItems, SqlDbType.NText);
                query.CreateParameter("@Multiple", pollMultiple, SqlDbType.Int);
                query.CreateParameter("@AlwaysEyeable", pollIsAlwaysEyeable, SqlDbType.Bit);
                query.CreateParameter("@ExpiresDate", pollExpiresDate, SqlDbType.DateTime);

                PollItemCollectionV5 pollitems = null;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    GetThread(reader, attachments, pollExpiresDate, out thread, out post, out attachmentIDs, out fileIDs);

                    if (reader.NextResult())
                    {
                        pollitems = new PollItemCollectionV5(reader);
                    }
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;

                if (returnValue != -1)
                {
                    totalThreads = (query.Parameters["@UserTotalThreads"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalThreads"].Value));
                    totalPosts = (query.Parameters["@UserTotalPosts"].Value == DBNull.Value ? 0 : Convert.ToInt32(query.Parameters["@UserTotalPosts"].Value));
                }
                else
                {
                    totalThreads = 0;
                    totalPosts = 0;
                    return false;
                }


                string extendData = PollThreadV5.GetExtendData(pollIsAlwaysEyeable, pollExpiresDate, pollMultiple, pollitems, new List<int>());

                thread.SetExtendData(extendData);

                UpdateThreadExtendData(extendData, thread.ThreadID, query);

                return true;


            }

        }
Esempio n. 48
0
 private void SetAttachmentParams(SqlQuery query, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs)
 {
     query.CreateParameter("@AttachmentIds", attachments.BuildIds(), SqlDbType.VarChar, 8000);
     query.CreateParameter("@AttachmentFileNames", attachments.BuildFileNames(), SqlDbType.NText);
     query.CreateParameter("@AttachmentFileIds", attachments.BuildFileIds(), SqlDbType.Text);
     query.CreateParameter("@AttachmentFileSizes", attachments.BuildFileSizes(), SqlDbType.VarChar, 8000);
     query.CreateParameter("@AttachmentPrices", attachments.BuildPrices(), SqlDbType.VarChar, 8000);
     query.CreateParameter("@AttachmentFileExtNames", attachments.BuildFileExtNames(), SqlDbType.NText);
     query.CreateParameter("@HistoryAttachmentIDs", StringUtil.Join(historyAttachmentIDs), SqlDbType.VarChar, 500);
 }
Esempio n. 49
0
 /// <summary>
 /// Initializes an empty instance of the OpaqueMail.MailMessage class.
 /// </summary>
 public MailMessage()
     : base()
 {
     AllRecipients = new List<string>();
     AlternateViews = new AlternateViewCollection();
     Attachments = new AttachmentCollection();
     Bcc = new MailAddressCollection();
     Body = "";
     BodyContentType = "";
     BodyDecoded = false;
     CC = new MailAddressCollection();
     CharSet = "";
     ContentLanguage = "";
     ContentTransferEncoding = "";
     ContentType = "";
     DeliveredTo = "";
     Headers = new NameValueCollection();
     Importance = "";
     MimeBoundaryName = "OpaqueMail-boundary";
     ProcessingFlags = MailMessageProcessingFlags.IncludeRawHeaders | MailMessageProcessingFlags.IncludeRawBody;
     RawFlags = new HashSet<string>();
     ReturnPath = "";
     SmimeEncryptedEnvelope = false;
     SmimeEncryptionOptionFlags = SmimeEncryptionOptionFlags.RequireCertificateVerification;
     SmimeSettingsMode = SmimeSettingsMode.RequireExactSettings;
     SmimeSigned = false;
     SmimeSigningCertificateChain = new X509Certificate2Collection();
     SmimeSigningOptionFlags = SmimeSigningOptionFlags.SignTime;
     SmimeTripleWrapped = false;
     SubjectIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
     To = new MailAddressCollection();
 }
Esempio n. 50
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.BodyBuilder"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="BodyBuilder"/>.
		/// </remarks>
		public BodyBuilder ()
		{
			LinkedResources = new AttachmentCollection (true);
			Attachments = new AttachmentCollection ();
		}
Esempio n. 51
0
        public override bool CreatePost(int threadID, bool getPost, bool isApproved, PostType postType, int iconID, string subject, string content
            , bool enableHtml, bool enableMaxCode3, bool enableSignature, bool enableReplyNotice, int forumID, int postUserID, string userName
            , string ipAddress, int parentID, bool updateSortOrder, AttachmentCollection attachments, IEnumerable<int> historyAttachmentIDs
            , BasicThread thread
            , out PostV5 post, out int totalPosts, out List<int> AttachmentIDs, out Dictionary<string, int> fileIDs, out bool threadEnableReplyNotice)
        {
            AttachmentIDs = new List<int>();
            fileIDs = new Dictionary<string, int>();
            threadEnableReplyNotice = true;

            post = null;
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandType = CommandType.StoredProcedure;
                query.CommandText = "bx_v5_CreatePost";

                SetCreatePostParams(query, forumID, iconID, subject, postUserID, userName, content, enableHtml, enableMaxCode3
                    , enableSignature, enableReplyNotice, ipAddress, attachments, historyAttachmentIDs);

                query.CreateParameter<int>("@ThreadID", threadID, SqlDbType.Int);
                query.CreateParameter<int>("@PostType", (int)postType, SqlDbType.TinyInt);

                query.CreateParameter<bool>("@IsApproved", isApproved, SqlDbType.Bit);
                query.CreateParameter<int>("@PostRandNumber", GetSortNumber("post"), SqlDbType.TinyInt);

                query.CreateParameter<int>("@ParentID", parentID, SqlDbType.Int);
                query.CreateParameter<bool>("@UpdateSortOrder", updateSortOrder, SqlDbType.Bit);
                query.CreateParameter("@GetExtendedInfo", true, SqlDbType.Bit);
                query.CreateParameter("@GetThreadEnableReplyNotice", true, SqlDbType.Bit);
                query.CreateParameter<int>("@PostID", SqlDbType.Int, ParameterDirection.Output);
                query.CreateParameter<bool>("@GetPost", getPost, SqlDbType.Bit);
                query.CreateParameter<bool>("@GetThread", false, SqlDbType.Bit);

                string extendData = null;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        threadEnableReplyNotice = reader.Get<bool>("EnableReplyNotice");
                    }

                    if (attachments.Count > 0)
                    {
                        if (reader.NextResult())
                        {
                            while (reader.Read())
                            {
                                AttachmentIDs.Add(reader.Get<int>(0));
                            }
                            if (reader.NextResult())
                            {
                                while (reader.Read())
                                {
                                    string fileID = reader.Get<string>("fileID");
                                    if (fileIDs.ContainsKey(fileID) == false)
                                        fileIDs.Add(fileID, reader.Get<int>("attachmentID"));
                                }
                            }
                        }
                    }

                    if (getPost)
                    {
                        PostCollectionV5 posts = GetPosts(reader, false);
                        if (posts.Count > 0)
                            post = posts[0];
                        else
                            post = null;
                    }

                    extendData = GetExtendData(thread, thread.ThreadType, reader, false);

                }

                if (getPost == false)
                {
                    post = new PostV5();
                    post.PostID = (int)query.Parameters["@PostID"].Value;
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;
                if (returnValue != -1)
                {
                    totalPosts = Convert.ToInt32(query.Parameters["@UserTotalPosts"].Value);
                    if (extendData != null)
                    {
                        UpdateThreadExtendData(extendData, threadID, query);
                    }
                }
                else
                {
                    totalPosts = 0;
                    return false;
                }

                return true;
            }
        }