Example #1
0
        public async Task SavePatternLine(PatternLine line, bool isNewLine = false)
        {
            Uri uri;

            try
            {
                var json    = JsonConvert.SerializeObject(line);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewLine)
                {
                    uri      = new Uri(string.Format(Constants.patternLinePostString, line.LeftHand, line.RightHand));
                    response = await client.PostAsync(uri, content);
                }
                else
                {
                    uri      = new Uri(string.Format(Constants.patternLinePutString, line.ID, line.LeftHand, line.RightHand));
                    response = await client.PutAsync(uri, content);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine("Pattern Line successfully saved.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERROR {0}", ex.Message);
            }
        }
        public IHttpActionResult PutPatternLine(int id, PatternLine patternLine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != patternLine.Id)
            {
                return(BadRequest());
            }

            db.Entry(patternLine).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatternLineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
 protected override void OnAppearing()
 {
     //the "pageNavigated flag" is necessary to stop the multiple stacking of pages.
     pageNavigated = false;
     PatternDetailsViewModel.OnRefreshCommand();
     MessagingCenter.Subscribe <PatternDetailsViewModel, string>(this, "NewLine", (sender, rank) =>
     {
         //navigate to pattern line page
         PatternLine line = new PatternLine(rank);
         if (!pageNavigated)
         {
             Navigation.PushAsync(new PatternLinePage(line));
         }
         pageNavigated = true;
     });
     MessagingCenter.Subscribe <PatternDetailsViewModel, PatternLine>(this, "EditLine", (sender, patternLine) =>
     {
         //navigate to pattern line page to edit
         if (!pageNavigated)
         {
             Navigation.PushAsync(new PatternLinePage(patternLine));
         }
         pageNavigated = true;
     });
     MessagingCenter.Subscribe <PatternDetailsViewModel, int>(this, "DeleteLine", (sender, ID) =>
     {
         ShowDeleteDialog(ID);
     });
     base.OnAppearing();
 }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            PatternLine patternLine = db.PatternLines.Find(id);

            db.PatternLines.Remove(patternLine);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #5
0
 public PatternLineViewModel(PatternLine patternLine)
 {
     Rank = patternLine.Rank;
     if (patternLine.Order == 0)
     {
         isNewLine = true;
     }
     Line = patternLine;
     Init();
 }
Example #6
0
 public ActionResult Edit([Bind(Include = "Id,Rank,Order,Feet,LeftHand,RightHand")] PatternLine patternLine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(patternLine).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(patternLine));
 }
Example #7
0
        public ActionResult Create([Bind(Include = "Id,Rank,Order,Feet,LeftHand,RightHand")] PatternLine patternLine)
        {
            if (ModelState.IsValid)
            {
                db.PatternLines.Add(patternLine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(patternLine));
        }
        public IHttpActionResult GetPatternLine(int id)
        {
            PatternLine patternLine = db.PatternLines.Find(id);

            if (patternLine == null)
            {
                return(NotFound());
            }

            return(Ok(patternLine));
        }
        public IHttpActionResult PostPatternLine(PatternLine patternLine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PatternLines.Add(patternLine);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = patternLine.Id }, patternLine));
        }
        public IHttpActionResult DeletePatternLine(int id)
        {
            PatternLine patternLine = db.PatternLines.Find(id);

            if (patternLine == null)
            {
                return(NotFound());
            }

            db.PatternLines.Remove(patternLine);
            db.SaveChanges();

            return(Ok(patternLine));
        }
Example #11
0
        // GET: PatternLinesMvc/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PatternLine patternLine = db.PatternLines.Find(id);

            if (patternLine == null)
            {
                return(HttpNotFound());
            }
            return(View(patternLine));
        }
