Exemple #1
0
        /// <summary>
        /// Processes script declarations. Opens a datum. 
        /// Creates the script node and the initial "begin" expression.
        /// Generates the variable lookup. Pushes return types.
        /// </summary>
        /// <param name="context"></param>
        public override void EnterScriptDeclaration(HS_Gen1Parser.ScriptDeclarationContext context)
        {
            if(_debug)
            {
                _logger.Script(context, CompilerContextAction.Enter);
            }

            // Create new script object and add it to the table.
            Script script = ScriptObjectCreation.GetScriptFromContext(context, _currentIndex, _opcodes);
            _scripts.Add(script);

            // Generate the parameter lookup.
            for(ushort i = 0; i < script.Parameters.Count; i++)
            {
                ScriptParameter parameter = script.Parameters[i];
                var info = new ParameterInfo(parameter.Name, _opcodes.GetTypeInfo(parameter.Type).Name, i);
                _parameterLookup.Add(info.Name, info);
            }

            string returnType = context.VALUETYPE().GetTextSanitized();
            int expressionCount = context.expression().Count();

            // The final expression must match the return type of this script.
            _expectedTypes.PushType(returnType);
            // The other expressions can be of any type.
            if (expressionCount > 1)
            {
                _expectedTypes.PushTypes("void", expressionCount - 1);
            }

            CreateInitialBegin(returnType, context.GetCorrectTextPosition(_missingCarriageReturnPositions));
        }
Exemple #2
0
        public void ScriptWithTwoNoTypeParameters()
        {
            // Arrange
            var scriptContent = "param($a, $b) $a + $b";
            var aParameter    = new ScriptParameter {
                Name   = "a",
                Value  = "Good",
                Script = "param($argument) $argument + 4"
            };
            var bParameter = new ScriptParameter {
                Name   = "b",
                Value  = "Yo",
                Script = "param($argument) $argument + 'u'"
            };

            var expected = "Good4You";

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter, bParameter });

            // Assert
            Assert.NotNull(result);
            var actual = result.OutputObjectCollection.FormattedTextPresentation.Trim();

            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        private void CopyScriptParameter_Click(object sender, EventArgs e)
        {
            var selection = (SelectedObjectComboBoxItem)this.editorObjects.SelectedItem;
            var currentScriptParameter = selection.EditorObject as ScriptParameter;

            if (currentScriptParameter == null)
            {
                return;
            }

            var copiedScriptParameter = new ScriptParameter(currentScriptParameter);

            copiedScriptParameter.Name = GetScriptParameterName(currentScriptParameter);
            this.scriptParameters.Add(copiedScriptParameter);
            this.scriptParameters.Current = copiedScriptParameter;

            var comboBoxItem = new SelectedScriptParameterComboBoxItem(copiedScriptParameter);

            this.editorObjectComboItems.Add(comboBoxItem);
            this.editorObjects.SelectedItem  = comboBoxItem;
            this.propertyGrid.SelectedObject = copiedScriptParameter;
            this.HasScriptParameterChanged   = true;
            UpdateCurrentScriptParameterFlag();
            UpdateCommandState();
        }
Exemple #4
0
        private string GetScriptParameterName(ScriptParameter parameterCopied)
        {
            string baseName      = parameterCopied.Name;
            string copyTextBase  = " - Copy";
            int    copyTextIndex = baseName.IndexOf(copyTextBase, StringComparison.CurrentCultureIgnoreCase);

            if (copyTextIndex > 0)
            {
                baseName = baseName.Substring(0, copyTextIndex);
            }
            string name = baseName + copyTextBase;

            if (!ScriptParameterNameExists(name))
            {
                return(name);
            }

            for (int i = 2; i < 100; ++i)
            {
                name = baseName + copyTextBase + " " + i.ToString(CultureInfo.InvariantCulture);
                if (!ScriptParameterNameExists(name))
                {
                    return(name);
                }
            }
            return(name);
        }
