예제 #1
0
        static bool IsCompoundOperandCode(ScriptArgument value)
        {
            switch (value)
            {
            case ScriptArgument.Address:
            case ScriptArgument.Literal:
            case ScriptArgument.Opcode:
            case ScriptArgument.String:
            case ScriptArgument.Value:
            case ScriptArgument.ValueOrVariable:
            case ScriptArgument.Variable:
            case ScriptArgument.Comparison:
                return(false);

            case ScriptArgument.Array:
            case ScriptArgument.Optional:
                return(false);

            case ScriptArgument.None:
                throw new ArgumentException("value");

            default:
                throw new NotImplementedException();
            }
        }
예제 #2
0
        public T Invoke <T>(string methodName, ScriptArgument argument)
        {
            if (methodName == null || methodName == string.Empty)
            {
                throw new ArgumentException("전달인자 메소드의 이름이 null 이거나 empty값 입니다.");
            }

            var type = _MethodDictionary[methodName];

            if (type == null)
            {
                throw new ArgumentException("전달받은 메소드의 이름이 스크립트에 존재하지 않습니다.");
            }

            //파라메터 얻기
            //var ty = type.MethodInfo.GetParameters();
            var result = type.MethodInfo.Invoke(_InstanceObject, null);

            return((T)result);
        }
예제 #3
0
        internal bool MatchTypeCode(ScriptArgument value)
        {
            switch (value)
            {
            case ScriptArgument.Address: return(Type == ScriptOperandType.Address);

            case ScriptArgument.Comparison: return(Type == ScriptOperandType.Comparison);

            case ScriptArgument.Literal:
            case ScriptArgument.Value: return(Type == ScriptOperandType.Value);

            case ScriptArgument.ValueOrVariable: return(Type == ScriptOperandType.Value || Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable);

            case ScriptArgument.String: return(Type == ScriptOperandType.String || Type == ScriptOperandType.StringVariable);

            case ScriptArgument.Variable: return(Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable);

            case ScriptArgument.Opcode:
            case ScriptArgument.Optional: throw new InvalidOperationException();

            default: throw new NotImplementedException();
            }
        }
예제 #4
0
        protected bool ReadOperand(BinaryReader reader, ScriptArgument operandCode)
        {
            int index = -1;

            return(ReadOperand(reader, null, ref index, operandCode));
        }
예제 #5
0
        protected bool ReadOperand(BinaryReader reader, string operands, ref int operandIndex, ScriptArgument operandCode)
        {
            long          offset = reader.BaseStream.Position;
            ScriptOperand token  = new ScriptOperand(reader, operandCode);

            token.Instruction = this;

            int outputIndex = OperandsMutable.Count;

            OperandsMutable.Add(token);
            switch (operandCode)
            {
            case ScriptArgument.Address:
            case ScriptArgument.Value:
            case ScriptArgument.ValueOrVariable:
            case ScriptArgument.String:
            case ScriptArgument.Variable:
            case ScriptArgument.Literal:
            case ScriptArgument.UnknownVariable:
            case ScriptArgument.Comparison:
                token.IsValid = token.MatchTypeCode(operandCode);
                break;

            case ScriptArgument.Array:
                ScriptArgument arrayCountType = (ScriptArgument)operands[++operandIndex];
                ScriptArgument arrayType      = (ScriptArgument)operands[++operandIndex];

                if (IsCompoundOperandCode(arrayCountType) || IsCompoundOperandCode(arrayType))
                {
                    throw new InvalidOperationException();
                }

                token.IsValid = token.MatchTypeCode(arrayCountType);
                if (!token.IsValid)
                {
                    OperandsMutable[outputIndex] = token;
                    return(false);
                }

                for (int index = 0; index < token.AsValue; index++)
                {
                    if (!ReadOperand(reader, operands, ref operandIndex, arrayType))
                    {
                        return(false);
                    }
                }
                break;

            case ScriptArgument.Optional:
                operandCode = (ScriptArgument)operands[++operandIndex];
                if (!token.MatchTypeCode(operandCode))
                {
                    reader.BaseStream.Position = offset;
                    OperandsMutable.RemoveAt(outputIndex);
                    return(true);
                }
                break;

            default:
                throw new InvalidOperationException("Invalid operand type code '" + operandCode + "'.");
            }

            OperandsMutable[outputIndex] = token;
            return(true);
        }
예제 #6
0
 /// <summary>
 /// Attribute가 붙은 스크립트 메소드를 Invoke 합니다.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="methodName"></param>
 /// <param name="argument"></param>
 /// <returns></returns>
 public T Invoke <T>(string methodName, ScriptArgument argument)
 {
     return(default(T));
 }
