예제 #1
0
 //private
 //public cq Results { get; set; }
 //public Selector selector;
 public cq(string html)
 {
     var dom = new Dom(html).DomContainer;
     //this.Elements = new List<DomElement> { dom };
     this.Parent = this;
     this.Elements = new List<DomElement> { dom };
     //this.Document = null;
     //this.Results = new cq(this.domEls);
     //this.selector = null;
     //string Text = this.Dom.Text();
 }
예제 #2
0
        public void TestMethod1()
        {
            //var reader = new StringReader("c");
            //var c = reader.Read();
            //c = reader.Read();
            cq cq = new cq("<div id='my-id'>Hello<div class='class1 class2 class3'> world<ul class='my-class'> Some Text here...</ul></div></div>");
            //cq sz2 = cq["#my-id .class2"];
            //cq sz3 = sz2[".my-class"];

            cq = cq[".class3 ul"];

            //Assert.AreEqual(cq.te)
            //var sz2 = cq["p div#my-id.class1.class2.class3"];
        }
예제 #3
0
 public cq this[string sel]
 {
     get
     {
         var selector = new Selector(sel);
         List<DomElement> matchEls = new List<DomElement>();
         matchEls.AddRange(this.Elements);
         foreach(var s in selector.Selectors)
         {
             matchEls = GetElements(matchEls, s);
         }
         var sz = new cq(this.Parent, matchEls);
         return sz;
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            //var contents = File.ReadAllText(@"C:\Users\tporter\Desktop\Extracts\CSV\artworks.txt");
            //var lines = contents.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            //  `(.*?)`( .*?) (.*)
            //$1$2||
            //string header = "id bigint(20)||site varchar(30)||isLive int(1)||record_type int(1)||type varchar(125)||typeSort varchar(255)||typeID bigint(20)||selected_artwork_types Text||stockNumber varchar(255)||stockNumberPrefix varchar(8)||stockNumberNumber int(8)||stockNumberSuffix varchar(8)||artistStockNumber varchar(255)||barcode varchar(255)||artist varchar(255)||artistSort varchar(255)||artistSortTitleYear varchar(255)||artistID bigint(20)||artist_id bigint(20)||title Text||titleSort varchar(255)||artistTitleYear Text||displayDate varchar(255)||isEdition int(1)||editionPublisherOrNotes Text||medium Text||dimensions Text||signedAndDated Text||periodID bigint(20)||series varchar(60)||artistDates varchar(60)||detailsOverride Text||hasWebsiteOverride int(1)||websiteOverride Text||editionDetails Text||editionMasterRecord int(1)||editionNumber int(5)||editionNumberManuallyEntered varchar(60)||editionNumberAsText varchar(60)||editionArtistProofNumber int(5)||editionArtistProof int(1)||editionTotal int(6)||editionArtistProofTotal int(6)||editionID bigint(20)||printedStatus int(1)||marketID int(1)||financial_preset bigint(20)||gallery bigint(20)||consultant Text||location_id bigint(20)||location_code varchar(128)||locationContactID bigint(20)||location Text||location2 Text||locationNotes Text||locationHistory Text||locationUpdateDate date||country_of_origin varchar(60)||lastExaminedBy Text||lastExaminedDate date||currentOwner Text||current_owner_id bigint(20)||currentOwnerNotes Text||currentOwnerUpdateDate date||shippedToContactID bigint(20)||shipped_to_location_id bigint(20)||shipping Text||shippingNotes Text||shippingHistory Text||shippingUpdateDate date||shipperID bigint(20)||shipper varchar(60)||importNumber Text||exportNumber Text||imageData Text||hasImage int(1)||image_last_modified datetime||pictureCredits Text||additionalPictureFilenames Text||additionalPhotoCredits Text||exhibitions Text||exhibitionIDs Text||accountingCurrency bigint(20)||consignedBy varchar(120)||consignedByID bigint(20)||consigneeIsTheArtist int(1)||consignedFromDate date||consignedToDate date||consigned_in_reminder_date date||consignedByPercentageToGallery decimal(24,8)||consignedByNetValue decimal(18,2)||consignedByCalculateFromNet int(1)||consignorContractSigned int(1)||consignorNonStandardContract int(1)||consignmentNotes Text||consignmentReturned int(1)||consignedTo varchar(120)||consignedToID bigint(20)||consignedToFromDate date||consignedToToDate date||consigned_out_reminder_date date||consignedToPercentage decimal(24,8)||consignedToNetValue decimal(18,2)||consignedToCalculateFromNet int(1)||consignmentToNotes Text||consignedToReturned int(1)||loanedTo varchar(120)||loanedToID bigint(20)||loanedToFromDate date||loanedToToDate date||loaned_to_reminder_date date||loanHistory Text||loanedToNotes Text||loanedToReturned int(1)||purchasedFrom varchar(120)||purchasedFromID bigint(20)||purchaseDate date||purchasePrice decimal(18,2)||purchaseCurrency bigint(20)||purchaseTaxRate Text||purchase_price_for_calculations decimal(18,2)||purchaseConversionRate decimal(24,8)||purchasePriceAltCurrencyCurrencyID bigint(20)||purchasePriceAltCurrencyConversionRate decimal(24,8)||purchasePriceAltCurrencyValue decimal(18,2)||purchasePriceInSaleCurrency decimal(18,2)||purchaseShare decimal(18,2)||ownedInShares int(1)||otherOwners Text||otherOwnersShare decimal(18,2)||purchase_paid_date date||purchase_notes Text||production_status int(1)||production_status_date date||productionCostsTotalGallery decimal(18,2)||productionCostsTotalThirdParties decimal(18,2)||productionCostsTotalArtist decimal(18,2)||productionCostsTotal decimal(18,2)||productionCostDetails Text||productionCostsInvoiceText Text||costsIncurredGallery Text||costsIncurredThirdParties Text||costsIncurredArtist Text||costsIncurredArtists Text||costsPaidBy Text||costs_breakdown mediumblob||financialAdditionalInfo Text||notesOnCommissions Text||accounts_version decimal(24,8)||retailPrice decimal(18,2)||retailCurrency bigint(20)||retailPriceOverrideTextAfter int(1)||retailPriceTextAfter varchar(30)||retailTaxRate decimal(24,8)||apply_tax_at_current_rate int(1)||selling_price_for_calculations decimal(18,2)||retailPriceExtrasText varchar(120)||retailPriceExtras decimal(18,2)||retailPriceExtrasPaidByArtist int(1)||retailPriceExtrasAddToRetailPrice int(1)||retailPriceShippingExtrasText varchar(120)||retailPriceShippingExtras decimal(18,2)||retailPriceShippingExtrasPaidByArtist int(1)||retailPriceShippingExtrasAddToRetailPrice int(1)||retailPriceTotalExTax decimal(18,2)||retailPriceTotal decimal(18,2)||retailPriceCalculateFromTotal int(1)||retailPriceUpdateDate date||retailPriceHistory mediumblob||retail_data_json mediumblob||arr_applies int(1)||arr_notes Text||display_price_override varchar(60)||display_price_tax_inclusive_override varchar(60)||display_price_currency_2 varchar(60)||display_price_currency_3 varchar(60)||calculateAccountsAutomatically int(1)||marginPurchaseTaxRate decimal(24,8)||margin decimal(18,2)||importDutyPaid decimal(18,2)||on_ta_report int(1)||ta_reminder_date date||ta_expiry_date date||ta_notes Text||insured int(1)||insuranceValue decimal(18,2)||insuranceValueDate date||insuranceValuedBy varchar(255)||insured_by varchar(255)||insured_by_id bigint(20)||insurance_value_curr1 decimal(18,2)||insurance_value_curr2 decimal(18,2)||insurance_value_curr3 decimal(18,2)||insurance_value_curr4 decimal(18,2)||insurance_value_curr1_date date||insurance_value_curr2_date date||insurance_value_curr3_date date||insurance_value_curr4_date date||insurance_value_curr1_note varchar(120)||insurance_value_curr2_note varchar(120)||insurance_value_curr3_note varchar(120)||insurance_value_curr4_note varchar(120)||insuranceNotes Text||insuranceHistory mediumblob||status int(3)||availability int(3)||availability_detail Text||paymentStatus int(1)||prevStatus int(3)||invoiceID bigint(20)||invoiceDocumentID bigint(20)||invoiceNumber varchar(60)||invoiceName Text||soldTo varchar(120)||soldToID bigint(20)||saleDate date||salePrice decimal(18,2)||saleCurrencyID bigint(20)||saleCurrency varchar(8)||saleDiscount decimal(24,8)||saleDiscountValue decimal(18,2)||invoiceDiscountRate decimal(24,8)||invoiceDiscountValue decimal(18,2)||taxStatus bigint(20)||is_margin_scheme int(1)||saleTax decimal(18,2)||saleTaxRate decimal(24,8)||salePriceExtrasText varchar(120)||salePriceExtras decimal(18,2)||saleInvoiceValue decimal(18,2)||final_sale_price_total decimal(18,2)||threeWaySplit int(1)||removeProductionBeforeDiscount int(1)||saleConversionRate decimal(24,8)||proformaConversionRate decimal(24,8)||taxConversionRate decimal(24,8)||taxProformaConversionRate decimal(24,8)||saleDetails Text||sales_data_json mediumblob||offeredTo varchar(120)||offerPrice varchar(120)||offerNotes Text||offeredToID bigint(20)||offeredDate date||offeredBy varchar(120)||underOffer int(1)||exclusiveOfferPrevAvailability int(3)||offers Text||reservedFor varchar(120)||reservedForID bigint(20)||reservedForUntil date||reserves Text||courtesyOrCreditLine Text||copyrightInfo Text||provenance Text||literature Text||publications Text||publicationIDs Text||collections mediumblob||showOnWebsite int(1)||additional_website_export_item int(1)||showPictureOnWebsite int(1)||showPriceOnWebsite int(1)||websiteCopyrightLine Text||description_for_website mediumtext||replace_artwork_detail_with_video int(1)||use_video_on_private_views int(1)||include_secondary_images_in_private_views int(1)||video_embed_code Text,||add_to_online_shop int(1)||featured_in_shop int(1)||websiteOption1 int(1)||websiteSort int(8)||sort_for_store int(8)||showOnArtistsPage int(1)||in_artists_representative_works int(1)||artists_representative_works_sort int(8)||selected_categories Text||is_defining_work_in_categories Text||represents_category Text||represents_period int(1)||featured_artwork int(1)||main_image Text||secondary_images mediumtext||technical_images mediumtext||show_secondary_images int(1)||main_image_uploaded int(1)||main_image_dimensions varchar(12)||images_hash varchar(60)||mediaFiles Text||auctionHistory Text||press Text||commentaryOrDescription Text||commentaryOrDescriptionLang2 Text||excludeDescriptionFromPresentations int(1)||excludeProvenanceFromPresentations int(1)||excludeLiteratureFromPresentations int(1)||excludePublicationsFromPresentations int(1)||excludeExhibitionsFromPresentations int(1)||publicPresentationPage int(1)||publicPresentationPageUID varchar(60)||condition Text||conditionReportFilepath Text||conditionReportStatus int(3)||conservation Text||materials Text||manufacturer Text||framed int(1)||framing Text||weight varchar(255)||shipping_weight decimal(24,8)||shipping_volumetric_weight decimal(24,8)||shipping_width decimal(24,8)||shipping_height decimal(24,8)||shipping_depth decimal(24,8)||packingAndCrating Text||packingAndCratingNotes Text||availablePhotographs Text||photographyStatus int(1)||slideLabelOverride Text||links Text||notes Text||locked int(1)||isArchive int(1)||ownedPersonally int(1)||financialLocked int(1)||showAllFinancialFields int(1)||certificatesInfo Text||additionalDocumentsInfo Text||searchTerms Text||narrative_search mediumtext||selected_artwork_lists Text||selected_interests Text||custom_int_field1 bigint(20)||custom_int_field2 bigint(20)||custom_int_field3 bigint(20)||custom_int_field4 bigint(20)||custom_dec_field1 decimal(24,12)||custom_dec_field2 decimal(24,12)||sales_points mediumtext||share_sales_points_to_privateviews int(1)||fact_sheet_auto int(1)||fact_sheet_override mediumtext||share_fact_sheet_to_privateviews int(1)||share_fact_sheet_as_qr_code int(1)||privateviews_export_documents mediumtext||attached_high_resolution_images mediumtext,||high_res_image_for_website Text||qr_code_page_url Text||qr_code_image_url Text||qr_code_page_settings Text||pv_by_artist_include Text||pv_by_artist_exclude Text||pv_by_artist_cover_image int(1)||pv_by_artist_always_show_price Text||pv_by_artist_hide_price_by_default int(1)||pv_by_artist_do_not_export_price int(1)||pv_by_artwork_type_include Text||pv_by_artwork_type_exclude Text||pv_by_artwork_type_cover_image int(1)||pv_by_artwork_type_hide_price_by_default int(1)||pv_by_artwork_type_do_not_export_price int(1)||pv_by_artwork_list_include Text||pv_by_artwork_list_exclude Text||pv_by_artwork_list_cover_image int(1)||pv_by_artwork_list_hide_price_by_default int(1)||pv_by_artwork_list_do_not_export_price int(1)||sharing_options Text||import_source Text||importID varchar(40)||imported_json_data mediumblob||importID2 varchar(40)||importID3 varchar(40)||importSoldToID varchar(40)||importedFinancialInformation Text||importPurchaseCurrency varchar(8)||importRetailCurrency varchar(8)||importSaleCurrency varchar(8)||importedArtworkTypes Text||importedInterests Text||importedStatus varchar(30)||importedAvailability varchar(30)||importedTaxStatus varchar(30)||importedConsigneeID varchar(30)||importedNFS int(1)||importedImageData Text||lastSavedBy varchar(50)||lastSaved datetime||createdBy varchar(50)||creationDate date||modificationDate timestamp||revision_id varchar(60)||flRecsCheckedItems Text||_checked_items Text";
            string header = "id bigint(20)||site varchar(30)||isLive int(1)||record_type int(1)||type varchar(125)||typeSort varchar(255)||typeID bigint(20)||selected_artwork_types text||stockNumber varchar(255)||stockNumberPrefix varchar(8)||stockNumberNumber int(8)||stockNumberSuffix varchar(8)||artistStockNumber varchar(255)||barcode varchar(255)||artist varchar(255)||artistSort varchar(255)||artistSortTitleYear varchar(255)||artistID bigint(20)||artist_id bigint(20)||title text||titleSort varchar(255)||artistTitleYear text||displayDate varchar(255)||isEdition int(1)||editionPublisherOrNotes text||medium text||dimensions text||signedAndDated text||periodID bigint(20)||series varchar(60)||artistDates varchar(60)||detailsOverride text||hasWebsiteOverride int(1)||websiteOverride text||editionDetails text||editionMasterRecord int(1)||editionNumber int(5)||editionNumberManuallyEntered varchar(60)||editionNumberAsText varchar(60)||editionArtistProofNumber int(5)||editionArtistProof int(1)||editionTotal int(6)||editionArtistProofTotal int(6)||editionID bigint(20)||printedStatus int(1)||marketID int(1)||financial_preset bigint(20)||gallery bigint(20)||consultant text||location_id bigint(20)||location_code varchar(128)||locationContactID bigint(20)||location text||location2 text||locationNotes text||locationHistory text||locationUpdateDate date||country_of_origin varchar(60)||lastExaminedBy text||lastExaminedDate date||currentOwner text||current_owner_id bigint(20)||currentOwnerNotes text||currentOwnerUpdateDate date||shippedToContactID bigint(20)||shipped_to_location_id bigint(20)||shipping text||shippingNotes text||shippingHistory text||shippingUpdateDate date||shipperID bigint(20)||shipper varchar(60)||importNumber text||exportNumber text||imageData text||hasImage int(1)||image_last_modified datetime||pictureCredits text||additionalPictureFilenames text||additionalPhotoCredits text||exhibitions text||exhibitionIDs text||accountingCurrency bigint(20)||consignedBy varchar(120)||consignedByID bigint(20)||consigneeIsTheArtist int(1)||consignedFromDate date||consignedToDate date||consigned_in_reminder_date date||consignedByPercentageToGallery decimal(24,8)||consignedByNetValue decimal(18,2)||consignedByCalculateFromNet int(1)||consignorContractSigned int(1)||consignorNonStandardContract int(1)||consignmentNotes text||consignmentReturned int(1)||consignedTo varchar(120)||consignedToID bigint(20)||consignedToFromDate date||consignedToToDate date||consigned_out_reminder_date date||consignedToPercentage decimal(24,8)||consignedToNetValue decimal(18,2)||consignedToCalculateFromNet int(1)||consignmentToNotes text||consignedToReturned int(1)||loanedTo varchar(120)||loanedToID bigint(20)||loanedToFromDate date||loanedToToDate date||loaned_to_reminder_date date||loanHistory text||loanedToNotes text||loanedToReturned int(1)||purchasedFrom varchar(120)||purchasedFromID bigint(20)||purchaseDate date||purchasePrice decimal(18,2)||purchaseCurrency bigint(20)||purchaseTaxRate text||purchase_price_for_calculations decimal(18,2)||purchaseConversionRate decimal(24,8)||purchasePriceAltCurrencyCurrencyID bigint(20)||purchasePriceAltCurrencyConversionRate decimal(24,8)||purchasePriceAltCurrencyValue decimal(18,2)||purchasePriceInSaleCurrency decimal(18,2)||purchaseShare decimal(18,2)||ownedInShares int(1)||otherOwners text||otherOwnersShare decimal(18,2)||purchase_paid_date date||purchase_notes text||production_status int(1)||production_status_date date||productionCostsTotalGallery decimal(18,2)||productionCostsTotalThirdParties decimal(18,2)||productionCostsTotalArtist decimal(18,2)||productionCostsTotal decimal(18,2)||productionCostDetails text||productionCostsInvoiceText text||costsIncurredGallery text||costsIncurredThirdParties text||costsIncurredArtist text||costsIncurredArtists text||costsPaidBy text||costs_breakdown mediumtext||financialAdditionalInfo text||notesOnCommissions text||accounts_version decimal(24,8)||retailPrice decimal(18,2)||retailCurrency bigint(20)||retailPriceOverrideTextAfter int(1)||retailPriceTextAfter varchar(30)||retailTaxRate decimal(24,8)||apply_tax_at_current_rate int(1)||selling_price_for_calculations decimal(18,2)||retailPriceExtrasText varchar(120)||retailPriceExtras decimal(18,2)||retailPriceExtrasPaidByArtist int(1)||retailPriceExtrasAddToRetailPrice int(1)||retailPriceShippingExtrasText varchar(120)||retailPriceShippingExtras decimal(18,2)||retailPriceShippingExtrasPaidByArtist int(1)||retailPriceShippingExtrasAddToRetailPrice int(1)||retailPriceTotalExTax decimal(18,2)||retailPriceTotal decimal(18,2)||retailPriceCalculateFromTotal int(1)||retailPriceUpdateDate date||retailPriceHistory mediumtext||retail_data_json mediumtext||arr_applies int(1)||arr_notes text||display_price_override varchar(60)||display_price_tax_inclusive_override varchar(60)||display_price_currency_2 varchar(60)||display_price_currency_3 varchar(60)||calculateAccountsAutomatically int(1)||marginPurchaseTaxRate decimal(24,8)||margin decimal(18,2)||importDutyPaid decimal(18,2)||on_ta_report int(1)||ta_reminder_date date||ta_expiry_date date||ta_notes text||insured int(1)||insuranceValue decimal(18,2)||insurance_currency_id int(1)||insuranceValueDate date||insuranceValuedBy varchar(255)||insured_by varchar(255)||insured_by_id bigint(20)||insurance_value_curr1 decimal(18,2)||insurance_value_curr2 decimal(18,2)||insurance_value_curr3 decimal(18,2)||insurance_value_curr4 decimal(18,2)||insurance_value_curr1_date date||insurance_value_curr2_date date||insurance_value_curr3_date date||insurance_value_curr4_date date||insurance_value_curr1_note varchar(120)||insurance_value_curr2_note varchar(120)||insurance_value_curr3_note varchar(120)||insurance_value_curr4_note varchar(120)||insuranceNotes text||insuranceHistory mediumtext||status int(3)||availability int(3)||availability_detail text||paymentStatus int(1)||prevStatus int(3)||invoiceID bigint(20)||invoiceDocumentID bigint(20)||invoiceNumber varchar(60)||invoiceName text||soldTo varchar(120)||soldToID bigint(20)||saleDate date||salePrice decimal(18,2)||saleCurrencyID bigint(20)||saleCurrency varchar(8)||saleDiscount decimal(24,8)||saleDiscountValue decimal(18,2)||invoiceDiscountRate decimal(24,8)||invoiceDiscountValue decimal(18,2)||taxStatus bigint(20)||is_margin_scheme int(1)||saleTax decimal(18,2)||saleTaxRate decimal(24,8)||salePriceExtrasText varchar(120)||salePriceExtras decimal(18,2)||saleInvoiceValue decimal(18,2)||final_sale_price_total decimal(18,2)||threeWaySplit int(1)||removeProductionBeforeDiscount int(1)||saleConversionRate decimal(24,8)||proformaConversionRate decimal(24,8)||taxConversionRate decimal(24,8)||taxProformaConversionRate decimal(24,8)||saleDetails text||sales_data_json mediumtext||offeredTo varchar(120)||offerPrice varchar(120)||offerNotes text||offeredToID bigint(20)||offeredDate date||offeredBy varchar(120)||underOffer int(1)||exclusiveOfferPrevAvailability int(3)||offers text||reservedFor varchar(120)||reservedForID bigint(20)||reservedForUntil date||reserves text||courtesyOrCreditLine text||copyrightInfo text||provenance text||literature text||publications text||publicationIDs text||collections mediumtext||showOnWebsite int(1)||additional_website_export_item int(1)||showPictureOnWebsite int(1)||showPriceOnWebsite int(1)||websiteCopyrightLine text||description_for_website mediumtext||replace_artwork_detail_with_video int(1)||use_video_on_private_views int(1)||include_secondary_images_in_private_views int(1)||video_embed_code text||add_to_online_shop int(1)||featured_in_shop int(1)||websiteOption1 int(1)||websiteSort int(8)||sort_for_store int(8)||showOnArtistsPage int(1)||in_artists_representative_works int(1)||artists_representative_works_sort int(8)||selected_categories text||is_defining_work_in_categories text||represents_category text||represents_period int(1)||featured_artwork int(1)||main_image text||secondary_images mediumtext||images mediumtext||technical_images mediumtext||show_secondary_images int(1)||main_image_uploaded int(1)||main_image_dimensions varchar(12)||images_hash varchar(60)||mediaFiles text||auctionHistory text||press text||commentaryOrDescription text||commentaryOrDescriptionLang2 text||excludeDescriptionFromPresentations int(1)||excludeProvenanceFromPresentations int(1)||excludeLiteratureFromPresentations int(1)||excludePublicationsFromPresentations int(1)||excludeExhibitionsFromPresentations int(1)||publicPresentationPage int(1)||publicPresentationPageUID varchar(60)||condition text||conditionReportFilepath text||conditionReportStatus int(3)||conservation text||materials text||manufacturer text||framed int(1)||framing text||weight varchar(255)||shipping_weight decimal(24,8)||shipping_volumetric_weight decimal(24,8)||shipping_width decimal(24,8)||shipping_height decimal(24,8)||shipping_depth decimal(24,8)||packingAndCrating text||packingAndCratingNotes text||availablePhotographs text||photographyStatus int(1)||slideLabelOverride text||links text||notes text||locked int(1)||isArchive int(1)||ownedPersonally int(1)||financialLocked int(1)||showAllFinancialFields int(1)||certificatesInfo text||additionalDocumentsInfo text||searchTerms text||narrative_search mediumtext||selected_artwork_lists text||selected_interests text||custom_int_field1 bigint(20)||custom_int_field2 bigint(20)||custom_int_field3 bigint(20)||custom_int_field4 bigint(20)||custom_dec_field1 decimal(24,12)||custom_dec_field2 decimal(24,12)||sales_points mediumtext||share_sales_points_to_privateviews int(1)||fact_sheet_auto int(1)||fact_sheet_override mediumtext||share_fact_sheet_to_privateviews int(1)||share_fact_sheet_as_qr_code int(1)||privateviews_export_documents mediumtext||attached_high_resolution_images mediumtext||high_res_image_for_website text||qr_code_page_url text||qr_code_image_url text||qr_code_page_settings text||pv_by_artist_include text||pv_by_artist_exclude text||pv_by_artist_cover_image int(1)||pv_by_artist_always_show_price text||pv_by_artist_hide_price_by_default int(1)||pv_by_artist_do_not_export_price int(1)||pv_by_artwork_type_include text||pv_by_artwork_type_exclude text||pv_by_artwork_type_cover_image int(1)||pv_by_artwork_type_hide_price_by_default int(1)||pv_by_artwork_type_do_not_export_price int(1)||pv_by_artwork_list_include text||pv_by_artwork_list_exclude text||pv_by_artwork_list_cover_image int(1)||pv_by_artwork_list_hide_price_by_default int(1)||pv_by_artwork_list_do_not_export_price int(1)||sharing_options text||import_source text||importID varchar(40)||imported_json_data mediumtext||importID2 varchar(40)||importID3 varchar(40)||importSoldToID varchar(40)||importedFinancialInformation text||importPurchaseCurrency varchar(8)||importRetailCurrency varchar(8)||importSaleCurrency varchar(8)||importedArtworkTypes text||importedInterests text||importedStatus varchar(30)||importedAvailability varchar(30)||importedTaxStatus varchar(30)||importedConsigneeID varchar(30)||importedNFS int(1)||importedImageData text||lastSavedBy varchar(50)||lastSaved datetime||createdBy varchar(50)||creationDate date||modificationDate timestamp||revision_id varchar(60)||flRecsCheckedItems text||_checked_items text||";
            var header2 = header.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
            var htmlFields = new List<string> { "literature", "provenance", "exhibited", "publications" };

            DataTable dt = new DataTable();
            foreach(var h in header2)
            {
                var header3 = h.Split(' ');
                var title = header3[0];
                var type = header3[1];
                Type columnType = null;
                if (type.Contains("varchar") || type.Contains("text") || type.Contains("blob"))
                    columnType = typeof(string);
                else if (type.Contains("bigint") || type.Contains("decimal"))
                    columnType = typeof(double);
                else if (type.Contains("int"))
                    columnType = typeof(int);
                else if (type.Contains("date") || type.Contains("time"))
                    columnType = typeof(DateTime);
                else
                    throw new Exception();

                columnType = typeof(string);
                dt.Columns.Add(title, columnType);
            }

            //var contents = File.ReadAllText(@"C:\Users\tporter\Desktop\Extracts\CSV\artworks.txt", Encoding.UTF8);
            StreamReader reader = new StreamReader(@"C:\Users\tporter\Desktop\Extracts\CSV\artworks-7-14_2.txt", Encoding.UTF8);
            //Regex rx = new Regex("\\\r(?=\n)");
            //contents = rx.Replace(contents, "\n");

            var fieldCount = header2.Count();
            var delimiter = ",";
            var newLine = "\r\n";
            //var position = 0;
            //var xx = (char)53;

            //var data = new List<List<string>>();
            //var lineData = new List<string>();
            var row = new object[fieldCount];
            var i = 0;
            while(true)
            {
                if (reader.EndOfStream)
                    break;
                var c = reader.Peek();

                //var test = contents[position + 1];
                if (c == '"')
                {
                    StringBuilder token = new StringBuilder();
                    //position++;
                    reader.Read();
                    while (true)
                    {
                        //c = contents[position++];
                        c = reader.Read();
                        if (c == '\\')
                        {
                            //token.Append((char)c);
                            var c2 = reader.Read();
                            if (c2 == '\r')
                            {
                                token.Append("<br />");
                            }
                            else if (c2 == '"')
                            {
                                token.Append("\"");
                            }
                            else
                            {
                                token.Append((char)c);
                                token.Append((char)c2);
                            }

                            //var c2 = contents[position++];
                            //token.Append(c2);
                        }
                        else if (c == '"')
                        {
                            var cell = token.ToString();
                            //var head = dt.Columns[i];
                            //if (htmlFields.Contains(head.ColumnName) && cell.Length > 0)
                            //{
                            //}

                            row[i++] = cell;
                            //lineData.Add(token.ToString());
                            //dt.Rows.
                            break;
                        }
                        else
                        {
                            token.Append((char)c);
                        }
                    }
                }
                else if (c == ',')
                {
                    //lineData = new List<string>();
                    reader.Read();
                    //position++;
                    continue;
                }
                else if (c == '\r')
                {
                    reader.Read();
                    c = reader.Read();
                    //c = contents[++position];
                    if (c == '\n')
                    {
                        //position++;
                        //reader.Read();
                        //if (lineData.Count() != fieldCount)
                        //    throw new Exception();
                        //data.Add(lineData);
                        //lineData = new List<string>();
                        dt.Rows.Add(row);
                        row = new object[fieldCount];
                        i = 0;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else if (c == '\\')
                {
                    //c = contents[++position];
                    reader.Read();
                    c = reader.Read();
                    if (c == 'N')
                    {
                        reader.Read();
                        //position++;
                        //lineData.Add("");
                        row[i++] = "";
                    }
                    else
                        throw new Exception();
                }

            }

            var columns = File.ReadAllText(@"c:\users\tporter\desktop\artworksHeaders.txt").Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            var columns2 = columns.Select(x => x.Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries));

            //List<string> bad = new List<string>();
            //var sql = "CREATE TABLE ArtWorks (~~";
            foreach(var c in columns2)
            {
                var first = c.First();
                if (dt.Columns.Contains(first))
                {
                    //var thisCol = dt.Columns[first];
                    dt.Columns[first].ColumnName = c.Last().Replace(" ", "_");

                    //sql += c.Last().Replace(" ", "_") + " NVARCHAR(MAX) NULL,~~";
                }
                else
                {
                    //throw new Exception();
                    //bad.Add(c.First());
                }
            }

            //sql = sql.Substring(0, sql.Length - 2);
            //sql += ")";

            DataClasses1DataContext db = new DataClasses1DataContext();
            db.ExecuteCommand("DELETE FROM ArtWorks");

            //var query = (from a in db.ArtWorks_Dirties
            //             select a);
            //db.ArtWorks_Dirties.DeleteAllOnSubmit(query);
            //db.SubmitChanges();

            var count = dt.Rows.Count;
            var artWorks = new List<ArtWork>();
            //Parallel.ForEach(dt.AsEnumerable(), (row2) =>
            foreach(var row2 in dt.AsEnumerable())
                {
                    var id = row2["id"].ToString();
                    var aw = new ArtWork();
                    var properties = typeof(ArtWork).GetProperties();
                    foreach (var property in properties)
                    {
                        if (dt.Columns.Contains(property.Name))
                        {
                            if (htmlFields.Contains(property.Name))
                            {
                                //if (row2["id"].ToString() == "34")
                                //{

                                //}
                                var prop = row2[property.Name].ToString();
                                if (prop.Length == 0)
                                {
                                    property.SetValue(aw, "");
                                }
                                else
                                {
                                    //var prop2 = Regex.Replace(prop, "<!--.*?-->", "");
                                    //CsQuery.CQ el = prop2;

                                    //CsQuery.CQ test = "<p><em>Hello</em><em>World</em></p>";
                                    //test.Select("em").Before("{EM_BEFORE}");
                                    //test.Select("em").After("{EM_AFTER}");
                                    //test.Remove("em");
                                    //var test2 = test.Text().Replace("{EM_BEFORE}", "<em>").Replace("{EM_AFTER}", "</em>");

                                    //el.Select("br");
                                        //.Before("{BREAK}");
                                    //el.Remove("br");

                                    //el.Select("em").Before("{EM_BEFORE}");
                                    //el.Select("em").After("{EM_AFTER}");
                                    //el.Remove("em");

                                    //el.Select("i").Before("{EM_BEFORE}");
                                    //el.Select("i").After("{EM_AFTER}");
                                    //el.Remove("i");

                                    //el.Select("strong").Before("{STRONG_BEFORE}");
                                    //el.Select("strong").After("{STRONG_AFTER}");
                                    //el.Remove("strong");

                                    //el.Select("b").Before("{STRONG_BEFORE}");
                                    //el.Select("b").After("{STRONG_AFTER}");
                                    //el.Remove("b");

                                    //var Text = el.Text();
                                    //var sb = new StringBuilder(Text)
                                    //    .Replace("{BREAK}", "<br />")
                                    //    .Replace("{EM_BEFORE}", "<em>")
                                    //    .Replace("{EM_AFTER}", "</em>")
                                    //    .Replace("{STRONG_BEFORE}", "<strong>")
                                    //    .Replace("{STRONG_AFTER}", "</strong>");

                                    //if (artWorks.Count() == 2781)
                                    //{
                                    //    File.WriteAllText(@"c:\users\tporter\desktop\debug.txt", prop);
                                    //}

                                    cQuery.cq sz = new cQuery.cq(prop);
                                    sz["br"].Before("<br />");

                                    sz["em,i"].Before("<em>");
                                    sz["em,i"].After("</em>");

                                    //cq["i"].Before("<em>");
                                    //cq["i"].After("</em>");

                                    sz["strong,b"].Before("<strong>");
                                    sz["strong,b"].After("</strong>");

                                    //cq["b"].Before("<strong>");
                                    //cq["b"].After("</strong>");

                                    //cq em = cq["em"];
                                    var text = sz.Text();
                                    //var sz2 = cq["em"];

                                    //var sb = new StringBuilder();

                                    property.SetValue(aw, text);
                                }
                            }
                            else
                                property.SetValue(aw, row2[property.Name]);
                        }

                    }
                    artWorks.Add(aw);
                    Console.WriteLine(artWorks.Count() + "/" + count);
                    //db.ArtWorks.InsertOnSubmit(aw);
                }
            //);
            db.ArtWorks.InsertAllOnSubmit(artWorks);

            //foreach(DataRow row2 in dt.Rows)
            //{
            //    var aw = new ArtWork();
            //    var properties = typeof(ArtWork).GetProperties();
            //    foreach(var property in properties)
            //    {
            //        if (dt.Columns.Contains(property.Name))
            //        {
            //            if (htmlFields.Contains(property.Name))
            //            {
            //                var prop = row2[property.Name].ToString();
            //                CsQuery.CQ el = prop;

            //                el.Select("br").Before("{BREAK}");
            //                el.Remove("br");

            //                el.Select("em").Before("{EM_BEFORE}");
            //                el.Select("em").After("{EM_AFTER}");
            //                el.Remove("em");

            //                el.Select("i").Before("{EM_BEFORE}");
            //                el.Select("i").After("{EM_AFTER}");
            //                el.Remove("i");

            //                el.Select("strong").Before("{STRONG_BEFORE}");
            //                el.Select("strong").After("{STRONG_AFTER}");
            //                el.Remove("strong");

            //                el.Select("b").Before("{STRONG_BEFORE}");
            //                el.Select("b").After("{STRONG_AFTER}");
            //                el.Remove("b");

            //                //var Text = el.Text();
            //                string Text = "";
            //                if (el.Count() > 0)
            //                {
            //                    Text = el.Children().Text().Replace("{BREAK}", "<br />")
            //                    .Replace("{EM_BEFORE}", "<em>")
            //                    .Replace("{EM_AFTER}", "</em>")
            //                    .Replace("{STRONG_BEFORE}", "<strong>")
            //                    .Replace("{STRONG_AFTER}", "</strong>");
            //                }
            //                //else
            //                //{

            //                //}

            //                //Text = Text.Replace("{BREAK}", "<br />")
            //                //    .Replace("{EM_BEFORE}", "<em>")
            //                //    .Replace("{EM_AFTER}", "</em>")
            //                //    .Replace("{STRONG_BEFORE}", "<strong>")
            //                //    .Replace("{STRONG_AFTER}", "</strong>");

            //                property.SetValue(aw, Text);
            //            }
            //            else
            //                property.SetValue(aw, row2[property.Name]);
            //        }

            //    }
            //    db.ArtWorks.InsertOnSubmit(aw);
            //}
            db.SubmitChanges();
            db.Dispose();

            Console.WriteLine("Complete!");
            Console.ReadLine();

            //dt.Columns.

            //foreach(DataColumn col in dt.Columns)
            //{
            //    if (columns2.Where(x => x.First() == col.ColumnName).Count() > 0)
            //    {

            //    }
            //    else
            //    {
            //        //throw new Exception();
            //    }
            //}

            //ExcelControl ec = new ExcelControl();
            //ec.CreateWorkbook(@"C:\Users\tporter\Desktop\Extracts\CSV\artworks - Copy.xlsx", dt);

            //int xx = 3;

            //new StreamReader(new MemoryStream())

            //TextFieldParser parser = new TextFieldParser(@"C:\Users\tporter\Desktop\Extracts\CSV\artworks.txt");
            ////TextFieldParser parser = new TextFieldParser();
            //parser.TextFieldType = FieldType.Delimited;
            //parser.SetDelimiters(",");
            //parser.HasFieldsEnclosedInQuotes = true;

            //while (!parser.EndOfData)
            //{
            //    //Process row

            //    string[] fields = parser.ReadFields();
            //    if (fields.Count() != header2.Count())
            //        throw new Exception();
            //    for(int i = 0; i < fields.Count(); ++i)
            //    {
            //        var header3 = header2[i].Split(' ');
            //        var title = header3[0];
            //        var type = header3[1];
            //        Type columnType = null;
            //        if (type.Contains("varchar") || type.Contains("Text") || type.Contains("blob"))
            //            columnType = typeof(string);
            //        else if (type.Contains("bigint") || type.Contains("decimal"))
            //            columnType = typeof(double);
            //        else if (type.Contains("int"))
            //            columnType = typeof(int);
            //        else if (type.Contains("date") || type.Contains("time"))
            //            columnType = typeof(DateTime);
            //        else
            //            throw new Exception();
            //    }

            //    //foreach (string field in fields)
            //    //{

            //    //}
            //}
            //parser.Close();
        }
예제 #5
0
 private cq(cq parent, List<DomElement> els)
 {
     this.Parent = parent;
     this.Elements = els;
 }