public override void SetUp()
        {
            base.SetUp();

            _tableViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <TableDefinition> >();
            _unionViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <UnionViewDefinition> >();
            _filterViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <FilterViewDefinition> >();
            _emptyViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <EmptyViewDefinition> >();

            _builder = new ViewScriptBuilder(
                _tableViewElementFactoryStub,
                _unionViewElementFactoryStub,
                _filterViewElementFactoryStub,
                _emptyViewElementFactoryStub,
                new SqlCommentScriptElementFactory());

            _tableDefinition1      = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition2      = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _unionViewDefinition1  = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _unionViewDefinition2  = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _filterViewDefinition1 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _filterViewDefinition2 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _emptyViewDefinition1  = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _emptyViewDefinition2  = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
        public override void SetUp()
        {
            base.SetUp();

            _indexScriptElementFactoryStub = MockRepository.GenerateStub <IIndexScriptElementFactory>();

            _builder = new IndexScriptBuilder(_indexScriptElementFactoryStub, new SqlCommentScriptElementFactory());

            _indexDefinition1 = MockRepository.GenerateStub <IIndexDefinition>();
            _indexDefinition2 = MockRepository.GenerateStub <IIndexDefinition>();
            _indexDefinition3 = MockRepository.GenerateStub <IIndexDefinition>();

            _tableDefinition1 = TableDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition1 });
            _tableDefinition2 = TableDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition2, _indexDefinition3 });
            _unionViewDefinition1 = UnionViewDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition1 });
            _unionViewDefinition2 = UnionViewDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition2, _indexDefinition3 });
            _filterViewDefinition1 = FilterViewDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition1 });
            _filterViewDefinition2 = FilterViewDefinitionObjectMother.CreateWithIndexes(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _indexDefinition2, _indexDefinition3 });

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
Пример #3
0
        public override void SetUp()
        {
            base.SetUp();

            _factoryStub = MockRepository.GenerateStub <IForeignKeyConstraintScriptElementFactory>();

            _builder = new ForeignKeyConstraintScriptBuilder(_factoryStub, new SqlCommentScriptElementFactory());

            _tableName   = new EntityNameDefinition(null, "Table");
            _constraint1 = new ForeignKeyConstraintDefinition("FK1", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);
            _constraint2 = new ForeignKeyConstraintDefinition("FK2", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);
            _constraint3 = new ForeignKeyConstraintDefinition("FK3", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);

            _tableDefinition1 = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                _tableName,
                null,
                new[] { _constraint1 });
            _tableDefinition2 = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                _tableName,
                null,
                new[] { _constraint2, _constraint3 });

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
Пример #4
0
 /// <summary>
 /// Evals the element for identifier.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>System.String.</returns>
 protected override string EvalElementForId(IScriptElement value)
 {
     if (Constants.Scripts.GenericKeys.Any(s => s.Equals(value.Key, StringComparison.OrdinalIgnoreCase)))
     {
         return(value.Value);
     }
     return(base.EvalElementForId(value));
 }
Пример #5
0
        public void SetUp()
        {
            _elementCollection = new ScriptElementCollection();

            _elementMock1 = MockRepository.GenerateStrictMock <IScriptElement> ();
            _elementMock2 = MockRepository.GenerateStrictMock <IScriptElement> ();
            _elementMock3 = MockRepository.GenerateStrictMock <IScriptElement> ();
        }
Пример #6
0
 /// <summary>
 /// Evals the element for identifier.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>System.String.</returns>
 protected override string EvalElementForId(IScriptElement value)
 {
     if (Common.Constants.Scripts.GraphicsTypeName.Equals(value.Key, StringComparison.OrdinalIgnoreCase))
     {
         return(value.Value);
     }
     return(base.EvalElementForId(value));
 }
Пример #7
0
        /// <summary>
        /// Method to move the item into the clipboard.
        /// </summary>
        /// <param name="path"></param>
        public void MoveToClipboard(List <int> path)
        {
            clipboard_item = actions.GetElement(path);

            actions.Remove(path);

            clipboard_path = path;
            clipboard_path[clipboard_path.Count - 1] -= 1;
        }
Пример #8
0
 /// <summary>
 /// Evals the element for identifier.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>System.String.</returns>
 protected override string EvalElementForId(IScriptElement value)
 {
     if (parsingBookmark && value.Key.Equals("name", StringComparison.OrdinalIgnoreCase))
     {
         return(value.Value);
     }
     else if (value.Key.Equals("key", StringComparison.OrdinalIgnoreCase))
     {
         return(value.Value);
     }
     return(base.EvalElementForId(value));
 }