예제 #7
0
 static bool IsCompoundOperandCode(ScriptArgument value)
 {
     switch (value) {
         case ScriptArgument.Address:
         case ScriptArgument.Literal:
         case ScriptArgument.Opcode:
         case ScriptArgument.String:
         case ScriptArgument.Value:
         case ScriptArgument.ValueOrVariable:
         case ScriptArgument.Variable:
         case ScriptArgument.Comparison:
             return false;
         case ScriptArgument.Array:
         case ScriptArgument.Optional:
             return false;
         case ScriptArgument.None:
             throw new ArgumentException("value");
         default:
             throw new NotImplementedException();
     }
 }
예제 #8
0
 protected bool ReadOperand(BinaryReader reader, ScriptArgument operandCode)
 {
     int index = -1;
     return ReadOperand(reader, null, ref index, operandCode);
 }
예제 #9
0
        protected bool ReadOperand(BinaryReader reader, string operands, ref int operandIndex, ScriptArgument operandCode)
        {
            long offset = reader.BaseStream.Position;
            ScriptOperand token = new ScriptOperand(reader, operandCode);
            token.Instruction = this;

            int outputIndex = OperandsMutable.Count;
            OperandsMutable.Add(token);
            switch (operandCode) {
                case ScriptArgument.Address:
                case ScriptArgument.Value:
                case ScriptArgument.ValueOrVariable:
                case ScriptArgument.String:
                case ScriptArgument.Variable:
                case ScriptArgument.Literal:
                case ScriptArgument.UnknownVariable:
                case ScriptArgument.Comparison:
                    token.IsValid = token.MatchTypeCode(operandCode);
                    break;

                case ScriptArgument.Array:
                    ScriptArgument arrayCountType = (ScriptArgument)operands[++operandIndex];
                    ScriptArgument arrayType = (ScriptArgument)operands[++operandIndex];

                    if (IsCompoundOperandCode(arrayCountType) || IsCompoundOperandCode(arrayType))
                        throw new InvalidOperationException();

                    token.IsValid = token.MatchTypeCode(arrayCountType);
                    if (!token.IsValid) {
                        OperandsMutable[outputIndex] = token;
                        return false;
                    }

                    for (int index = 0; index < token.AsValue; index++)
                        if (!ReadOperand(reader, operands, ref operandIndex, arrayType))
                            return false;
                    break;

                case ScriptArgument.Optional:
                    operandCode = (ScriptArgument)operands[++operandIndex];
                    if (!token.MatchTypeCode(operandCode)) {
                        reader.BaseStream.Position = offset;
                        OperandsMutable.RemoveAt(outputIndex);
                        return true;
                    }
                    break;

                default:
                    throw new InvalidOperationException("Invalid operand type code '" + operandCode + "'.");
            }

            OperandsMutable[outputIndex] = token;
            return true;
        }
예제 #10
0
        /// <summary></summary>
        public ScriptOperand(BinaryReader reader, ScriptArgument expected)
        {
            ScriptOperandType value = (ScriptOperandType)reader.ReadByte();

            // Expectations can transform the result due to overlapping in coding, so deal with them here.
            switch (expected)
            {
            case ScriptArgument.Literal:                     // Single code byte, any value
                Type             = ScriptOperandType.Value;
                CoreIntegerValue = (byte)value;
                return;

            case ScriptArgument.Opcode:                     // Single byte, any value
                if (value == ScriptOperandType.Value || value == ScriptOperandType.Variable || value == ScriptOperandType.UnknownVariable)
                {
                    Type             = ScriptOperandType.Opcode;
                    CoreIntegerValue = (byte)value;
                    return;
                }
                break;

            case ScriptArgument.Address:                     // 0x01
                if (value == ScriptOperandType.Variable)
                {
                    Type             = ScriptOperandType.Address;
                    CoreIntegerValue = reader.ReadUInt16();
                    return;
                }
                break;

            case ScriptArgument.Comparison:                     // Single code byte
                Type             = ScriptOperandType.Comparison;
                CoreIntegerValue = (byte)value;
                return;

            default:
                break;
            }

            // Now we can freely handle the data.
            switch (value)
            {
            case ScriptOperandType.Value:                     // 0x00
                Type             = ScriptOperandType.Value;
                CoreIntegerValue = reader.ReadByte();
                break;

            case ScriptOperandType.Variable:                     // 0x01
                Type             = ScriptOperandType.Variable;
                CoreIntegerValue = reader.ReadUInt16();
                break;

            case ScriptOperandType.UnknownVariable:                     // 0x03
                Type             = ScriptOperandType.UnknownVariable;
                CoreIntegerValue = reader.ReadUInt16();
                break;

            case ScriptOperandType.String:                     // 0x80
                Type = ScriptOperandType.String;
                byte stringLength = reader.ReadByte();
                long end          = reader.BaseStream.Position + stringLength;
                CoreStringValue            = Engine.ReadCodedString(reader, stringLength + 1);
                reader.BaseStream.Position = end;
                break;

            case ScriptOperandType.StringVariable:                     // 0x81
                Type             = ScriptOperandType.StringVariable;
                CoreIntegerValue = reader.ReadUInt16();
                break;

            default:                     // Anything else
                Type             = ScriptOperandType.Opcode;
                CoreIntegerValue = (byte)value;
                break;
            }
        }
