Example #1
0
        private void TraceOperation(IRemoraOperation operation, IComponentDefinition componentDefinition)
        {
            var category = GetCategory(componentDefinition);

            if (!componentDefinition.Properties.ContainsKey("directory"))
            {
                Logger.WarnFormat(
                    "Unable to trace operation {0}: no directory has been provided. You must use the directory attribute in the component configuration.",
                    operation);
                return;
            }
            var directoryPath = componentDefinition.Properties["directory"];

            if (!Directory.Exists(directoryPath))
            {
                try
                {
                    Directory.CreateDirectory(directoryPath);
                }
                catch (Exception ex)
                {
                    Logger.WarnFormat(ex,
                                      "Unable to trace operation {0}: the directory {1} does not exists and there has been an error when creating it.",
                                      operation, directoryPath);
                    return;
                }
            }

            var fileName = Path.Combine(directoryPath,
                                        string.Format("{0}-{1}-{2}.xml",
                                                      DateTime.UtcNow.ToString("s").MakeValidFileName(),
                                                      category.MakeValidFileName(), operation.OperationId));

            if (Logger.IsDebugEnabled)
                Logger.DebugFormat("Operation {0}: saving trace ({1}) in {2}...", operation, category, fileName);

            var serializableOperation = new SerializableOperation(operation);

            var stopwatchExecutionProperty = GetStopwatchExecutionPropertyKey(category);
            if (operation.ExecutionProperties.ContainsKey(stopwatchExecutionProperty))
            {
                var stopwatch = (Stopwatch) operation.ExecutionProperties[stopwatchExecutionProperty];
                stopwatch.Stop();
                serializableOperation.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds;
            }

            using (var writeStream = File.OpenWrite(fileName))
            {
                serializableOperation.Serialize(writeStream);
            }

            if (Logger.IsDebugEnabled)
                Logger.DebugFormat("Operation {0}: successfully traced ({1}) in {1}.", operation, category, fileName);
        }
Example #2
0
        private void EndRecordSoapOperation(IRemoraOperation operation, IComponentDefinition componentDefinition)
        {
            if (!operation.ExecutionProperties.ContainsKey(SoapActionKey))
                return;

            var soapActionName = (string) operation.ExecutionProperties[SoapActionKey];

            if (!componentDefinition.Properties.ContainsKey("directory"))
            {
                Logger.WarnFormat(
                    "Unable to record operation {0}: no directory has been provided. You must use the directory attribute in the component configuration.",
                    operation);
                return;
            }
            var directoryPath = componentDefinition.Properties["directory"];

            if (!Directory.Exists(directoryPath))
            {
                try
                {
                    Directory.CreateDirectory(directoryPath);
                }
                catch (Exception ex)
                {
                    Logger.WarnFormat(ex,
                                      "Unable to record operation {0}: the directory {1} does not exists and there has been an error when creating it.",
                                      operation, directoryPath);
                    return;
                }
            }

            var randomAppendToFileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            var fileName = Path.Combine(directoryPath,
                                        string.Format("{0}.{1}.xml", soapActionName.MakeValidFileName(),
                                                      randomAppendToFileName));

            if (Logger.IsDebugEnabled)
                Logger.DebugFormat("Operation {0}: saving record for {1} in {2}...", operation, soapActionName, fileName);

            var serializableOperation = new SerializableOperation(operation);

            try
            {
                using (var writeStream = File.OpenWrite(fileName))
                {
                    serializableOperation.Serialize(writeStream);
                }

                if (Logger.IsDebugEnabled)
                    Logger.DebugFormat("Operation {0}: successfully recorded in {1}.", operation, fileName);
            }
            catch (Exception ex)
            {
                Logger.WarnFormat(ex, "There has been an error while saving record file {0} for operation {1}.",
                                  fileName, operation);
            }
        }
Example #3
0
        private bool MockMatch(SerializableOperation serializableOperation, XDocument requestDoc,
                               IComponentDefinition componentDefinition)
        {
            var refDoc = XDocument.Parse(serializableOperation.Request.Content).Normalize();

            var refBody = _soapTransformer.GetBody(refDoc);
            var currentBody = _soapTransformer.GetBody(requestDoc);

            return XNode.DeepEquals(refBody, currentBody);
        }