Example #12
0
 public PatternLine(RegParser.SimpleregexContext expr, char[] alphabet)
 {
     Alphabet = alphabet;
     if (expr.concat() != null)
     {
         Op    = RegOperation.Concat;
         Left  = new PatternLine(expr.concat().basicregex(), alphabet);
         Right = new PatternLine(expr.concat().simpleregex(), alphabet);
     }
     else if (expr.basicregex() != null)
     {
         Op   = RegOperation.NonGroup;
         Left = new PatternLine(expr.basicregex(), alphabet);
     }
     else
     {
         Console.WriteLine("\tSR" + expr.GetText());
         Op = RegOperation.Unknown;
     }
 }
Example #13
0
 public PatternLine(RegParser.RegexContext expr, char[] alphabet)
 {
     Alphabet = alphabet;
     if (expr.union() != null)
     {
         Op    = RegOperation.Union;
         Left  = new PatternLine(expr.union().simpleregex(), alphabet);
         Right = new PatternLine(expr.union().regex(), alphabet);
     }
     else if (expr.simpleregex() != null)
     {
         Op   = RegOperation.NonGroup;
         Left = new PatternLine(expr.simpleregex(), alphabet);
     }
     else
     {
         Console.WriteLine("\tR" + expr.GetText());
         Console.WriteLine($"\t{expr.union()}—{expr.simpleregex()}");
         Op = RegOperation.Unknown;
     }
 }
Example #14
0
 public PatternLine(RegParser.BasicregexContext expr, char[] alphabet)
 {
     Alphabet = alphabet;
     if (expr.star() != null)
     {
         Op   = RegOperation.Star;
         Left = new PatternLine(expr.star().elementaryregex(), alphabet);
     }
     else if (expr.plus() != null)
     {
         Op   = RegOperation.Plus;
         Left = new PatternLine(expr.plus().elementaryregex(), alphabet);
     }
     else if (expr.elementaryregex() != null)
     {
         Op   = RegOperation.NonGroup;
         Left = new PatternLine(expr.elementaryregex(), alphabet);
     }
     else
     {
         Console.WriteLine("\tBR" + expr.GetText());
         Op = RegOperation.Unknown;
     }
 }
