private static void AggregateActivities(Unea_Company company) { // aggregate HeaderActivities, Detail1Activities, Detail2Activities in Activities1, Activities2, Activities2 // header contain Level1 // detail1 contain Level1, Activity // detail2 contain Level1 (uppercase), Level2, Activity if (company.Detail2Activities == null) { company.Activities1 = new string[0]; company.Activities2 = new string[0]; company.Activities3 = new string[0]; return; } SortedDictionary <string, SortedDictionary <string, Unea_Activity> > dictionary = ActivitiesToDictionary(company.Detail2Activities); List <string> activities2 = new List <string>(); if (company.Detail1Activities != null) { foreach (Unea_Activity activity in company.Detail1Activities) { bool found = false; string key1 = activity.Level1.ToLower(); if (dictionary.ContainsKey(key1)) { SortedDictionary <string, Unea_Activity> dictionary2 = dictionary[key1]; string key2 = activity.Activity.ToLower(); if (dictionary2.ContainsKey(key2)) { found = true; dictionary2[key2].Level1 = activity.Level1; } } if (!found) { activities2.Add(activity.Level1 + " : " + activity.Activity); } } } company.Activities2 = activities2.ToArray(); List <string> activities3 = new List <string>(); if (company.HeaderActivities != null) { foreach (Unea_Activity activity in company.HeaderActivities) { string key1 = activity.Level1.ToLower(); if (!dictionary.ContainsKey(key1)) { activities3.Add(activity.Level1); } } } company.Activities3 = activities3.ToArray(); company.Activities1 = dictionary.Values.SelectMany(dictionary2 => dictionary2.Values).Select(activity => activity.Level1 + " - " + activity.Level2 + " : " + activity.Activity).ToArray(); }
public static void AddUniqueValues(Unea_CompanyUniqueValues uniqueValues, Unea_Company company) { //AddUniqueValues(uniqueValues.Activities, company.HeaderActivities.Keys); //AddUniqueValues(uniqueValues.Activities, company.Detail1Activities.Keys); //AddUniqueValues(uniqueValues.Activities, company.Detail2Activities.Keys); //SortedDictionary<string, SortedDictionary<string, string>> AddUniqueValues(uniqueValues.Sectors, company.Detail1Sectors.Keys); AddUniqueValues(uniqueValues.Sectors, company.Detail2Sectors.Keys); AddUniqueValues(uniqueValues.DownloadDocumentsName, from doc in company.Detail1DownloadDocuments select doc.Value.Name); AddUniqueValues(uniqueValues.DownloadDocumentsUrl, from doc in company.Detail1DownloadDocuments select doc.Value.Url); AddUniqueValues(uniqueValues.DownloadDocumentsName, from doc in company.Detail2DownloadDocuments select doc.Value.Name); AddUniqueValues(uniqueValues.DownloadDocumentsUrl, from doc in company.Detail2DownloadDocuments select doc.Value.Url); AddUniqueValues(uniqueValues.Photos, company.Detail1Photos.Keys); AddUniqueValues(uniqueValues.Photos, company.Detail2Photos.Keys); AddUniqueValues(uniqueValues.UnknowInfos, company.HeaderUnknowInfos); AddUniqueValues(uniqueValues.UnknowInfos, company.Detail1UnknowInfos); AddUniqueValues(uniqueValues.UnknowInfos, company.Detail2UnknowInfos); }
public void ExportXml(IEnumerable <HeaderDetail <Unea_Header_v2, Unea_Detail_v2> > headerDetails) { Trace.WriteLine("export Unea"); Trace.WriteLine($" file \"{_xmlFile}\""); Trace.WriteLine($" file detail \"{_detailXmlFile}\""); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; zfile.CreateFileDirectory(_xmlFile); zfile.CreateFileDirectory(_detailXmlFile); Unea_Company_DuplicateExists duplicate = new Unea_Company_DuplicateExists(); Unea_CompanyUniqueValues uniqueValues = new Unea_CompanyUniqueValues(); using (XmlWriter xw = XmlWriter.Create(_xmlFile, settings), xwDetail = XmlWriter.Create(_detailXmlFile, settings)) { xw.WriteStartElement("Unea"); xwDetail.WriteStartElement("Unea"); foreach (HeaderDetail <Unea_Header_v2, Unea_Detail_v2> headerDetail in headerDetails) { Unea_Company company = UneaData.AggregateCompanyData(headerDetail.Header, headerDetail.Detail); UneaData.AggregateDuplicateData(company); ExportXml_Company(xw, company, false); ExportXml_Company(xwDetail, company, true); UneaData.GetCompany_Duplicate(company, duplicate); UneaData.AddUniqueValues(uniqueValues, company); } xw.WriteEndElement(); xwDetail.WriteEndElement(); } Export_Duplicate(duplicate); ExportUniqueValues(uniqueValues); }
public static void AggregateDuplicateData(Unea_Company company) { AggregateDuplicateData(ref company.HeaderName, ref company.Detail1Name, ref company.Detail2Name); AggregateDuplicateData(ref company.HeaderLocation, ref company.Detail1Location); AggregateDuplicateData(ref company.Detail1Address, ref company.Detail2Address); AggregateDuplicateData(ref company.HeaderPhone, ref company.Detail1Phone, ref company.Detail2Phone); AggregateDuplicateData(ref company.HeaderFax, ref company.Detail1Fax, ref company.Detail2Fax); AggregateDuplicateData(ref company.HeaderEmail, ref company.Detail1Email, ref company.Detail2Email); AggregateDuplicateData(ref company.Detail1WebSite, ref company.Detail2WebSite); AggregateDuplicateData(ref company.Detail1Presentation, ref company.Detail2Presentation); AggregateDuplicateData(ref company.Detail1Clients, ref company.Detail2Clients); AggregateDuplicateData(ref company.Detail1Leader, ref company.Detail2Leader); AggregateDuplicateData(ref company.Detail1EmployeNumber, ref company.Detail2EmployeNumber); AggregateDuplicateData(ref company.Detail1LastYearRevenue, ref company.Detail2LastYearRevenue); AggregateDuplicateData(ref company.Detail1Certification, ref company.Detail2Certification); AggregateDuplicateData(ref company.Detail1Siret, ref company.Detail2Siret); AggregateActivities(company); //AggregateDuplicateData(company.Detail1Activities, company.HeaderActivities); //AggregateDuplicateData(company.Detail2Activities, company.HeaderActivities, company.Detail1Activities); AggregateDuplicateData(company.Detail2Sectors, company.Detail1Sectors); AggregateDuplicateData(company.Detail2DownloadDocuments, company.Detail1DownloadDocuments); AggregateDuplicateData(company.Detail2Photos, company.Detail1Photos); }
public static void GetCompany_Duplicate(Unea_Company company, Unea_Company_DuplicateExists duplicate) { if (company.Detail1Name != null) { duplicate.Detail1Name = true; } if (company.Detail2Name != null) { duplicate.Detail2Name = true; } if (company.Detail1Location != null) { duplicate.Detail1Location = true; } if (company.Detail2Address != null) { duplicate.Detail2Address = true; } if (company.Detail1Phone != null) { duplicate.Detail1Phone = true; } if (company.Detail2Phone != null) { duplicate.Detail2Phone = true; } if (company.Detail1Fax != null) { duplicate.Detail1Fax = true; } if (company.Detail2Fax != null) { duplicate.Detail2Fax = true; } if (company.Detail1Email != null) { duplicate.Detail1Email = true; } if (company.Detail2Email != null) { duplicate.Detail2Email = true; } if (company.Detail2WebSite != null) { duplicate.Detail2WebSite = true; } if (company.Detail2Presentation != null) { duplicate.Detail2Presentation = true; } if (company.Detail2Clients != null) { duplicate.Detail2Clients = true; } if (company.Detail2Leader != null) { duplicate.Detail2Leader = true; } if (company.Detail2EmployeNumber != null) { duplicate.Detail2EmployeNumber = true; } if (company.Detail2LastYearRevenue != null) { duplicate.Detail2LastYearRevenue = true; } if (company.Detail2Certification != null) { duplicate.Detail2Certification = true; } if (company.Detail2Siret != null) { duplicate.Detail2Siret = true; } //if (company.Detail1Activities.Count > 0) // duplicate.Detail1Activities = true; //if (company.Detail2Activities.Count > 0) // duplicate.Detail2Activities = true; if (company.Detail2Sectors.Count > 0) { duplicate.Detail2Sectors = true; } if (company.Detail2DownloadDocuments.Count > 0) { duplicate.Detail2DownloadDocuments = true; } if (company.Detail2Photos.Count > 0) { duplicate.Detail2Photos = true; } if (company.HeaderUnknowInfos.Count > 0) { duplicate.HeaderUnknowInfos = true; } if (company.Detail1UnknowInfos.Count > 0) { duplicate.Detail1UnknowInfos = true; } if (company.Detail2UnknowInfos.Count > 0) { duplicate.Detail2UnknowInfos = true; } }
public static Unea_Company AggregateCompanyData(Unea_Header_v2 header, Unea_Detail_v2 detail) { Unea_Detail1_v2 detail1 = detail.Detail1; Unea_Detail2_v2 detail2 = detail.Detail2; Unea_Company company = new Unea_Company(); //company.urlHeader = header.sourceUrl; company.LoadFromWebDate = header.LoadFromWebDate; company.UrlDetail1 = header.UrlDetail1; company.UrlDetail2 = header.UrlDetail2; company.HeaderName = header.Name; company.HeaderLocation = header.Location; company.HeaderPhone = header.Phone; company.HeaderFax = header.Fax; company.HeaderEmail = header.Email; company.HeaderActivities = header.Activities; company.HeaderUnknowInfos = header.UnknowInfos; if (detail1 != null) { company.Detail1Name = detail1.Name; company.Detail1Location = detail1.Location; company.Detail1Activities = detail1.Activities; company.Detail1Sectors = detail1.Sectors; company.Detail1Presentation = detail1.Presentation; company.Detail1Clients = detail1.Clients; company.Detail1Leader = detail1.Leader; company.Detail1EmployeNumber = detail1.EmployeNumber; company.Detail1LastYearRevenue = detail1.LastYearRevenue; company.Detail1Certification = detail1.Certification; company.Detail1Siret = detail1.Siret; company.Detail1Photos = detail1.Photos; company.Detail1DownloadDocuments = detail1.DownloadDocuments; company.Detail1Address = detail1.Address; company.Detail1Phone = detail1.Phone; company.Detail1Fax = detail1.Fax; company.Detail1Email = detail1.Email; company.Detail1WebSite = detail1.WebSite; company.Detail1UnknowInfos = detail1.UnknowInfos; } if (detail2 != null) { company.Detail2Name = detail2.Name; company.Detail2Presentation = detail2.Presentation; company.Detail2Activities = detail2.Activities; company.Detail2Sectors = detail2.Sectors; company.Detail2DownloadDocuments = detail2.DownloadDocuments; company.Detail2Address = detail2.Address; company.Detail2Phone = detail2.Phone; company.Detail2Fax = detail2.Fax; company.Detail2Email = detail2.Email; company.Detail2WebSite = detail2.WebSite; company.Detail2Leader = detail2.Leader; company.Detail2EmployeNumber = detail2.EmployeNumber; company.Detail2LastYearRevenue = detail2.LastYearRevenue; company.Detail2Siret = detail2.Siret; company.Detail2Certification = detail2.Certification; company.Detail2Clients = detail2.Clients; company.Detail2UnknowInfos = detail2.UnknowInfos; } return(company); }
private static void ExportXml_Company(XmlWriter xw, Unea_Company company, bool detail, Unea_Company_DuplicateExists duplicate = null) { IEnumerator <string> headerActivities = null; IEnumerator <string> detail1Activities = null; IEnumerator <string> detail2Activities = null; IEnumerator <string> detail1Sectors = null; IEnumerator <string> detail2Sectors = null; IEnumerator <Unea_Document> detail1DownloadDocuments = null; IEnumerator <Unea_Document> detail2DownloadDocuments = null; IEnumerator <string> detail1Photos = null; IEnumerator <string> detail2Photos = null; IEnumerator <string> headerUnknowInfos = null; IEnumerator <string> detail1UnknowInfos = null; IEnumerator <string> detail2UnknowInfos = null; if (detail) { //headerActivities = ((IEnumerable<string>)company.HeaderActivities.Keys).GetEnumerator(); //detail1Activities = ((IEnumerable<string>)company.Detail1Activities.Keys).GetEnumerator(); //detail2Activities = ((IEnumerable<string>)company.Detail2Activities.Keys).GetEnumerator(); headerActivities = ((IEnumerable <string>)company.Activities1).GetEnumerator(); detail1Activities = ((IEnumerable <string>)company.Activities2).GetEnumerator(); detail2Activities = ((IEnumerable <string>)company.Activities3).GetEnumerator(); detail1Sectors = ((IEnumerable <string>)company.Detail1Sectors.Keys).GetEnumerator(); detail2Sectors = ((IEnumerable <string>)company.Detail2Sectors.Keys).GetEnumerator(); detail1DownloadDocuments = ((IEnumerable <Unea_Document>)company.Detail1DownloadDocuments.Values).GetEnumerator(); detail2DownloadDocuments = ((IEnumerable <Unea_Document>)company.Detail2DownloadDocuments.Values).GetEnumerator(); detail1Photos = ((IEnumerable <string>)company.Detail1Photos.Keys).GetEnumerator(); detail2Photos = ((IEnumerable <string>)company.Detail2Photos.Keys).GetEnumerator(); headerUnknowInfos = ((IEnumerable <string>)company.HeaderUnknowInfos).GetEnumerator(); detail1UnknowInfos = ((IEnumerable <string>)company.Detail1UnknowInfos).GetEnumerator(); detail2UnknowInfos = ((IEnumerable <string>)company.Detail2UnknowInfos).GetEnumerator(); } xw.WriteStartElement("Company"); xw.zWriteElementText("société", company.HeaderName); xw.zWriteElementText("société2", company.Detail1Name); xw.zWriteElementText("société3", company.Detail2Name); xw.zWriteElementText("emplacement", company.HeaderLocation); xw.zWriteElementText("emplacement2", company.Detail1Location); if (detail) { string text1, text2; text1 = null; if (headerActivities.MoveNext()) { text1 = headerActivities.Current; } xw.zWriteElementText("activité", text1); text1 = null; if (detail1Activities.MoveNext()) { text1 = detail1Activities.Current; } xw.zWriteElementText("activité2", text1); text1 = null; if (detail2Activities.MoveNext()) { text1 = detail2Activities.Current; } xw.zWriteElementText("activité3", text1); text1 = null; if (detail1Sectors.MoveNext()) { text1 = detail1Sectors.Current; } xw.zWriteElementText("filière", text1); text1 = null; if (detail2Sectors.MoveNext()) { text1 = detail2Sectors.Current; } xw.zWriteElementText("filière2", text1); text1 = null; text2 = null; if (detail1DownloadDocuments.MoveNext()) { text1 = detail1DownloadDocuments.Current.Name; text2 = detail1DownloadDocuments.Current.Url; } xw.zWriteElementText("document", text1); xw.zWriteElementText("document_url", text2); text1 = null; text2 = null; if (detail2DownloadDocuments.MoveNext()) { text1 = detail2DownloadDocuments.Current.Name; text2 = detail2DownloadDocuments.Current.Url; } xw.zWriteElementText("document2", text1); xw.zWriteElementText("document2_url", text2); text1 = null; if (detail1Photos.MoveNext()) { text1 = detail1Photos.Current; } xw.zWriteElementText("image", text1); text1 = null; if (detail2Photos.MoveNext()) { text1 = detail2Photos.Current; } xw.zWriteElementText("image2", text1); text1 = null; if (headerUnknowInfos.MoveNext()) { text1 = headerUnknowInfos.Current; } xw.zWriteElementText("inconnu", text1); text1 = null; if (detail1UnknowInfos.MoveNext()) { text1 = detail1UnknowInfos.Current; } xw.zWriteElementText("inconnu2", text1); text1 = null; if (detail2UnknowInfos.MoveNext()) { text1 = detail2UnknowInfos.Current; } xw.zWriteElementText("inconnu3", text1); } xw.zWriteElementText("adresse", company.Detail1Address); xw.zWriteElementText("adresse2", company.Detail2Address); xw.zWriteElementText("tel", company.HeaderPhone); xw.zWriteElementText("tel2", company.Detail1Phone); xw.zWriteElementText("tel3", company.Detail2Phone); xw.zWriteElementText("fax", company.HeaderFax); xw.zWriteElementText("fax2", company.Detail1Fax); xw.zWriteElementText("fax3", company.Detail2Fax); xw.zWriteElementText("email", company.HeaderEmail); xw.zWriteElementText("email2", company.Detail1Email); xw.zWriteElementText("email3", company.Detail2Email); xw.zWriteElementText("site", company.Detail1WebSite); xw.zWriteElementText("site2", company.Detail2WebSite); xw.zWriteElementText("présentation", company.Detail1Presentation); xw.zWriteElementText("présentation2", company.Detail2Presentation); xw.zWriteElementText("client", company.Detail1Clients); xw.zWriteElementText("client2", company.Detail2Clients); xw.zWriteElementText("dirigeant", company.Detail1Leader); xw.zWriteElementText("dirigeant2", company.Detail2Leader); xw.zWriteElementText("nb_salarié", company.Detail1EmployeNumber.ToString()); xw.zWriteElementText("nb_salarié2", company.Detail2EmployeNumber.ToString()); xw.zWriteElementText("chiffre_affaire", company.Detail1LastYearRevenue); xw.zWriteElementText("chiffre_affaire2", company.Detail2LastYearRevenue); xw.zWriteElementText("certification", company.Detail1Certification); xw.zWriteElementText("certification2", company.Detail2Certification); xw.zWriteElementText("siret", company.Detail1Siret); xw.zWriteElementText("siret2", company.Detail2Siret); xw.zWriteElementText("url_detail1", company.UrlDetail1); xw.zWriteElementText("url_detail2", company.UrlDetail2); xw.WriteEndElement(); while (detail) { bool headerActivity = headerActivities.MoveNext(); bool detail1Activity = detail1Activities.MoveNext(); bool detail2Activity = detail2Activities.MoveNext(); bool detail1Sector = detail1Sectors.MoveNext(); bool detail2Sector = detail2Sectors.MoveNext(); bool detail1DownloadDocument = detail1DownloadDocuments.MoveNext(); bool detail2DownloadDocument = detail2DownloadDocuments.MoveNext(); bool detail1Photo = detail1Photos.MoveNext(); bool detail2Photo = detail2Photos.MoveNext(); bool headerUnknowInfo = headerUnknowInfos.MoveNext(); bool detail1UnknowInfo = detail1UnknowInfos.MoveNext(); bool detail2UnknowInfo = detail2UnknowInfos.MoveNext(); if (!headerActivity && !detail1Activity && !detail2Activity && !detail1Sector && !detail2Sector && !detail1DownloadDocument && !detail2DownloadDocument && !headerUnknowInfo && !detail1UnknowInfo && !detail2UnknowInfo) { break; } xw.WriteStartElement("Company"); if (headerActivity) { xw.zWriteElementText("activité", headerActivities.Current); } if (detail1Activity) { xw.zWriteElementText("activité2", detail1Activities.Current); } if (detail2Activity) { xw.zWriteElementText("activité3", detail2Activities.Current); } if (detail1Sector) { xw.zWriteElementText("filière", detail1Sectors.Current); } if (detail2Sector) { xw.zWriteElementText("filière2", detail2Sectors.Current); } if (detail1DownloadDocument) { xw.zWriteElementText("document", detail1DownloadDocuments.Current.Name); xw.zWriteElementText("document_url", detail1DownloadDocuments.Current.Url); } if (detail2DownloadDocument) { xw.zWriteElementText("document2", detail2DownloadDocuments.Current.Name); xw.zWriteElementText("document2_url", detail2DownloadDocuments.Current.Url); } if (detail1Photo) { xw.zWriteElementText("image", detail1Photos.Current); } if (detail2Photo) { xw.zWriteElementText("image2", detail2Photos.Current); } if (headerUnknowInfo) { xw.zWriteElementText("inconnu", headerUnknowInfos.Current); } if (detail1UnknowInfo) { xw.zWriteElementText("inconnu2", detail1UnknowInfos.Current); } if (detail2UnknowInfo) { xw.zWriteElementText("inconnu3", detail2UnknowInfos.Current); } xw.WriteEndElement(); } }