private void MapCategories1To2(ITaskItemWrapper source, ITodo target)
        {
            if (!string.IsNullOrEmpty(source.Inner.Categories))
            {
                var useTaskCategoryAsFilter = _configuration.UseTaskCategoryAsFilter;

                var sourceCategories = CommonEntityMapper.SplitCategoryString(source.Inner.Categories)
                                       .Where(c => !useTaskCategoryAsFilter || c != _configuration.TaskCategory);

                foreach (var sourceCategory in sourceCategories)
                {
                    target.Categories.Add(sourceCategory);
                }
            }
        }
        public GoogleContactWrapper Map1To2(ContactItemWrapper source, GoogleContactWrapper targetWrapper, IEntityMappingLogger logger)
        {
            var target = targetWrapper.Contact;

            #region Title/FileAs
            if (!string.IsNullOrEmpty(source.Inner.FileAs))
            {
                target.Title = source.Inner.FileAs;
            }
            else if (!string.IsNullOrEmpty(source.Inner.CompanyAndFullName))
            {
                target.Title = source.Inner.CompanyAndFullName;
            }
            else if (!string.IsNullOrEmpty(source.Inner.FullName))
            {
                target.Title = source.Inner.FullName;
            }
            else if (!string.IsNullOrEmpty(source.Inner.CompanyName))
            {
                target.Title = source.Inner.CompanyName;
            }
            else if (!string.IsNullOrEmpty(source.Inner.Email1Address))
            {
                target.Title = source.Inner.Email1Address;
            }
            #endregion Title/FileAs

            #region Name
            Name name = new Name()
            {
                GivenName      = source.Inner.FirstName,
                FamilyName     = source.Inner.LastName,
                AdditionalName = source.Inner.MiddleName,
                NamePrefix     = source.Inner.Title,
                NameSuffix     = source.Inner.Suffix,
            };

            //Use the Google's full name to save a unique identifier. When saving the FullName, it always overwrites the Google Title
            if (!string.IsNullOrEmpty(source.Inner.FullName)) //Only if source.FullName has a value, i.e. not only a company or email contact
            {
                name.FullName = source.Inner.FileAs;
            }

            target.Name = name;

            #endregion Name

            MapEmailAddresses1To2(source.Inner, target, logger);

            MapPostalAddresses1To2(source.Inner, target);

            MapPhoneNumbers1To2(source.Inner, target);

            target.ContactEntry.Nickname = source.Inner.NickName;
            target.ContactEntry.Initials = source.Inner.Initials;

            #region company
            target.Organizations.Clear();
            if (!string.IsNullOrEmpty(source.Inner.Companies))
            {
                //Companies are expected to be in form of "[Company]; [Company]".
                string[] companiesRaw = source.Inner.Companies.Split(';');
                foreach (string companyRaw in companiesRaw)
                {
                    Organization company = new Organization();
                    company.Name       = (target.Organizations.Count == 0) ? source.Inner.CompanyName : companyRaw;
                    company.Title      = (target.Organizations.Count == 0) ? source.Inner.JobTitle : null;
                    company.Department = (target.Organizations.Count == 0) ? source.Inner.Department : null;
                    company.Primary    = target.Organizations.Count == 0;
                    company.Rel        = ContactsRelationships.IsWork;
                    target.Organizations.Add(company);
                }
            }

            if (target.Organizations.Count == 0 && (!string.IsNullOrEmpty(source.Inner.CompanyName) || !string.IsNullOrEmpty(source.Inner.Department) ||
                                                    !string.IsNullOrEmpty(source.Inner.JobTitle)))
            {
                target.Organizations.Add(new Organization()
                {
                    Name       = source.Inner.CompanyName,
                    Department = source.Inner.Department,
                    Title      = source.Inner.JobTitle,
                    Rel        = ContactsRelationships.IsWork,
                    Primary    = true,
                });
            }
            #endregion company

            target.ContactEntry.Occupation = source.Inner.Profession;

            target.Location = source.Inner.OfficeLocation;

            target.ContactEntry.Websites.Clear();
            if (!string.IsNullOrEmpty(source.Inner.WebPage))
            {
                target.ContactEntry.Websites.Add(new Website()
                {
                    Href    = source.Inner.WebPage,
                    Rel     = REL_HOMEPAGE,
                    Primary = true,
                });
            }
            if (!string.IsNullOrEmpty(source.Inner.BusinessHomePage))
            {
                target.ContactEntry.Websites.Add(new Website()
                {
                    Href    = source.Inner.BusinessHomePage,
                    Rel     = REL_WORK,
                    Primary = target.ContactEntry.Websites.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.Inner.PersonalHomePage))
            {
                target.ContactEntry.Websites.Add(new Website()
                {
                    Href    = source.Inner.PersonalHomePage,
                    Rel     = REL_HOME,
                    Primary = target.ContactEntry.Websites.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.Inner.FTPSite))
            {
                target.ContactEntry.Websites.Add(new Website()
                {
                    Href    = source.Inner.FTPSite,
                    Rel     = REL_FTP,
                    Primary = target.ContactEntry.Websites.Count == 0,
                });
            }

            #region birthday
            if (_configuration.MapBirthday && !source.Inner.Birthday.Equals(OU_OUTLOOK_DATE_NONE))
            {
                target.ContactEntry.Birthday = source.Inner.Birthday.ToString("yyyy-MM-dd");
            }
            else
            {
                target.ContactEntry.Birthday = null;
            }
            #endregion birthday

            #region anniversary
            //Todo: Check, if (_configuration.MapAnniversary)
            //{

            //First remove anniversary
            foreach (Event ev in target.ContactEntry.Events)
            {
                if (ev.Relation != null && ev.Relation.Equals(REL_ANNIVERSARY))
                {
                    target.ContactEntry.Events.Remove(ev);
                    break;
                }
            }
            try
            {
                //Then add it again if existing
                if (!source.Inner.Anniversary.Equals(OU_OUTLOOK_DATE_NONE)) //earlier also || source.Inner.Birthday.Year < 1900
                {
                    Event ev = new Event();
                    ev.Relation       = REL_ANNIVERSARY;
                    ev.When           = new When();
                    ev.When.AllDay    = true;
                    ev.When.StartTime = source.Inner.Anniversary.Date;
                    target.ContactEntry.Events.Add(ev);
                }
            }
            catch (System.Exception ex)
            {
                s_logger.Warn("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex);
                logger.LogMappingWarning("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex);
            }
            //}

            #endregion anniversary

            #region relations (spouse, child, manager and assistant)
            //First remove spouse, child, manager and assistant
            for (int i = target.ContactEntry.Relations.Count - 1; i >= 0; i--)
            {
                Relation rel = target.ContactEntry.Relations[i];
                if (rel.Rel != null && (rel.Rel.Equals(REL_SPOUSE) || rel.Rel.Equals(REL_CHILD) || rel.Rel.Equals(REL_MANAGER) || rel.Rel.Equals(REL_ASSISTANT)))
                {
                    target.ContactEntry.Relations.RemoveAt(i);
                }
            }
            //Then add spouse again if existing
            if (!string.IsNullOrEmpty(source.Inner.Spouse))
            {
                Relation rel = new Relation();
                rel.Rel   = REL_SPOUSE;
                rel.Value = source.Inner.Spouse;
                target.ContactEntry.Relations.Add(rel);
            }
            //Then add children again if existing
            if (!string.IsNullOrEmpty(source.Inner.Children))
            {
                Relation rel = new Relation();
                rel.Rel   = REL_CHILD;
                rel.Value = source.Inner.Children;
                target.ContactEntry.Relations.Add(rel);
            }
            //Then add manager again if existing
            if (!string.IsNullOrEmpty(source.Inner.ManagerName))
            {
                Relation rel = new Relation();
                rel.Rel   = REL_MANAGER;
                rel.Value = source.Inner.ManagerName;
                target.ContactEntry.Relations.Add(rel);
            }
            //Then add assistant again if existing
            if (!string.IsNullOrEmpty(source.Inner.AssistantName))
            {
                Relation rel = new Relation();
                rel.Rel   = REL_ASSISTANT;
                rel.Value = source.Inner.AssistantName;
                target.ContactEntry.Relations.Add(rel);
            }
            #endregion relations (spouse, child, manager and assistant)

            #region IMs
            target.IMs.Clear();

            if (!string.IsNullOrEmpty(source.Inner.IMAddress))
            {
                //IMAddress are expected to be in form of ([Protocol]: [Address]; [Protocol]: [Address])
                string[] imsRaw = source.Inner.IMAddress.Split(';');
                foreach (string imRaw in imsRaw)
                {
                    string[]  imDetails = imRaw.Trim().Split(':');
                    IMAddress im        = new IMAddress();
                    if (imDetails.Length == 1)
                    {
                        im.Address = imDetails[0].Trim();
                    }
                    else
                    {
                        im.Protocol = imDetails[0].Trim();
                        im.Address  = imDetails[1].Trim();
                    }

                    //Only add the im Address if not empty (to avoid Google exception "address" empty)
                    if (!string.IsNullOrEmpty(im.Address))
                    {
                        im.Primary = target.IMs.Count == 0;
                        im.Rel     = ContactsRelationships.IsHome;
                        target.IMs.Add(im);
                    }
                }
            }
            #endregion IMs

            target.Content = !string.IsNullOrEmpty(source.Inner.Body) ?
                             System.Security.SecurityElement.Escape(source.Inner.Body) : null;

            target.ContactEntry.Sensitivity = MapPrivacy1To2(source.Inner.Sensitivity);

            target.Languages.Clear();
            if (!string.IsNullOrEmpty(source.Inner.Language))
            {
                foreach (var lang in source.Inner.Language.Split(';'))
                {
                    target.Languages.Add(new Language()
                    {
                        Label = lang
                    });
                }
            }

            target.ContactEntry.Hobbies.Clear();
            if (!string.IsNullOrEmpty(source.Inner.Hobby))
            {
                foreach (var hobby in source.Inner.Hobby.Split(';'))
                {
                    target.ContactEntry.Hobbies.Add(new Hobby(hobby));
                }
            }

            targetWrapper.Groups.Clear();
            targetWrapper.Groups.AddRange(CommonEntityMapper.SplitCategoryString(source.Inner.Categories));

            if (_configuration.MapContactPhoto)
            {
                MapPhoto1To2(source.Inner, targetWrapper, logger);
            }

            return(targetWrapper);
        }