Esempio n. 1
0
        /// <summary>
        /// 解析一组联系人详细信息
        /// </summary>
        /// <param name="groupDataViewList">联系人详情信息分组列表(同一raw_contact_id)</param>
        /// <param name="contactList">联系人对象列表</param>
        /// <param name="groupList">群组列表</param>
        private void TryParseSingleGroupDataView(List <dynamic> groupDataViewList, List <Contact> contactList, IEnumerable <dynamic> groupList)
        {
            // 查找当前分组中,保存电话号码数据行列表
            //List<dynamic> phoneDataViewList = groupDataViewList.Where(c => c.mimetype.Contains("phone")).ToList();
            List <dynamic> phoneDataViewList = groupDataViewList;
            string         number            = "";

            foreach (var phoneDataView in phoneDataViewList)
            {
                number = DataParseHelper.NumberToStu(phoneDataView.data1);
                // 号码过滤
                if (!DataParseHelper.ValidateNumber(number))
                {
                    continue;
                }

                Contact contact = contactList.FirstOrDefault(s => s.Id == phoneDataView.raw_contact_id);
                if (contact == null)
                {
                    contact           = new Contact();
                    contact.Id        = DynamicConvert.ToSafeInt(phoneDataView.raw_contact_id);
                    contact.Number    = number;
                    contact.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(phoneDataView.XLY_DataType, EnumDataState.Normal);
                    contactList.Add(contact);
                }

                TryParseSingleDataView(contact, groupDataViewList, groupList);
            }
        }
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="datasource"></param>
        public void BuildData(CallDataSource datasource)
        {
            if (!FileHelper.IsValid(MainDbPath))
            {
                return;
            }

            var list = JArray.Parse(System.IO.File.ReadAllText(MainDbPath));

            foreach (JObject call in list)
            {
                var item = new Call();
                item.DataState = EnumDataState.Normal;
                item.Number    = call["number"].ToSafeString();
                // 号码过滤,验证号码长度
                if (!DataParseHelper.ValidateNumber(item.Number))
                {
                    continue;
                }

                item.Name = call["name"].ToSafeString();

                int  duration = 0, type = 0;
                long date = 0;
                int.TryParse(call["duration"].ToSafeString(), out duration);
                int.TryParse(call["type"].ToSafeString(), out type);
                long.TryParse(call["date"].ToSafeString(), out date);

                item.DurationSecond = duration;
                switch (type)
                {
                case 1:
                    item.Type = 0 == duration ? EnumCallType.MissedCallIn : EnumCallType.CallIn;
                    break;

                case 2:
                    item.Type = 0 == duration ? EnumCallType.MissedCallOut : EnumCallType.CallOut;
                    break;

                case 3:
                    item.Type           = EnumCallType.MissedCallIn;
                    item.DurationSecond = 0;
                    break;

                default:
                    item.Type = EnumCallType.None;
                    break;
                }

                item.StartDate = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(date / 1000).AddHours(8);

                datasource.Items.Add(item);
            }
        }
