コード例 #1
0
            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);
            }
コード例 #2
0
            private string GenerateBody(string content, AttachmentCollection fs)
            {
                var             body    = content ?? string.Empty;
                MatchCollection images  = _imagesRegex.Matches(body);
                MatchCollection images1 = _imagesRegexnewRTE.Matches(body);

                if (images.Count > 0)
                {
                    var sb           = new StringBuilder();
                    var currentIndex = 0;
                    foreach (Match match in images)
                    {
                        Group fileid = match.Groups[_FILEID_REGEX_GROUP];
                        Group 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();
                }
                // ToDo for RTE (old and new links)
                else
                {
                    if (images1.Count > 0)
                    {
                        var sb           = new StringBuilder();
                        var currentIndex = 0;
                        foreach (Match match in images1)
                        {
                            Group filename = match.Groups[1];
                            Group src      = match.Groups[1];

                            foreach (var result in
                                     PXSelect <UploadFile,
                                               Where <UploadFile.name, Equal <Required <UploadFile.name> > > > .
                                     SelectWindowed(new PXGraph(), 0, 1, HttpUtility.UrlDecode(filename.Value)))
                            {
                                UploadFile uf = result[typeof(UploadFile)] as UploadFile;
                                if (uf != null)
                                {
                                    Guid imgId = (Guid)uf.FileID;
                                    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, filename.Index + filename.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);
            }