예제 #1
0
        private void ConvertImage(AppointMenInput input)
        {
            //如果是图片的话,必须使用CID
            if (string.IsNullOrEmpty(input.Body))
            {
                input.Body = "";
            }
            if (input.Attachments == null)
            {
                input.Attachments = new List <AttachmentInput>();
            }
            Regex regImg  = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
            var   matches = regImg.Matches(input.Body);

            if (matches.Count == 0)
            {
                return;
            }
            foreach (Match match in matches)
            {
                var imgSrc       = match.Groups[1].Value;
                var imgBase64    = imgSrc.Split(',')[1];
                var imgBytes     = Convert.FromBase64String(imgBase64);
                var attachmentId = Guid.NewGuid().ToString("N").ToLower() + ".jpg";
                input.Body = input.Body.Replace(imgSrc, "cid:" + attachmentId);

                input.Attachments.Add(new AttachmentInput()
                {
                    Id    = attachmentId,
                    Name  = attachmentId,
                    Bytes = imgBytes
                });
            }
        }
예제 #2
0
        public async Task <string> CreateAppointMentAsync(AppointMenInput input, string username, string password)
        {
            var mailManager = MailManager.Create(username, password);

            input.Body = MailService.ConverToHtml(input.Body);
            var dto = this._mapper.Map <AppointMentDto>(input);

            dto.Attachments = new List <Exchange.AttachmentMailModel>();
            foreach (var item in input.Attachments)
            {
                dto.Attachments.Add(new Exchange.AttachmentMailModel()
                {
                    Bytes     = item.Bytes,
                    Name      = item.Name,
                    Id        = item.Id,
                    IsPackage = item.IsPackage
                });
            }
            var id = await mailManager.CreateAppointMentAsync(dto);

            return(id);
        }
예제 #3
0
        public async Task <IActionResult> CreateAppointMent([FromForm] AppointMenInput input)
        {
            var userName = this.GetUserName();

            if (input.Attendees != null && input.Attendees.Count == 1)
            {
                var attends = input.Attendees[0].Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
                input.Attendees = attends;
            }
            var employee = await this._employeeService.FindByUserNameAsync(userName);

            if (employee == null)
            {
                return(BadRequest());
            }
            this.ConvertImage(input);
            if (input.Attachment != null)
            {
                foreach (var it in input.Attachment)
                {
                    var stream = it.OpenReadStream();
                    var bytes  = new byte[it.Length];
                    await stream.ReadAsync(bytes, 0, bytes.Length);

                    var name = Guid.NewGuid().ToString("N").ToLower() + "-" + it.FileName;
                    input.Attachments.Add(new AttachmentInput()
                    {
                        Bytes     = bytes,
                        Name      = name,
                        Id        = name,
                        IsPackage = true,
                    });
                }
            }
            if (input.AddToSkype)
            {
                var skypeResult = await this._meetingService.CreateOnlineMeetingAsync(input.Title, input.Body, employee.Account, employee.Password);

                var joinhttp = skypeResult.JoinUrl;
                var joinUrl  = "<a target=\"blank\" href =\"" + joinhttp + "\">点击参加Skype会议</a>";
                input.Body += joinUrl;
            }
            try
            {
                var attendEmployees = await this._employeeService.FindByUserNamesAsync(input.Attendees.ToArray());

                //send to oa
                foreach (var item in attendEmployees)
                {
                    await this._oaSystemOprationService.CreateAppointmentAsync(new Services.Dtos.OAAppoinmentInputDto()
                    {
                        Keyword1 = input.Title,
                        First    = "您有一条会议提醒",
                        MeetId   = Guid.NewGuid().ToString(),
                        UserNum  = item.Number,
                        Keyword2 = DateTime.Parse(input.Start + " " + input.StartTime).ToString("yyyy-MM-dd"),
                        Keyword3 = input.Location,
                        Remark   = "",
                    });;
                }
            }
            catch (Exception e)
            {
            }

            await this._calendarService.CreateAppointMentAsync(input, employee.Account, employee.Password);

            return(Json(new { success = true }));
        }