private static LogRowFormatter CreateLogRowForFirstLine(string executingUser, byte[] cookie, NameValueCollection parameters, string responseIdentity) { string cookieInBase = (cookie == null) ? null : Convert.ToBase64String(cookie); string parameters2 = (parameters == null) ? null : BackSyncAuditLog.ToParametersString(parameters); return(BackSyncAuditLog.CreateLogRow(executingUser, cookieInBase, parameters2, responseIdentity, null, null, null, null, null, null)); }
private static LogRowFormatter CreateLogRowForSyncObject(string responseIdentity, object syncObject, string objectInXml) { string objectId = null; string sourceId = null; string targetId = null; string contextId; if (syncObject is DirectoryObject) { DirectoryObject directoryObject = (DirectoryObject)syncObject; objectId = directoryObject.ObjectId; contextId = directoryObject.ContextId; } else if (syncObject is DirectoryObjectError) { DirectoryObjectError directoryObjectError = (DirectoryObjectError)syncObject; objectId = directoryObjectError.ObjectId; contextId = directoryObjectError.ContextId; } else { if (!(syncObject is DirectoryLink)) { throw new NotSupportedException("Don't know how to extract IDs for new type: " + syncObject.GetType().Name); } DirectoryLink directoryLink = (DirectoryLink)syncObject; contextId = directoryLink.ContextId; sourceId = directoryLink.SourceId; targetId = directoryLink.TargetId; } return(BackSyncAuditLog.CreateLogRow(null, null, null, responseIdentity, objectId, contextId, sourceId, targetId, objectInXml, null)); }
private void Append(string responseIdentity, Dictionary <SyncObject, Exception> errors) { foreach (KeyValuePair <SyncObject, Exception> keyValuePair in errors) { this.Append(BackSyncAuditLog.CreateLogRowForError(responseIdentity, keyValuePair.Key, keyValuePair.Value)); } }
private void Append <T>(string responseIdentity, T[] objects) { if (objects == null || objects.Length == 0) { return; } XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); StringBuilder stringBuilder = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = false }; for (int i = 0; i < objects.Length; i++) { using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, settings)) { xmlSerializer.Serialize(xmlWriter, objects[i]); this.Append(BackSyncAuditLog.CreateLogRowForSyncObject(responseIdentity, objects[i], stringBuilder.ToString())); stringBuilder.Length = 0; } } }
public void Append(string executingUser, byte[] cookie, NameValueCollection parameters, object response, Dictionary <SyncObject, Exception> errors) { string responseIdentity = Guid.NewGuid().ToString("N"); this.Append(BackSyncAuditLog.CreateLogRowForFirstLine(executingUser, cookie, parameters, responseIdentity)); if (response is GetChangesResponse) { DirectoryChanges getChangesResult = ((GetChangesResponse)response).GetChangesResult; this.Append <DirectoryObject>(responseIdentity, getChangesResult.Objects); this.Append <DirectoryLink>(responseIdentity, getChangesResult.Links); } else { if (!(response is GetDirectoryObjectsResponse)) { throw new NotImplementedException("Need implement writing audit log for response type: " + response.GetType().Name); } DirectoryObjectsAndLinks getDirectoryObjectsResult = ((GetDirectoryObjectsResponse)response).GetDirectoryObjectsResult; this.Append <DirectoryObject>(responseIdentity, getDirectoryObjectsResult.Objects); this.Append <DirectoryLink>(responseIdentity, getDirectoryObjectsResult.Links); this.Append <DirectoryObjectError>(responseIdentity, getDirectoryObjectsResult.Errors); } this.Append(responseIdentity, errors); }
private static LogRowFormatter CreateLogRowForError(string responseIdentity, SyncObject syncObject, Exception e) { return(BackSyncAuditLog.CreateLogRow(null, null, null, responseIdentity, syncObject.ObjectId, syncObject.ContextId, null, null, null, e.Message)); }