Пример #9
0
        public override void SetUp()
        {
            base.SetUp();

            _tableViewElementFactoryStub  = MockRepository.GenerateStub <ISynonymScriptElementFactory <TableDefinition> >();
            _unionViewElementFactoryStub  = MockRepository.GenerateStub <ISynonymScriptElementFactory <UnionViewDefinition> >();
            _filterViewElementFactoryStub = MockRepository.GenerateStub <ISynonymScriptElementFactory <FilterViewDefinition> >();
            _emptyViewElementFactoryStub  = MockRepository.GenerateStub <ISynonymScriptElementFactory <EmptyViewDefinition> >();

            _builder = new SynonymScriptBuilder(
                _tableViewElementFactoryStub,
                _unionViewElementFactoryStub,
                _filterViewElementFactoryStub,
                _emptyViewElementFactoryStub,
                new SqlCommentScriptElementFactory());

            _synonym1 = new EntityNameDefinition(null, "Synonym1");
            _synonym2 = new EntityNameDefinition(null, "Synonym2");
            _synonym3 = new EntityNameDefinition(null, "Synonym3");

            _tableDefinition1 = TableDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym1 });
            _tableDefinition2 = TableDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym2, _synonym3 });
            _unionViewDefinition1 = UnionViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym1 });
            _unionViewDefinition2 = UnionViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym2, _synonym3 });
            _filterViewDefinition1 = FilterViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym1 });
            _filterViewDefinition2 = FilterViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym2, _synonym3 });
            _emptyViewDefinition1 = EmptyViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym1 });
            _emptyViewDefinition2 = EmptyViewDefinitionObjectMother.CreateWithSynonyms(
                SchemaGenerationFirstStorageProviderDefinition,
                new[] { _synonym2, _synonym3 });

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
        public override void SetUp()
        {
            base.SetUp();

            _tableScriptfactoryStub = MockRepository.GenerateStub <ITableScriptElementFactory>();
            _builder = new TableScriptBuilder(_tableScriptfactoryStub, new SqlCommentScriptElementFactory());

            _tableDefinition1 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition2 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition3 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
Пример #11
0
        private void button_Apply_Click(object sender, EventArgs e)
        {
            IScriptElement element = (IScriptElement)listBox_ScriptMessages.SelectedItem;

            if (element.GetType() == typeof(ScriptMessage))
            {
                ScriptMessage message = (ScriptMessage)element;
                message.Content = richTextBox_ScriptMessage.Text.Replace("\n", "\r\n");
            }

            ScriptDocument script = (ScriptDocument)listBox_ScriptFiles.SelectedItem;

            ScriptParser.Parse(script, _elements);

            richTextBox_ScriptFile.Select(0, 0);
            richTextBox_ScriptFile.ScrollToCaret();
            richTextBox_ScriptFile.Text = script.TextBuffer;
        }
Пример #12
0
        /// <summary>
        /// Method for element moving.
        /// </summary>
        /// <param name="target">Element to move.</param>
        /// <param name="path">Set of indexes for destination identification.</param>
        /// <returns>True if the movement was successful, false otherwise.</returns>
        public bool MoveTo(IScriptElement target, List <int> path)
        {
            int root;

            // Check for adding to the root category, append the element in this case.
            if (path.Count == 0)
            {
                root = data.Count - 1;
            }
            else
            {
                // Special root edit for the attempt to put the element into zeroth place (after element -1, which
                // is non-existent).
                root = Math.Max(path[0], 0);
                path.RemoveAt(0);
            }

            if (path.Count == 0)
            {
                Type type = data[root].GetType();

                // Special check for an attempt to add an action to a condition array and vise-versa.
                if (!target.GetType().IsSubclassOf(type.BaseType))
                {
                    return(false);
                }

                // Another special check for an attempt to put the element after virtual elements.
                if ((type == typeof(VirtualNewAction)) || (type == typeof(VirtualNewCondition)))
                {
                    IScriptElement item = data[root];
                    data.Remove(item);
                    data.Add(target);
                    data.Add(item);
                }
                else
                {
                    data.Insert(root + 1, target);
                }
                return(true);
            }

            return(data[root].AddSubElement(target, path));
        }
Пример #13
0
        /// <summary>
        /// Formats the code.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="skipVariables">if set to <c>true</c> [skip variables].</param>
        /// <returns>System.String.</returns>
        protected virtual string FormatCode(IScriptElement element, string parent = Shared.Constants.EmptyParam, bool skipVariables = false)
        {
            void performVariableCheck(StringBuilder sb, string item)
            {
                // Ignore variables as they are separate definitions
                if (skipVariables)
                {
                    if (!item.Trim().StartsWith(Constants.Scripts.VariableId))
                    {
                        sb.AppendLine(item);
                    }
                }
                else
                {
                    sb.AppendLine(item);
                }
            }

            if (string.IsNullOrWhiteSpace(parent))
            {
                var code  = codeParser.FormatCode(element, 0);
                var lines = code.SplitOnNewLine();
                var sb    = new StringBuilder();
                foreach (var item in lines)
                {
                    performVariableCheck(sb, item);
                }
                return(sb.ToString());
            }
            else
            {
                var code  = codeParser.FormatCode(element, 1);
                var lines = code.SplitOnNewLine();
                var sb    = new StringBuilder();
                sb.AppendLine($"{parent} = {{");
                foreach (var item in lines)
                {
                    performVariableCheck(sb, item);
                }
                sb.Append("}");
                return(sb.ToString());
            }
        }
Пример #14
0
        /// <summary>
        /// Method for sub element addition.
        /// </summary>
        /// <param name="target">Element to add.</param>
        /// <param name="path">Set of indexes for destination identification.</param>
        /// <returns>True if the addition was successful, false otherwise.</returns>
        public override bool AddSubElement(IScriptElement target, List <int> path)
        {
            int root = path[0];

            path.RemoveAt(0);

            switch (root)
            {
            case 0:
                return(conditions.MoveTo(target, path));

            case 1:
                return(true_branch.MoveTo(target, path));

            case 2:
                return(false_branch.MoveTo(target, path));
            }

            return(false);
        }
Пример #15
0
        public void UpdateScriptMessage()
        {
            if (_changingMessageSelection)
            {
                return;
            }

            IScriptElement element = (IScriptElement)listBox_ScriptMessages.SelectedItem;

            if (element == null)
            {
                return;
            }
            if (element.GetType() == typeof(ScriptMessage))
            {
                ScriptMessage message = (ScriptMessage)element;
                message.Content = richTextBox_ScriptMessage.Text.Replace("\n", "\r\n");
                UpdatePreview(message);
            }

            ScriptDocument script = (ScriptDocument)listBox_ScriptFiles.SelectedItem;

            ScriptParser.Parse(script, _elements);

            _updatingMessage = true;

            Win32.LockWindow(this.Handle);
            int scrollPos = Win32.GetScrollPos(richTextBox_ScriptFile.Handle, 1);
            int pos       = richTextBox_ScriptFile.SelectionStart;
            int len       = richTextBox_ScriptFile.SelectionLength;

            richTextBox_ScriptFile.Text            = script.TextBuffer;
            richTextBox_ScriptFile.SelectionStart  = pos;
            richTextBox_ScriptFile.SelectionLength = len;
            Win32.SetScrollPos(richTextBox_ScriptFile.Handle, 1, scrollPos, true);
            Win32.PostMessage(richTextBox_ScriptFile.Handle, 0x115, 4 + 0x10000 * scrollPos, 0);
            Win32.LockWindow(IntPtr.Zero);

            _updatingMessage = false;
        }
        public override void SetUp()
        {
            base.SetUp();

            _indexDefinitionElementFactoryMock          = MockRepository.GenerateStub <ISqlIndexDefinitionScriptElementFactory <SqlIndexDefinition> >();
            _primaryIndexDefinitionElementFactoryMock   = MockRepository.GenerateStub <ISqlIndexDefinitionScriptElementFactory <SqlPrimaryXmlIndexDefinition> > ();
            _secondaryIndexDefinitionElementFactoryMock =
                MockRepository.GenerateStub <ISqlIndexDefinitionScriptElementFactory <SqlSecondaryXmlIndexDefinition> >();

            _factory = new SqlIndexScriptElementFactory(
                _indexDefinitionElementFactoryMock, _primaryIndexDefinitionElementFactoryMock, _secondaryIndexDefinitionElementFactoryMock);

            var simpleColumn  = ColumnDefinitionObjectMother.CreateColumn("Column");
            var indexedColumn = new SqlIndexedColumnDefinition(simpleColumn, IndexOrder.Desc);

            _entityNameDefinition     = new EntityNameDefinition(null, "Table");
            _indexDefinition          = new SqlIndexDefinition("Index1", new[] { indexedColumn });
            _primaryIndexDefinition   = new SqlPrimaryXmlIndexDefinition("Index2", simpleColumn);
            _secondaryIndexDefinition = new SqlSecondaryXmlIndexDefinition(
                "Index3", simpleColumn, "PrimaryIndexName", SqlSecondaryXmlIndexKind.Property);

            _fakeScriptElement = MockRepository.GenerateStub <IScriptElement>();
        }
 private void AddElements(IScriptElement createElement, IScriptElement dropElement)
 {
     _createScriptElements.AddElement(createElement);
     _dropScriptElements.AddElement(dropElement);
 }
Пример #18
0
 /// <summary>
 /// Method for sub element addition.
 /// </summary>
 /// <param name="target">Element to add.</param>
 /// <param name="path">Set of indexes for destination identification.</param>
 /// <returns>True, if the addition was successful, false otherwise.</returns>
 public virtual bool AddSubElement(IScriptElement target, List <int> path)
 {
     return(false);
 }
Пример #19
0
 IHeadElement IContentModel<IHeadElement, IScriptElement>.this[IScriptElement child]
 {
     get { return this[child]; }
 }
Пример #20
0
 /// <summary>
 /// Evals the element for identifier.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>System.String.</returns>
 protected virtual string EvalElementForId(IScriptElement value)
 {
     return(string.Empty);
 }
Пример #21
0
 /// <summary>
 /// Removal method.
 /// </summary>
 /// <param name="element">Element to remove.</param>
 public void Remove(IScriptElement element)
 {
     data.Remove(element);
 }
        public void AddElement(IScriptElement element)
        {
            ArgumentUtility.CheckNotNull("element", element);

            _elements.Add(element);
        }
Пример #23
0
 IHeadElement IContentModel <IHeadElement, IScriptElement> .this[IScriptElement child]
 {
     get { return(this[child]); }
 }
Пример #24
0
 /// <summary>
 /// Addition method.
 /// </summary>
 /// <param name="element">Element to add.</param>
 public void Add(IScriptElement element)
 {
     data.Add(element);
 }
Пример #25
0
 /// <summary>
 /// Formats the code.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="indentLevel">The indent level.</param>
 /// <returns>System.String.</returns>
 public string FormatCode(IScriptElement element, int indentLevel = 0)
 {
Пример #26
0
 private void AddIndexDefinition(SqlIndexDefinition indexDefinition, EntityNameDefinition ownerName)
 {
     _createScriptElement = _indexDefinitionElementFactory.GetCreateElement(indexDefinition, ownerName);
     _dropScriptElement   = _indexDefinitionElementFactory.GetDropElement(indexDefinition, ownerName);
 }
Пример #27
0
            static string format(IScriptElement element, int indent, bool noLeadingSpace = false)
            {
                var sb = new StringBuilder();

                if (element.IsSimpleType)
                {
                    if (!string.IsNullOrWhiteSpace(element.Value))
                    {
                        if (!string.IsNullOrWhiteSpace(element.Operator))
                        {
                            sb.Append($"{new string(' ', indent * 4)}{element.Key} {element.Operator} {element.Value}");
                        }
                        else
                        {
                            sb.Append($"{new string(' ', indent * 4)}{element.Key} {element.Value}");
                        }
                    }
                    else
                    {
                        sb.Append($"{new string(' ', indent * 4)}{element.Key}");
                    }
                }
                else
                {
                    var inlineChildValues = element.Values?.Where(p => Common.Constants.Scripts.InlineOperators.Any(a => a.Equals(p.Key, StringComparison.OrdinalIgnoreCase)));
                    if (inlineChildValues?.Count() > 0 && inlineChildValues.Count() == element.Values?.Count())
                    {
                        if (!string.IsNullOrWhiteSpace(element.Operator))
                        {
                            sb.Append($"{new string(' ', indent * 4)}{element.Key} {element.Operator} ");
                        }
                        else
                        {
                            sb.Append($"{new string(' ', indent * 4)}{element.Key} ");
                        }
                        if (element.Values.Count() > 0)
                        {
                            foreach (var value in element.Values)
                            {
                                sb.Append(format(value, indent, true));
                            }
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(element.Operator))
                        {
                            if (noLeadingSpace)
                            {
                                sb.AppendLine($"{element.Key} {element.Operator} {Common.Constants.Scripts.OpenObject}");
                            }
                            else
                            {
                                sb.AppendLine($"{new string(' ', indent * 4)}{element.Key} {element.Operator} {Common.Constants.Scripts.OpenObject}");
                            }
                        }
                        else
                        {
                            if (noLeadingSpace)
                            {
                                sb.AppendLine($"{element.Key} {Common.Constants.Scripts.OpenObject}");
                            }
                            else
                            {
                                sb.AppendLine($"{new string(' ', indent * 4)}{element.Key} {Common.Constants.Scripts.OpenObject}");
                            }
                        }
                        if (element.Values?.Count() > 0)
                        {
                            foreach (var value in element.Values)
                            {
                                sb.AppendLine(format(value, indent + 1));
                            }
                        }
                        sb.Append($"{new string(' ', indent * 4)}{Common.Constants.Scripts.CloseObject}");
                    }
                }
                return(sb.ToString());
            }