private void StoreInteractions(FileInfo fileinfo) { //we aren't messing with non-text files if (fileinfo.Extension.EndsWith("txt") == false) { return; } //double check that the user file is the only one being parse here. if (fileinfo.FullName.ToLower().Contains("interaction") == false) { return; } //write the file to the screen Console.WriteLine(String.Concat("Reading ", fileinfo.FullName)); //set the log separator string[] logseparator = new string[] { ConfigurationManager.AppSettings["LogRecordSeparator"].ToString() }; //use linq to query the file var InteractionLog = from logdetails in File.ReadAllLines(fileinfo.FullName) let logrow = logdetails.Split(logseparator, 0) select new Interaction() { DateStamp = Convert.ToDateTime(logrow[0]), BannerID = Convert.ToInt32(logrow[1]), TagName = logrow[2], EventID = Convert.ToInt32(logrow[3]), EventValue = logrow[4], SessionID = logrow[6], ListingID = logrow[5] }; //connect to the database setMongoDb sm = new setMongoDb(); mongodb mongo = new mongodb(); var cred = MongoCredential.CreateMongoCRCredential(sm.MongodbName, sm.MongodbUser, sm.MongodbPass); var settings = new MongoClientSettings { Credentials = new[] { cred } }; MongoClient client = new MongoClient(settings); MongoServer server = client.GetServer(); MongoDatabase db = server.GetDatabase(sm.MongodbName); //create the collection (table) name string collect = string.Concat("Interactions", CreateTableName(fileinfo.Name)); //check if the collection can be found, if not create it, then load if (mongo.CreateCollection(db, collect) == true) { foreach (Interaction interactionlogentry in InteractionLog) { MongoCollection<BsonDocument> interactions = db.GetCollection<BsonDocument>(collect); BsonDocument Interaction = new BsonDocument { {"DateStamp" , interactionlogentry.DateStamp }, {"BannerID", interactionlogentry.BannerID}, {"TagName", interactionlogentry.TagName}, {"EventID", interactionlogentry.EventID}, {"EventValue", interactionlogentry.EventValue}, {"SessionID", interactionlogentry.SessionID}, {"ListingID", interactionlogentry.ListingID} }; interactions.Insert(Interaction); } //end for } // end create collection if //clean up the ImpressionLog InteractionLog = null; }
private void StoreImpressions(FileInfo fileinfo ) { //we aren't messing with non-text files if (fileinfo.Extension.EndsWith("txt") == false) { return; } //write the file to the screen Console.WriteLine(String.Concat("Reading ", fileinfo.FullName)); //set the log separator string[] logseparator = new string[] { ConfigurationManager.AppSettings["LogRecordSeparator"].ToString() }; //use linq to query the file var ImpressionLog = from logdetails in File.ReadAllLines(fileinfo.FullName) let logrow = logdetails.Split(logseparator, 0) select new Impression() { datestamp = Convert.ToDateTime(logrow[0]), bannerid = Convert.ToInt32(logrow[1]), tagname = logrow[2], browser = logrow[4], version = logrow[5], session = logrow[8], referrer = logrow[6], ip = logrow[7] }; //connect to the database setMongoDb sm = new setMongoDb(); mongodb mongo = new mongodb(); var cred = MongoCredential.CreateMongoCRCredential(sm.MongodbName, sm.MongodbUser, sm.MongodbPass); var settings = new MongoClientSettings { Credentials = new[] { cred } }; MongoClient client = new MongoClient(settings); MongoServer server = client.GetServer(); MongoDatabase db = server.GetDatabase(sm.MongodbName); //create the collection (table) name string collect; collect = string.Concat("Impressions", CreateTableName(fileinfo.Name)); //check if the collection can be found, if not create it, then load if (mongo.CreateCollection(db, collect) == true) { foreach (Impression impressionlogentry in ImpressionLog) { MongoCollection<BsonDocument> impressions = db.GetCollection<BsonDocument>(collect); BsonDocument impression = new BsonDocument { {"DateStamp" , impressionlogentry.datestamp }, {"BannerID", impressionlogentry.bannerid}, {"TagName", impressionlogentry.tagname}, {"Browser", impressionlogentry.browser}, {"Version", impressionlogentry.version}, {"SessionID", impressionlogentry.session}, {"IP", impressionlogentry.ip}, {"UrlRefer", impressionlogentry.referrer} }; //add to the table impressions.Insert(impression); } //end for } // end create collection if //clean up the ImpressionLog ImpressionLog = null; }