Exemple #1
0
        private static List <Call> ReadCalls(CSource source)
        {
            var calls = new List <Call>();

            foreach (COMlib.CPhonebook phonebook in source.Phonebooks)
            {
                if (phonebook.Type != COMlib.CPhonebook.EType.Dialed &&
                    phonebook.Type != COMlib.CPhonebook.EType.Missed &&
                    phonebook.Type != COMlib.CPhonebook.EType.Received)
                {
                    continue;
                }

                //try
                //{
                phonebook.Entries.Update();
                //    phonebook.Entries.Push();
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine("phonebook update error: " + e.Message);
                //}
                foreach (CEntry entry in phonebook.Entries)
                {
                    var call = new Call();
                    call.Type = phonebook.Type == COMlib.CPhonebook.EType.Received ? CallType.Received :
                                phonebook.Type == COMlib.CPhonebook.EType.Missed ? CallType.Missed :
                                CallType.Dialed;
                    foreach (CEntryItem item in entry.Items)
                    {
                        if (item.DataType != CEntryItem.EDataType.Empty)
                        {
                            string dateType = item.DataType.ToString();
                            if (item.Data is CEntryItem.CData.CTextData)
                            {
                                //if (dateType == "Label")
                                //    call.Name = (item.Data as CEntryItem.CData.CTextData).Text;
                            }
                            else if (item.Data is CEntryItem.CData.CNumberData)
                            {
                                call.Number = (item.Data as CEntryItem.CData.CNumberData).Number;
                            }
                            else if (item.Data is CEntryItem.CData.CTimeData)
                            {
                                //(item.Data as CEntryItem.CData.CTimeData).Time.ToString();
                            }
                            else if (item.Data is CEntryItem.CData.CAddressData)
                            {
                                //(item.Data as CEntryItem.CData.CAddressData).Street
                                //+ ";" + (item.Data as CEntryItem.CData.CAddressData).City
                                //+ ";" + (item.Data as CEntryItem.CData.CAddressData).Country;
                            }
                            else
                            {
                                throw new NotImplementedException("call history data type not supported");
                            }
                        }
                    }
                    calls.Add(call);
                }
            }
            return(calls);
        }