Exemple #5
0
        public EnumControl(ScriptParameter p, string ObiFont)
            : this()
        {
            m_Parameter = p;
            m_EnumData  = (DataTypes.EnumDataType)p.ParameterDataType;

            mNiceNameLabel.Text      = GetLocalizedString(p.NiceName);
            mComboBox.AccessibleName = GetLocalizedString(p.NiceName);
            base.DescriptionLabel    = GetLocalizedString(p.Description);

            DataTypes.EnumDataType EnumData = (DataTypes.EnumDataType)p.ParameterDataType;
            foreach (string s in EnumData.GetNiceNames)
            {
                mComboBox.Items.Add(s);
            }

            base.Size = this.Size;
            if (m_EnumData.SelectedIndex >= 0 && m_EnumData.SelectedIndex < m_EnumData.GetValues.Count)
            {
                mComboBox.SelectedIndex = m_EnumData.SelectedIndex;
            }
            if (ObiFont != this.Font.Name)
            {
                this.Font = new Font(ObiFont, this.Font.Size, FontStyle.Regular);//@fontconfig
            }
        }
Exemple #6
0
        public static Script GetScriptFromContext(HS_Gen1Parser.ScriptDeclarationContext context, DatumIndex rootExpressionIndex, OpcodeLookup opcodes)
        {
            // Create a new Script.
            Script script = new Script
            {
                Name                = context.scriptID().GetTextSanitized(),
                ExecutionType       = (short)opcodes.GetScriptTypeOpcode(context.SCRIPTTYPE().GetTextSanitized()),
                ReturnType          = (short)opcodes.GetTypeInfo(context.VALUETYPE().GetTextSanitized()).Opcode,
                RootExpressionIndex = rootExpressionIndex
            };
            // Handle scripts with parameters.
            var parameterContext = context.scriptParameters();

            if (parameterContext != null)
            {
                var parameters = parameterContext.parameter();
                for (ushort i = 0; i < parameters.Length; i++)
                {
                    string name          = parameters[i].ID().GetTextSanitized();
                    var    valueTypeNode = parameters[i].VALUETYPE();
                    string valueType     = valueTypeNode is null ? "script" : valueTypeNode.GetTextSanitized();

                    // Add the parameter to the script object.
                    ScriptParameter parameter = new ScriptParameter
                    {
                        Name = name,
                        Type = opcodes.GetTypeInfo(valueType).Opcode
                    };
                    script.Parameters.Add(parameter);
                }
            }
            return(script);
        }
 void RaiseOnSliderValueChanged(ScriptParameter parameter)
 {
     if (this.SliderValueChanged == null)
     {
         return;
     }
     this.SliderValueChanged(this, new ScriptParameterEventArgs(parameter));
 }
 /// <inheritdoc />
 public override void VisitScriptParameter(ScriptParameter parameter)
 {
     if (existing.Contains(parameter.Variable.Name))
     {
         return;
     }
     parameters.Add(new ParameterInfo(parameter.Variable.Name, parameter.DefaultValue != null));
     existing.Add(parameter.Variable.Name);
 }
    public void ReceiveScriptFlag(ScriptParameter scriptParameter)
    {
        ScriptFlag = true;
        ScriptCommand = scriptParameter.ScriptCommand;
        ArrayOfParameter = scriptParameter.ArrayOfParameter;

        MethodInfo methodInfo = this.GetType().GetMethod(ScriptCommand);
        methodInfo.Invoke(this, ArrayOfParameter);
    }
