/// <summary> /// Create a new ProjectSourceEntry object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="projectSourceId">Initial value of the ProjectSourceId property.</param> /// <param name="sourceEntryId">Initial value of the SourceEntryId property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="createdBy">Initial value of the CreatedBy property.</param> /// <param name="createdOn">Initial value of the CreatedOn property.</param> public static ProjectSourceEntry CreateProjectSourceEntry(global::System.Int32 id, global::System.Int32 projectSourceId, global::System.Int32 sourceEntryId, global::System.String title, global::System.String createdBy, global::System.DateTime createdOn) { ProjectSourceEntry projectSourceEntry = new ProjectSourceEntry(); projectSourceEntry.Id = id; projectSourceEntry.ProjectSourceId = projectSourceId; projectSourceEntry.SourceEntryId = sourceEntryId; projectSourceEntry.Title = title; projectSourceEntry.CreatedBy = createdBy; projectSourceEntry.CreatedOn = createdOn; return(projectSourceEntry); }
/// <summary> /// Deprecated Method for adding a new object to the ProjectSourceEntries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProjectSourceEntries(ProjectSourceEntry projectSourceEntry) { base.AddObject("ProjectSourceEntries", projectSourceEntry); }
public ProcessProjectSources() { //We need to go through each type to see what needs to run. We open and close the connection since there are some long //calls before we hit up the DB again var configsToProcess = GetTypesThatNeedToRun(); foreach (var config in configsToProcess) { var domain = AppDomain.CurrentDomain.Load(config.AssemblyName); Type type = domain.GetType(config.FullClassName); //we will only use only instance of the project source adapter IProjectSource projectSource = Activator.CreateInstance(type) as IProjectSource; if (projectSource == null) { //if we couldnt initialize the type then the string is probably wrong so throw an error throw new Exception(); } //go through each instance for that adapter and call to get data and save it //pull back all of the data before writing any to the db so we dont have to keep a transaction open and //we dont risk writing part of the data but not all of it //a dictionary is kept so we can associate our projectSourceId to its entries var entriesFromSource = new Dictionary<int, IEnumerable<SourceEntryObj>>(); foreach (var sourceInstance in config.ProjectSources) { projectSource.Configure(sourceInstance.Configuration); entriesFromSource.Add(sourceInstance.Id, projectSource.GetEntriesSince(config.LastRun ?? DateTime.MinValue)); } using (var db = GetDb()) { using (var transaction = new TransactionScope()) { //go through each source foreach (var source in entriesFromSource) { //go through each entry for that source foreach (var entry in source.Value) { //check and see if an entry already exists for that Id. If it does then update it, otherwise create a new one ProjectSourceEntry dbEntry = db.ProjectSourceEntries.SingleOrDefault(e => e.SourceEntryId == entry.Id); if (dbEntry == null) { dbEntry = new ProjectSourceEntry { SourceEntryId = entry.Id.Value, ProjectSourceId = source.Key, CreatedBy = System.Environment.UserName, CreatedOn = DateTime.Now }; db.ProjectSourceEntries.AddObject(dbEntry); } else { dbEntry.UpdatedBy = System.Environment.UserName; dbEntry.UpdatedOn = DateTime.Now; } dbEntry.Title = entry.Title; dbEntry.Message = entry.Message; db.SaveChanges(); } } //regrab the config since we already closed the connection that grabbed the config var configToUpdate = db.ProjectSourceTypes.Single(p => p.Id == config.Id); configToUpdate.LastRun = DateTime.Now; configToUpdate.NextRun = configToUpdate.LastRun.Value.AddMinutes(configToUpdate.Interval); db.SaveChanges(); transaction.Complete(); } } } }
/// <summary> /// Create a new ProjectSourceEntry object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="projectSourceId">Initial value of the ProjectSourceId property.</param> /// <param name="sourceEntryId">Initial value of the SourceEntryId property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="createdBy">Initial value of the CreatedBy property.</param> /// <param name="createdOn">Initial value of the CreatedOn property.</param> public static ProjectSourceEntry CreateProjectSourceEntry(global::System.Int32 id, global::System.Int32 projectSourceId, global::System.Int32 sourceEntryId, global::System.String title, global::System.String createdBy, global::System.DateTime createdOn) { ProjectSourceEntry projectSourceEntry = new ProjectSourceEntry(); projectSourceEntry.Id = id; projectSourceEntry.ProjectSourceId = projectSourceId; projectSourceEntry.SourceEntryId = sourceEntryId; projectSourceEntry.Title = title; projectSourceEntry.CreatedBy = createdBy; projectSourceEntry.CreatedOn = createdOn; return projectSourceEntry; }
/// <summary> /// Deprecated Method for adding a new object to the ProjectSourceEntries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProjectSourceEntries(ProjectSourceEntry projectSourceEntry) { base.AddObject("ProjectSourceEntries", projectSourceEntry); }
public ProcessProjectSources() { //We need to go through each type to see what needs to run. We open and close the connection since there are some long //calls before we hit up the DB again var configsToProcess = GetTypesThatNeedToRun(); foreach (var config in configsToProcess) { var domain = AppDomain.CurrentDomain.Load(config.AssemblyName); Type type = domain.GetType(config.FullClassName); //we will only use only instance of the project source adapter IProjectSource projectSource = Activator.CreateInstance(type) as IProjectSource; if (projectSource == null) { //if we couldnt initialize the type then the string is probably wrong so throw an error throw new Exception(); } //go through each instance for that adapter and call to get data and save it //pull back all of the data before writing any to the db so we dont have to keep a transaction open and //we dont risk writing part of the data but not all of it //a dictionary is kept so we can associate our projectSourceId to its entries var entriesFromSource = new Dictionary <int, IEnumerable <SourceEntryObj> >(); foreach (var sourceInstance in config.ProjectSources) { projectSource.Configure(sourceInstance.Configuration); entriesFromSource.Add(sourceInstance.Id, projectSource.GetEntriesSince(config.LastRun ?? DateTime.MinValue)); } using (var db = GetDb()) { using (var transaction = new TransactionScope()) { //go through each source foreach (var source in entriesFromSource) { //go through each entry for that source foreach (var entry in source.Value) { //check and see if an entry already exists for that Id. If it does then update it, otherwise create a new one ProjectSourceEntry dbEntry = db.ProjectSourceEntries.SingleOrDefault(e => e.SourceEntryId == entry.Id); if (dbEntry == null) { dbEntry = new ProjectSourceEntry { SourceEntryId = entry.Id.Value, ProjectSourceId = source.Key, CreatedBy = System.Environment.UserName, CreatedOn = DateTime.Now }; db.ProjectSourceEntries.AddObject(dbEntry); } else { dbEntry.UpdatedBy = System.Environment.UserName; dbEntry.UpdatedOn = DateTime.Now; } dbEntry.Title = entry.Title; dbEntry.Message = entry.Message; db.SaveChanges(); } } //regrab the config since we already closed the connection that grabbed the config var configToUpdate = db.ProjectSourceTypes.Single(p => p.Id == config.Id); configToUpdate.LastRun = DateTime.Now; configToUpdate.NextRun = configToUpdate.LastRun.Value.AddMinutes(configToUpdate.Interval); db.SaveChanges(); transaction.Complete(); } } } }