Example #15
0
 public PatternLine(RegParser.ElementaryregexContext expr, char[] alphabet)
 {
     Alphabet = alphabet;
     if (expr.group() != null)
     {
         Op   = RegOperation.Group;
         Left = new PatternLine(expr.group().regex(), alphabet);
     }
     else if (expr.set() != null)
     {
         Op      = RegOperation.Set;
         Content = expr.set().STRING().GetText();
     }
     else if (expr.STRING() != null)
     {
         Op      = RegOperation.String;
         Content = expr.STRING().GetText();
     }
     else
     {
         Console.WriteLine("\tER" + expr.GetText());
         Op = RegOperation.Unknown;
     }
 }
 public PatternLinePage(PatternLine line)
 {
     InitializeComponent();
     PatternLineViewModel = new PatternLineViewModel(line);
     this.BindingContext  = PatternLineViewModel;
 }
        // Public ---------------------------------------------------------------------------------
        public void Parse(String PatternFilename)
        {
            List <String> PatternLine = null;
            List <String> PatternLoop = null;
            List <String> LineToCheck = null;
            List <String> LoopToCheck = null;
            String        CurrentLine, TestLine, ResultPattern, ResultValue;

            int iCurrentLine = 0, PatternLen = 0, iterator = 0, PatternLoopInitialValue = 0;

            TextFile PatternFile = new TextFile(PatternFilename);

            if ((_File == null) || (null == PatternFile))
            {
                return;
            }

            // Clear unused data
            PatternFile.RemoveUnusedLine();
            _File.RemoveUnusedLine();

            // Search for Loops
            for (iCurrentLine = 1; iCurrentLine <= PatternFile.GetSize(); iCurrentLine++)
            {
                // Read the current line from patter file
                CurrentLine = PatternFile.GetLine(iCurrentLine);

                // Search for inital tag
                if (CurrentLine == "// StructuredFileLoopBegin")
                {
                    // Read the next line
                    iCurrentLine++;
                    CurrentLine = PatternFile.GetLine(iCurrentLine);
                    PatternLen  = 0;

                    if (PatternLoop == null)
                    {
                        PatternLoopInitialValue = 0;
                    }
                    else
                    {
                        PatternLoopInitialValue = PatternLoop.Count();
                    }

                    // Search for final tag into Pattern File
                    while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= PatternFile.GetSize()))
                    {
                        if (PatternLoop == null)
                        {
                            PatternLoop = new List <string>();
                        }

                        if (LoopToCheck == null)
                        {
                            LoopToCheck = new List <string>();
                        }

                        // Check equivalent line into _File
                        TestLine = _File.GetLine(iCurrentLine);

                        // Add lines into the loop checker (if TestLine is valid)
                        if (TestLine != "// StructuredFileLoopEnd")
                        {
                            PatternLoop.Add(CurrentLine);
                            LoopToCheck.Add(TestLine);
                            if (CurrentLine != "// LoopID = 'LOOPID'")   // This line is not included into the pattern
                            {
                                PatternLen++;
                            }

                            // Remove added line (for current file)
                            _File.RemoveLine(iCurrentLine);
                        }
                        // Remove added line (for pattern file)
                        PatternFile.RemoveLine(iCurrentLine);

                        CurrentLine = PatternFile.GetLine(iCurrentLine);
                    }

                    iterator    = PatternLoopInitialValue + 1; // Initial value is computed before adding the first LoopPattern value
                    CurrentLine = _File.GetLine(iCurrentLine);

                    // Search for final tag into current File
                    while ((CurrentLine != "// StructuredFileLoopEnd") && (iCurrentLine <= _File.GetSize()))
                    {
                        // Add lines to the loop checker
                        PatternLoop.Add(PatternLoop[iterator].ToString());
                        LoopToCheck.Add(_File.GetLine(iCurrentLine));

                        // Remove added lines
                        _File.RemoveLine(iCurrentLine);

                        CurrentLine = _File.GetLine(iCurrentLine);

                        iterator++;
                        if (iterator > PatternLoopInitialValue + PatternLen)
                        {
                            iterator = PatternLoopInitialValue + 1;
                        }
                    }
                }
            }

            // Clear unchanged line between the Pattern File and currentFile
            for (int i = 1; i <= _File.GetSize(); i++)
            {
                if (PatternFile.GetLine(i) != _File.GetLine(i))
                {
                    if (PatternLine == null)
                    {
                        PatternLine = new List <string>();
                    }

                    if (LineToCheck == null)
                    {
                        LineToCheck = new List <string>();
                    }

                    // Add line we have to compare
                    PatternLine.Add(PatternFile.GetLine(i));
                    LineToCheck.Add(_File.GetLine(i));
                }
            }

            // Create the result list for non-loop values
            if (PatternLine != null)
            {
                if (_Items == null)
                {
                    _Items = new List <StructuredFileKey>();
                }

                // Lecture ligne a ligne et sauvegarde des infos
                for (iCurrentLine = 0; iCurrentLine < PatternLine.Count(); iCurrentLine++)
                {
                    int iCurrentPatternChar = 0, iCurrentValueChar = 0;
                    // Traitement de la ligne en cours
                    for (iCurrentValueChar = 0; iCurrentValueChar < LineToCheck[iCurrentLine].Length; iCurrentValueChar++)
                    {
                        // Si nous n'avons pas d'overflow
                        if (iCurrentPatternChar < PatternLine[iCurrentLine].Length)
                        {
                            if (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1))
                            {
                                iCurrentPatternChar++;
                                iCurrentValueChar++;

                                int iStartPatternChar = iCurrentPatternChar;
                                // Des que nous voyons une difference dans les lignes
                                // On recherche la fin du pattern
                                while ((iCurrentPatternChar < PatternLine[iCurrentLine].Length) && (PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'"))
                                {
                                    iCurrentPatternChar++;
                                }

                                ResultPattern = PatternLine[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar);

                                // Read the next char to get the end of pattern block
                                iCurrentPatternChar++;

                                if (iCurrentPatternChar < PatternLine[iCurrentLine].Length)
                                {
                                    int    iFirstChar = iCurrentValueChar - 1;
                                    string sLastChar  = PatternLine[iCurrentLine].Substring(iCurrentPatternChar, 1);

                                    // Lecture de la valeur reelle dans la liste LineToCheck
                                    while ((iCurrentValueChar < LineToCheck[iCurrentLine].Length) && (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar))
                                    {
                                        iCurrentValueChar++;
                                    }

                                    // if the correct kay has been found
                                    if (LineToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar)
                                    {
                                        ResultValue = LineToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar);
                                        _Items.Add(new StructuredFileKey(-1, iCurrentLine, ResultPattern, ResultValue));
                                    }
                                }
                            }
                        }

                        // Incremente la valeur pour suivre iCurrentValueChar
                        iCurrentPatternChar++;
                    }
                }
            }

            // Create result list for loop values
            if (PatternLoop != null)
            {
                int CurrentLoopID = -1;

                if (_Items == null)
                {
                    _Items = new List <StructuredFileKey>();
                }

                // Lecture ligne a ligne et sauvegarde des infos
                for (iCurrentLine = 0; iCurrentLine < PatternLoop.Count(); iCurrentLine++)
                {
                    if (PatternLoop[iCurrentLine] == "// LoopID = 'LOOPID'")
                    {
                        CurrentLoopID = int.Parse(LoopToCheck[iCurrentLine].Substring("// LoopID = ".Length));
                    }
                    else if (PatternLoop[iCurrentLine] == "// StructuredFileLoopEnd")
                    {
                        CurrentLoopID = -1;
                    }
                    else
                    {
                        int iCurrentPatternChar = 0, iCurrentValueChar = 0;
                        // Traitement de la ligne en cours
                        for (iCurrentValueChar = 0; iCurrentValueChar < LoopToCheck[iCurrentLine].Length; iCurrentValueChar++)
                        {
                            // Si nous n'avons pas d'overflow
                            if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length)
                            {
                                if (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1))
                                {
                                    iCurrentPatternChar++;
                                    iCurrentValueChar++;

                                    int iStartPatternChar = iCurrentPatternChar;
                                    // Des que nous voyons une difference dans les lignes
                                    // On recherche la fin du pattern
                                    while ((iCurrentPatternChar < PatternLoop[iCurrentLine].Length) && (PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1) != "'"))
                                    {
                                        iCurrentPatternChar++;
                                    }

                                    ResultPattern = PatternLoop[iCurrentLine].Substring(iStartPatternChar, iCurrentPatternChar - iStartPatternChar);

                                    // Read the next char to get the end of pattern block
                                    iCurrentPatternChar++;

                                    if (iCurrentPatternChar < PatternLoop[iCurrentLine].Length)
                                    {
                                        int    iFirstChar = iCurrentValueChar - 1;
                                        string sLastChar  = PatternLoop[iCurrentLine].Substring(iCurrentPatternChar, 1);

                                        // Lecture de la valeur reelle dans la liste LineToCheck
                                        while ((iCurrentValueChar < LoopToCheck[iCurrentLine].Length) && (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) != sLastChar))
                                        {
                                            iCurrentValueChar++;
                                        }

                                        if (iCurrentValueChar < LoopToCheck[iCurrentLine].Length)
                                        {
                                            // if the correct key has been found
                                            if (LoopToCheck[iCurrentLine].Substring(iCurrentValueChar, 1) == sLastChar)
                                            {
                                                ResultValue = LoopToCheck[iCurrentLine].Substring(iFirstChar, iCurrentValueChar - iFirstChar);
                                                _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, ResultValue));
                                            }
                                        }
                                        else
                                        {
                                            _Items.Add(new StructuredFileKey(CurrentLoopID, iCurrentLine, ResultPattern, "\t"));
                                        }
                                    }
                                }
                            }

                            // Incremente la valeur pour suivre iCurrentValueChar
                            iCurrentPatternChar++;
                        }
                    }
                }
            }

            return;
        }
Example #18
0
    public override object VisitPattern(RegParser.PatternContext context)
    {
        var line = new PatternLine(context.regex(), Alphabet);

        return(line);
    }