Esempio n. 3
0
        private void CreateSMS(string data, ref SMS createItem)
        {
            var tmpValue1 = data.Split(':');
            var tmpValue2 = data.Split(';');

            //电话
            if (tmpValue1[0].Equals("TEL") && DataParseHelper.ValidateNumber(tmpValue1[1]))
            {
                createItem.Number = tmpValue1[1];
            }
            //消息类型
            else if (tmpValue1[0].Equals("X-BOX"))
            {
                createItem.SmsState = tmpValue1[1] == "INBOX" ? EnumSMSState.ReceiveSMS : EnumSMSState.SendSMS;
            }
            //日期
            else if (tmpValue1[0].Equals("Date"))
            {
                DateTime dateTmp;
                if (DateTime.TryParse(data.Remove(0, 5), out dateTmp))
                {
                    createItem.StartDate = dateTmp;
                }
            }
            string dx = "";

            if (tmpValue2[0].Equals("Subject") || tmpValue2[0].StartsWith("Subject"))
            {
                dx = tmpValue1[1];
            }
            else if (data.StartsWith("=") && createItem.Content != "")
            {
                dx = data;
            }

            if ("" != dx)
            {
                createItem.Content = createItem.Content + dx;
                if (!dx.EndsWith("="))
                {
                    if (Regex.IsMatch(createItem.Content, @"(=[0-9A-F]{2})+"))
                    {
                        var datas = createItem.Content.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                        var bDatas = datas.ToList().ConvertAll((t) =>
                        {
                            return(Convert.ToByte(t, 16));
                        });
                        createItem.Content = Encoding.UTF8.GetString(bDatas.ToArray());
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 验证序列化结果
        /// </summary>
        /// <param name="entityItem">序列化后的实体</param>
        /// <returns></returns>
        private bool ValidateEntityItem(VivoSMSModel entityItem)
        {
            bool   result    = false;
            int    sendState = -1;
            double dateValue;

            result = DataParseHelper.ValidateNumber(entityItem.address);
            result = int.TryParse(entityItem.type, out sendState);
            result = double.TryParse(entityItem.date, out dateValue);
            result = int.TryParse(entityItem.status, out sendState);
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="datasource"></param>
        public void BuildData(CallDataSource datasource)
        {
            if (!FileHelper.IsValid(MainDbPath))
            {
                return;
            }

            SqliteContext mainContext = null;

            try
            {
                //主数据库对象
                var mainDbPath = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\IOS_Call\call_history.db.charactor", "call", true);
                mainContext = new SqliteContext(mainDbPath);

                mainContext.UsingSafeConnection("SELECT * FROM call", r =>
                {
                    Call call;
                    dynamic callObj;

                    while (r.Read())
                    {
                        callObj = r.ToDynamic();
                        call    = new Call();

                        call.DataState = DynamicConvert.ToEnumByValue(callObj.XLY_DataType, EnumDataState.Normal);
                        call.Number    = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(callObj.address));
                        // 号码过滤,验证号码长度
                        if (!DataParseHelper.ValidateNumber(call.Number))
                        {
                            continue;
                        }

                        call.DurationSecond = DynamicConvert.ToSafeInt(callObj.duration);
                        call.StartDate      = DynamicConvert.ToSafeDateTime(callObj.date);

                        call.Type = GetCallStatus(DynamicConvert.ToSafeInt(callObj.flags), call.DurationSecond);

                        datasource.Items.Add(call);
                    }
                });
            }
            finally
            {
                mainContext?.Dispose();
                mainContext = null;
            }
        }
Esempio n. 6
0
        private void TryParseCall(List <Call> items, IEnumerable <dynamic> calls)
        {
            foreach (var v in calls)
            {
                var item = new Call();
                item.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(v.XLY_DataType, EnumDataState.Normal);
                item.Number    = DataParseHelper.NumberToStu(v.number);
                // 号码过滤,验证号码长度
                if (!DataParseHelper.ValidateNumber(v.number))
                {
                    continue;
                }
                item.DurationSecond = DynamicConvert.ToSafeInt(v.duration);
                int type = DynamicConvert.ToSafeInt(v.type);
                switch (type)
                {
                case 1:
                case 3:
                    item.Type = type.ToEnumByValue <EnumCallType>();
                    break;

                case 2:
                    item.Type = item.DurationSecond > 0 ? EnumCallType.CallOut : EnumCallType.MissedCallOut;
                    break;

                case 10:    //新建联系人事件
                    continue;

                default:
                    item.Type = EnumCallType.None;
                    break;
                }
                if (item.DataState == EnumDataState.Normal)
                {
                    item.Name = DynamicConvert.ToSafeString(v.name);
                }

                if ("1" == DynamicConvert.ToSafeString(v.mark_deleted) || "1" == DynamicConvert.ToSafeString(v.deleted))
                {//红米
                    item.DataState = EnumDataState.Deleted;
                }

                item.StartDate = DynamicConvert.ToSafeDateTime(v.date);
                items.Add(item);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="datasource"></param>
        public void BuildData(CallDataSource datasource)
        {
            if (!FileHelper.IsValid(MainDbPath))
            {
                return;
            }

            XmlSerializer xml = new XmlSerializer(typeof(CallLog));

            using (FileStream fs = File.OpenRead(DealXml(MainDbPath)))
            {
                var lstCallDatas = xml.Deserialize(fs) as CallLog;
                foreach (var item in lstCallDatas.listDatas)
                {
                    int  typeTmp;
                    long dateTmp;
                    int  durationTmp;
                    // 号码过滤,验证号码长度
                    if (!DataParseHelper.ValidateNumber(item.number))
                    {
                        continue;
                    }

                    if (int.TryParse(item.type, out typeTmp) &&
                        long.TryParse(item.date, out dateTmp) &&
                        int.TryParse(item.duration, out durationTmp))
                    {
                        Call callTmp = new Call();
                        callTmp.Number         = item.number;
                        callTmp.Name           = item.name;
                        callTmp.Type           = ConvertToEnumCallType(typeTmp, durationTmp > 0);
                        callTmp.DataState      = EnumDataState.Normal;
                        callTmp.StartDate      = new DateTime(1970, 1, 1).AddSeconds(dateTmp / 1000).AddHours(8);
                        callTmp.DurationSecond = durationTmp;

                        datasource.Items.Add(callTmp);
                    }
                }
                fs.Close();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 根据phone_lookup表,解析联系人号码
        /// </summary>
        /// <param name="items">联系人列表</param>
        /// <param name="phoneLookupList">phone_lookup表集合</param>
        private void TryParsePhoneLookup(List <Contact> items, IEnumerable <dynamic> phoneLookupList)
        {
            if (items.IsInvalid() || phoneLookupList.IsInvalid())
            {
                return;
            }

            foreach (var p in phoneLookupList)
            {
                try
                {
                    string number = DynamicConvert.ToSafeString(p.normalized_number);

                    number = DataParseHelper.NumberToStu(number);

                    // 号码过滤
                    if (!DataParseHelper.ValidateNumber(number))
                    {
                        continue;
                    }

                    //已存在,则跳过
                    //这儿不能过滤,存在两个联系人同一号码的情况
                    //if (items.Any(s => s.Number == number))
                    //{
                    //    continue;
                    //}

                    var c = items.Find(s => s.Id == p.raw_contact_id);
                    if (c == null)
                    {
                        var ncc = new Contact();
                        ncc.Id        = DynamicConvert.ToSafeInt(p.raw_contact_id);
                        ncc.Number    = number;
                        ncc.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(p.XLY_DataType, EnumDataState.Normal);
                        items.Add(ncc);
                        continue;
                    }

                    if (c.Number.IsInvalid())
                    {
                        c.Number = number;
                        continue;
                    }

                    if (c.Number == number)
                    {
                        continue;
                    }

                    //new
                    var nc = new Contact();
                    nc.Id              = c.Id;
                    nc.Name            = c.Name;
                    nc.LastContactDate = c.LastContactDate;
                    nc.Remark          = c.Remark;
                    var dataState = DynamicConvert.ToEnumByValue <EnumDataState>(p.XLY_DataType, EnumDataState.Normal);
                    if (dataState == EnumDataState.Deleted || dataState == EnumDataState.Fragment)
                    {
                        nc.DataState = EnumDataState.Deleted;
                    }
                    else
                    {
                        nc.DataState = c.DataState;
                    }
                    nc.Number = number;
                    items.Add(nc);
                }
                catch
                {
                }
            }
        }
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="datasource"></param>
        public void BuildData(ContactDataSource datasource)
        {
            if (!FileHelper.IsValid(MainDbPath))
            {
                return;
            }

            SqliteContext mainContext = null;

            try
            {
                var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\IOS_Contact\AddressBook.sqlitedb_V7.charactor", "ABPerson,ABMultiValue,ABGroupMembers,ABGroup", true);
                mainContext = new SqliteContext(rMainDbFile);

                string groupString = "select member_id,Name from ABGroupMembers m left join ABGroup g on m.group_id == g.ROWID";
                var    groups      = mainContext.Find(groupString);

                mainContext.UsingSafeConnection("select p.*,v.record_id,v.property,v.label,v.[value] from ABPerson p,ABMultiValue v WHERE p.ROWID = v.record_id", r =>
                {
                    Contact contact;
                    dynamic contactObj;

                    while (r.Read())
                    {
                        contactObj = r.ToDynamic();
                        contact    = new Contact();

                        contact.DataState = DynamicConvert.ToEnumByValue(contactObj.XLY_DataType, EnumDataState.Normal);

                        //正常的联系人,目前只处理电话号码的信息,如亲属关系,社交等暂不处理。
                        if (contact.DataState == EnumDataState.Normal)
                        {
                            int propertyId = DynamicConvert.ToSafeInt(contactObj.property);
                            if (propertyId != 3)
                            {
                                continue;
                            }
                        }

                        contact.Name   = DynamicConvert.ToSafeString(contactObj.Last) + DynamicConvert.ToSafeString(contactObj.First);
                        contact.Name   = FragmentHelper.RemoveNullityDataNew(contact.Name);
                        contact.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(contactObj.value));
                        // 号码过滤,验证号码长度
                        if (!DataParseHelper.ValidateNumber(contact.Number))
                        {
                            continue;
                        }

                        //创建时间(最后修改时间)
                        contact.CreateDate = DynamicConvert.ToSafeDateTime(contactObj.ModificationDate, 2001);

                        //联系人分组
                        int contactId = DynamicConvert.ToSafeInt(contactObj.ROWID);
                        var groupObj  = groups.FirstOrDefault(g => DynamicConvert.ToSafeInt(g.member_id) == contactId);
                        if (groupObj != null)
                        {
                            contact.GroupName = DynamicConvert.ToSafeString(groupObj.Name);
                        }

                        //基础备注
                        contact.Remark = BuildRemark(contactObj).ToString().TrimStart(';');

                        datasource.Items.Add(contact);
                    }
                });
            }
            finally
            {
                mainContext?.Dispose();
                mainContext = null;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="datasource"></param>
        public void BuildData(CallDataSource datasource)
        {
            if (!FileHelper.IsValid(MainDbPath))
            {
                return;
            }

            SqliteContext mainContext = null;

            try
            {
                //主数据库对象
                var mainDbPath = SqliteRecoveryHelper.DataRecovery(MainDbPath, "", "ZCALLRECORD", true);
                mainContext = new SqliteContext(mainDbPath);

                IEnumerable <dynamic> addressDynamicList = null;

                if (FileHelper.IsValid(AddrDbPath))
                {
                    var           addressDbPath = SqliteRecoveryHelper.DataRecovery(AddrDbPath, @"chalib\IOS_Contact\AddressBook.sqlitedb.charactor", "ABMultiValue,ABPerson", true);
                    SqliteContext addrContext   = new SqliteContext(addressDbPath);

                    addressDynamicList = addrContext.Find("select p.[value],p.[record_id],v.[Last],v.[ROWID] from ABMultiValue p left join ABPerson v on p.[record_id]=v.[ROWID] where p.[property]=3");

                    addrContext.Dispose();
                    addrContext = null;
                }

                mainContext.UsingSafeConnection("select XLY_DataType,ZDURATION,Z_OPT,ZDURATION,ZORIGINATED,cast(ZADDRESS as varchar) as number, cast(ZDATE as DATETIME) as phonetime from ZCALLRECORD", r =>
                {
                    Call call;
                    dynamic callObj;

                    while (r.Read())
                    {
                        callObj = r.ToDynamic();
                        call    = new Call();

                        call.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(callObj.number));
                        // 号码过滤,验证号码长度
                        if (!DataParseHelper.ValidateNumber(call.Number))
                        {
                            continue;
                        }

                        if (addressDynamicList.IsValid())
                        {
                            var addressname = addressDynamicList.FirstOrDefault(o => DynamicConvert.ToSafeString(o.value).Replace("-", "").Equals(callObj.number));
                            if (addressname != null)
                            {
                                call.Name = FragmentHelper.RemoveNullityDataNew(DynamicConvert.ToSafeString(addressname.Last));
                            }
                        }

                        call.DataState      = DynamicConvert.ToEnumByValue(callObj.XLY_DataType, EnumDataState.Normal);
                        call.DurationSecond = DynamicConvert.ToSafeInt(callObj.ZDURATION);

                        string time     = DynamicConvert.ToSafeString(callObj.phonetime).Insert(0, "1");
                        double opertime = time.ToDouble() - 21692848;
                        call.StartDate  = DynamicConvert.ToSafeDateTime(opertime);

                        call.Type = GetCallV10Status(DynamicConvert.ToSafeInt(callObj.ZORIGINATED), call.DurationSecond);

                        datasource.Items.Add(call);
                    }
                });
            }
            finally
            {
                mainContext?.Dispose();
                mainContext = null;
            }
        }