Exemplo n.º 1
0
        ///<summary>
        /// Format call stack as readable text for dumps
        ///</summary>
        ///<param name="afterEachLine">Insert this text after each line</param>
        ///<param name="afterLastLine">Insert this text after the last line</param>
        ///<param name="reverse">true, if print in reverse order</param>
        ///<param name="skipDuplicateOperations">if true, do not print operation if it did not change</param>
        ///<returns>Formatted call stack</returns>
        public string Format(string afterEachLine, string afterLastLine, bool reverse, bool skipDuplicateOperations)
        {
            StringBuilder sb = new StringBuilder();

            CallStackItem[] a = ToArray();
            if (reverse)
            {
                Array.Reverse(a);
            }
            bool            first        = true;
            ScriptOperation oldOperation = ScriptOperation.None;

            foreach (CallStackItem item in a)
            {
                sb.Append(first ? string.Empty : afterEachLine);
                if (!skipDuplicateOperations || item.Operation != oldOperation)
                {
                    sb.Append("[" + item.Operation + "]" + " ");
                }
                sb.Append(item.ScriptAction.ToString());
                first        = false;
                oldOperation = item.Operation;
            }
            sb.Append(afterLastLine);
            return(sb.ToString());
        }
        /// <summary>
        /// Handle Script As Update requests
        /// </summary>
        private static string QueueScriptOperation(
            ScriptOperation operation,
            ConnectionInfo connInfo,
            ObjectMetadata metadata)
        {
            // get or create the current parse info object
            ScriptParseInfo parseInfo = LanguageServiceInstance.GetScriptParseInfo(connInfo.OwnerUri);

            if (Monitor.TryEnter(parseInfo.BuildingMetadataLock, LanguageService.BindingTimeout))
            {
                try
                {
                    QueueItem queueItem = LanguageServiceInstance.BindingQueue.QueueBindingOperation(
                        key: parseInfo.ConnectionKey,
                        bindingTimeout: ScriptingService.ScriptingOperationTimeout,
                        bindOperation: (bindingContext, cancelToken) =>
                    {
                        if (operation == ScriptOperation.Select)
                        {
                            return(string.Format(
                                       @"SELECT TOP 1000 * " + Environment.NewLine + @"FROM {0}.{1}",
                                       metadata.Schema, metadata.Name));
                        }
                        else if (operation == ScriptOperation.Create)
                        {
                            return(ScriptAsCreate(bindingContext, connInfo, metadata));
                        }
                        else if (operation == ScriptOperation.Update)
                        {
                            return(ScriptAsUpdate(bindingContext, connInfo, metadata));
                        }
                        else if (operation == ScriptOperation.Insert)
                        {
                            return(ScriptAsInsert(bindingContext, connInfo, metadata));
                        }
                        else if (operation == ScriptOperation.Delete)
                        {
                            return(ScriptAsDelete(bindingContext, connInfo, metadata));
                        }
                        else
                        {
                            return(null);
                        }
                    });

                    queueItem.ItemProcessed.WaitOne();

                    return(queueItem.GetResultAsT <string>());
                }
                finally
                {
                    Monitor.Exit(parseInfo.BuildingMetadataLock);
                }
            }

            return(string.Empty);
        }
Exemplo n.º 3
0
        /// Execute the given script action on call stack
        protected object RunOnStack(ScriptOperation operation, IScriptAction action, ScriptExecuteMethod method)
        {
            if (action == null)
            {
                return(null);
            }

            using (var scope = new ScriptContextScope(this))
            {
                _callStack.Push(operation, action);

                OnProgress(0);
                try
                {
                    // one can put a breakpoint here to be called on every method call
                    object ret = method();
                    OnProgressInternal(100, null);
                    return(ret);
                }
                catch (ScriptTerminateException)
                {
                    throw;
                }
                catch (ScriptExceptionWithStackTrace)
                {
                    throw;
                }
                catch (ThreadAbortException)
                {
                    _abortStarted = true;
                    throw;
                }
                catch (Exception e)
                {
                    throw new ScriptExceptionWithStackTrace(this, e);
                }
                finally
                {
                    _callStack.Pop();
                }
            }
        }
Exemplo n.º 4
0
 public CallStackItem(ScriptOperation operation, IScriptAction o)
 {
     Operation    = operation;
     ScriptAction = o;
 }
Exemplo n.º 5
0
 public void Push(ScriptOperation operation, IScriptAction action)
 {
     Push(new CallStackItem(operation, action));
 }
        private async Task <Mock <RequestContext <ScriptingScriptAsResult> > > SendAndValidateScriptRequest(ScriptOperation operation, string objectType)
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <ScriptingScriptAsResult> >();

            requestContext.Setup(x => x.SendResult(It.IsAny <ScriptingScriptAsResult>())).Returns(Task.FromResult(new object()));

            var scriptingParams = new ScriptingScriptAsParams
            {
                OwnerUri  = result.ConnectionInfo.OwnerUri,
                Operation = operation,
                Metadata  = GenerateMetadata(objectType)
            };

            await ScriptingService.HandleScriptingScriptAsRequest(scriptingParams, requestContext.Object);

            return(requestContext);
        }
Exemplo n.º 7
0
        private async Task <Mock <RequestContext <ScriptingScriptAsResult> > > SendAndValidateScriptRequest(ScriptOperation operation)
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <ScriptingScriptAsResult> >();

            requestContext.Setup(x => x.SendResult(It.IsAny <ScriptingScriptAsResult>())).Returns(Task.FromResult(new object()));

            var scriptingParams = new ScriptingScriptAsParams
            {
                OwnerUri  = result.ConnectionInfo.OwnerUri,
                Operation = operation,
                Metadata  = new ObjectMetadata()
                {
                    MetadataType     = MetadataType.Table,
                    MetadataTypeName = "Table",
                    Schema           = SchemaName,
                    Name             = TableName
                }
            };

            await ScriptingService.HandleScriptingScriptAsRequest(scriptingParams, requestContext.Object);

            return(requestContext);
        }