예제 #11
0
 public void Deconstruct(out ScriptArgument arg, out LabelReference offset)
 {
     arg    = Arg;
     offset = Offset;
 }
예제 #12
0
 public Branch(ScriptArgument arg, LabelReference offset)
 {
     Arg    = arg;
     Offset = offset;
 }
예제 #13
0
        internal bool MatchTypeCode(ScriptArgument value)
        {
            switch (value) {
                case ScriptArgument.Address: return Type == ScriptOperandType.Address;
                case ScriptArgument.Comparison: return Type == ScriptOperandType.Comparison;
                case ScriptArgument.Literal:
                case ScriptArgument.Value: return Type == ScriptOperandType.Value;
                case ScriptArgument.ValueOrVariable: return Type == ScriptOperandType.Value || Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable;
                case ScriptArgument.String: return Type == ScriptOperandType.String || Type == ScriptOperandType.StringVariable;
                case ScriptArgument.Variable: return Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable;

                case ScriptArgument.Opcode:
                case ScriptArgument.Optional: throw new InvalidOperationException();
                default: throw new NotImplementedException();
            }
        }
예제 #14
0
        /// <summary></summary>
        public ScriptOperand(BinaryReader reader, ScriptArgument expected)
        {
            ScriptOperandType value = (ScriptOperandType)reader.ReadByte();

            // Expectations can transform the result due to overlapping in coding, so deal with them here.
            switch (expected) {
                case ScriptArgument.Literal: // Single code byte, any value
                    Type = ScriptOperandType.Value;
                    CoreIntegerValue = (byte)value;
                    return;

                case ScriptArgument.Opcode: // Single byte, any value
                    if (value == ScriptOperandType.Value || value == ScriptOperandType.Variable || value == ScriptOperandType.UnknownVariable) {
                        Type = ScriptOperandType.Opcode;
                        CoreIntegerValue = (byte)value;
                        return;
                    }
                    break;

                case ScriptArgument.Address: // 0x01
                    if (value == ScriptOperandType.Variable) {
                        Type = ScriptOperandType.Address;
                        CoreIntegerValue = reader.ReadUInt16();
                        return;
                    }
                    break;

                case ScriptArgument.Comparison: // Single code byte
                    Type = ScriptOperandType.Comparison;
                    CoreIntegerValue = (byte)value;
                    return;

                default:
                    break;
            }

            // Now we can freely handle the data.
            switch (value) {
                case ScriptOperandType.Value: // 0x00
                    Type = ScriptOperandType.Value;
                    CoreIntegerValue = reader.ReadByte();
                    break;

                case ScriptOperandType.Variable: // 0x01
                    Type = ScriptOperandType.Variable;
                    CoreIntegerValue = reader.ReadUInt16();
                    break;

                case ScriptOperandType.UnknownVariable: // 0x03
                    Type = ScriptOperandType.UnknownVariable;
                    CoreIntegerValue = reader.ReadUInt16();
                    break;

                case ScriptOperandType.String: // 0x80
                    Type = ScriptOperandType.String;
                    byte stringLength = reader.ReadByte();
                    long end = reader.BaseStream.Position + stringLength;
                    CoreStringValue = Engine.ReadCodedString(reader, stringLength + 1);
                    reader.BaseStream.Position = end;
                    break;

                case ScriptOperandType.StringVariable: // 0x81
                    Type = ScriptOperandType.StringVariable;
                    CoreIntegerValue = reader.ReadUInt16();
                    break;

                default: // Anything else
                    Type = ScriptOperandType.Opcode;
                    CoreIntegerValue = (byte)value;
                    break;
            }
        }
