/// <summary> /// Compacts and, if necessary, repairs the database. Applies only to SQL CE. A detailed message describing /// the result of the operation is assigned to <paramref name="message" />. /// </summary> /// <param name="message">A detailed message describing the result of the operation.</param> /// <returns>Returns <c>true</c> if the operation is successful; otherwise returns <c>false</c>.</returns> public static bool CompactAndRepairSqlCeDatabase(out string message) { var sqlCeController = new SqlCeController(Factory.GetConnectionStringSettings().ConnectionString); var compactSuccessful = false; var repairNeeded = false; var repairSuccessful = false; Exception ex = null; try { if (!sqlCeController.Verify()) { repairNeeded = true; sqlCeController.Repair(); repairSuccessful = sqlCeController.Verify(); } sqlCeController.Compact(); compactSuccessful = true; } catch (Exception exception) { ex = exception; EventController.RecordError(ex, AppSetting.Instance); } message = GetCompactAndRepairMessage(ex, compactSuccessful, repairNeeded, repairSuccessful); return (compactSuccessful && (!repairNeeded || repairSuccessful)); }
/// <summary> /// Gets the app events from the DTO objects. Returns an empty collection if no events. /// </summary> /// <param name="eventDtos">An enumerable object containing the app event data transfer objects.</param> /// <returns>Returns an <see cref="IEventCollection" />.</returns> private static IEventCollection GetEventsFromDtos(IEnumerable<EventDto> eventDtos) { var events = new EventCollection(); try { foreach (var ev in eventDtos) { events.Add(new Event(ev.EventId, ev.EventType, ev.FKGalleryId, ev.TimeStampUtc, ev.ExType, ev.Message, Deserialize(ev.EventData), ev.ExSource, ev.ExTargetSite, ev.ExStackTrace, ev.InnerExType, ev.InnerExMessage, ev.InnerExSource, ev.InnerExTargetSite, ev.InnerExStackTrace, Deserialize(ev.InnerExData), ev.Url, Deserialize(ev.FormVariables), Deserialize(ev.Cookies), Deserialize(ev.SessionVariables), Deserialize(ev.ServerVariables))); } } catch (InvalidOperationException ex) { if (ex.Source.Equals("System.Data.SqlServerCe")) { // We hit the SQL CE bug described here: http://connect.microsoft.com/SQLServer/feedback/details/606152 // Clear the table. var sqlCeController = new SqlCeController(GetConnectionStringSettings().ConnectionString); sqlCeController.ClearEventLog(); events.Clear(); } else throw; } return events; }