/// Function - RunAllChecks
        /// <summary>
        /// Thread starts all checks.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="pathes"></param>
        static void RunAllChecks(string filePath, string destPath, string [] pathes, ArrayList tools)
        {
            //variable declaration.
            Hashtable keywords = new Hashtable();
            Hashtable includes = new Hashtable();
            Dictionary <string, string>    defines       = new Dictionary <string, string>();
            Dictionary <string, ArrayList> funcVariables = new Dictionary <string, ArrayList>();
            ArrayList globalVariable = new ArrayList();

            //initialize
            try
            {
                GeneralCompilerFunctions.initializeKeywordsAndSyntext(ansiCFile, filePath, CSyntextFile, ignoreVariablesTypesPath, keywords, includes, defines, pathes);
            }
            catch (Exception e)
            {
                AddToLogString(filePath, "ERROR IN PREPROCESSOR");
                ConnectionServer.CloseConnection(threadNumber, "ERROR IN PREPROCESSOR " + e.ToString(), GeneralConsts.ERROR);
            }

            AddToLogString(filePath, keywords.Count.ToString());
            //Syntax Check.
            try
            {
                compileError = GeneralCompilerFunctions.SyntaxCheck(filePath, globalVariable, keywords, funcVariables, threadNumber);
            }
            catch (Exception e)
            {
                AddToLogString(filePath, "ERROR IN SyntaxCheck");
                ConnectionServer.CloseConnection(threadNumber, "ERROR IN SyntaxCheck " + e.ToString(), GeneralConsts.ERROR);
            }

            if (!compileError)
            {
                GeneralCompilerFunctions.printArrayList(filePath, keywords);
                AddToLogString(filePath, keywords.Count.ToString());
                //just tests.
                try
                {
                    GeneralRestApiServerMethods.CreateFinalJson(filePath, includes, globalVariable, funcVariables, defines, final_json);
                }
                catch (Exception e)
                {
                    AddToLogString(filePath, "ERROR Creating final json");
                    ConnectionServer.CloseConnection(threadNumber, "ERROR Creating final json " + e.ToString(), GeneralConsts.ERROR);
                }

                string dataJson = JsonConvert.SerializeObject(final_json[filePath]["codeInfo"]);
                AddToLogString(filePath, "new json " + dataJson);
                Thread threadOpenTools = new Thread(() => RunAllTasks(filePath, destPath, tools));
                threadOpenTools.Start();
                threadOpenTools.Join(GeneralConsts.TIMEOUT_JOIN);
                ConnectionServer.CloseConnection(threadNumber, FINISH_SUCCESFULL, GeneralConsts.FINISHED_SUCCESFULLY);
                AddToLogString(filePath, FINISH_SUCCESFULL);
                Console.WriteLine(logFiles[filePath]);
                Thread writeToFile = new Thread(() => File.AppendAllText(logFile, logFiles[filePath]));
                writeToFile.Start();
                writeToFile.Join(GeneralConsts.TIMEOUT_JOIN);
            }
        }