Exemple #10
0
        public PathDataType(ScriptParameter p, XmlNode DataTypeNode)
        {
            m_Parameter = p;
            m_Path      = p.ParameterValue;
            XmlNode ChildNode = DataTypeNode.FirstChild;

            m_FileOrDirectory = ChildNode.Name == "file" ? FileOrDirectory.File : FileOrDirectory.Directory;
            m_InputOrOutput   = ChildNode.Attributes.GetNamedItem("type").Value == "input" ? InputOrOutput.input : InputOrOutput.output;
        }
    public void ReceiveScriptFlag(ScriptParameter scriptParameter)
    {
        ScriptFlag       = true;
        ScriptCommand    = scriptParameter.ScriptCommand;
        ArrayOfParameter = scriptParameter.ArrayOfParameter;

        MethodInfo methodInfo = this.GetType().GetMethod(ScriptCommand);

        methodInfo.Invoke(this, ArrayOfParameter);
    }
Exemple #12
0
        private readonly string m_strFalse_Val; // string value being used by False flag in script

        public BoolDataType(ScriptParameter p, XmlNode DataTypeNode)
        {
            m_Parameter = p;
            XmlNode FirstChild = DataTypeNode.FirstChild;

            m_Val = p.ParameterValue == "1" ? true : false;
            //m_strTrue_Val = FirstChild.Attributes.GetNamedItem("true").Value;
            //m_strFalse_Val = FirstChild.Attributes.GetNamedItem("false").Value;
            m_strTrue_Val  = "true";
            m_strFalse_Val = "false";
        }
 void slider_ValueCurrentChanged(object sender, EventArgs e)
 {
     try {
         SliderComboControl slider = sender as SliderComboControl;
         ScriptParameter    scriptParameterChanged = slider.Tag as ScriptParameter;
         scriptParameterChanged.ValueCurrent = (double)slider.ValueCurrent;
         this.Strategy.DropChangedValueToScriptAndCurrentContextAndSerialize(scriptParameterChanged);
         this.RaiseOnSliderValueChanged(scriptParameterChanged);
     } catch (Exception ex) {
         Assembler.PopupException("slider_ValueCurrentChanged()", ex);
     }
 }
Exemple #14
0
        private SliderComboControl SliderComboFactory(ScriptParameter parameter)
        {
            //v1 WOULD_BE_TOO_EASY ret = this.templateSliderControl.Clone();
            //BEGIN merged with SlidersAutoGrow.Designer.cs:InitializeComponent()
            SliderComboControl ret = new SliderComboControl();

            //SCHEMA1
            //ret.ColorBgMouseOver = System.Drawing.Color.Gold;
            //ret.ColorBgValueCurrent = System.Drawing.SystemColors.ActiveCaption;
            //ret.ColorFgParameterLabel = System.Drawing.Color.RoyalBlue;
            //ret.ColorFgValues = System.Drawing.Color.Lime;
            //SCHEMA2
            //ret.ColorBgMouseOver = System.Drawing.Color.Gold;
            //ret.ColorBgValueCurrent = System.Drawing.Color.LightSteelBlue;
            //ret.ColorFgParameterLabel = System.Drawing.Color.AliceBlue;
            //ret.ColorFgValues = System.Drawing.Color.Magenta;
            //SCHEMA3
            //ret.ColorBgMouseOver = System.Drawing.Color.Thistle;
            //ret.ColorBgValueCurrent = System.Drawing.Color.LightSteelBlue;
            //ret.ColorFgParameterLabel = System.Drawing.Color.White;
            //ret.ColorFgValues = System.Drawing.Color.DeepPink;
            //Designer!
            ret.ColorBgMouseOverEnabled = this.templateSliderControl.ColorBgMouseOverEnabled;
//			ret.ColorBgMouseOverDisabled = this.templateSliderControl.ColorBgMouseOverDisabled;
            ret.ColorBgValueCurrent   = this.templateSliderControl.ColorBgValueCurrent;
            ret.ColorFgParameterLabel = this.templateSliderControl.ColorFgParameterLabel;
            ret.ColorFgValues         = this.templateSliderControl.ColorFgValues;

            //ret.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
            //ret.Padding = new System.Windows.Forms.Padding(4, 0, 4, 0);
            ret.Anchor             = this.templateSliderControl.Anchor;
            ret.Padding            = this.templateSliderControl.Padding;
            ret.PaddingPanelSlider = this.templateSliderControl.PaddingPanelSlider;
            //END merged

            ret.LabelText     = parameter.Name;
            ret.Name          = "parameter_" + parameter.Name;
            ret.ValueCurrent  = new decimal(parameter.ValueCurrent);
            ret.ValueMax      = new decimal(parameter.ValueMax);
            ret.ValueMin      = new decimal(parameter.ValueMin);
            ret.ValueStep     = new decimal(parameter.ValueIncrement);
            ret.EnableBorder  = this.AllSlidersHaveBorder;
            ret.EnableNumeric = this.AllSlidersHaveNumeric;
            //DOESNT_WORK?... ret.PanelFillSlider.Padding = new System.Windows.Forms.Padding(0, 1, 0, 0);
            //ret.PaddingPanelSlider = new System.Windows.Forms.Padding(0, 1, 0, 0);
            ret.Location             = new System.Drawing.Point(0, this.PreferredHeight + this.VerticalSpaceBetweenSliders);
            ret.Size                 = new System.Drawing.Size(this.Width, ret.Size.Height);
            ret.Tag                  = parameter;
            ret.ValueCurrentChanged += slider_ValueCurrentChanged;
            // WILL_ADD_PARENT_MENU_ITEMS_IN_Opening
            return(ret);
        }
