Exemplo n.º 1
0
        void GenerateCodeInMultipleFiles()
        {
            // first generate subroutines or paths
            // then main program to call them
            StringBuilder sb = new StringBuilder();

            foreach (Shape s in _currentToolPaths.Shapes)
            {
                if (s is Polygon)
                {
                    GenerateSubFromPolygon(ref sb, (s as Polygon));
                }
                else if (s is Windows.UI.Xaml.Shapes.Path)
                {
                    GenerateSubFromPath(ref sb, (s as Windows.UI.Xaml.Shapes.Path));
                }

                string filename = string.Empty;
                string ext      = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
                // now deal with name and save in code list
                if ((bool)BasicLib.GetSetting(SettingsNames.USE_NAMED_O_WORDS))
                {
                    BindableCodeTemplate tmpl = _context.Templates.SubFilenameTemplate;
                    tmpl.DataContext = _context;
                    filename         = System.IO.Path.ChangeExtension(tmpl.Text, ext);
                }
                else
                {
                    filename = System.IO.Path.ChangeExtension(_context.SubPathName.ToString(), ext);
                }
                Code.Add(new GcodeFile(filename, sb.ToString()));
            }

            GenerateMain();
        }
Exemplo n.º 2
0
        void GenerateCodeInSingleFile()
        {
            BindableCodeTemplate tmpl;
            StringBuilder        sb = new StringBuilder();

            Bind(ref sb, _context.Templates.Header_Template);
            Bind(ref sb, _context.Templates.Globals_Template);

            foreach (Shape s in _currentToolPaths.Shapes)
            {
                if (s is Polygon)
                {
                    GenerateSubFromPolygon(ref sb, (s as Polygon));
                }
                else if (s is Windows.UI.Xaml.Shapes.Path)
                {
                    GenerateSubFromPath(ref sb, (s as Windows.UI.Xaml.Shapes.Path));
                }
            }

            Bind(ref sb, _context.Templates.MainProgramTemplate);
            foreach (Shape s in _currentToolPaths.Shapes)
            {
                Bind(ref sb, _context.Templates.SubCallTemplate);
            }
            Bind(ref sb, _context.Templates.ProgramEndTemplate);
            tmpl             = _context.Templates.MainFilenameTemplate;
            tmpl.DataContext = _context;
            // now add main program
            Code.Add(new GcodeFile(tmpl.Text, sb.ToString()));
        }
Exemplo n.º 3
0
 private void EnsureMemory(long index)
 {
     while (index >= Code.Count)
     {
         Code.Add(0);
     }
 }
Exemplo n.º 4
0
 internal void Add(IEnumerable <int> ints)
 {
     Code.Add(ints.Count());
     foreach (var x in ints)
     {
         Code.Add(x);
     }
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var a = new Code();

            a.Add(new Using());
            a.Add(new Using());
            var n = new Namespace()
            {
                Name = "测试"
            };

            n.AddChunk(new Class()
            {
                Name = "测试"
            });

            n.AddChunk(new If());

            a.Add(n);
            File.WriteAllText("1.txt", a.ToString());
            Console.WriteLine(a);
        }
Exemplo n.º 6
0
        public T Register <T>(Type type) where T : ILStruct, new()
        {
            var source = Code.OfType <T>().FirstOrDefault(
                s => s.Type == type
                );

            source ??= ILStruct.Compile <T>(type, this);

            if (!Code.Contains(source))
            {
                Code.Add(source);
            }

            return(source);
        }
Exemplo n.º 7
0
        public T Compile <T>(MethodInfo info) where T : ILSource, new()
        {
            var source = Code.OfType <T>().FirstOrDefault(
                s => s.Info.Equals(info)
                );

            source ??= ILSource.Compile <T>(info, this);

            if (!Code.Contains(source))
            {
                Code.Add(source);
            }

            return(source);
        }