Beispiel #2
0
        /// Function - SyntaxCheck
        /// <summary>
        /// that function uses the Function "ChecksInSyntaxCheck" if that is in a scope
        /// or outside a scope according to the situation.
        /// </summary>
        /// <param name="path"> The path of the c code type string.</param>
        /// <param name="keywords"> keywords type Hashtable that conatins the code keywords.</param>
        public static bool SyntaxCheck(string path, ArrayList globalVariable, Hashtable keywords, Dictionary <string, ArrayList> funcVariables, int threadNumber)
        {
            MyStream sr = null;

            try
            {
                sr = new MyStream(path, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
                Server.ConnectionServer.CloseConnection(threadNumber, FILE_NOT_FOUND, GeneralConsts.ERROR);
            }
            if (sr != null)
            {
                //in order to delete struct keywords when they come in a function at the end of the function.
                ArrayList parameters     = new ArrayList();
                ArrayList blocksAndNames = new ArrayList();
                ArrayList variables      = new ArrayList();
                //adds an ArrayList inside blocksAndNames ArrayList for the action outside the scopes.
                blocksAndNames.Add(new ArrayList());
                string codeLine;
                int    scopeLength  = 0;
                string lastFuncLine = "";
                while ((codeLine = sr.ReadLine()) != null && !CompileError)
                {
                    scopeLength = 0;
                    //handling the scopes.
                    if (OpenBlockPattern.IsMatch(codeLine))
                    {
                        NextScopeLength(sr, ref codeLine, ref scopeLength, true);
                        ChecksInSyntaxCheck(path, sr, codeLine, true, keywords, threadNumber, variables, globalVariable, blocksAndNames, parameters, scopeLength + 1);
                        parameters.Clear();
                    }
                    // if there is a function it saves its parameters.
                    else if (FunctionPatternInC.IsMatch(codeLine))
                    {
                        parameters.AddRange(GeneralRestApiServerMethods.FindParameters(codeLine));
                        if (lastFuncLine != "")
                        {
                            funcVariables.Add(lastFuncLine, new ArrayList(variables));
                            variables.Clear();
                        }
                        lastFuncLine = codeLine;
                    }
                    //handling outside the scopes.
                    else
                    {
                        ChecksInSyntaxCheck(path, sr, codeLine, false, keywords, threadNumber, variables, globalVariable, blocksAndNames);
                    }
                }
                if (lastFuncLine != "")
                {
                    funcVariables.Add(lastFuncLine, new ArrayList(variables));
                    variables.Clear();
                }
            }
            return(CompileError);
        }
Beispiel #3
0
        /// Function - SyncServer
        /// <summary>
        /// Creation of the rest api server.
        /// </summary>
        /// <param name="filePath"> Path for the code file.</param>
        /// <param name="includes"> Hashtable for all of the includes in the code.</param>
        /// <param name="defines"> Dictionary that stores all of the defines in the code.</param>
        public SyncServer()
        {
            var listener = new HttpListener();

            //add prefixes.
            listener.Prefixes.Add("http://localhost:8081/");
            listener.Prefixes.Add("http://127.0.0.1:8081/");
            //start listening.
            listener.Start();

            while (ConnectionServer.GetCloseAllBool() == false)
            {
                try
                {
                    //if gets connection.
                    var context = listener.GetContext(); //Block until a connection comes in
                    context.Response.StatusCode  = 200;
                    context.Response.SendChunked = true;
                    context.Response.ContentType = "application/json";
                    string dataJson = GeneralConsts.EMPTY_STRING;
                    Dictionary <string, Dictionary <string, object> > final_json = MainProgram.GetFinalJson();
                    string filePath          = context.Request.QueryString["filePath"];
                    bool   not_found_pattern = false;
                    bool   not_found         = false;
                    char[] trimChars         = { '/', ' ' };
                    int    totalTime         = 0;
                    string path = GeneralConsts.EMPTY_STRING;
                    Regex  r;
                    //All GET commands.
                    if (context.Request.HttpMethod == "GET")
                    {
                        if (context.Request.QueryString["pattern"] != null)
                        {
                            MainProgram.AddToLogString(filePath, context.Request.QueryString["pattern"]);
                            MainProgram.AddToLogString(filePath, context.Request.QueryString["returnSize"]);
                            r = new Regex(context.Request.QueryString["pattern"]);
                            string    returnSize = context.Request.QueryString["returnSize"];
                            string [] result     = GeneralRestApiServerMethods.SearchPattern(r, returnSize, filePath);
                            dataJson = JsonConvert.SerializeObject(result);
                            MainProgram.AddToLogString(filePath, dataJson);
                        }
                        else if (context.Request.QueryString["readyPattern"] != null)
                        {
                            MainProgram.AddToLogString(filePath, context.Request.QueryString["readyPattern"]);
                            MainProgram.AddToLogString(filePath, context.Request.QueryString["returnSize"]);
                            if (GeneralRestApiServerMethods.TakePatternFromFile(context.Request.QueryString["readyPattern"]) == GeneralConsts.EMPTY_STRING)
                            {
                                not_found_pattern = true;
                            }
                            else
                            {
                                r = new Regex(GeneralRestApiServerMethods.TakePatternFromFile(context.Request.QueryString["readyPattern"]));
                                string   returnSize = context.Request.QueryString["returnSize"];
                                string[] result     = GeneralRestApiServerMethods.SearchPattern(r, returnSize, filePath);
                                dataJson = JsonConvert.SerializeObject(result);
                            }
                        }
                        else
                        {
                            path = context.Request.RawUrl;
                            path = path.Trim(trimChars);
                            path = path.Split('?')[0];
                            MainProgram.AddToLogString(filePath, path);
                            //switch case for get commands.
                            switch (path)
                            {
                            case "functions":
                                dataJson = JsonConvert.SerializeObject(final_json[filePath]["function"]);
                                MainProgram.AddToLogString(filePath, dataJson);
                                break;

                            case "codeInfo":
                                dataJson = JsonConvert.SerializeObject(final_json[filePath]["codeInfo"]);
                                MainProgram.AddToLogString(filePath, dataJson);
                                break;

                            default:
                                break;
                            }
                        }
                        byte [] bytes;
                        if (not_found)
                        {
                            bytes = Encoding.UTF8.GetBytes(NOT_FOUND_500);
                            context.Response.StatusCode = 500;
                        }
                        else
                        {
                            if (dataJson.Length < 0)
                            {
                                bytes = Encoding.UTF8.GetBytes(NOT_FOUND_404);
                                context.Response.StatusCode = 404;
                            }
                            else
                            {
                                bytes = Encoding.UTF8.GetBytes(dataJson);
                            }
                        }

                        Stream OutputStream = context.Response.OutputStream;
                        //sends the message back.
                        OutputStream.Write(bytes, 0, bytes.Length);
                        //Close connection.
                        OutputStream.Close();
                    }
                }


                catch (Exception)
                {
                    // Client disconnected or some other error - ignored for this example
                }
            }
        }