Exemple #15
0
 public BoolControl(ScriptParameter p, string ObiFont)
     : this()
 {
     base.DescriptionLabel = GetLocalizedString(p.Description);
     checkBox1.Text        = GetLocalizedString(p.NiceName);
     m_Parameter           = p;
     m_boolDataType        = (DataTypes.BoolDataType)p.ParameterDataType;
     checkBox1.Checked     = m_boolDataType.Value;
     if (ObiFont != this.Font.Name)
     {
         this.Font = new Font(ObiFont, this.Font.Size, FontStyle.Regular);//@fontconfig
     }
 }
Exemple #16
0
    protected override string?PropertyValidation(PropertyInfo pi)
    {
        if (pi.Name == nameof(Name) && Name != scriptParameter.Name)
        {
            return(ValidationMessage._0ShouldBe12.NiceToString(pi.NiceName(), ComparisonType.EqualTo.NiceToString(), scriptParameter.Name));
        }

        if (pi.Name == nameof(Value))
        {
            return(ScriptParameter.Validate(this.Value, this.ScriptParameter.GetToken(this.ParentChart)));
        }

        return(base.PropertyValidation(pi));
    }
Exemple #17
0
        public EnumDataType(ScriptParameter p, XmlNode node)
        {
            m_Parameter     = p;
            m_ValueList     = new List <string>();
            m_NiceNameList  = new List <string>();
            m_SelectedIndex = -1;
            PopulateListFromNode(node);

            // select list node as default value if default  exists
            if (p.ParameterValue != null && p.ParameterValue != "" &&
                m_ValueList.Contains(p.ParameterValue))
            {
                m_SelectedIndex = m_ValueList.BinarySearch(p.ParameterValue);
            }
        }
