Ejemplo n.º 1
0
      // returns short XML name of message for logging
      private static string _getTag(BplMessage message, out string id) {
         id = "";
         if (message == null) return null;

         Func<OscarSessionData, string> getId = s => {
            if (s == null) return "";
            if (s.VehicleId.IsEmpty || (s.VehicleId.LocalId as string) == null) return s.VehicleSN;
            if ((s.VehicleId.LocalId as string).StartsWith("Factory")) return s.VehicleSN;
            return s.VehicleId.LocalId as string;
         };
         Func<BplObject, string> getTag = o => {
            var prefix = BplLanguage.Schemas.Contains(o.Class.Schema) ? BplLanguage.Schemas[o.Class.Schema] : "";
            return "{0}:{1}".Substitute(prefix, o.Class.TagName.LocalName);
         };

         if (message.IsA<OscarRequestWrapper>()) {
            id = getId(((OscarRequestWrapper)message).SessionData);

            return getTag(((OscarRequestWrapper)message).Input ?? message);
         } else if (message.IsA<OscarResponseWrapper>()) {
            id = getId(((OscarResponseWrapper)message).SessionData);
            return getTag(((OscarResponseWrapper)message).Output ?? message);
         } else if (message.IsA<OscarFailureWrapper>()) {
            id = getId(((OscarFailureWrapper)message).SessionData);
            return getTag(((OscarFailureWrapper)message).Error ?? message);
         } else {
            id = ((BplLegacyMessage)message).ClientId.LocalId as string;
            return getTag(message);
         }
      }
Ejemplo n.º 2
0
      private static void _logMessage(string dir, int len, BplMessage message, BplMessage request) {
         if (!CommunicationManager.LogMessages || message == null) return;

         // filtering is done by request, if request != null, then message is the response, so request is used
         var originalRequest = request ?? message;
         var filterable = _unwrapMessage(originalRequest);
         if (filterable == null) return;

         var role = originalRequest.IsA<OscarRequestWrapper>() ? (((OscarRequestWrapper)originalRequest).SessionData != null ? (((OscarRequestWrapper)originalRequest).SessionData).ClientRole : null) : null;
         if (_excludedLogRoles.Contains(role)) return;
         if (_excludedLogMessages.Contains(filterable.Class)) return;
         if (_excludedLogPatterns.Any(p => filterable.Class.CanonicName.StartsWith(p))) return;

         var formatter = BplXmlFormatter.Minimal;
         var log = formatter.Format(message) ? formatter.Output : "Failed to serialize '{0}'. {1}".Substitute(message.Class.Name, formatter.Errors.ToString());
         try {
            if (!LogSessionData) log = Regex.Replace(log, "<sessionData>(.*?)</sessionData>", "");
            if (!LogNamespaces) log = Regex.Replace(log, "\\sxmlns[^\"]+\"[^\"]+\"", "");
         } catch { };

         var id = "";
         var name = "";
         if (message.IsA<OscarRequestWrapper>()) {
            name = _getTag(message, out id);
         } else if (message.IsA<OscarResponseWrapper>()) {
            name = (request != null) ? _getTag(request, out id) + "_Result" : _getTag(message, out id);
         } else if (message.IsA<OscarFailureWrapper>()) {
            name = (request != null) ? _getTag(request, out id) + "_Failure" : _getTag(message, out id);
         } else if (message.IsA<BplLegacyMessage>()) {
            name = _getTag(message, out id);
         }
         
         Log.Record<CommunicationManager>("{0,-3}; {1,5}; {2,18}; {3}; {4}", dir, len, id, name, log);
      }