Beispiel #1
0
        /// <summary>
        /// 断点续传
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="fileName"></param>
        /// <param name="fileType"></param>
        /// <param name="msgId"></param>
        /// <param name="InitProgress"></param>
        /// <param name="downloadProgressChanged"></param>
        /// <param name="downloadDataCompleted"></param>
        /// <param name="cancellationToken"></param>
        public static void DownloadFileWithResume(string resourceName, string fileName, FileType fileType, Action <long> downloadProgressChanged,
                                                  Action <bool> downloadDataCompleted, string msgId, Action <long, long> InitProgress = null, System.Threading.CancellationToken?cancellationToken = null)
        {
            void UpdateFileState(DB.messageDB message, int fileState)
            {
                if (message == null)
                {
                    return;
                }
                int i = Util.Helpers.Async.Run(async() => await SDKProperty.SQLiteConn.ExecuteAsync($"update messageDB set fileState={fileState} where Id='{message.Id}'"));
            }

            var m = Util.Helpers.Async.Run(async() => await DAL.DALMessageHelper.Get(msgId));


            UpdateFileState(m, (int)ResourceState.Working);
            string sourceUrl = string.Format("{0}{1}", Protocol.ProtocolBase.DownloadFileWithResume, resourceName);
            string basePath  = null;

            if (!Path.IsPathRooted(fileName))
            {
                switch (fileType)
                {
                case FileType.img:
                    basePath = Path.Combine(SDKProperty.imgPath, SDKClient.Instance.property.CurrentAccount.loginId);
                    if (!Directory.Exists(basePath))
                    {
                        Directory.CreateDirectory(basePath);
                    }
                    break;

                case FileType.file:
                    basePath = Path.Combine(SDKProperty.filePath, SDKClient.Instance.property.CurrentAccount.loginId);
                    if (!Directory.Exists(basePath))
                    {
                        Directory.CreateDirectory(basePath);
                    }
                    break;

                default:
                    break;
                }
                fileName = Path.Combine(basePath, fileName);
            }
            IMRequest.DownloadFileWithResume(sourceUrl, fileName, InitProgress, downloadProgressChanged, (b) => {
                if (b)
                {
                    UpdateFileState(m, (int)ResourceState.IsCompleted);
                }
                else
                {
                    UpdateFileState(m, (int)ResourceState.Working);
                }
                downloadDataCompleted?.Invoke(b);
            }, cancellationToken);
        }
Beispiel #2
0
        public string GetGroupMemberList(int groupId, bool isLoaclData = false)
        {
            //var dbobj = Util.Helpers.Async.Run(async () => await DAL.DALGroupOptionHelper.GetGroupListPackage());

            var card = SDKClient.Instance.property.CurrentAccount.imei ?? System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(N => N.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Loopback)?.GetPhysicalAddress().ToString();


            if (isLoaclData && SDKClient.Instance.property.CurrentAccount.preimei == card)
            {
                var dbobj = Util.Helpers.Async.Run(async() => await DAL.DALGroupOptionHelper.GetGroupMemberListPackage(groupId));
                if (dbobj != null && dbobj.getGroupMemberListPackage != null)
                {
                    var groupListPackage = Util.Helpers.Json.ToObject <GetGroupMemberListPackage>(dbobj.getGroupMemberListPackage);
                    SDKClient.Instance.OnNewDataRecv(groupListPackage);
                }
            }
            GetGroupMemberListPackage package = new GetGroupMemberListPackage();

            package.ComposeHead(SDKClient.Instance.property.ServerJID, SDKClient.Instance.property.CurrentAccount.userID.ToString());
            package.data = new groupmemberlist()
            {
                max     = 100,
                min     = 1,
                groupId = groupId //普通群
            };
            var obj = IMRequest.GetMemberList(package);

            if (obj != null)
            {
                var groupMemberListPackage = obj;
                if (groupMemberListPackage != null)
                {
                    try
                    {
                        var cmd = SDKClient.Instance.CommmandSet.FirstOrDefault(c => c.Name == groupMemberListPackage.api);
                        cmd?.ExecuteCommand(SDKClient.Instance.ec, groupMemberListPackage);//日志及入库操作
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"获取群成员数据处理异常:error:{ex.Message},stack:{ex.StackTrace};\r\ncontent:{Util.Helpers.Json.ToJson(groupMemberListPackage)}");

                        System.Threading.Interlocked.CompareExchange(ref SDKClient.Instance.property.CanHandleMsg, 2, 1);
                        logger.Info("CanHandleMsg 值修改为:2");
                    }
                }
            }
            else
            {
            }
            //package.Send(ec).id
            return(package.id);
        }