Exemple #2
0
        private static List <Contact> ReadPhoneBook(CSource source)
        {
            var contacts = new List <Contact>();

            foreach (COMlib.CPhonebook phonebook in source.Phonebooks)
            {
                if (phonebook.Type != COMlib.CPhonebook.EType.Phonebook)
                {
                    continue;
                }

                phonebook.Entries.Update();
                foreach (CEntry entry in phonebook.Entries)
                {
                    var contact = new Contact();
                    foreach (CEntryItem item in entry.Items)
                    {
                        if (item.DataType != CEntryItem.EDataType.Empty)
                        {
                            string dateType = item.DataType.ToString();
                            if (item.Data is CEntryItem.CData.CTextData)
                            {
                                if (dateType == "Label" || dateType == "FirstName" || dateType == "LastName")
                                {
                                    if (contact.Name == null)
                                    {
                                        contact.Name = (item.Data as CEntryItem.CData.CTextData).Text;
                                    }
                                    else
                                    {
                                        contact.Name += " " + contact.Name;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("not supported text data type: " + dateType);
                                }
                            }
                            else if (item.Data is CEntryItem.CData.CNumberData)
                            {
                                contact.Number = (item.Data as CEntryItem.CData.CNumberData).Number;
                            }
                            else if (item.Data is CEntryItem.CData.CTimeData)
                            {
                                //(item.Data as CEntryItem.CData.CTimeData).Time.ToString();
                            }
                            else if (item.Data is CEntryItem.CData.CAddressData)
                            {
                                //(item.Data as CEntryItem.CData.CAddressData).Street
                                //+ ";" + (item.Data as CEntryItem.CData.CAddressData).City
                                //+ ";" + (item.Data as CEntryItem.CData.CAddressData).Country;
                            }
                            else
                            {
                                //throw new NotImplementedException("phonebook data not supported");
                                if (item.Data != null)
                                {
                                    Console.WriteLine("not supported phone book data: " + item.DataType);
                                }
                            }
                        }
                    }
                    contacts.Add(contact);
                }
            }
            return(contacts);
        }
Exemple #3
0
        private void DoImport(CSource source, bool importContact, bool importCall, bool importSms, bool importFs)
        {
            try
            {
                if (source is CSource.CMobilePhone)
                {
                    CSource.CMobilePhone phone = source as CSource.CMobilePhone;
                    if (phone.IsConnectorRequired)
                    {
                        //Form_Progress installConnectorProgress = new Form_Progress();
                        //installConnectorProgress.Text = "Installing connector";
                        //installConnectorProgress.Show();
                        //phone.InstallConnector(installConnectorProgress.Progress);
                        //installConnectorProgress.Close();
                        phone.InstallConnector();

                        //System.Windows.Forms.MessageBox.Show("Connector was installed, please wait until the device is connected");
                        return;
                    }

                    List <Sms>     sms      = null;
                    List <Contact> contacts = null;
                    List <Call>    calls    = null;

                    if (importContact)
                    {
                        Log("读取联系人...\n");
                        contacts = ReadPhoneBook(source);
                        Log("完成\n");
                    }
                    if (importCall)
                    {
                        Log("读取通话记录...\n");
                        calls = ReadCalls(source);
                        Log("完成\n");
                    }
                    if (importSms)
                    {
                        Log("读取短信...\n");
                        sms = ReadSms(source);
                        Log("完成\n");
                    }
                    if (sms != null && sms.Count > 0 ||
                        contacts != null && contacts.Count > 0 ||
                        calls != null && calls.Count > 0)
                    {
                        Log("保存...\n");
                        SaveToDB(phone, contacts, calls, sms);
                        Log("导入完成!\n");
                    }
                    else
                    {
                        Log("没有需要保存的记录\n");
                    }
                }
                else if (source is CSource.CSIMCard)
                {
                    Log("读取文件系统...\n");
                    //string rootFolder = ReadFS(source);
                    string root       = @"G:\data\";
                    string rootFolder = System.IO.Path.Combine(root, source.UniqueIdentifier);
                    Log("完成\n");
                    Log("保存...\n");
                    SaveToDB(source, rootFolder);
                    Log("导入完成!\n");
                }
            }
            catch (Exception ex)
            {
                Log("导入时发生了错误: " + ex.Message + "\n");
            }
        }
Exemple #4
0
 /// <summary>
 /// Add source value to the source part of the URL.
 /// </summary>
 /// <param name="src">Source definition of the URL.</param>
 /// <param name="value">Source value to add.</param>
 /// <returns>Updated source definition.</returns>
 public static CSource Add(CSource src, string value)
 {
     return(OpAddition(src, value));
 }
Exemple #5
0
        static void Main(string[] args)
        {
            //Obsolute way - Static Api

            /*
             * Mapper.Initialize(cfg => cfg.CreateMap<Source, Destination>());
             *
             * var source = new Source()
             * {
             *  Value = "Alabama"
             * };
             *
             *
             * var destination = Mapper.Map<Destination>(source);
             *
             * Console.WriteLine($"Source : {source.Value}");
             * Console.WriteLine($"Destination : {destination.Value}");
             */


            //Instance Api - DIP

            /*
             * var cfg = new MapperConfiguration(x => x.CreateMap<Source, Destination>());
             * var mapper = cfg.CreateMapper();
             *
             * var source = new Source()
             * {
             *  Value = "Alabama"
             * };
             *
             *
             * var destination = mapper.Map<Destination>(source);
             *
             * Console.WriteLine($"Source : {source.Value}");
             * Console.WriteLine($"Destination : {destination.Value}");
             */

            var source = new Source()
            {
                Date = DateTime.Now
            };
            var cfg    = new MapperConfiguration(x => x.AddProfile <IntroProfile>());
            var mapper = cfg.CreateMapper();

            var destination = mapper.Map <Destination>(source);

            Console.WriteLine($"Source:{source.Date.Day}.{source.Date.Month}.{source.Date.Year}");
            Console.WriteLine($"Destination:{destination.Day}.{destination.Month}.{destination.Year}");

            Mapper.Initialize(x =>
            {
                x.CreateMap <CSource, CDest>();
                x.CreateMap <string, int>().ConvertUsing(s => Convert.ToInt32(s));
                x.CreateMap <string, DateTime>().ConvertUsing <StringDateTimeConverter>();
            });

            var csrc = new CSource()
            {
                Number = "5",
                Date   = "01/01/2018"
            };

            var cdest = Mapper.Map <CSource, CDest>(csrc);

            Console.WriteLine(csrc.Number);
            Console.WriteLine(cdest.Number);

            Console.WriteLine($"Source:{csrc.Date}");
            Console.WriteLine($"Destination:{cdest.Date.Day}/{cdest.Date.Month}/{cdest.Date.Year}");

            var acfg = new MapperConfiguration(x => {
                x.CreateMap <ASource, ADest>();
                x.CreateMap <ASourceParent, ADestParent>().Include <ASource, ADest>();
            });
            var aMapper = acfg.CreateMapper();
            var srcArr  = new[]
            {
                new ASource()
                {
                    Value = 1, Value1 = 1
                },
                new ASource()
                {
                    Value = 2, Value1 = 2
                }
            };

            var destArr  = aMapper.Map <ASource[], ADest[]>(srcArr);
            var destList = aMapper.Map <ASource[], List <ADest> >(srcArr);


            var personcfg = new MapperConfiguration(x =>
            {
                x.CreateMap <PersonRequest, PersonResponse>()
                .ForMember(dest => dest.FullName, opt => opt.MapFrom <PersonResolver>());
                x.ValueTransformers.Add <string>(val => val + "!!!");
            });

            var personMapper = personcfg.CreateMapper();

            var request = new PersonRequest()
            {
                FirstName = "Vuk",
                LastName  = "Isic"
            };

            var response = personMapper.Map <PersonResponse>(request);

            var pricecfg = new MapperConfiguration(
                x => x.CreateMap <DecimalPrice, StringPrice>()
                .ForMember(dest => dest.Price, opt => opt.ConvertUsing(new PriceConverter())));

            var priceMapper = pricecfg.CreateMapper();

            var price1 = new DecimalPrice()
            {
                Price = new decimal(234.44)
            };

            var price2 = priceMapper.Map <StringPrice>(price1);


            var pConfig = new MapperConfiguration(
                x => x.CreateMap <Person, PersonDTO>()
                .BeforeMap((src, des) => src.Age   += 10)
                .AfterMap((src, dest) => dest.Name += "Mr."));

            var pMapper = pConfig.CreateMapper();

            var per = new Person
            {
                Name = "Vuk",
                Age  = 11
            };

            var per2 = pMapper.Map <PersonDTO>(per);


            var eventcfg = new MapperConfiguration(x => x.CreateMap <SrcEvent, DestEvent>()
                                                   .ForMember(dest => dest.EventName, opt => opt.NullSubstitute("NullEvent")));

            var eventMapper = eventcfg.CreateMapper();

            var eventsrc = new SrcEvent()
            {
                EventName = null
            };
            var eventdes = eventMapper.Map <DestEvent>(eventsrc);


            var gencfg    = new MapperConfiguration(x => x.CreateMap(typeof(GenSource <>), typeof(GenDest <>)));
            var genMapper = gencfg.CreateMapper();

            var gs = new GenSource <int> {
                Value = 10
            };
            var ds = genMapper.Map <GenSource <int>, GenDest <int> >(gs);

            Console.ReadLine();
        }
Exemple #6
0
 public static string Field1([FromSource] CSource source) => source.Value;