コード例 #1
0
ファイル: ModelConverter.cs プロジェクト: LUO12826/CodeChat
        /// <summary>
        /// 将SDK的topic类型转换为界面ChatList中的项类型
        /// </summary>
        public static ChatListChatItemVM TopicToChatListItem(Topic topic)
        {
            if (topic == null)
            {
                return(null);
            }

            var contact = CommunicationCore.GetContactByTopicName(topic.Name);

            var chatListItem = new ChatListChatItemVM()
            {
                TopicName      = topic.Name,
                Contact        = contact,
                LastActiveTime = GlobalFunctions.TimestampToDateTime(topic.LastUsed),
                RawTopic       = topic,
                MaxMsgSeq      = topic.MaxLocalSeqId
            };

            return(chatListItem);
        }
コード例 #2
0
        /// <summary>
        /// 在应用程序由最终用户正常启动时进行调用。
        /// 将在启动应用程序以打开特定文件等情况下使用。
        /// </summary>
        /// <param name="e">有关启动请求和过程的详细信息。</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            CommunicationCore.ConfigClient();

            //窗口最小尺寸的最大值只能到500*500。
            ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(800.0, 600.0));
            ApplicationView.PreferredLaunchViewSize      = new Size(1200, 800);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            Frame rootFrame = Window.Current.Content as Frame;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                }

                GlobalRef.RootFrame    = rootFrame;
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    rootFrame.Navigate(GlobalConfigs.startPage, e.Arguments);
                }

                Window.Current.Activate();
            }
        }
コード例 #3
0
ファイル: ModelConverter.cs プロジェクト: LUO12826/CodeChat
        /// <summary>
        /// 将SDK的消息类型转换为界面消息类型
        /// </summary>
        public static MessageItemBaseVM MessageToMessageVM(ChatMessage msg)
        {
            if (msg == null)
            {
                return(null);
            }
            var  contact  = CommunicationCore.GetContactByTopicName(msg.TopicName);
            bool sendByMe = !(msg.From == msg.TopicName);

            //判断是否为代码消息
            if (msg.IsCode == true)
            {
                return(new CodeMessageVM()
                {
                    Code = msg.Text,
                    Language = GlobalFunctions.SDKcodeTypeToString(msg.CodeType),
                    RunResult = null,
                    ID = msg.Id,
                    Contact = contact,
                    SendByMe = sendByMe,
                    RawMessage = msg
                });
            }

            //判断是否为附件消息
            if (msg.IsAttachment == true)
            {
                var attach = ChatMessageParser.ParseGenericAttachment(msg);

                //通过消息解析器获取URL列表
                List <string> urls = ChatMessageParser.ParseUrl(msg, CommunicationCore.client.ApiBaseUrl);

                string url  = urls.Count > 0 ? urls[0] : "";
                string name = attach.Count > 0 ? attach[0].Name : "";
                string mime = attach.Count > 0 ? attach[0].Mime : "";

                //假如是以文件形式发送的图片
                if (GlobalFunctions.FindPosInImageMineList(GlobalConfigs.ImageMime, mime.ToLower()) != -1)
                {
                    return(new ImageMessageVM()
                    {
                        Contact = contact,
                        ID = msg.Id,
                        SendByMe = sendByMe,
                        RawMessage = msg,
                        ImageUri = url
                    });
                }

                return(new FileMessageVM()
                {
                    Contact = contact,
                    ID = msg.Id,
                    SendByMe = sendByMe,
                    RawMessage = msg,
                    DownloadState = -1,
                    FileUri = url,
                    FileName = name,
                });
            }

            //判断是否为图片消息
            if (msg.IsPlainText == false)
            {
                List <string> base64s = ChatMessageParser.ParseImageBase64(msg);
                string        base64  = base64s.Count > 0 ? base64s[0] : "";
                return(new ImageMessageVM()
                {
                    Contact = contact,
                    ID = msg.Id,
                    SendByMe = sendByMe,
                    RawMessage = msg,
                    ImageBase64 = base64,
                });
            }

            return(new TextMessageVM()
            {
                Contact = contact,
                ID = msg.Id,
                SendByMe = sendByMe,
                RawMessage = msg,
                Text = msg.Text
            });
        }