Beispiel #3
0
        /// <summary>
        /// 创建拉取任务,从近到远
        /// </summary>
        /// <param name="room"></param>
        internal static async void CreateTask_Offline(RoomInfo room, bool needShow = false)
        {
            room.pullType = 1;//从近到远
            room.pageNum  = 100;
            bool isGroup = room.entryType == 2 ? true : false;

            Task head = Task.Run(async() =>
            {
                await SDKProperty.SQLiteReader.FindAsync <OffLineMsgTask>(o => o.roomId == room.entryId && o.isGroup == isGroup && o.earlyTime == room.earlyTime)
                .ContinueWith(async t =>
                {
                    if (t.IsFaulted)
                    {
                        OffLineMsgTask firstTask = new OffLineMsgTask()
                        {
                            deadTime  = room.fromTime,
                            isGroup   = room.entryType == 2 ? true : false,
                            roomId    = room.entryId,
                            earlyTime = room.earlyTime
                        };
                        await SDKProperty.SQLiteConn.InsertAsync(firstTask);
                    }
                    else
                    {
                        var item = t.Result;
                        if (item != null)
                        {
                            item.deadTime = room.fromTime;
                            await SDKProperty.SQLiteConn.UpdateAsync(item);
                        }
                        else
                        {
                            OffLineMsgTask firstTask = new OffLineMsgTask()
                            {
                                deadTime  = room.fromTime,
                                isGroup   = room.entryType == 2 ? true : false,
                                roomId    = room.entryId,
                                earlyTime = room.earlyTime
                            };
                            await SDKProperty.SQLiteConn.InsertAsync(firstTask);
                        }
                    }
                }, TaskContinuationOptions.NotOnCanceled);
            });


            var lst = await IMRequest.GetMessage(room);//获取到条目消息

            if (lst.success)
            {
                head.Wait();
                List <DB.messageDB> dblst = new List <messageDB>();
                foreach (var item in lst.msgList.Where(l => l.content.reply == null || l.content.reply != 1))
                {
                    var msg = await DAL.DALMessageHelper.ReceiveMsgtoDB(item.content);

                    if (msg != null)
                    {
                        dblst.Add(msg);
                    }
                }
                if (dblst.Any())
                {
                    OfflineMessageContext offlineMessage = new OfflineMessageContext();
                    foreach (var item in dblst)
                    {
                        var isgroup = item.roomType == 1 ? true : false;
                        IList <MessageEntity> msglst = new List <MessageEntity>();
                        //  if (offlineMessage.context.TryAdd((item.roomId, isgroup), msglst))

                        if (offlineMessage.context.TryAdd(new Tuple <int, bool>(item.roomId, isgroup), msglst))
                        {
                            MessageEntity messageEntity = new MessageEntity()
                            {
                                db = item
                            };
                            msglst.Add(messageEntity);
                        }
                        else
                        {
                            // if (offlineMessage.context.TryGetValue((item.roomId, isgroup), out msglst))
                            if (offlineMessage.context.TryGetValue(new Tuple <int, bool>(item.roomId, isgroup), out msglst))
                            {
                                MessageEntity messageEntity = new MessageEntity()
                                {
                                    db = item
                                };
                                var target = msglst.FirstOrDefault(m => m.MsgId == item.msgId);
                                if (target == null)
                                {
                                    msglst.Add(messageEntity);
                                }
                                else
                                {
                                    msglst.Remove(target);
                                    msglst.Add(messageEntity);
                                }
                            }
                        }
                    }
                    if (needShow)
                    {
                        SDKClient.Instance.OnOffLineMessageEventHandle(offlineMessage);//推送到UI
                    }
                    room.fromTime = lst.msgList.Min(o => o.time);
                    CreateTask_Offline(room);
                }
                else //没消息说明已经拉完,删除任务
                {
                    await SDKProperty.SQLiteReader.FindAsync <OffLineMsgTask>(o => o.roomId == room.entryId && o.isGroup == isGroup && o.earlyTime == room.earlyTime).ContinueWith(async t =>
                    {
                        if (t.IsFaulted)
                        {
                            return;
                        }
                        else
                        {
                            var item = t.Result;
                            if (item != null)
                            {
                                await SDKProperty.SQLiteConn.DeleteAsync(item);
                            }
                        }
                    });
                }
            }
        }