예제 #1
0
        public async Task <bool> UpdateTokAsync(Tok tok)
        {
            var apiUrl = $"{_apiSettings.ApiPrefix}/tok/{tok.Id}{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";
            HttpResponseMessage response = await _httpClient.PutAsJsonAsync(apiUrl, tok);

            return(response.IsSuccessStatusCode);
        }
        public void SacuvajTokoveZaProces(long idProcesa, List <Tok> tokovi)
        {
            Proces proces = _procesOPP.VratiProcesPoIDSaTokovima(idProcesa);

            if (proces != null)
            {
                if (tokovi == null || !tokovi.Any())
                {
                    proces.Tokovi.AddRange(tokovi);
                }
                else
                {
                    tokovi.ForEach(tok =>
                    {
                        Tok tokUProcesu = proces.Tokovi.FirstOrDefault(t => t.RBToka == tok.RBToka);

                        if (tokUProcesu == null)
                        {
                            proces.Tokovi.Add(tok);
                        }
                        else
                        {
                            tokUProcesu.AktivnostiUToku = tok.AktivnostiUToku;
                            tokUProcesu.PodprocesiUToku = tok.PodprocesiUToku;
                        }
                    });
                }

                _procesOPP.SacuvajPromene();
                return;
            }
            throw new Exception("Процес " + idProcesa + " не постоји.");
        }
예제 #3
0
        public Operator(GeneralLanguageDef languageDef)
            :
            base(
                inp =>
        {
            var res = Tok.Lexeme(
                from name in new Oper(languageDef)
                where !OpsHelper.IsReservedOp(name, languageDef)
                select new OperatorToken(name, inp.First().Location))
                      .Parse(inp);

            if (res.IsFaulted)
            {
                return(res);
            }

            if (res.Value.IsEmpty)
            {
                return(ParserResult.Fail <OperatorToken>("unexpected: reserved operator", inp));
            }

            return(res);
        }
                )
        { }
예제 #4
0
        public Identifier(GeneralLanguageDef languageDef)
            :
            base(
                inp =>
        {
            var res = Tok.Lexeme(
                from name in new Ident(languageDef)
                where !IdentHelper.IsReservedName(name, languageDef)
                select new IdentifierToken(name, inp.First().Location)
                )
                      .Parse(inp);

            if (res.IsFaulted)
            {
                return(res);
            }

            if (res.Value.IsEmpty)
            {
                return(ParserResult.Fail <IdentifierToken>("unexpected: reserved word", inp));
            }

            return(res);
        }
                )
        { }
        public string SacuvajTokoveZaProces(long id, List <TokPodaci> tokovi)
        {
            if (tokovi.Any())
            {
                try
                {
                    List <Tok> tokoviModel = new List <Tok>();

                    tokovi.ForEach(t =>
                    {
                        int prebroj = 0;

                        Tok novi = new Tok
                        {
                            IDProcesa = id,
                            RBToka    = t.rbToka
                        };

                        if (t.aktivnostiUToku != null)
                        {
                            prebroj += t.aktivnostiUToku.Count;
                            novi.AktivnostiUToku = t.aktivnostiUToku.Select(aut => new AktivnostUToku()
                            {
                                IDProcesa    = id,
                                RBToka       = t.rbToka,
                                IDAktivnosti = aut.idAktivnosti
                            }).ToList();
                        }

                        if (t.podprocesiUToku != null)
                        {
                            prebroj += t.podprocesiUToku.Count;
                            novi.PodprocesiUToku = t.podprocesiUToku.Select(put => new ProcesUToku()
                            {
                                IDNadprocesa = id,
                                RBToka       = t.rbToka,
                                IDPodprocesa = put.idProcesa
                            }).ToList();
                        }

                        if (prebroj < 2)
                        {
                            throw new Exception("Сваки ток мора имати најмање једну активност или подпроцес.");
                        }

                        tokoviModel.Add(novi);
                    });

                    _procesServis.SacuvajTokoveZaProces(id, tokoviModel);
                    return("Токови за процес " + id + " су успешно сачувани.");
                }
                catch (DbUpdateException ex)
                {
                    throw new Exception("Дошло је до грешке, систем не може сачувати токове за процес " + id + ".", ex);
                }
            }
            throw new Exception("Процес мора имати бар један ток.");
        }
예제 #6
0
        public void SymbolTest()
        {
            var sym = from s in Tok.Symbol("***")
                      select s;

            var res = sym.Parse("***   ");

            Assert.True(!res.IsFaulted);
        }
예제 #7
0
        public async Task <bool> CreateTokAsync(Tok tok)
        {
            InitializeApiClientUser(true);
            client.BaseAddress = new Uri($"{baseUrl}/tok{codePrefix}{apiKey}");
            HttpResponseMessage response = await client.PostAsJsonAsync(client.BaseAddress, tok);

            client = new HttpClient();
            return(response.IsSuccessStatusCode);
        }