예제 #15
0
        public void RunsTask()
        {
            _engine      = new AutomationEngineInstance(null);
            _runTask     = new RunTaskCommand();
            _textFile    = new TextFile.WriteCreateTextFileCommand();
            _setVariable = new Variable.SetVariableCommand();
            _taskScript  = new Script();

            List <ScriptVariable> variables = new List <ScriptVariable>();
            ScriptVariable        var1      = new ScriptVariable();

            var1.VariableName  = "output";
            var1.VariableValue = "outputValue";
            var1.VariableType  = typeof(string);
            variables.Add(var1);

            _taskScript.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // set script variables
            _taskScript.Variables = variables;

            List <ScriptArgument> arguments = new List <ScriptArgument>();
            ScriptArgument        arg1      = new ScriptArgument();

            arg1.ArgumentName  = "inputArg";
            arg1.Direction     = ScriptArgumentDirection.In;
            arg1.ArgumentValue = "default";
            arg1.ArgumentType  = typeof(string);
            arguments.Add(arg1);
            ScriptArgument arg2 = new ScriptArgument();

            arg2.ArgumentName     = "outputArg";
            arg2.Direction        = ScriptArgumentDirection.Out;
            arg2.ArgumentValue    = "default";
            arg2.AssignedVariable = "{outputVar}";
            arg2.ArgumentType     = typeof(string);
            arguments.Add(arg2);

            // set script arguments
            _taskScript.Arguments = arguments;

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string filePath         = Path.Combine(projectDirectory, @"Resources");

            _textFile.v_FilePath    = Path.Combine(filePath, @"test.txt");
            _textFile.v_TextToWrite = "{inputArg}";
            _textFile.v_Overwrite   = "Overwrite";
            _engine.AutomationEngineContext.FilePath = Path.Combine(filePath, "task.obscript");
            _engine.AutomationEngineContext.IsTest   = true;
            List <ScriptAction> commands = new List <ScriptAction>();
            ScriptAction        com1     = new ScriptAction();

            com1.ScriptCommand = _textFile;
            commands.Add(com1);

            _setVariable.v_Input = "outputValue";
            _setVariable.v_OutputUserVariableName = "{outputArg}";
            ScriptAction com2 = new ScriptAction();

            com2.ScriptCommand = _setVariable;
            commands.Add(com2);

            _taskScript.Commands = commands;

            //write to file
            var serializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Objects,
            };
            JsonSerializer serializer = JsonSerializer.Create(serializerSettings);

            using (StreamWriter sw = new StreamWriter(_engine.AutomationEngineContext.FilePath))
                using (JsonWriter writer = new JsonTextWriter(sw)
                {
                    Formatting = Formatting.Indented
                })
                {
                    serializer.Serialize(writer, _taskScript, typeof(Script));
                }

            DataTable argumentTable = new DataTable();

            argumentTable.Columns.Add("ArgumentName");
            argumentTable.Columns.Add("ArgumentType");
            argumentTable.Columns.Add("ArgumentValue");
            argumentTable.Columns.Add("ArgumentDirection");
            argumentTable.Columns[1].DataType = typeof(Type);
            DataRow arg1row = argumentTable.NewRow();

            arg1row["ArgumentName"]      = "inputArg";
            arg1row["ArgumentType"]      = typeof(string);
            arg1row["ArgumentValue"]     = "{taskInput}";
            arg1row["ArgumentDirection"] = "In";
            DataRow arg2row = argumentTable.NewRow();

            arg2row["ArgumentName"]      = "outputArg";
            arg2row["ArgumentType"]      = typeof(string);
            arg2row["ArgumentValue"]     = "{outputVar}";
            arg2row["ArgumentDirection"] = "Out";
            argumentTable.Rows.Add(arg1row);
            argumentTable.Rows.Add(arg2row);

            _runTask.v_TaskPath            = _engine.AutomationEngineContext.FilePath;
            _runTask.v_AssignArguments     = true;
            _runTask.v_ArgumentAssignments = argumentTable;

            List <ScriptAction> mainCommands  = new List <ScriptAction>();
            ScriptAction        runTaskAction = new ScriptAction();

            runTaskAction.ScriptCommand = _runTask;

            VariableMethods.CreateTestVariable("inputValue", _engine, "taskInput", typeof(string));
            VariableMethods.CreateTestVariable("default", _engine, "taskOutput", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "outputVar", typeof(string));

            _engine.ExecuteCommand(runTaskAction);

            Assert.Equal("outputValue", "{outputVar}".ConvertUserVariableToString(_engine));
            Assert.True(OBIO.File.Exists(Path.Combine(filePath, @"test.txt")));
            Assert.Equal("inputValue", OBIO.File.ReadAllText(Path.Combine(filePath, @"test.txt")));

            OBIO.File.Delete(Path.Combine(filePath, @"test.txt"));
            OBIO.File.Delete(Path.Combine(filePath, @"task.obscript"));
        }