Ejemplo n.º 1
0
        public static string GetReadXml(UnanetClient una, string sourceFolder, string syncFileA = null)
        {
            var addresses = AddressModel.Read(una, sourceFolder).OrderBy(x => x.street_address1).ToLookup(x => x.Key, x => x.Value);
            var emails    = EmailModel.Read(una, sourceFolder).OrderBy(x => x.email_address).ToLookup(x => x.Key, x => x.Value);
            var phones    = PhoneModel.Read(una, sourceFolder).OrderBy(x => x.phone_number).ToLookup(x => x.Key, x => x.Value);
            var xml       = new XElement("r", Read(una, sourceFolder).Select(x => new XElement("p",
                                                                                               XAttribute("oc", x.organization_code), XAttribute("s", x.salutation), XAttribute("fn", x.first_name), XAttribute("mi", x.middle_initial), XAttribute("ln", x.last_name), XAttribute("s2", x.suffix), XAttribute("t", x.title), XAttribute("c", x.comment),
                                                                                               XAttribute("a", x.active), XAttribute("dbt", x.default_bill_to), XAttribute("dst", x.default_ship_to), XAttribute("drt", x.default_remit_to), XAttribute("cc", x.contact_category),
                                                                                               XAttribute("u1", x.user01), XAttribute("u2", x.user02), XAttribute("u3", x.user03), XAttribute("u4", x.user04), XAttribute("u5", x.user05), XAttribute("u6", x.user06), XAttribute("u7", x.user07), XAttribute("u8", x.user08), XAttribute("u9", x.user09), XAttribute("u10", x.user10),
                                                                                               addresses[x.Key].ToArray(), emails[x.Key].ToArray(), phones[x.Key].ToArray()
                                                                                               )).ToArray()).ToString();

            if (syncFileA == null)
            {
                return(xml);
            }
            var syncFile = string.Format(syncFileA, ".o_c.xml");

            if (!Directory.Exists(Path.GetDirectoryName(syncFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(syncFile));
            }
            File.WriteAllText(syncFile, xml);
            return(xml);
        }