public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = data as Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry; if (logEntry != null) { using (ApplicationDataContext context = new ApplicationDataContext()) { Data.Applications.LogEntry dbLogEntry = new Data.Applications.LogEntry(); dbLogEntry.LogEntryId = Guid.NewGuid(); dbLogEntry.LogTypeId = (int)logEntry.Severity; dbLogEntry.ApplicationId = BrokerContext.Current.ApplicationId; dbLogEntry.UserToken = BrokerContext.Current.UserToken; dbLogEntry.UserId = BrokerContext.Current.UserName; dbLogEntry.ActivityID = BrokerContext.Current.ActivityId; dbLogEntry.MethodName = Strings.ObjectToString(logEntry.ExtendedProperties[Constants.Logging.MethodName]); dbLogEntry.Text = logEntry.Message; dbLogEntry.DataObjectType = Strings.ObjectToString(logEntry.ExtendedProperties[Constants.Logging.DataObjectType]); dbLogEntry.DataObjectXml = Strings.ObjectToString(logEntry.ExtendedProperties[Constants.Logging.DataObjectXml]); dbLogEntry.LogDate = logEntry.TimeStamp; context.LogEntries.InsertOnSubmit(dbLogEntry); context.SubmitChanges(); } } }
/// <summary> /// Adds the User object specified by the user input parameter to the data source and updates its Id property. /// </summary> /// <param name="user">The User object to add to the data source.</param> /// <returns>True if the data operation was successful, or false otherwise.</returns> public bool AddUser(User user) { using (ApplicationDataContext dataContext = DataContext) { DbUser dbUser = new DbUser(); dbUser.Name = user.Name; dbUser.Age = user.Age; dataContext.DbUsers.InsertOnSubmit(dbUser); dataContext.SubmitChanges(ConflictMode.FailOnFirstConflict); user.Id = dbUser.Id; return(true); } }
public bool UnregisterApp(string targetAppToken) { // Mark the application as unregistered using (ApplicationDataContext context = new ApplicationDataContext()) { var application = context.Applications.SingleOrDefault(app => app.Token == targetAppToken); if (application != null) { application.IsApproved = false; context.SubmitChanges(); return(true); } return(false); } }
/// <summary> /// Saves the User object specified by the user input parameter in the data source. /// </summary> /// <param name="user">The User object to update in the data source.</param> /// <returns>True if the data operation was successful, or false otherwise.</returns> public bool SaveUser(User user) { using (ApplicationDataContext dataContext = DataContext) { DbUser dbUser = dataContext.DbUsers.SingleOrDefault(u => u.Id == user.Id); if (dbUser == null) { return(false); } dbUser.Name = user.Name; dbUser.Age = user.Age; dataContext.SubmitChanges(ConflictMode.FailOnFirstConflict); return(true); } }
public bool ApproveAppRegistration(string targetAppToken) { // Mark the application as approved using (ApplicationDataContext context = new ApplicationDataContext()) { var application = context.Applications.SingleOrDefault(app => app.Token == targetAppToken); if (application != null) { application.IsApproved = true; application.ApprovedDate = DateTime.Now; context.SubmitChanges(); return(true); } return(false); } }
public ApplicationType RequestAppRegistration(string name) { // Create a new application and assign a new app token using (ApplicationDataContext context = new ApplicationDataContext()) { var application = new Application(); application.ApplicationId = Guid.NewGuid(); application.Token = Guid.NewGuid().ToString(); context.Applications.InsertOnSubmit(application); application.Name = name; application.RegistrationDate = DateTime.Now; application.IsApproved = false; context.SubmitChanges(); return(application.ToXmlType()); } }
public static void LogAction(this IPerCallDataProvider provider, String operation, string input, Boolean success) { //We find the cost for this call decimal cost = provider.GetOperationCost(operation); //We put a row into the DataProviderCall table using (var dataContext = new ApplicationDataContext()) { var call = new DataProviderCall { DataProviderCallId = System.Guid.NewGuid(), ActivityId = BrokerContext.Current.ActivityId, CallTime = DateTime.Now, Cost = cost, Input = input, DataProviderType = provider.GetType().ToString(), Operation = operation, Success = success, }; dataContext.DataProviderCalls.InsertOnSubmit(call); dataContext.SubmitChanges(); } }
public void Dispose() { DataContext.SubmitChanges(); DataContext.Dispose(); }