예제 #8
0
파일: ErrorFactory.cs 프로젝트: tmteam/NFun
        public static Exception ArrayIntervalInitializeCbrMissed(Tok openBracket, Tok lastToken, bool hasStep)
        {
            int start  = openBracket.Start;
            int finish = lastToken.Finish;

            return(new FunParseException(240,
                                         $"{(hasStep?"[x..y..step ???]":"[x..y ???]")}. ']' was missed'{Nl} Example: a[1..5..2]", start,
                                         finish));
        }
예제 #9
0
 public Symbol(string name)
     :
     base(
         inp => (from sym in Tok.Lexeme <ImmutableList <ParserChar> >(Prim.String(name))
                 select new SymbolToken(sym))
         .Parse(inp)
         )
 {
 }
예제 #10
0
파일: ErrorFactory.cs 프로젝트: tmteam/NFun
        public static Exception ArrayIndexCbrMissed(Tok openBracket, Tok lastToken)
        {
            int start  = openBracket.Start;
            int finish = lastToken.Finish;

            return(new FunParseException(243,
                                         $"a[x ??? <- was missed ']'{Nl} Example: a[1] or a[1:2] or a[1:5:2]", start,
                                         finish));
        }
예제 #11
0
 public void NextLexem()
 {
     PassSpaces();
     // R К этому моменту первый символ лексемы считан в ch
     LexText = "";
     LexRow  = row;
     LexCol  = col;
     // Тип лексемы определяется по ее первому символу
     // Для каждой лексемы строится синтаксическая диаграмма
     if (currentCh == ';')
     {
         NextCh();
         LexKind = Tok.SEMICOLON;
     }
     else if (currentCh == ':')
     {
         NextCh();
         if (currentCh != '=')
         {
             LexError("= was expected");
         }
         NextCh();
         LexKind = Tok.ASSIGN;
     }
     else if (char.IsLetter(currentCh))
     {
         while (char.IsLetterOrDigit(currentCh))
         {
             NextCh();
         }
         if (keywordsMap.ContainsKey(LexText))
         {
             LexKind = keywordsMap[LexText];
         }
         else
         {
             LexKind = Tok.ID;
         }
     }
     else if (char.IsDigit(currentCh))
     {
         while (char.IsDigit(currentCh))
         {
             NextCh();
         }
         LexValue = Int32.Parse(LexText);
         LexKind  = Tok.INUM;
     }
     else if ((int)currentCh == 0)
     {
         LexKind = Tok.EOF;
     }
     else
     {
         LexError("Incorrect symbol " + currentCh);
     }
 }
예제 #12
0
        public void OneLineComment()
        {
            var p = from v in Tok.OneLineComment(new HaskellDef())
                    select v;

            var res = p.Parse("-- This whole line is a comment");

            Assert.True(!res.IsFaulted);
        }
예제 #13
0
        public List <Token> ParseUntil(Tok type)
        {
            var toks = new List <Token>();

            while (PeekType() != type)
            {
                toks.Add(Read());
            }
            return(toks);
        }
예제 #14
0
 private void TokOrTokEq(Tok tok, Tok tokEq)
 {
     NextCh();
     LexKind = tok;
     if (currentCh == '=')
     {
         NextCh();
         LexKind = tokEq;
     }
 }
예제 #15
0
        private void Is(Tok t, int skip = 0, int len = 0)
        {
            var lt = _read[_tok++];

            Assert.AreEqual(t, lt.Token);
            _pos += skip;
            Assert.AreEqual(_pos, lt.Start);
            Assert.AreEqual(len, lt.Length);
            _pos += len;
        }
예제 #16
0
 public Natural()
     :
     base(
         inp => (from lex in Tok.Lexeme(new Int())
                 select lex)
         .Fail("natural")
         .Parse(inp)
         )
 {
 }
예제 #17
0
파일: ErrorFactory.cs 프로젝트: tmteam/NFun
        public static Exception ArraySliceCbrMissed(Tok openBracket, Tok lastToken, bool hasStep)
        {
            int start  = openBracket.Start;
            int finish = lastToken.Finish;

            return(new FunParseException(246,
                                         $"a{(hasStep?"[x:y:step]":"[x:y]")} <- ']' was missed{Nl} Example: a[1:5:2]",
                                         start,
                                         finish));
        }
예제 #18
0
 public Integer()
     :
     base(
         inp => (from lex in Tok.Lexeme(new Int())
                 select lex)
         .Fail("integer")
         .Parse(inp)
         )
 {
 }
예제 #19
0
        public void LexemeTest()
        {
            var lex = from l in Tok.Lexeme <ParserChar>(Prim.Character('A'))
                      select l;

            var res = lex.Parse("A");

            Assert.True(!res.IsFaulted);

            res = lex.Parse("A   ");
            Assert.True(!res.IsFaulted);
        }
예제 #20
0
        public async Task <bool> CreateTokAsync(Tok tok)
        {
            var apiUrl = $"{_apiSettings.ApiPrefix}/tok{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";

            _httpClient.DefaultRequestHeaders.Add("tokgroupid", tok.TokGroup.ToIdFormat());
            _httpClient.DefaultRequestHeaders.Add("toktypeid", tok.TokTypeId);
            _httpClient.DefaultRequestHeaders.Add("categoryid", tok.CategoryId);

            HttpResponseMessage response = await _httpClient.PostAsJsonAsync(apiUrl, tok);

            return(response.IsSuccessStatusCode);
        }