Exemple #18
0
        private Script ReadScript(BinaryReader reader)
        {
            Script script = new Script();

            // Read the name and source code.
            script.Name     = ReadString(reader);
            script.Code     = ReadString(reader);
            script.IsHidden = reader.ReadBoolean();

            // Read the parameters.
            int paramCount = reader.ReadInt32();

            for (int i = 0; i < paramCount; i++)
            {
                ScriptParameter param = new ScriptParameter();
                param.Type = ReadString(reader);
                param.Name = ReadString(reader);
                script.Parameters.Add(param);
            }

            // Read errors and warnings.
            int errorCount = reader.ReadInt32();

            for (int i = 0; i < errorCount; i++)
            {
                ScriptCompileError error = new ScriptCompileError();
                error.Line        = reader.ReadInt32();
                error.Column      = reader.ReadInt32();
                error.ErrorNumber = ReadString(reader);
                error.ErrorText   = ReadString(reader);
                error.IsWarning   = true;
                script.Errors.Add(error);
            }
            int warningCount = reader.ReadInt32();

            for (int i = 0; i < warningCount; i++)
            {
                ScriptCompileError warning = new ScriptCompileError();
                warning.Line        = reader.ReadInt32();
                warning.Column      = reader.ReadInt32();
                warning.ErrorNumber = ReadString(reader);
                warning.ErrorText   = ReadString(reader);
                warning.IsWarning   = true;
                script.Warnings.Add(warning);
            }

            return(script);
        }
        public StringDataType(ScriptParameter p, XmlNode DataTypeNode)
        {
            m_Parameter = p;

            m_Val = p.ParameterValue;

            XmlNode FirstChild = DataTypeNode.FirstChild;

            if (FirstChild.Attributes.Count > 0)
            {
                m_RegularExpression = FirstChild.Attributes.GetNamedItem("regex").Value;
            }
            else
            {
                m_RegularExpression = "";
            }
        }
        public PathBrowserControl(ScriptParameter p, string SelectedPath, string ProjectDirectory, string ObiFont)
            : this()
        {
            m_SelectedPath     = SelectedPath;
            m_ProjectDirectory = ProjectDirectory;
            m_Parameter        = p;
            mPathData          = (DataTypes.PathDataType)p.ParameterDataType;

            int wdiff = mNiceNameLabel.Width;

            mNiceNameLabel.Text = GetLocalizedString(p.NiceName);
            wdiff -= mNiceNameLabel.Width;
            if (wdiff < 0)
            {
                Point location = mNiceNameLabel.Location;
                Width -= wdiff;
                mNiceNameLabel.Location = location;
            }
            else
            {
                mNiceNameLabel.Location = new Point(mNiceNameLabel.Location.X - wdiff, mNiceNameLabel.Location.Y);
            }
            mTextBox.AccessibleName = GetLocalizedString(p.Description);
            base.DescriptionLabel   = GetLocalizedString(p.Description);
            if (mLabel.Width + mLabel.Margin.Horizontal > Width)
            {
                Width = mLabel.Width + mLabel.Margin.Horizontal;
            }
            if (mPathData.isInputOrOutput == PipelineInterface.DataTypes.PathDataType.InputOrOutput.input)
            {
                mTextBox.Text = SelectedPath;
            }
            else if (mPathData.IsFileOrDirectory == PipelineInterface.DataTypes.PathDataType.FileOrDirectory.Directory)
            {
                mTextBox.Text = Path.IsPathRooted(p.ParameterValue) ? p.ParameterValue :
                                Path.GetFullPath(Path.Combine(ProjectDirectory, p.ParameterValue));
            }
            else
            {
                mTextBox.Text = p.ParameterValue;
            }
            if (ObiFont != this.Font.Name)
            {
                this.Font = new Font(ObiFont, this.Font.Size, FontStyle.Regular);//@fontconfig
            }
        }
Exemple #21
0
        /// <summary>
        /// Checks if the extension of the specified file matches with one
        /// of the extensions recognized as sql script files.
        /// </summary>
        /// <param name="fileName">The file name</param>
        /// <returns>
        /// <c>true</c> if the specified file name ends with a sql script extension; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsSqlScript(ScriptParameter currentPararmeter, string fileName)
        {
            IEnumerable <string> extensions = currentPararmeter.ScriptExtensions;

            if (extensions == null || !extensions.GetEnumerator().MoveNext())
            {
                extensions = DefaultScriptExtensions;
            }
            foreach (string extension in extensions)
            {
                if (fileName.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #22
0
        public void ArgumentTransformationErrorMakesScriptFail()
        {
            // Arrange
            var scriptContent = "param([Parameter()][int]$a) $result = $a + 5; $result";
            var aParameter    = new ScriptParameter {
                Name   = "a",
                Value  = 1,
                Script = "param($argument) throw 'ArgTransformError'; $argument + 2"
            };
            var expectedError = "ArgTransformError";

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter });

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(Types.ScriptState.Error, result.State);
            Assert.IsTrue(result.Reason.Contains(expectedError));
        }
Exemple #23
0
        public void SwitchParameter()
        {
            // Arrange
            var scriptContent = "param([Parameter()][Switch]$a) if ($a) { 5 } else { 0 }";
            var aParameter    = new ScriptParameter {
                Name = "a"
            };
            var expected = 5;

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter });

            // Assert
            Assert.NotNull(result);
            Assert.IsTrue(int.TryParse(
                              result.OutputObjectCollection.FormattedTextPresentation.Trim(),
                              out var actual));
            Assert.AreEqual(expected, actual);
        }
