Esempio n. 1
0
        private void SendVideoLinks(HashSet <long> receivers, KidsNoteContent content)
        {
            LinkedList <string> videoLinks = new LinkedList <string>();

            foreach (var attach in content.Attachments)
            {
                if (attach.Type == AttachmentType.VIDEO && attach.DownloadUrl != "")
                {
                    videoLinks.AddLast(attach.DownloadUrl);
                }
            }

            foreach (var user in receivers)
            {
                foreach (var link in videoLinks)
                {
                    try
                    {
                        string message = String.Format("아래 링크를 클릭하시면 동영상 재생이 됩니다.\n\n{0}", MakeRedirectUri(link));
                        System.Diagnostics.Trace.WriteLine(message);
                        var task = TheClient.SendTextMessageAsync(user, message);
                        task.Wait();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Esempio n. 2
0
        private LinkedList <string> Upload(KidsNoteContent content, string dateFolderId, bool encrypt)
        {
            string folderName         = string.Format("[{0}] {1}", content.Type, content.Id);
            string containingFolderId = CreateFolder(dateFolderId, folderName);

            MemoryStream ms = null;

            if (encrypt)
            {
                byte[] plain     = Encoding.UTF8.GetBytes(content.FormatContent());
                byte[] encrypted = new byte[plain.Length];

                EncryptorChaCha chacha = new EncryptorChaCha(true, EncryptorChaCha.DefaultChaChaEncKey, EncryptorChaCha.DefaultChaChaEncNonce);
                chacha.Process(plain, 0, plain.Length, encrypted, 0);
                ms = new MemoryStream(encrypted);
            }
            else
            {
                ms = new MemoryStream(Encoding.UTF8.GetBytes(content.FormatContent()));
            }
            ms.Seek(0, SeekOrigin.Begin);

            LinkedList <string> idList = new LinkedList <string>();

            UploadProgress(string.Format("Uploding [{0}] {1}", content.Type, content.Id));

            string name = encrypt ? "본문.txt.chacha" : "본문.txt";
            // 이미 암호화 해 두었다.
            string bodyId = UploadFile(ms, containingFolderId, name, name, Constants.GOOGLE_DRIVE_MIMETYPE_TEXT);

            idList.AddLast(bodyId);

            int i = 0;

            foreach (var each in content.Attachments)
            {
                ++i;
                int    pos = each.DownloadUrl.LastIndexOf('.');
                string ext = "";
                if (pos > 0)
                {
                    ext = each.DownloadUrl.Substring(pos + 1);
                    ext = ext.ToLower();
                }

                bool   isVideo = each.Type == AttachmentType.VIDEO;
                string id      = isVideo ? UploadVideoAttachment(each, i, containingFolderId, ext, encrypt)
                                    : UploadPhotoAttachment(each, i, containingFolderId, ext, encrypt);
                if (id != null && id.Length > 0)
                {
                    idList.AddLast(id);
                }
            }

            return(idList);
        }
Esempio n. 3
0
        private void SendImageLinks(HashSet <long> receivers, KidsNoteContent content)
        {
            LinkedList <string> imageLinks = new LinkedList <string>();

            foreach (var attach in content.Attachments)
            {
                if (IsImageAttachment(attach) && attach.ImageSource != "")
                {
                    imageLinks.AddLast(attach.ImageSource);
                }
            }

            foreach (var user in receivers)
            {
                foreach (var attach in content.Attachments)
                {
                    if (IsImageAttachment(attach) && attach.DownloadUrl != "")
                    {
                        // 일반 이미지
                        if (attach.Type == AttachmentType.IMAGE)
                        {
                            try
                            {
                                string link         = attach.DownloadUrl.IndexOf("%") >= 0 ? attach.ImageSource : attach.DownloadUrl;
                                string originalLink = attach.DownloadUrl.Replace("&amp;", "&");
                                string message      = String.Format("사진을 전송합니다. 잠시 기다리시면 미리보기가 나타납니다.\n\n{0}", link);
                                message += String.Format("\n\n깨끗한 사진을 보시리면 아래 링크를 클릭하세요.\n\n{0}", originalLink);
                                var task = TheClient.SendTextMessageAsync(user, message);
                                task.Wait();
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else // 식단표
                        {
                            try
                            {
                                string menuType = ContentTypeConverter.AttachmentLunchTypeToString(attach.Type);

                                StringBuilder sb = new StringBuilder();
                                sb.AppendFormat("{0} : {1}\n\n", menuType, attach.Description);
                                sb.Append(attach.DownloadUrl);

                                var task = TheClient.SendTextMessageAsync(user, sb.ToString());
                                task.Wait();
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private string FormatContent(ContentType type, KidsNoteContent content)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0} [{1}]", BoardName(type), content.Id);
            sb.AppendFormat("\n제목 : {0}, 작성자 : {1}", content.Title, content.Writer);
            sb.Append("\n\n");
            sb.Append(content.Content);

            return(sb.ToString());
        }
Esempio n. 5
0
        private void SendImageAttachments(HashSet <long> receivers, KidsNoteContent content)
        {
            List <MemoryStream> attachmentStreams = new List <MemoryStream>();

            for (int i = 0; i < content.Attachments.Count; ++i)
            {
                var attach = content.Attachments[i];

                if (attach.Data == null)
                {
                    // TODO: 관리 사용자에게 통지.
                    // attachmentStreams.Add(null);
                }
                else
                {
                    if (IsImageAttachment(attach))
                    {
                        MemoryStream ms = new MemoryStream();
                        attach.Data.CopyTo(ms);
                        attachmentStreams.Add(ms);
                    }
                    else if (attach.Type == AttachmentType.VIDEO)
                    {
                        // Video Link 로 따로 보낸다. (chrome redirect)
                    }
                    else
                    {
                        // Telegram 으로는 Image 만 보낸다.
                        // otherAttachments.AddLast(new InputMediaDocument(media));

                        attachmentStreams.Add(null);
                    }
                }
            }

            List <Task <Message[]> > mediaTaskList = new List <Task <Message[]> >();

            foreach (var user in receivers)
            {
                LinkedList <InputMediaPhoto> photoAlbum = new LinkedList <InputMediaPhoto>();
                for (int i = 0; i < content.Attachments.Count; ++i)
                {
                    var attach = content.Attachments[i];
                    if (attachmentStreams[i] != null)
                    {
                        MemoryStream copied = new MemoryStream();
                        attachmentStreams[i].Seek(0, SeekOrigin.Begin);
                        attachmentStreams[i].CopyTo(copied);
                        copied.Seek(0, SeekOrigin.Begin);
                        InputMedia media = new InputMedia(copied, String.Format("{0}_{1}", i + 1, attach.Name));
                        photoAlbum.AddLast(new InputMediaPhoto(media));
                    }
                }

                if (photoAlbum.Count > 0)
                {
                    Task <Message[]> task = TheClient.SendMediaGroupAsync(photoAlbum, user);
                    try
                    {
                        // 메시지 순서가 섞이지 않도록 모두 보내질 때까지 대기.
                        task.Wait();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Trace.WriteLine(e);
                    }
                }
            }
        }