Exemplo n.º 8
0
        private void ParseCode(string s)
        {
            ParseParameters(s);
            var code  = s.GetTextBetween('{', '}');
            var lines = code.BeautifyMethod();

            foreach (var line in lines)
            {
                Code.Add(new Line(line, this));
            }
            if (Code.Any(x => x.hasReturn))
            {
                ReturnType = Code.Single(x => x.hasReturn).ReturnType.Value;
            }
        }
Exemplo n.º 9
0
        public string ExportLine(WordLibrary wl)
        {
            var codes = wl.Codes;

            if (IsShortCode)
            {
                codes = new Code();
                foreach (var c in wl.Codes)
                {
                    codes.Add(new List <string>()
                    {
                        c[0][0].ToString()
                    });
                }
            }
            return(string.Format(PhraseFormat, wl.Word, CollectionHelper.Descartes(codes)[0], wl.Rank == 0?DefaultRank:wl.Rank));
        }
Exemplo n.º 10
0
        private void Read_Script(uint obj_addr)
        {
            long prev_addr = Reader.BaseStream.Position;

            Reader.BaseStream.Seek(obj_addr, SeekOrigin.Begin);

            uint addr = Reader.ReadUInt32() - 4;

            Reader.BaseStream.Seek(addr, SeekOrigin.Begin);

            string codeString = Encoding.UTF8.GetString(Reader.ReadBytes(Reader.ReadInt32()));

            Debug.Assert(Reader.ReadByte() == 0);

            Code.Add(codeString);

            Reader.BaseStream.Seek(prev_addr, SeekOrigin.Begin);
        }
Exemplo n.º 11
0
        private void GenerateMain()
        {
            StringBuilder sb = new StringBuilder();

            Bind(ref sb, _context.Templates.Header_Template);
            Bind(ref sb, _context.Templates.Globals_Template);
            Bind(ref sb, _context.Templates.MainProgramTemplate);
            foreach (Shape s in _currentToolPaths.Shapes)
            {
                Bind(ref sb, _context.Templates.SubCallTemplate);
            }
            Bind(ref sb, _context.Templates.ProgramEndTemplate);

            string ext = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
            BindableCodeTemplate tmpl = _context.Templates.MainFilenameTemplate;

            tmpl.DataContext = _context;
            Code.Add(new GcodeFile(System.IO.Path.ChangeExtension(tmpl.Text, ext), sb.ToString()));
        }