Exemple #24
0
        /// <summary>
        /// Apply the renaming of a grouped script to all items in the group.
        /// </summary>
        /// <param name="projectItem">The project item renamed.</param>
        /// <param name="oldName">The old name of the project item</param>
        public static void OnRename(ProjectItem projectItem, string oldName)
        {
            if (isRenaming)
            {
                return;
            }

            SettingsManager settingsManager = SettingsManager.GetInstance(projectItem.DTE);
            ScriptParameter scriptParameter = settingsManager.CurrentScriptParameter;

            if (!FileClassification.IsSqlScript(scriptParameter, oldName))
            {
                return;
            }

            if (projectItem.ProjectItems == null || projectItem.ProjectItems.Count == 0)
            {
                return;
            }

            string oldStem = Path.GetFileNameWithoutExtension(oldName);
            string newName = projectItem.get_FileNames(1);
            string newStem = Path.GetFileNameWithoutExtension(newName);

            if (newStem.ToLowerInvariant().EndsWith(".all"))
            {
                newStem = Path.GetFileNameWithoutExtension(newStem);
            }

            isRenaming = true;
            try {
                projectItem.DTE.SuppressUI = true;
                foreach (ProjectItem subItem in projectItem.ProjectItems)
                {
                    RenameSubItem(subItem, oldStem, newStem);
                }
            }
            finally {
                projectItem.DTE.SuppressUI = false;
                isRenaming = false;
            }
        }
Exemple #25
0
        public void ScriptWithOneParameter()
        {
            // Arrange
            var scriptContent = "param([Parameter()][int]$a) $result = $a + 5; $result";
            var aParameter    = new ScriptParameter {
                Name  = "a",
                Value = 1
            };
            var expected = 6;

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter });

            // Assert
            Assert.NotNull(result);
            Assert.IsTrue(int.TryParse(
                              result.OutputObjectCollection.FormattedTextPresentation.Trim(),
                              out var actual));
            Assert.AreEqual(expected, actual);
        }
Exemple #26
0
        public IntDataType(ScriptParameter p, XmlNode DataTypeNode)
        {
            m_Parameter = p;

            XmlNode FirstChild = DataTypeNode.FirstChild;

            if (FirstChild.Attributes.Count > 0)
            {
                string min = FirstChild.Attributes.GetNamedItem("min").Value;
                string max = FirstChild.Attributes.GetNamedItem("max").Value;

                m_Min = int.Parse(min);
                m_Max = int.Parse(max);
            }
            else
            {
                m_Max = 231;
                m_Min = -231;
            }
        }
