Example #1
0
        private RavenJObject ApplySingleScript(RavenJObject doc, ScriptedPatchRequest patch, int size, string docId, ScriptedJsonPatcherOperationScope scope)
        {
            Engine jintEngine;

            try
            {
                jintEngine = ScriptsCache.CheckoutScript(CreateEngine, patch);
            }
            catch (NotSupportedException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (JavaScriptException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (Exception e)
            {
                throw new ParseException("Could not parse: " + Environment.NewLine + patch.Script, e);
            }

            try
            {
                PrepareEngine(patch, docId, size, scope, jintEngine);

                var jsObject = scope.ToJsObject(jintEngine, doc);
                jintEngine.Invoke("ExecutePatchScript", jsObject);

                CleanupEngine(patch, jintEngine, scope);

                OutputLog(jintEngine);

                ScriptsCache.CheckinScript(patch, jintEngine);

                return(scope.ConvertReturnValue(jsObject));
            }
            catch (ConcurrencyException)
            {
                throw;
            }
            catch (Exception errorEx)
            {
                jintEngine.ResetStatementsCount();

                OutputLog(jintEngine);
                var errorMsg = "Unable to execute JavaScript: " + Environment.NewLine + patch.Script;
                var error    = errorEx as JavaScriptException;
                if (error != null)
                {
                    errorMsg += Environment.NewLine + "Error: " + Environment.NewLine + string.Join(Environment.NewLine, error.Error);
                }
                if (Debug.Count != 0)
                {
                    errorMsg += Environment.NewLine + "Debug information: " + Environment.NewLine +
                                string.Join(Environment.NewLine, Debug);
                }

                var targetEx = errorEx as TargetInvocationException;
                if (targetEx != null && targetEx.InnerException != null)
                {
                    throw new InvalidOperationException(errorMsg, targetEx.InnerException);
                }

                throw new InvalidOperationException(errorMsg, errorEx);
            }
        }
		private RavenJObject ApplySingleScript(RavenJObject doc, ScriptedPatchRequest patch, int size, string docId, ScriptedJsonPatcherOperationScope scope)
		{
			Engine jintEngine;
			try
			{
				jintEngine = ScriptsCache.CheckoutScript(CreateEngine, patch);
			}
			catch (NotSupportedException e)
			{
				throw new ParseException("Could not parse script", e);
			}
			catch (JavaScriptException e)
			{
				throw new ParseException("Could not parse script", e);
			}
			catch (Exception e)
			{
				throw new ParseException("Could not parse: " + Environment.NewLine + patch.Script, e);
			}

			try
			{
				PrepareEngine(patch, docId, size, scope, jintEngine);

				var jsObject = scope.ToJsObject(jintEngine, doc);
			    jintEngine.Invoke("ExecutePatchScript", jsObject);

			    CleanupEngine(patch, jintEngine);

				OutputLog(jintEngine);

			    ScriptsCache.CheckinScript(patch, jintEngine);

				return scope.ConvertReturnValue(jsObject);
			}
			catch (ConcurrencyException)
			{
			    throw;
			}
			catch (Exception errorEx)
			{
				jintEngine.ResetStatementsCount();

				OutputLog(jintEngine);
				var errorMsg = "Unable to execute JavaScript: " + Environment.NewLine + patch.Script;
				var error = errorEx as JavaScriptException;
				if (error != null)
					errorMsg += Environment.NewLine + "Error: " + Environment.NewLine + string.Join(Environment.NewLine, error.Error);
				if (Debug.Count != 0)
					errorMsg += Environment.NewLine + "Debug information: " + Environment.NewLine +
								string.Join(Environment.NewLine, Debug);

				var targetEx = errorEx as TargetInvocationException;
				if (targetEx != null && targetEx.InnerException != null)
					throw new InvalidOperationException(errorMsg, targetEx.InnerException);

				throw new InvalidOperationException(errorMsg, errorEx);
			}
		}
Example #3
0
        private RavenJObject ApplySingleScript(RavenJObject doc, ScriptedPatchRequest patch, int size, string docId, ScriptedJsonPatcherOperationScope scope)
        {
            Engine jintEngine;
            var    customFunctions = scope.CustomFunctions != null ? scope.CustomFunctions.DataAsJson : null;

            try
            {
                jintEngine = ScriptsCache.CheckoutScript(CreateEngine, patch, customFunctions);
            }
            catch (NotSupportedException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (JavaScriptException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (Exception e)
            {
                throw new ParseException("Could not parse: " + Environment.NewLine + patch.Script, e);
            }

            try
            {
                PrepareEngine(patch, docId, size, scope, jintEngine);

                var jsObject = scope.ToJsObject(jintEngine, doc);
                jintEngine.Invoke("ExecutePatchScript", jsObject);

                CleanupEngine(patch, jintEngine, scope);

                OutputLog(jintEngine);
                if (scope.DebugMode)
                {
                    Debug.Add(string.Format("Statements executed: {0}", jintEngine.StatementsCount));
                }

                ScriptsCache.CheckinScript(patch, jintEngine, customFunctions);

                return(scope.ConvertReturnValue(jsObject));
            }
            catch (ConcurrencyException)
            {
                throw;
            }
            catch (Exception errorEx)
            {
                jintEngine.ResetStatementsCount();

                OutputLog(jintEngine);
                var errorMsg = "Unable to execute JavaScript: " + Environment.NewLine + patch.Script + Environment.NewLine;
                var error    = errorEx as JavaScriptException;
                if (error != null)
                {
                    errorMsg += Environment.NewLine + "Error: " + Environment.NewLine + string.Join(Environment.NewLine, error.Error);
                }
                if (Debug.Count != 0)
                {
                    errorMsg += Environment.NewLine + "Debug information: " + Environment.NewLine +
                                string.Join(Environment.NewLine, Debug);
                }

                if (error != null)
                {
                    errorMsg += Environment.NewLine + "Stacktrace:" + Environment.NewLine + error.CallStack;
                }

                var targetEx = errorEx as TargetInvocationException;
                if (targetEx != null && targetEx.InnerException != null)
                {
                    throw new InvalidOperationException(errorMsg, targetEx.InnerException);
                }

                var recursionEx = errorEx as RecursionDepthOverflowException;
                if (recursionEx != null)
                {
                    errorMsg += Environment.NewLine + "Max recursion depth is limited to: " + MaxRecursionDepth;
                }

                throw new InvalidOperationException(errorMsg, errorEx);
            }
        }
Example #4
0
        private RavenJObject ApplySingleScript(RavenJObject doc, ScriptedPatchRequest patch, int size, string docId, ScriptedJsonPatcherOperationScope scope)
        {
            Engine jintEngine;
            var customFunctions = scope.CustomFunctions != null ? scope.CustomFunctions.DataAsJson : null;
            try
            {
                jintEngine = ScriptsCache.CheckoutScript(CreateEngine, patch, customFunctions);
            }
            catch (NotSupportedException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (JavaScriptException e)
            {
                throw new ParseException("Could not parse script", e);
            }
            catch (Exception e)
            {
                throw new ParseException("Could not parse: " + Environment.NewLine + patch.Script, e);
            }

            try
            {
                PrepareEngine(patch, docId, size, scope, jintEngine);

                var jsObject = scope.ToJsObject(jintEngine, doc);
                jintEngine.Invoke("ExecutePatchScript", jsObject);

                CleanupEngine(patch, jintEngine, scope);

                OutputLog(jintEngine);
                if (scope.DebugMode)
                    Debug.Add(string.Format("Statements executed: {0}", jintEngine.StatementsCount));

                ScriptsCache.CheckinScript(patch, jintEngine, customFunctions);

                return scope.ConvertReturnValue(jsObject);
            }
            catch (ConcurrencyException)
            {
                throw;
            }
            catch (Exception errorEx)
            {
                jintEngine.ResetStatementsCount();

                OutputLog(jintEngine);
                var errorMsg = "Unable to execute JavaScript: " + Environment.NewLine + patch.Script + Environment.NewLine;
                var error = errorEx as JavaScriptException;
                if (error != null)
                    errorMsg += Environment.NewLine + "Error: " + Environment.NewLine + string.Join(Environment.NewLine, error.Error);
                if (Debug.Count != 0)
                    errorMsg += Environment.NewLine + "Debug information: " + Environment.NewLine +
                                string.Join(Environment.NewLine, Debug);

                if (error != null)
                    errorMsg += Environment.NewLine + "Stacktrace:" + Environment.NewLine + error.CallStack;

                var targetEx = errorEx as TargetInvocationException;
                if (targetEx != null && targetEx.InnerException != null)
                    throw new InvalidOperationException(errorMsg, targetEx.InnerException);

                var recursionEx = errorEx as RecursionDepthOverflowException;
                if (recursionEx != null)
                    errorMsg += Environment.NewLine + "Max recursion depth is limited to: " + MaxRecursionDepth;

                throw new InvalidOperationException(errorMsg, errorEx);
            }
        }