/// <summary> /// Delete an IncidentType with the supplied id /// </summary> /// <param name="id">Id as string</param> /// <param name="dataController">Document storeage as RavenDataController</param> public void DeleteIncidentType(string id, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(id), "IncidentTypeController.DeleteIncidentType - id can not be null"); dataController.Delete<IncidentType>(id); }
public Incident GetIncident(string id, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(id) == false, "ErrorLoggingController.GetIncident - id can not be null"); return dataController.Get<Incident>(id); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="repository"></param> public void DeleteIncident(string id, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(id) == false, "ErrorLoggingController.DeleteIncident - id can not be null"); dataController.Delete<Incident>(id); }
/// <summary> /// Save an IncidentType to document store /// </summary> /// <param name="jsonIncidentType">Serilized IncidentType as Json string</param> /// <param name="repository">Document Storage as RavenDataController</param> /// <returns>Id of saved IncidentType as string</returns> public string CreateIncidentType(string jsonIncidentType, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(jsonIncidentType) == false, "ErrorLoggingConntroller.CreateIncidentType - jsonIncidentType can not be null"); var incidentType = JsonConvert.DeserializeObject<IncidentType>(jsonIncidentType); dataController.Save<IncidentType>(incidentType); return incidentType.Id; }
void Application_Start(object sender, EventArgs e) { // Connect to RavenDB string connection = ConfigurationManager.ConnectionStrings["RavenDBLocal"].ConnectionString; DocumentStore documentStore = new DocumentStore() { Url = connection }; documentStore.Initialize(); var dataController = new RavenDataController(documentStore); Application["RavenDataController"] = dataController; // Create Indexes CreateReducioIndexes(documentStore); }
/// <summary> /// Given a hash of an incident title, find the very first occurence of an incident with the /// same hashed title. /// </summary> /// <param name="hashTitle">Title hash as string</param> /// <param name="repository">Document storage as RavenDataController</param> /// <returns>On sucess, the parent incident. On failure a new Incident with no Id</returns> public Incident FindParent(string hashTitle, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(hashTitle) == false, "ErrorLoggingController.FindParent - hashTitle can not be null"); var results = dataController.GetAllWhere<Incident>(x => x.HashedTitle == hashTitle) .ToList<Incident>(); if((results == null) | (results.Count == 0)) { return new Incident(); } var parent = results.Aggregate((item, comp) => item.IncidentDateTime < comp.IncidentDateTime ? item : comp); if (parent == null) { return new Incident(); } return parent; }
public void CanFetchAllIncidents() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIndicents = Create15Incidents(); var dataController = new RavenDataController(docStore); batchIndicents.ForEach(x => dataController.Save<Incident>(x)); int totalCount = 0; using(var session = docStore.OpenSession()) { totalCount = session.Query<Incident>() .Customize(x => x.WaitForNonStaleResults()) .Count(); } // Test var allIncidents = dataController.GetAll<Incident>(); Assert.AreEqual(totalCount, allIncidents.Count); }
public void CanDeleteIncident() { // Prep var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var repository = new RavenDataController(docStore); var incident = CreateTransitionError(); incident.PageName = "FindAnDeleteMe"; var errorLoggingController = new ErrorLoggingController(); string id = errorLoggingController .LogIncident(JsonConvert.SerializeObject(incident), repository); int postLogCount = 0; using (var session = docStore.OpenSession()) { postLogCount = session.Query<Incident>() .Customize(x => x.WaitForNonStaleResults()) .Count(); } // Test errorLoggingController.DeleteIncident(id, repository); int postDeleteCount = 0; using (var session = docStore.OpenSession()) { postDeleteCount = session.Query<Incident>() .Customize(x => x.WaitForNonStaleResults()) .Count(); } Assert.AreEqual(postLogCount, postDeleteCount + 1); }
/// <summary> /// Fetch an IncidentType for a Id /// </summary> /// <param name="id">Id as string</param> /// <param name="dataController">Document storeage as RavenDataController</param> /// <returns>The IncidentType, Id == null on failure</returns> public IncidentType GetIncidentType(string id, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(id), "IncidentTypeController.GetIncidentType - id can not be null"); return dataController.Get<IncidentType>(id); }
public void CanLogIncidentAndAssociateToParent() { // Prep var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); // Parent var parentIncident = CreateTransitionError(); parentIncident.IncidentType = new IncidentType("ParentTypeError", new DateTime(2012, 1, 31), "The Parent Type", "Truncate database"); var repository = new RavenDataController(docStore); repository.Save<Incident>(parentIncident); // 2 more incidents for our searching var incident2 = CreateTransitionError(); incident2.PageName = "Incident 2"; repository.Save<Incident>(incident2); var incident3 = CreateTransitionError(); incident3.PageName = "Incident 3"; repository.Save<Incident>(incident3); //The child incident var childincident = CreateTransitionError(); var errorController = new ErrorLoggingController(); string childId = errorController.LogIncident(JsonConvert.SerializeObject(childincident), repository); var savedChild = repository.Get<Incident>(childId); Console.WriteLine("Child Parent Id " + savedChild.ParentIncidentId + " : Parent Id " + parentIncident.Id); Assert.AreEqual(parentIncident.Id, savedChild.ParentIncidentId); }
/// <summary> /// Accept an Incident object, locate a potential parent incident /// and related incidents, and save to document storeage /// </summary> /// <param name="incident">The new Incident object</param> /// <param name="dataController">Document storeage as RavenDataController</param> /// <returns>Logged Incident Id as string</returns> public string LogIncident(Incident incident, RavenDataController dataController) { // When the minimum data is missing catalog this as unserviceable then save if (incident.CanIncidentBeLogged() == false) { incident.Title = "Unspecified error!"; incident.IncidentDateTime = DateTime.Now; incident.Catalogged = false; incident.PageName = "No page name!"; var unspecifiedIncidentType = new IncidentType("Unspecified", DateTime.Now, "Error logging did not capture results", "Gather more data"); incident.IncidentType = unspecifiedIncidentType; } // Has this occurred before? Associate to parent / primary occurence var parentIncident = FindParent(incident.HashedTitle, dataController); if (string.IsNullOrEmpty(parentIncident.Id) == false) { incident.ParentIncidentId = parentIncident.Id; incident.RelatedIncidents = parentIncident.RelatedIncidents; incident.Resolved = parentIncident.Resolved; incident.Catalogged = parentIncident.Catalogged; } dataController.Save<Incident>(incident); return incident.Id; }
/// <summary> /// Fetch all IncidentTypes /// </summary> /// <param name="dataController">Document storeage as RavenDataController</param> /// <returns></returns> public List<IncidentType> GetAllIncidentTypes(RavenDataController dataController) { return dataController.GetAll<IncidentType>(); }
public void CanQueryForJavascriptIncidentType() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIndicents = Create15Incidents(); var dataController = new RavenDataController(docStore); batchIndicents.ForEach(x => dataController.Save<Incident>(x)); int totalJavascriptCount = 0; using(var session = docStore.OpenSession()) { totalJavascriptCount = session.Query<Incident>() .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.IncidentType.Type == "javascript") .Count(); } // Test var javascriptIncidents = dataController.GetAllWhere<Incident>(inc => inc.IncidentType.Type == "javascript"); Assert.AreEqual(totalJavascriptCount, javascriptIncidents.Count); }
public void CanQueryIndexForJavascriptIncidentType() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIndicents = Create15Incidents(); var dataController = new RavenDataController(docStore); batchIndicents.ForEach(x => dataController.Save<Incident>(x)); Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(DistinctIncidentTypeIndex).Assembly, docStore); var javascriptIncidentType = dataController.GetAllWhere<DistinctIncidentTypeIndex.DistinctIncidentType> (x => x.Name == "javascript", "DistinctIncidentTypeIndex"); Assert.AreEqual(5, javascriptIncidentType[0].Count); }
/// <summary> /// When an update is performed against an IncidentType, /// propogate changes to all incidents with this type /// </summary> public void CascadeUpdateForIncidentType(IncidentType incidentType, RavenDataController dataController) { }
/// <summary> /// A change to a IncidentType.Type on a parent propogates to all of the /// children Incidents. That is, switching IncidentType = database to IncidentType /// = javascript updates all Incidents /// </summary> /// <param name="id"></param> /// <param name="incidentTypeId"></param> public void CascadeParentIncidentType(string id, string incidentTypeId, RavenDataController dataController) { }
public void CanLogIncident() { // Prep var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); int postUpdateCount = 0; var newIncident = CreateTransitionError(); var repository = new RavenDataController(docStore); var errorLoggingController = new ErrorLoggingController(); string json = JsonConvert.SerializeObject(newIncident); errorLoggingController.LogIncident(json, repository); using (var session = docStore.OpenSession()) { postUpdateCount = session.Query<Incident>() .Customize(x => x.WaitForNonStaleResults()) .Count(); } Assert.AreEqual(1, postUpdateCount); }
/// <summary> /// Accept a json representation of an incident, deserialize, locate a potential parent incident /// and related incidents, and save to document storeage /// </summary> /// <param name="jsonIncident">Incident serialized as Json string</param> /// <param name="dataController">Document storeage as RavenDataController</param> /// <returns>Logged Incident Id as string</returns> public string LogIncident(string jsonIncident, RavenDataController dataController) { Enforce.That(string.IsNullOrEmpty(jsonIncident) == false, "ErrorLoggingController.GetIncident - jsonIncident can not be null"); var newIncident = JsonConvert.DeserializeObject<Incident>(jsonIncident); return LogIncident(newIncident, dataController); }
public void CanFindParentIncident() { // Prep var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var parentIncident = CreateTransitionError(); parentIncident.IncidentType = new IncidentType("ParentTypeError", new DateTime(2012, 1, 31), "The Parent Type", "Truncate database"); var repository = new RavenDataController(docStore); repository.Save<Incident>(parentIncident); // 2 more incidents for our searching var incident2 = CreateTransitionError(); incident2.PageName = "Incident 2"; repository.Save<Incident>(incident2); var incident3 = CreateTransitionError(); incident3.PageName = "Incident 3"; repository.Save<Incident>(incident3); // Test var errorLoggingController = new ErrorLoggingController(); var foundParent = errorLoggingController.FindParent(parentIncident.HashedTitle, repository); Console.WriteLine(parentIncident.Id); Assert.AreEqual(parentIncident.IncidentType.Type, foundParent.IncidentType.Type); }
public void CreateIncidentTypes() { var docStore = GetDocStore(); TruncateIncidentTypes(docStore); var dataController = new RavenDataController(docStore); var databaseType = new IncidentType("Database", new DateTime(2012, 3, 4), "Database offline", "reboot"); dataController.Save<IncidentType>(databaseType); var javascriptType = new IncidentType("Javascript", new DateTime(2012, 3, 4), "jQuery not loaded", "review script"); dataController.Save<IncidentType>(javascriptType); var nullObjectType = new IncidentType("Null Object Reference", new DateTime(2012, 3, 4), "Not record returned", "check database"); dataController.Save<IncidentType>(nullObjectType); var pageNotFound = new IncidentType("Page Not Found", new DateTime(2012, 3, 4), "404", "check IIS"); dataController.Save<IncidentType>(pageNotFound); }
public void CanQueryIndexForUnresolvedIncidents() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIncidents = Create15Incidents(); // Mark 5 of these as resolved for (int i = 0; i <= 4; i++ ) { batchIncidents[i].Resolved = true; } var dataController = new RavenDataController(docStore); batchIncidents.ForEach(x => dataController.Save<Incident>(x)); Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(UnresolvedIncidentIndex).Assembly, docStore); var unresolved = dataController.GetAll<Incident>("UnresolvedIncidentIndex"); Assert.AreEqual(10, unresolved.Count); }
public void CanQueryIndexForParentIncidents() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIncidents = Create15Incidents(); var dataController = new RavenDataController(docStore); batchIncidents.ForEach(x => dataController.Save<Incident>(x)); var parentIncidents = dataController.GetAll<Incident>("ParentIncidentIndex"); Assert.AreEqual(2, parentIncidents.Count); }
public List<Incident> GetParentIncidents(RavenDataController dataController) { return dataController.GetAllWhere<Incident>(x => string.IsNullOrEmpty(x.ParentIncidentId)); }
/// <summary> /// Fetch distribution of IncidentTypes: count of of each IncidentType /// </summary> /// <param name="dataController"></param> /// <returns>IncidentType.Type and Count as Json string</returns> public string GetIncidentTypeDistribution(RavenDataController dataController) { var distribution = dataController.GetAll<DistinctIncidentTypeIndex .DistinctIncidentType>("DistinctIncidentTypeIndex"); return JsonConvert.SerializeObject(distribution); }
/// <summary> /// Remove the parent association from an incident /// </summary> public void BreakParentRelationship(string parentIncidentId, string incidentId, RavenDataController dataController) { }
public void CanGetDistincIncidentTypeByIndex() { var docStore = GetDocStore(); TruncateIncidentDocuments(docStore); var batchIndicents = Create15Incidents(); var dataController = new RavenDataController(docStore); batchIndicents.ForEach(x => dataController.Save<Incident>(x)); Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(DistinctIncidentTypeIndex).Assembly, docStore); var distinctIncidentTypes = dataController .GetAll<DistinctIncidentTypeIndex.DistinctIncidentType> ("DistinctIncidentTypeIndex"); Assert.AreEqual(4, distinctIncidentTypes.Count); }