/// <summary>
 /// Method is used to extract controllers' data from specified source file into ControllersTable 
 /// </summary>
 /// <returns>true if essential changes in controllers' declarations were detected,
 /// else - otherwise</returns>
 public bool FillControllerInfo()
 {
     TextReader rd = new StreamReader(srcFilename);
     controllerInfo.Clear();
     Extract(rd.ReadToEnd(), "<source>");
     if (parseTree == null) return false;
     AddParseNodeRec(parseTree.Root,false);
     //if source file has been recently added to the project,add new row into ControllersTable
     //else if there were any changes in source file,update corresponding row in ControllersTable
     if (!infobyFiles.ContainsKey(srcFilename))
     {
         ControllersTable curtbl = new ControllersTable(controllerInfo);
         infobyFiles.Add(srcFilename, curtbl);
         return true;
     }
     else
     {
         bool equal = new AttributesComparer().Equals(infobyFiles[srcFilename], controllerInfo);
         if (!equal)
         {
             if (infobyFiles.Remove(srcFilename))
             {
                 ControllersTable curtbl = new ControllersTable(controllerInfo);
                 infobyFiles.Add(srcFilename, curtbl);
                 return true;
             }
         }
         return false;
     }
 }
Example #2
0
        private void Process(HttpListenerContext context)
        {
            string urlData = context.Request.Url.AbsolutePath;

            Console.WriteLine(urlData);

            Uri    url = context.Request.Url;
            string key = (context.Request.UrlReferrer == null)
                         ? url.AbsolutePath.Split('/')[1]
                         : context.Request.UrlReferrer.AbsolutePath.Split('/')[1];

            if (!ControllersTable.ContainsKey(key))
            {
                Console.WriteLine($@"Attempt to find missing key: {key}");
                goto ProceessEnd;
            }

            switch (context.Request.HttpMethod)
            {
            case "GET":
                this.ControllersTable[key].ForEach(webController => webController.Get(ref context));
                break;

            case "POST":
                this.ControllersTable[key].ForEach(webController => webController.Post(ref context));
                break;

            case "PUT":
                this.ControllersTable[key].ForEach(webController => webController.Put(ref context));
                break;

            case "PATCH":
                this.ControllersTable[key].ForEach(webController => webController.Patch(ref context));
                break;

            case "DELETE":
                this.ControllersTable[key].ForEach(webController => webController.Delete(ref context));
                break;
            }

ProceessEnd:

            context.Response.OutputStream.Flush();
            context.Response.OutputStream.Close();
        }
        public MetadataExtractor(string lang, string fname)
        {
            language = lang;
            parseTree = null;
            if (String.Compare(lang, "c#") == 0)
                grammar = new CSharpGrammar();
            else if (String.Compare(lang, "f#") == 0)
                grammar = new FSharpGrammar();
            else
            {
                throw new Exception("The grammar name you've typed is not supported");

            }
            parser = new Parser(new LanguageData(grammar));
            srcFilename = fname;
            controllerInfo = new ControllersTable();
            infobyFiles = new Dictionary<string, ControllersTable>();
        }