public IActionResult GetDeleted([FromQuery] string filter, [FromHeader] string CPDataPaging) { int pageCount = 0; string entityAsJson = ""; try { _logger.LogInformation("CPAPI: GetDeleted"); // Get any Paging data requests POCO.DataPaging dataPaging = new POCO.DataPaging(); if (CPDataPaging != null && CPDataPaging != string.Empty) { _logger.LogDebug("Deserializing datapaging of length: " + CPDataPaging.Length); string pagingDecoded = System.Net.WebUtility.HtmlDecode(CPDataPaging); pagingDecoded = System.Net.WebUtility.UrlDecode(pagingDecoded); dataPaging = JsonConvert.DeserializeObject <POCO.DataPaging>(pagingDecoded); } DataFactory.DataConfig dataConfig = Utils.GetDataConfig(); List <POCO.O365.AuditLogEntry> logEntries = new List <POCO.O365.AuditLogEntry>(); List <DataFactory.Filter> filters = new List <DataFactory.Filter>(); string nextPageId = string.Empty; DataFactory.Filter deleteFilter = new DataFactory.Filter("Operation", "FileDeleted", "eq"); logEntries = DataFactory.O365.AuditLog.GetActionableEvents(dataConfig, string.Empty, filters, string.Empty, Utils.GetMaxRows(), out nextPageId); // Get the last 3 months of log data by default //DateTime today = DateTime.UtcNow; //for (int i = 0; i < 2; i++) //{ // // Calculate the suffix of the table // DateTime tableSuffixDate = today.AddMonths(-1 * i); // string tableSuffix = tableSuffixDate.ToString(Utils.TableSuffixDateFormatYM); // // Add the range for the month to our final collection // List<POCO.O365.AuditLogEntry> monthEntries = DataFactory.O365.AuditLog.GetActionableEvents(dataConfig, tableSuffix); // logEntries.AddRange(monthEntries); //} // Sort the data by descending date logEntries.Sort((x, y) => DateTime.Compare(y.CreationDateTime, x.CreationDateTime)); // Check if a data page has been specified PagedData paged = new PagedData(); if (logEntries.Count > 0 && dataPaging.page > 0 && dataPaging.perPage > 0) { List <POCO.O365.AuditLogEntry> pageOfData = new List <POCO.O365.AuditLogEntry>(); // Check that the requested data is in range dataPaging.page--; // pages are zero-based to calculate the correct range int startOfPage = (dataPaging.page * dataPaging.perPage); if (logEntries.Count > startOfPage + dataPaging.perPage - 1) { pageOfData = logEntries.GetRange(startOfPage, dataPaging.perPage); } else { _logger.LogError("Data paging request out of range"); return(StatusCode((int)System.Net.HttpStatusCode.BadRequest)); } paged.data = pageOfData; paged.totalRecords = logEntries.Count; entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented); } else { paged.data = logEntries; paged.totalRecords = logEntries.Count; entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented); } } catch (Exception ex) { string exceptionMsg = "Record GET exception: " + ex.Message; //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message); if (ex.InnerException != null) { exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]"; } _logger.LogError(exceptionMsg); return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError)); } ObjectResult result = new ObjectResult(entityAsJson); return(result); }
public IActionResult GetActionableEventsByDate([FromQuery] string filter, [FromHeader] string CPDataPaging) { int pageCount = 0; string thisPageId = string.Empty; string nextPageId = string.Empty; string entityAsJson = ""; try { _logger.LogInformation("CPAPI: GetActionableEvents"); // Get filter requests ActionableEventsFilter eventsFilter = new ActionableEventsFilter(); if (filter != null && filter != string.Empty) { _logger.LogDebug("Deserializing filter of length: " + filter.Length); string filterDecoded = System.Net.WebUtility.HtmlDecode(filter); filterDecoded = System.Net.WebUtility.UrlDecode(filterDecoded); eventsFilter = JsonConvert.DeserializeObject <ActionableEventsFilter>(filterDecoded); } // Validate the date entries if (eventsFilter.datefrom.Trim() == string.Empty && eventsFilter.dateto.Trim() == string.Empty) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest)); } // Get the filters List <DataFactory.Filter> filters = GetActionableEventsDataFilter(eventsFilter); // Get any Paging data requests POCO.DataPaging dataPaging = new POCO.DataPaging(); if (CPDataPaging != null && CPDataPaging != string.Empty) { _logger.LogDebug("Deserializing datapaging of length: " + CPDataPaging.Length); string pagingDecoded = System.Net.WebUtility.HtmlDecode(CPDataPaging); pagingDecoded = System.Net.WebUtility.UrlDecode(pagingDecoded); dataPaging = JsonConvert.DeserializeObject <POCO.DataPaging>(pagingDecoded); } // Load the data DataFactory.DataConfig datacfg = Utils.GetDataConfig(); List <POCO.O365.AuditLogEntry> logEntries = new List <POCO.O365.AuditLogEntry>(); // Check for data page request token if (dataPaging != null && dataPaging.thisPageId != null && dataPaging.thisPageId != string.Empty) { thisPageId = dataPaging.thisPageId; } // Get the data int rowsToRequest = Utils.GetMaxRows() - logEntries.Count; logEntries = DataFactory.O365.AuditLog.GetActionableEvents(datacfg, "bydate", filters, thisPageId, rowsToRequest, out nextPageId); // Sort the data by descending date logEntries.Sort((x, y) => DateTime.Compare(y.CreationDateTime, x.CreationDateTime)); // Check if a data page has been specified PagedData paged = new PagedData(); paged.data = logEntries; paged.totalRecords = logEntries.Count; paged.nextPageId = nextPageId; entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented); } catch (Exception ex) { string exceptionMsg = "Record GET exception: " + ex.Message; //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message); if (ex.InnerException != null) { exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]"; } _logger.LogError(exceptionMsg); return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError)); } ObjectResult result = new ObjectResult(entityAsJson); return(result); }
public IActionResult GetDeletedByItemFilter([FromQuery] string filter, [FromHeader] string CPDataPaging) { int pageCount = 0; string entityAsJson = ""; try { _logger.LogInformation("CPAPI: GetDeletedByItemFilter"); // Deserialize the ontology filter RecordFilter oFilter = new RecordFilter(); if (filter != null && filter.Length > 0) { _logger.LogDebug("Deserializing Item filter of length: " + filter.Length); oFilter = JsonConvert.DeserializeObject <RecordFilter>(filter); } // Get any Paging data requests POCO.DataPaging dataPaging = new POCO.DataPaging(); if (CPDataPaging != null && CPDataPaging != string.Empty) { _logger.LogDebug("Deserializing datapaging of length: " + CPDataPaging.Length); string pagingDecoded = System.Net.WebUtility.HtmlDecode(CPDataPaging); pagingDecoded = System.Net.WebUtility.UrlDecode(pagingDecoded); dataPaging = JsonConvert.DeserializeObject <POCO.DataPaging>(pagingDecoded); } // Create filters List <DataFactory.Filter> filters = new List <DataFactory.Filter>(); DataFactory.Filter deleteFilter = new DataFactory.Filter("Operation", "FileDeleted", "eq"); if (oFilter.records.Count > 0) { foreach (RecordItemFilter rif in oFilter.records) { string cleanFilterPKey = Utils.CleanTableKey(rif.itemuri); //cleanFilterRKey = System.Web.HttpUtility.UrlEncode(cleanFilterRKey); //cleanFilterRKey = cleanFilterRKey.Replace("&", "&"); if (cleanFilterPKey != "") { DataFactory.Filter f1 = new DataFactory.Filter("PartitionKey", cleanFilterPKey, "ge"); filters.Add(f1); DataFactory.Filter f2 = new DataFactory.Filter("PartitionKey", Utils.GetLessThanFilter(cleanFilterPKey), "lt"); filters.Add(f2); } } } else { _logger.LogInformation("RecordFilter query BLANK"); } DataFactory.DataConfig dataConfig = Utils.GetDataConfig(); List <POCO.O365.AuditLogEntry> logEntries = new List <POCO.O365.AuditLogEntry>(); string nextPageId = string.Empty; logEntries = DataFactory.O365.AuditLog.GetActionableEvents(dataConfig, string.Empty, filters, dataPaging.thisPageId, Utils.GetMaxRows(), out nextPageId); // Get the last 3 months of log data by default //DateTime today = DateTime.UtcNow; //for (int i = 0; i < 2; i++) //{ // // Calculate the suffix of the table // DateTime tableSuffixDate = today.AddMonths(-1 * i); // string tableSuffix = tableSuffixDate.ToString(Utils.TableSuffixDateFormatYM); // // Add the range for the month to our final collection // List<POCO.O365.AuditLogEntry> monthEntries = DataFactory.O365.AuditLog.GetActionableEventsForItem(dataConfig, filters, tableSuffix); // logEntries.AddRange(monthEntries); //} // Sort the data by descending date logEntries.Sort((x, y) => DateTime.Compare(y.CreationDateTime, x.CreationDateTime)); // Check if a data page has been specified PagedData paged = new PagedData(); if (logEntries.Count > 0) { List <POCO.O365.AuditLogEntry> pageOfData = new List <POCO.O365.AuditLogEntry>(); // Check that the requested data is in range dataPaging.page--; // pages are zero-based to calculate the correct range int startOfPage = (dataPaging.page * dataPaging.perPage); if (logEntries.Count > startOfPage + dataPaging.perPage - 1) { pageOfData = logEntries.GetRange(startOfPage, dataPaging.perPage); } else { _logger.LogError("Data paging request out of range"); return(StatusCode((int)System.Net.HttpStatusCode.BadRequest)); } // Set the PageCount Response Header //decimal totalPages = (decimal)(logEntries.Count / dataPaging.perPage); //pageCount = (int)Math.Ceiling(totalPages); paged.data = pageOfData; paged.totalRecords = logEntries.Count; entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented); } else { paged.data = logEntries; paged.totalRecords = logEntries.Count; entityAsJson = JsonConvert.SerializeObject(paged, Formatting.Indented); } } catch (Exception ex) { string exceptionMsg = "Record GET exception: " + ex.Message; //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message); if (ex.InnerException != null) { exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]"; } _logger.LogError(exceptionMsg); return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError)); } ObjectResult result = new ObjectResult(entityAsJson); return(result); }