예제 #21
0
 public Reserved(string name, GeneralLanguageDef languageDef)
     :
     base(
         inp => Tok.Lexeme(
             from cs in IdentHelper.CaseString(name, languageDef)
             from nf in Prim.NotFollowedBy(languageDef.IdentLetter)
             .Fail("end of " + cs.AsString())
             select new ReservedToken(cs, inp.Head().Location)
             )
         .Parse(inp)
         )
 {
 }
예제 #22
0
파일: ErrorFactory.cs 프로젝트: tmteam/NFun
        public static Exception FunctionArgumentInBracketDefinition(FunCallSyntaxNode headNode, ISyntaxNode headNodeChild,
                                                                    Tok flowCurrent)
        {
            if (flowCurrent == null)
            {
                throw new ArgumentNullException(nameof(flowCurrent));
            }
            var sb = ErrorsHelper.ToFailureFunString(headNode, headNodeChild);

            return(new FunParseException(339,
                                         $"{headNode.Id}({sb}) = ... {Nl} Function argument is in bracket. Variable name (with optional type) without brackets expected",
                                         headNodeChild.Interval.Start, headNodeChild.Interval.Finish));
        }
예제 #23
0
 public Int()
     :
     base(
         inp => (from f in Tok.Lexeme <ParserChar>(new Sign())
                 from n in new Nat()
                 select new IntegerToken(
                     f.Value == '-' ? -n.Value : n.Value,
                     f.Location
                     ))
         .Parse(inp)
         )
 {
 }
예제 #24
0
 public ReservedOp(string name, GeneralLanguageDef languageDef)
     :
     base(
         inp => Tok.Lexeme(
             from op in Prim.String(name)
             from nf in Prim.NotFollowedBy(languageDef.OpLetter)
             .Fail("end of " + op.AsString())
             select new ReservedOpToken(op, inp.First().Location)
             )
         .Parse(inp)
         )
 {
 }
예제 #25
0
        public string TokToString(Tok t)
        {
            var result = t.ToString();

            switch (t)
            {
            case Tok.ID: result += ' ' + LexText;
                break;

            case Tok.INUM: result += ' ' + LexValue.ToString();
                break;
            }
            return(result);
        }
예제 #26
0
        public void WhiteSpaceTest()
        {
            var p = from v in Tok.WhiteSpace(new HaskellDef())
                    select v;

            var res = p.Parse(
                @"                              {- This whole {- line is a comment
                                                and so is -} this one with nested comments
                                                this too -}  let x=1");

            var left = res.Value.Head().Item2.AsString();

            Assert.True(!res.IsFaulted && left == "let x=1");
        }
예제 #27
0
 public CharLiteral()
     :
     base(
         inp => Tok.Lexeme(
             Prim.Between(
                 Prim.Character('\''),
                 Prim.Character('\'').Fail("end of character"),
                 new CharacterChar()
                 ))
         .Select(ch => new CharLiteralToken(ch, inp.Head().Location))
         .Fail("character")
         .Parse(inp)
         )
 {
 }
예제 #28
0
        public async Task <bool> UpdateTokAsync(Tok tok)
        {
            InitializeApiClientUser(true);
            if (User.Id != tok.UserId)
            {
                throw new UnauthorizedAccessException();
            }
            client.DefaultRequestHeaders.Add("userid", User.Id);
            client.DefaultRequestHeaders.Add("token", User.IdToken);
            client.BaseAddress = new Uri($"{baseUrl}/tok/{tok.Id}{codePrefix}{apiKey}");
            HttpResponseMessage response = await client.PutAsJsonAsync(client.BaseAddress, tok);

            client = new HttpClient();
            return(response.IsSuccessStatusCode);
        }
예제 #29
0
파일: ErrorFactory.cs 프로젝트: tmteam/NFun
        public static Exception ArrayInitializeStepMissed(Tok openBracket, Tok lastToken, Tok missedVal)
        {
            int start  = openBracket.Start;
            int finish = lastToken.Finish;

            if (string.IsNullOrWhiteSpace(missedVal?.Value))
            {
                return(new FunParseException(234,
                                             $"'[x..y..???]. Array step expected but was nothing'{Nl} Example: a[1..5..2]", start,
                                             finish));
            }
            else
            {
                return(new FunParseException(237,
                                             $"'[x..y..???]. Array step expected but was {ErrorsHelper.ToText(missedVal)}'{Nl} Example: a[1..5..2]", start, finish));
            }
        }
예제 #30
0
파일: cli.cs 프로젝트: stjordanis/plil
        public static void Main()
        {
            String[] args   = Environment.GetCommandLineArgs();
            CmdIo    source = new CmdIo();

            try {
                source = new CmdIo(args);
                Tok tokenizer   = new Tok(source);
                Lib funclibrary = new Lib();

                Parser parser = new Parser(source, tokenizer, funclibrary);
                parser.parse_and_compile();
                source.Finish();
            } catch {
                source.Message("plil: compiler error.");
            }
        }