Exemplo n.º 12
0
        public void RunComputation()
        {
            while (Code.currentOperationCode != 99)
            {
                switch (Code.currentOperationCode)
                {
                case 1:
                    Code.Add();
                    break;

                case 2:
                    Code.Multiply();
                    break;

                default:
                    break;
                }
                Code.MoveToNextExecutionSet();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Subroutines each have an individual header file
        /// </summary>
        /// <param name="cntxt"></param>
        void GenerateSubroutines()
        {
            foreach (List <Point> pl in CurrentPath)
            {
                CurrentPathIndex = CurrentPath.IndexOf(pl);
                BindableCodeTemplate tmpl;
                StringBuilder        sb = new StringBuilder();
                Bind(ref sb, _context.Templates.Header_Template);

                // add start of path
                Bind(ref sb, PathStartTemplate());

                // now generate points in path
                PathFragment points = new PathFragment(pl);
                //(_context.UseRotaryTable)
                //? MapToCylindricalList(pl) : MapToCartesianList(pl);
                if (!_context.UseAbsoluteMoves)
                {
                    points = OffsetList(points);
                }
                // loop round points in list
                foreach (Cartesian coord in points)
                {
                    CurrentPoint = coord;
                    tmpl         = (coord is Cartesian)
                         ?_context.Templates.XY_Point_Template
                         :_context.Templates.RA_Point_Template;

                    Bind(ref sb, tmpl);
                }
                // add end of path
                Bind(ref sb, PathEndTemplate());

                // now deal with name
                tmpl             = _context.Templates.SubFilenameTemplate;
                tmpl.DataContext = _context;
                Code.Add(new GcodeFile(tmpl.Text, sb.ToString()));
            }
        }
Exemplo n.º 14
0
Arquivo: Codegen.cs Projeto: hww/VARP
        private int GenerateCondition(AstCondition ast)
        {
            var temp = (byte)SP;

            if (ast.Conditions != null)
            {
                foreach (var v in ast.Conditions)
                {
                    var cond = v.AsLinkedList <Value>();
                    var c    = cond[0];
                    if (cond.count == 1)
                    {
                        Generate(cond[0].AsAST());
                    }
                    else if (cond.count > 1)
                    {
                        Generate(cond[0].AsAST());

                        // if ((bool)R(A) != (bool)C) then {skip next instruction}
                        Code.Add(Instruction.MakeABC(OpCode.TEST, temp, 0, 0));
                        var jmp_address = PC; Code.Add(Instruction.Nop);

                        Generate(cond[1].AsAST());

                        var else_address = PC;
                        Code[jmp_address] = Instruction.MakeASBX(OpCode.JMP, 0, Jmp(jmp_address, else_address));
                    }
                }
            }

            if (ast.ElseCase != null)
            {
                Generate(ast.ElseCase[1].AsAST());
            }

            SP = temp;
            return(temp);
        }
Exemplo n.º 15
0
        /// <summary>
        /// This is the code generator for abstract opcode
        /// different with arithmetics is the first expression
        /// returns true will terminate execution
        /// </summary>
        /// <param name="ast"></param>
        /// <param name="opcode"></param>
        /// <returns></returns>
        internal int GenerateAndOr(AstPrimitive ast, OpCode opcode)
        {
            var isOrOperation = opcode == OpCode.OR;
            var expected      = isOrOperation ? (short)1 : (short)0;
            /// This is the arguments list
            var args = ast.Arguments;
            /// Here will be jump instruction position for each argument
            var jumps = new int[args.Count];
            /// Put result to this value
            var result = Push();

            for (var i = 0; i < args.Count; i++)
            {
                var argpos = Generate(args[i].AsAST());
                /// =======================================================
                /// if (R(B).AsBool == (bool)C)
                ///     {skip next instruction}
                /// else
                ///     R(A) = R(B)
                /// =======================================================
                AddABC(OpCode.TESTSET, result, argpos, expected);
                jumps[i] = AddOpcode(Instruction.Nop);
                Pop();
            }
            Code.Add(Instruction.MakeAB(OpCode.LOADBOOL, result, isOrOperation ? (short)0 : (short)1));

            /// now make all jumps to the
            var pc = PC;

            foreach (var jmp in jumps)
            {
                Code[jmp] = Instruction.MakeASBX(OpCode.JMP, 0, Jmp(jmp, pc));
            }

            SP = result;
            return(result);
        }
Exemplo n.º 16
0
Arquivo: Codegen.cs Projeto: hww/VARP
        /// <summary>
        /// Generate literal and return the position of literal in values
        /// list.
        /// </summary>
        /// <param name="ast"></param>
        /// <returns></returns>
        private int GenerateLiteral(AstLiteral ast)
        {
            var value  = ast.isSyntaxLiteral ? ast.GetSyntax() : ast.GetDatum();
            var refval = value.RefVal;
            var sp     = Push();

            if (refval == null)
            {
                Code.Add(Instruction.MakeAB(OpCode.LOADNIL, sp, 1));
                return(sp);
            }
            else if (refval is BoolType)
            {
                Code.Add(Instruction.MakeAB(OpCode.LOADBOOL, sp, value.AsBool() ? (short)1 : (short)0));
                return(sp);
            }
            else if (refval is Symbol)
            {
                if (refval == Symbol.NULL)
                {
                    Code.Add(Instruction.MakeAB(OpCode.LOADNIL, sp, 1));
                }
                else
                {
                    var kid = DefineLiteral(value);
                    Code.Add(Instruction.MakeABX(OpCode.LOADK, sp, kid));
                }
                return(sp);
            }
            else
            {
                var kid = DefineLiteral(value);
                Code.Add(Instruction.MakeABX(OpCode.LOADK, sp, kid));
                return(sp);
            }
        }
Exemplo n.º 17
0
        public void Compile()
        {
            if (Function.IsAbstract || !Function.HasBody)
            {
                return;
            }

            CompileStatement(Function.Body, !Function.IsGenerated);

            if (Function.Stats.HasFlag(EntityStats.ImplicitReturn))
            {
                Emit(Opcodes.Ret);
            }

            if (_leaveCode.Count > 0)
            {
                foreach (var c in _leaveCode)
                {
                    if (c.Opcode == Opcodes.MarkLabel)
                    {
                        (c.Argument as Label).Offset = Code.Count;
                    }

                    Code.Add(c);
                }
            }


            // Remove redundant branches out of the code
            // Must be done, even if the branches are unreachable, else .NET complaints

            // Step 1 - remove redundant MarkLabels at the end of the program
            for (int i = Code.Count - 1; i >= 0; i--)
            {
                if (Code[i].Opcode == Opcodes.MarkLabel)
                {
                    Labels.Remove(Code[i].Argument as Label);
                    Code.RemoveAt(i);
                }
                else
                {
                    break;
                }
            }

            // Step 2 - Remove branches out of code
            // This is safe - assuming that control flow has already been validated
            for (int i = 0; i < Code.Count; i++)
            {
                if (Code[i].Opcode.IsBranch())
                {
                    var lbl = Code[i].Argument as Label;

                    if (lbl.Offset >= Code.Count)
                    {
                        foreach (var l in Labels)
                        {
                            if (l.Offset >= i)
                            {
                                l.Offset--;
                            }
                        }

                        Code.RemoveAt(i--);
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Scrapes the HTML page and populates the "Code" structure.
        /// </summary>
        public void FetchScriptTags()
        {
            if (!HtmlPage.IsEnabled)
            {
                return;
            }

            var scriptTags = HtmlPage.Document.GetElementsByTagName("script");

            foreach (ScriptObject scriptTag in scriptTags)
            {
                var e    = (HtmlElement)scriptTag;
                var type = (string)e.GetAttribute("type");
                var src  = (string)e.GetAttribute("src");

                string language = null;

                // Find the language by either mime-type or script's file extension
                if (type != null)
                {
                    language = GetLanguageByType(type);
                }
                else if (src != null)
                {
                    language = GetLanguageByExtension(Path.GetExtension(src));
                }

                // Only move on if the language was found
                if (language != null)
                {
                    var initParams = DynamicApplication.Current.InitParams;

                    // Process this script-tag if ...
                    if (
                        // it's class is "*" ... OR
                        (e.CssClass == "*") ||

                        // the xamlid initparam is set and matches this tag's class ... OR
                        (initParams.ContainsKey("xamlid") && initParams["xamlid"] != null &&
                         e.CssClass != null && e.CssClass == initParams["xamlid"]) ||

                        // the xamlid initparam is not set and this tag does not have a class
                        (!initParams.ContainsKey("xamlid") && (e.CssClass == null || e.CssClass.Length == 0))
                        )
                    {
                        bool defer = (bool)e.GetProperty("defer");

                        _LangConfig.LanguagesUsed[language] = true;

                        var sc = new ScriptCode(language, defer);

                        if (src != null)
                        {
                            sc.External = DynamicApplication.MakeUri(src);
                        }
                        else
                        {
                            var innerHtml = (string)e.GetProperty("innerHTML");
                            if (innerHtml != null)
                            {
                                // IE BUG: inline script-tags have an extra newline at the front,
                                // so remove it ...
                                if (HtmlPage.BrowserInformation.Name == "Microsoft Internet Explorer" && innerHtml.IndexOf("\r\n") == 0)
                                {
                                    innerHtml = innerHtml.Substring(2);
                                }

                                sc.Inline = innerHtml;
                            }
                        }

                        Code.Add(sc);
                    }

                    // Lastly, check to see if this is a zip file
                }
                else if (src != null && ((type != null && type == "application/x-zip-compressed") || Path.GetExtension(src) == ".zip"))
                {
                    ZipPackages.Add(DynamicApplication.MakeUri(src));
                }
            }
        }
Exemplo n.º 19
0
 internal void AddSupportingType(CodeElement codeElement)
 {
     Code.Add(codeElement);
 }
Exemplo n.º 20
0
        /// <summary>
        /// The rubber starts meeting the road here. Converts an action object to code
        /// </summary>
        /// <param name="action">action object to convert</param>
        public override void ActionToCode(ActionBase action)
        {
            string strtype = Regex.Match(action.GetType().ToString(), "\\.(\\w+)$").Groups[1].Value;

            string friendlyName = "";

            if (action.GetType().IsSubclassOf(typeof(ActionElementBase)))
            {
                //friendlyName = GetUniqueFriendlyName(((ActionElementBase) action).ActionFinder);
                friendlyName = ((ActionElementBase)action).ActionFinder.FriendlyName;
                ElementToProperty(friendlyName, (ActionElementBase)action);
            }

            string pagename = action.ActionWindow.InternalName;

            if (!_openedWindows.Contains(action.ActionWindow.InternalName))
            {
                Code.Add(CreateBrowser(pagename, BrowserType, action.ActionWindow.InitialUrl));
                _openedWindows.Add(action.ActionWindow.InternalName);
            }

            switch (strtype)
            {
            case "ActionBackward":
                Code.Add(CommandToString(pagename, null, "Back"));
                break;

            case "ActionForward":
                Code.Add(CommandToString(pagename, null, "Forward"));
                break;

            case "ActionRefresh":
                Code.Add(CommandToString(pagename, null, "Refresh"));
                break;

            case "ActionFocus":
                Code.Add(CommandToString(pagename, friendlyName, "Focus"));
                break;

            case "ActionCloseWindow":
                Code.Add(CommandToString(action.ActionWindow.InternalName, null, "CloseWindow"));
                _openedWindows.Remove(action.ActionWindow.InternalName);
                break;

            case "ActionNavigate":
                Code.Add(CommandToString(action.ActionWindow.InternalName, null, "GoTo",
                                         new List <string> {
                    "\"" + ((ActionNavigate)action).Url + "\""
                }));
                break;

            case "ActionSleep":
                Code.Add(CommandToString(null, null, "Sleep",
                                         new List <string> {
                    ((ActionSleep)action).Miliseconds.ToString(CultureInfo.InvariantCulture)
                }));
                break;

            case "ActionClick":
                Code.Add(((ActionElementBase)action).NoWait
                                 ? CommandToString(pagename, friendlyName, "ClickNoWait")
                                 : CommandToString(pagename, friendlyName, "Click"));
                break;

            case "ActionSelect":
                if (((ActionSelect)action).ByValue)
                {
                    Code.Add(CommandToString(pagename, friendlyName, "SelectByValue",
                                             new List <string> {
                        "\"" + ((ActionSelect)action).SelectedValue + "\""
                    }));
                }
                else
                {
                    Code.Add(CommandToString(pagename, friendlyName, "Select",
                                             new List <string> {
                        "\"" + ((ActionSelect)action).SelectedText + "\""
                    }));
                }
                break;

            case "ActionTypeText":
                var textaction = (ActionTypeText)action;
                if (textaction.Overwrite)
                {
                    Code.Add(SetElementToString(pagename + "." + friendlyName + ".Value", "\"" + textaction.TextToType + "\""));
                }
                else
                {
                    Code.Add(CommandToString(pagename, friendlyName, "AppendText",
                                             new List <string> {
                        "\"" + textaction.TextToType + "\""
                    }));
                }
                break;

            case "ActionAlertHandler":
                Code.Add(AlertDialog());
                RequiresClosureAfterLine = Code.Count + 1;
                break;

            default:
                Code.Add("//UNHANDLED CODE OBJECT: " + action.GetType());
                Code.Add("// This means I forgot to add it to the code generator...");
                break;
            }

            if (RequiresClosureAfterLine == Code.Count)
            {
                Code.Add(LineEnding);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// The rubber starts meeting the road here. Converts an action object to code
        /// </summary>
        /// <param name="action">action object to convert</param>
        public override void ActionToCode(ActionBase action)
        {
            string strtype = Regex.Match(action.GetType().ToString(), "\\.(\\w+)$").Groups[1].Value;

            string friendlyName = "";

            if (action.GetType().IsSubclassOf(typeof(ActionElementBase)))
            {
                friendlyName = GetPropertyType(((ActionElementBase)action).ActionFinder.TagName);
            }

            string pagename = action.ActionWindow.InternalName;

            if (!_openedWindows.Contains(action.ActionWindow.InternalName))
            {
                Code.Add(CreateBrowser(pagename, BrowserType, action.ActionWindow.InitialUrl));
                _openedWindows.Add(action.ActionWindow.InternalName);
            }

            string code;

            switch (strtype)
            {
            case "ActionBackward":
                Code.Add(CreateBrowserAction("back"));
                break;

            case "ActionForward":
                Code.Add(CreateBrowserAction("forward"));
                break;

            case "ActionRefresh":
                Code.Add(CreateBrowserAction("refresh"));
                break;

            case "ActionFocus":
                // does not appear to be supported
                break;

            case "ActionCloseWindow":
                Code.Add(CreateBrowserAction("close"));
                _openedWindows.Remove(action.ActionWindow.InternalName);
                break;

            case "ActionNavigate":
                code = CommandToString("browser", null, new NameValueCollection {
                    { "url", ((ActionNavigate)action).Url }
                });
                Code.Add(code);
                break;

            case "ActionClick":
                code = CommandToString(friendlyName, ((ActionElementBase)action).ActionFinder, new NameValueCollection {
                    { "click", "true" }
                });
                Code.Add(code);
                break;

            case "ActionSelect":
                code = CommandToString(friendlyName, ((ActionElementBase)action).ActionFinder, ((ActionSelect)action).ByValue ? new NameValueCollection {
                    { "set", ((ActionSelect)action).SelectedValue }
                } : new NameValueCollection {
                    { "set", ((ActionSelect)action).SelectedText }
                });
                Code.Add(code);
                break;

            case "ActionTypeText":
                var textaction = (ActionTypeText)action;
                code = CommandToString(friendlyName, ((ActionElementBase)action).ActionFinder, textaction.Overwrite ? new NameValueCollection {
                    { "set", textaction.TextToType }
                } : new NameValueCollection {
                    { "append", textaction.TextToType }
                });
                Code.Add(code);
                break;

            default:
                Code.Add("<!-- UNHANDLED CODE OBJECT: " + action.GetType() + " *** This means I forgot to add it to the code generator... -->");
                break;
            }

            if (RequiresClosureAfterLine == Code.Count)
            {
                Code.Add(LineEnding);
            }
        }
Exemplo n.º 22
0
 internal void AddCodeError(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType)
 {
     Code.Add(new ErrorPlugInInfo(attribute, type, errorType));
 }
Exemplo n.º 23
0
 public void AddInstruction(Instruction i)
 {
     Code.Add(i);
     i.BasicBlock = this;
 }
Exemplo n.º 24
0
        public override bool AddCodeLine(string command, string line)
        {
            Mesh p = Object as Mesh;

            if (p == null)
            {
                return(base.AddCodeLine(command, line));
            }

            Code.Add(line);// save the raw data

            string nub = Reader.GetRestOfWords(line);

            if (command == "VERTEX")
            {
                p.Vertecies.Add(Utilities.ReadVector3F(nub));
            }
            else if (command == "NORMAL")
            {
                p.Normals.Add(Utilities.ReadVector3F(nub));
            }
            else if (command == "TEXTCOORD")
            {
                p.UVs.Add(Utilities.ReadVector2F(nub));
            }
            else if (command == "INSIDE")
            {
                p.InsidePoints.Add(Utilities.ReadVector3F(nub));
            }
            else if (command == "OUTSIDE")
            {
                p.OutsidePoints.Add(Utilities.ReadVector3F(nub));
            }
            else if (command == "SHIFT" || command == "SPIN" || command == "SCALE" || command == "SHEAR")
            {
                p.Transforms.Add(ParseTransformation(command, nub));
            }
            else if (command == "FACE")
            {
                if (TempFace != null)
                {
                    p.Faces.Add(TempFace);
                }

                TempFace = new Mesh.Face();
            }
            else if (command == "ENDFACE")
            {
                if (TempFace != null)
                {
                    p.Faces.Add(TempFace);
                }

                TempFace = null;
            }
            else if (command == "PHYDRV")
            {
                if (TempFace != null)
                {
                    TempFace.PhysicsDriver = nub;
                }
                else
                {
                    p.PhysicsDriver = nub;
                }
            }
            else if (command == "NOCLOSTERS")
            {
                if (TempFace != null)
                {
                    TempFace.NoClusters = true;
                }
                else
                {
                    p.NoClusters = true;
                }
            }
            else if (command == "SMOOTHBOUNCE")
            {
                if (TempFace != null)
                {
                    TempFace.SmoothBounce = true;
                }
                else
                {
                    p.SmoothBounce = true;
                }
            }
            else if (command == "PASSABLE")
            {
                if (TempFace != null)
                {
                    TempFace.Passable = true;
                }
            }
            else if (command == "DRIVETHROUGH")
            {
                if (TempFace != null)
                {
                    TempFace.DriveThrough = true;
                }
            }
            else if (command == "SHOOTTHROUGH")
            {
                if (TempFace != null)
                {
                    TempFace.ShootThrough = true;
                }
            }
            else if (!base.AddCodeLine(command, line))
            {
                return(true);
            }

            return(true);
        }
Exemplo n.º 25
0
 public Account WithCode(Code code)
 {
     Code.Add(code);
     return(this);
 }
Exemplo n.º 26
0
        public void Run(int StoreID, Boolean relocation, int DeviceID)
        {
            if (PremadeLocation == null)
            {
                if (Type.ToLower().Equals("sql")) // TODO Test
                {
                    foreach (String Command in Code)
                    {
                        SQL.SqlHandler.RunCommand(StoreID, DeviceID, Command);
                    }
                }
                //                             Remote Desktop                               FTP GUI                            Control Panel
                else if (Type.ToLower().Equals("remotecontrol") || Type.ToLower().Equals("filetransfer") || Type.ToLower().Equals("openra"))
                {
                    RemotelyAnywhere(Type.ToLower(), StoreID, relocation, DeviceID);
                }
                else if (Type.ToLower().Equals("browser"))
                {
                    foreach (String line in Code)
                    {
                        try {
                            Process.Start(MainWindow.RA_Browser, ReplaceVariables(line, StoreID, DeviceID, relocation));
                        }
                        catch (Win32Exception e)
                        {
                            var psi = new ProcessStartInfo();
                            psi.UseShellExecute = true;
                            psi.FileName        = ReplaceVariables(line, StoreID, DeviceID, relocation);
                            Process.Start(psi);
                        }
                    }
                }
                else if (Type.ToLower().Equals("ftp"))
                {
                    String IP = JsonHandler.GetDevice(DeviceID).getIPForStore(StoreID);

                    foreach (String FTP in Code)
                    {
                        String[] Files = ReplaceVariables(FTP, StoreID, DeviceID, relocation).Split('>');

                        File.Copy(@"" + Files[0], @"" + Files[1], true);
                    }
                }
                else if (Type.ToLower().Equals("run"))
                {
                    foreach (String Application in Code)
                    {
                        System.Diagnostics.Process.Start(Application);
                    }
                }
                else if (Type.ToLower().Equals("shell") || Type.ToLower().Equals("batch"))
                {
                    String extension = "";

                    if (Type.ToLower().Equals("shell"))
                    {
                        extension = "sh";
                    }
                    else
                    {
                        extension = "bat";
                    }

                    List <String> FinalCode = new List <String>();

                    foreach (String line in Code)
                    {
                        FinalCode.Add(ReplaceVariables(line, StoreID, DeviceID, relocation));
                    }

                    Code.Add("del \" % ~f0\" & exit"); // Adding code to the script to automatically delete itself on completion

                    File.WriteAllLines(FolderLocation + Name + "." + extension, FinalCode);

                    if (Local == true) // Local
                    {
                        System.Diagnostics.Process.Start(FolderLocation + Name + "." + extension);
                    }
                    else // Remotely
                    {
                        String IP = JsonHandler.GetDevice(DeviceID).getIPForStore(StoreID, relocation);
                        File.Copy(FolderLocation + Name + "." + extension, @"\\" + IP + "\\c-drive\\QTreg\\RunOnce\\" + Name + "." + extension, true);
                    }
                }
            }
            else
            {
                if (Local == true)
                {
                    System.Diagnostics.Process.Start(PremadeLocation);
                }
                else
                {
                    String IP = JsonHandler.GetDevice(DeviceID).getIPForStore(StoreID, relocation);
                    File.Copy(PremadeLocation, @"\\" + IP + "\\c-drive\\QTreg\\RunOnce\\" + Name + "." + PremadeLocation.Split('.')[1], true);
                }
            }
        }
        public void Analyse(string code, int line = -1)
        {
            Code.Clear();
            Tokenizer          tokenizer = new Tokenizer();
            List <SyntaxGroup> list      =
                tokenizer.GroupTokensByBlocks(tokenizer.Tokenize(code, this))
                as List <SyntaxGroup>;

            //Set this logger as the tokenizer logger
            Logger.Errors = tokenizer.Logger.Errors;
            //Check if there are errors.
            if (Logger.hasErrors())
            {
                return;
            }
            //Return if list is null
            if (list == null || !list.Any())
            {
                return;
            }
            foreach (SyntaxGroup group in list)
            {
                try
                {
                    //Check if there is an assignation or code value at the end of the code
                    Assignation last = Code.LastOrDefault() as Assignation;
                    if (last != null)
                    {
                        //set its end line as this line's end - 1
                        last.EndLine = group.Component.line - 1;
                    }
                    Assignation      tempo = new Assignation(1);
                    RecursiveCodeLog log   = tempo.Analyse(group);
                    if (log != null)
                    {
                        Logger.Errors.Add(new SyntaxError(log.Message));
                        //We don't want to add broken code if possible
                        continue;
                    }
                    Code.Add(tempo);
                }
                catch (Exception)
                {
                    //TODO: Add language support
                    Logger.Errors.Add(new SyntaxError("Unknown error in script"));
                }
            }
            //Check if there is an assignation or code value at the end of the code
            Assignation Verylast = Code.LastOrDefault() as Assignation;

            if (Verylast != null)
            {
                //Check if the last is Empty
                if (list.Last().Component.line == Verylast.Line)
                {
                    //Empty block, set the end line as starting line + 2
                    Verylast.EndLine = Verylast.Line + 2;
                }
                else
                {
                    //Set its end line as this line's end - 1
                    Verylast.EndLine = list.Last().Component.line - 1;
                }
            }
        }
Exemplo n.º 28
0
 internal void Add(int x)
 {
     Code.Add(x);
 }
Exemplo n.º 29
0
 public void Add(ICode item)
 {
     Code.Add(item);
 }
Exemplo n.º 30
0
 public void Emit(Opcodes op, object arg = null)
 {
     Code.Add(new Instruction(op, arg));
 }