Exemplo n.º 1
0
        /// <summary>
        /// Convert address set
        /// </summary>
        internal List <Address> ConvertAddressSet(AddressSet addr)
        {
            List <Address> retVal = new List <Address>();

            foreach (var use in Enum.GetValues(typeof(AddressSet.AddressSetUse)))
            {
                if (((int)use == 0 && addr.Use == 0) ^ ((int)use != 0 && addr.Use.HasFlag((AddressSet.AddressSetUse)use)))
                {
                    Address adEntry = new Address();
                    // An address can have multiple uses
                    if ((AddressSet.AddressSetUse)use != AddressSet.AddressSetUse.Search)
                    {
                        adEntry.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.ADDRESS_USE, (AddressSet.AddressSetUse)use));
                        if (adEntry.Use == null || adEntry.Use.Value == null)
                        {
                            adEntry.Use = new PrimitiveCode <string>();
                            adEntry.Use.Extension.Add(ExtensionUtil.CreateADUseExtension((AddressSet.AddressSetUse)use));
                        }
                    }

                    foreach (var pt in addr.Parts)
                    {
                        switch (pt.PartType)
                        {
                        case AddressPart.AddressPartType.AddressLine:
                        case AddressPart.AddressPartType.StreetAddressLine:
                            adEntry.Line.Add(pt.AddressValue);
                            break;

                        case AddressPart.AddressPartType.City:
                            adEntry.City = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.Country:
                            adEntry.Country = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.PostalCode:
                            adEntry.Zip = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.State:
                            adEntry.State = pt.AddressValue;
                            break;

                        default:     // Can't find a place to put it and don't want to lose data ... so stuff it into an extension
                            adEntry.Extension.Add(ExtensionUtil.CreateADExtension(pt));
                            break;
                        }
                    }
                    retVal.Add(adEntry);
                }
            }
            return(retVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert telecom
        /// </summary>
        internal List <Telecom> ConvertTelecom(TelecommunicationsAddress tel)
        {
            var retVal = new List <Telecom>();
            var use    = MARC.Everest.Connectors.Util.Convert <SET <CS <TelecommunicationAddressUse> > >(tel.Use);

            foreach (var instance in use)
            {
                // Add telecom
                Telecom telInstance = new Telecom();
                // Convert use adding additional data if needed
                telInstance.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.TELECOM_USE, instance.Code));
                if (telInstance.Use == null || telInstance.Use.Value == null)
                {
                    telInstance.Use = new PrimitiveCode <string>();
                    telInstance.Use.Extension.Add(ExtensionUtil.CreateTELUseExtension((TelecommunicationAddressUse)instance.Code));
                }

                // Set values, etc
                try
                {
                    telInstance.Value = tel.Value;
                    switch (new Uri(telInstance.Value).Scheme)
                    {
                    case "mailto":
                        telInstance.System = new PrimitiveCode <string>("email");
                        break;

                    case "fax":
                        telInstance.System = new PrimitiveCode <string>("fax");
                        break;

                    case "tel":
                        telInstance.System = new PrimitiveCode <string>("phone");
                        break;

                    default:
                        telInstance.System = new PrimitiveCode <string>("url");
                        break;
                    }
                }
                catch { }
                retVal.Add(telInstance);
            }
            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process a name set
        /// </summary>
        protected HumanName ConvertNameSet(NameSet name)
        {
            HumanName retVal = new HumanName();

            if (name.Use != NameSet.NameSetUse.Search)
            {
                retVal.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.NAME_USE, name.Use));
                if (String.IsNullOrEmpty(retVal.Use.Value))
                {
                    retVal.Use.Extension.Add(ExtensionUtil.CreatePNUseExtension(name.Use));
                }
            }

            foreach (var pt in name.Parts)
            {
                switch (pt.Type)
                {
                case NamePart.NamePartType.Family:
                    retVal.Family.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Given:
                    retVal.Given.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Prefix:
                    retVal.Prefix.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Suffix:
                    retVal.Suffix.Add(pt.Value);
                    break;

                case NamePart.NamePartType.None:
                    retVal.Text = pt.Value;
                    break;
                }
            }
            return(retVal);
        }