Beispiel #1
0
        public async Task <int> Remove(Guid grammaticId)
        {
            try
            {
                Grammatics grammaticDb = _ltContext.Grammatics.Find(grammaticId);
                if (grammaticDb != null)
                {
                    VerifiedGrammars vg     = _ltContext.VerifiedGrammars.FirstOrDefault(s => s.GrammaticId == grammaticId);
                    GeneratedDLLs    genDLL = _ltContext.GeneratedDLLs.FirstOrDefault(s => s.GrammaticId == grammaticId);
                    if (genDLL != null)
                    {
                        _ltContext.GeneratedDLLs.Remove(genDLL);
                    }
                    if (vg != null)
                    {
                        _ltContext.VerifiedGrammars.Remove(vg);
                    }
                    _ltContext.Grammatics.Remove(_ltContext.Grammatics.Find(grammaticId));
                    await _ltContext.SaveChangesAsync();
                    await CalculatePath();

                    return(0);
                }
                return(-1);
            }
            catch (Exception e)
            {
                return(-1);
            }
        }
Beispiel #2
0
        public async Task <Grammatic> GenerataFile(Guid grammaticId)
        {
            VerifiedGrammars vgDb = FindVerifiedGrammar(grammaticId);

            if (vgDb != null)
            {
                string path = Directory.GetDirectories(Directory.GetCurrentDirectory() + "/Grammatics/").FirstOrDefault(s => s.Contains(vgDb.Title));
                if (path == null)
                {
                    path = Directory.GetCurrentDirectory() + "/Grammatics/" + vgDb.Title;
                }
                Directory.CreateDirectory(path);
                string           strCmdText = "/C coco " + vgDb.Path + " -frames " + Directory.GetCurrentDirectory() + " -o " + path;
                Process          process    = new Process();
                ProcessStartInfo startInfo  = new ProcessStartInfo()
                {
                    FileName  = "cmd.exe",
                    Arguments = strCmdText
                };
                process.StartInfo = startInfo;
                process.Start();

                process.WaitForExit();
                Grammatic grammatic = await FindAsync(grammaticId);

                Grammatics grammaticsDb = _ltContext.Grammatics.Find(grammatic.GrammaticId);
                grammatic.ResultGenerate = GenerateDLL(path, vgDb.Title);
                if (grammatic.ResultGenerate.ResultCode == 1)
                {
                    GeneratedDLLs generatedDLL = _ltContext.GeneratedDLLs.FirstOrDefault(s => s.GrammaticId == grammaticId);
                    if (generatedDLL != null)
                    {
                        generatedDLL.Image                   = grammatic.ResultGenerate.Result;
                        generatedDLL.FromLanguage            = grammatic.FromLanguage;
                        generatedDLL.ToLanguage              = grammatic.ToLanguage;
                        generatedDLL.Title                   = grammatic.Title;
                        _ltContext.Entry(generatedDLL).State = EntityState.Modified;
                    }
                    else
                    {
                        generatedDLL = new GeneratedDLLs()
                        {
                            GeneratedDLLId = Guid.NewGuid(),
                            GrammaticId    = grammaticId,
                            Image          = grammatic.ResultGenerate.Result,
                            Title          = grammatic.Title,
                            FromLanguage   = grammatic.FromLanguage,
                            ToLanguage     = grammatic.ToLanguage
                        };
                        _ltContext.GeneratedDLLs.Add(generatedDLL);
                    }

                    grammaticsDb.IsEdit = false;
                    _ltContext.Entry(grammaticsDb).State = EntityState.Modified;
                    await _ltContext.SaveChangesAsync();
                    await CalculatePath();
                }
                return(grammatic);
            }
            else
            {
                return(null);
            }
        }