Exemplo n.º 1
0
        public static string AddLogEntry(DataConfig providerConfig, POCO.O365.AuditLogEntry logEntry)
        {
            DateTime logEntryDate;
            bool     isDateValid = DateTime.TryParse(logEntry.CreationTime, out logEntryDate);

            string tableSuffix = logEntryDate.ToString(Utils.TableSuffixDateFormatYM);

            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":
                AzureAuditLogEntry az = new AzureAuditLogEntry(logEntry);

                CloudTable table = Utils.GetCloudTable(providerConfig, AzureTableNames.O365AuditLogEntry + tableSuffix);

                TableOperation insertReplace = TableOperation.InsertOrReplace(az);

                // Execute the insert operation.
                Task tResult = table.ExecuteAsync(insertReplace);
                tResult.Wait();
                break;

            case "internal.mongodb":
                IMongoCollection <MongoAuditLogEntry> collection = Utils.GetMongoCollection <MongoAuditLogEntry>(providerConfig, MongoTableNames.O365AuditLogEntry + tableSuffix);
                MongoAuditLogEntry mongoObject = Utils.ConvertType <MongoAuditLogEntry>(logEntry);
                collection.InsertOne(mongoObject);
                return(string.Empty);

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }

            //TODO return id of new object if supported
            return(string.Empty);
        }
Exemplo n.º 2
0
        public static void DeleteLogEntry(DataConfig providerConfig, string auditTableName, AuditLogEntry entry)
        {
            List <Filter> filters = new List <Filter>();
            Filter        pk      = new Filter("PartitionKey", entry.PartitionKey, "eq");

            filters.Add(pk);
            Filter rk = new Filter("RowKey", entry.RowKey, "eq");

            filters.Add(rk);

            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":

                auditTableName = "stlp" + auditTableName;

                AzureAuditLogEntry az = new AzureAuditLogEntry(entry);
                az.ETag = "*";

                CloudTable     table     = Utils.GetCloudTable(providerConfig, auditTableName);
                TableOperation operation = TableOperation.Delete(az);

                Task <TableResult> tDelete = table.ExecuteAsync(operation);
                tDelete.Wait();

                // Check for "success with no status" code
                if (tDelete.Result.HttpStatusCode != 204)
                {
                    // TODO
                    bool isNotDeleted = true;
                }



                break;

            case "internal.mongodb":
                FilterDefinition <BsonDocument> filter = Utils.GenerateMongoFilter <BsonDocument>(filters);

                // Delete the rows
                IMongoCollection <BsonDocument> collection = Utils.GetMongoCollection <BsonDocument>(providerConfig, auditTableName);
                DeleteResult result = collection.DeleteMany(filter);

                return;

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }
            return;
        }
Exemplo n.º 3
0
        public static string AddAuditableEventLogEntry(DataConfig providerConfig, AuditLogEntry logEntry, string auditLookupType)
        {
            string tableName = string.Empty;

            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":
                switch (auditLookupType)
                {
                case "byuser":
                {
                    tableName = AzureTableNames.O365AuditLogEntryActionableByUser;
                    break;
                }

                case "byday":
                {
                    tableName = AzureTableNames.O365AuditLogEntryActionableByDay;
                    break;
                }

                default:
                {
                    tableName = AzureTableNames.O365AuditLogEntryActionable;
                    break;
                }
                }

                AzureAuditLogEntry az = new AzureAuditLogEntry(logEntry);

                CloudTable table = Utils.GetCloudTable(providerConfig, tableName);

                TableOperation insertReplace = TableOperation.InsertOrReplace(az);

                // Execute the insert operation.
                Task tResult = table.ExecuteAsync(insertReplace);
                tResult.Wait();
                break;

            case "internal.mongodb":

                switch (auditLookupType)
                {
                case "byuser":
                {
                    tableName = MongoTableNames.O365AuditLogEntryActionableByUser;
                    break;
                }

                case "byday":
                {
                    tableName = MongoTableNames.O365AuditLogEntryActionableByDay;
                    break;
                }

                default:
                {
                    tableName = MongoTableNames.O365AuditLogEntryActionable;
                    break;
                }
                }

                IMongoCollection <MongoAuditLogEntry> collection = Utils.GetMongoCollection <MongoAuditLogEntry>(providerConfig, tableName);
                MongoAuditLogEntry mongoObject = Utils.ConvertType <MongoAuditLogEntry>(logEntry);
                collection.InsertOne(mongoObject);
                return(string.Empty);

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }

            //TODO return id of new object if supported
            return(string.Empty);
        }