Exemple #27
0
        public StringControl(ScriptParameter p, string ObiFont)
            : this()
        {
            m_Parameter  = p;
            m_StringData = (DataTypes.StringDataType)p.ParameterDataType;

            label1.Text             = GetLocalizedString(p.NiceName);
            textBox1.AccessibleName = GetLocalizedString(p.Description);
            if (p.ParameterValue != null)
            {
                textBox1.Text = p.ParameterValue;
            }

            base.DescriptionLabel = GetLocalizedString(p.Description);



            int wdiff = label1.Width;

            wdiff -= label1.Width;
            if (wdiff < 0)
            {
                Point location = label1.Location;
                Width          -= wdiff;
                label1.Location = location;
            }
            else
            {
                label1.Location = new Point(label1.Location.X - wdiff, label1.Location.Y);
            }
            if (mLabel.Width + mLabel.Margin.Horizontal > Width)
            {
                Width = mLabel.Width + mLabel.Margin.Horizontal;
            }
            base.Size = this.Size;
            if (ObiFont != this.Font.Name)
            {
                this.Font = new Font(ObiFont, this.Font.Size, FontStyle.Regular);//@fontconfig
            }
        }
Exemple #28
0
        public void PSObjectTransformation()
        {
            // Arrange
            var scriptContent = "param($a) $a.Age += 15; $a";
            var aParameter    = new ScriptParameter {
                Name   = "a",
                Value  = "{'Name':'Dimitar','Age':23}",
                Script = "param($argument) ConvertFrom-Json $argument"
            };

            var expectedName = "\"Name\": \"Dimitar\"";
            var expectedAge  = "\"Age\": 38";

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter }, Types.OutputObjectsFormat.Json);

            // Assert
            Assert.NotNull(result);
            var actual = result.OutputObjectCollection.SerializedObjects[0];

            Assert.IsTrue(actual.Contains(expectedName));
            Assert.IsTrue(actual.Contains(expectedAge));
        }
Exemple #29
0
        public override bool CanExecute(VsCommandEventArgs e)
        {
            if (IsExecuting)
            {
                return(false);
            }

            DTE2     application    = e.Application;
            Document activeDocument = application.ActiveDocument;

            if (activeDocument == null)
            {
                return(false);
            }

            SettingsManager settingsManager = SettingsManager.GetInstance(application);
            ScriptParameter scriptParameter = settingsManager.CurrentScriptParameter;

            string fileName    = activeDocument.FullName;
            bool   isSqlScript = FileClassification.IsSqlScript(scriptParameter, fileName);

            return(isSqlScript);
        }
Exemple #30
0
        public IntControl(ScriptParameter p, string ObiFont)
            : this()
        {
            m_Parameter = p;
            m_IntData   = (DataTypes.IntDataType)p.ParameterDataType;

            mNiceNameLabel.Text = GetLocalizedString(p.NiceName);

            mIntBox.AccessibleName = GetLocalizedString(p.Description);
            if (p.ParameterValue != null)
            {
                mIntBox.Text = p.ParameterValue;
            }
            base.DescriptionLabel = GetLocalizedString(p.Description);

            int x_IntBox = mNiceNameLabel.Location.X + mNiceNameLabel.Width + mNiceNameLabel.Margin.Right + mIntBox.Margin.Left;

            mIntBox.Location = new Point(x_IntBox, mIntBox.Location.Y);
            if (ObiFont != this.Font.Name)
            {
                this.Font = new Font(ObiFont, this.Font.Size, FontStyle.Regular);//@fontconfig
            }
        }
Exemple #31
0
        public void ArgumentTransformationStreamsAreHandled()
        {
            // Arrange
            var scriptContent = "param([Parameter()][int]$a) $result = $a + 5; $result";
            var aParameter    = new ScriptParameter {
                Name   = "a",
                Value  = 1,
                Script = "param($argument) Write-Error 'ArgTransformError'; $argument + 2"
            };
            var expected = 8;
            var expectedErrorStreamRecord = "ArgTransformError";

            // Act
            var result = _scriptExecutionEngine.ExecuteScript(scriptContent, new[] { aParameter });

            // Assert
            Assert.NotNull(result);
            Assert.IsTrue(int.TryParse(
                              result.OutputObjectCollection.FormattedTextPresentation.Trim(),
                              out var actual));
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(1, result.Streams.Error.Length);
            Assert.AreEqual(expectedErrorStreamRecord, result.Streams.Error[0].Message);
        }