示例#1
0
        public static async Task <string> AddNewSentence(SentenceBase sentence)
        {
            string postData = "value" + "=" + sentence.Text.UrlEncode()
                              + "&" + "selectedLang" + "=" + sentence.Language.Iso.UrlEncode();

            var resp = await client.PostAsync <string>(TatoebaConfig.UrlConfig.NewSentence, postData).ConfigureAwait(false);

            if (resp.Content == null)
            {
                return(null);
            }

            try
            {
                HtmlDocument doc = new HtmlDocument
                {
                    OptionFixNestedTags = true
                };

                doc.LoadHtml(resp.Content);

                return(doc.CreateNavigator().Evaluate <string>("string(//*[@class=\"sentenceContent\"]/@data-sentence-id)"));
            }
            catch
            {
                return(null);
            }
        }
示例#2
0
        public static async Task EditSentence(SentenceBase sentence)
        {
            string postData = "value" + "=" + sentence.Text.UrlEncode()
                              + "&" + "id=" + sentence.Language.Iso + "_" + sentence.Id.UrlEncode();

            await client.PostAsync <string>(TatoebaConfig.UrlConfig.EditSentence, postData).ConfigureAwait(false);
        }
        /// <summary>
        ///		Interpreta una sentencia
        /// </summary>
        private SentenceBase ParseSentence()
        {
            SentenceBase sentence = null;
            TokenSqlBase token    = Lexer.Next();

            // Interpreta la sentencia
            switch (token)
            {
            case TokenSqlComment tokenInner:
                sentence = ParseSentenceComment(tokenInner);
                break;

            case TokenSqlCommand tokenInner:
                sentence = ParseSentenceCommand(tokenInner);
                break;

            case TokenSqlReservedWord tokenInner:
                sentence = ParseSentenceReservedWord(tokenInner);
                break;

            default:
                AddError("Unknown token", token);
                break;
            }
            // Devuelve la sentencia generada
            return(sentence);
        }
示例#4
0
        public NewSentenceViewModel(string iso)
        {
            Title         = Resx.AppResources.NewSentence;
            SaveCommand   = new Command(async() => await ExecuteSaveCommand());
            CancelCommand = new Command(async() => await ExecuteCancelCommand());

            var selectedLanguage = MainService.Languages?.Where(x => x.Iso == iso).FirstOrDefault();

            Item = new SentenceBase
            {
                Text     = "",
                Language = selectedLanguage,
            };
        }
示例#5
0
        /// <summary>
        ///		Ejecuta las sentencias particulares de base de datos
        /// </summary>
        protected override async Task ExecuteAsync(SentenceBase sentence, CancellationToken cancellationToken)
        {
            switch (sentence)
            {
            case SentenceSql executionSentence:
                await ExecuteSqlAsync(executionSentence, cancellationToken);

                break;

            default:
                AddError("Unknown sentence");
                break;
            }
        }
        /// <summary>
        ///		Interpreta una sentencia de una palabra reservada
        /// </summary>
        private SentenceBase ParseSentenceReservedWord(TokenSqlReservedWord token)
        {
            SentenceBase sentence = null;

            // Obtiene la sentencia a partir del tipo de token
            switch (token.Type)
            {
            case TokenSqlReservedWord.ReservedWordType.If:
                sentence = ParseSentenceIf();
                break;

            case TokenSqlReservedWord.ReservedWordType.Declare:
                sentence = ParseSentenceDeclare();
                break;

            case TokenSqlReservedWord.ReservedWordType.Set:
                sentence = ParseSentenceSet();
                break;

            case TokenSqlReservedWord.ReservedWordType.For:
                break;

            case TokenSqlReservedWord.ReservedWordType.While:
                sentence = ParseSentenceWhile();
                break;

            case TokenSqlReservedWord.ReservedWordType.Do:
                sentence = ParseSentenceDo();
                break;

            case TokenSqlReservedWord.ReservedWordType.Sub:
                sentence = ParseSentenceSubDefinition();
                break;

            case TokenSqlReservedWord.ReservedWordType.Call:
                sentence = ParseSentenceSubCall();
                break;

            case TokenSqlReservedWord.ReservedWordType.Return:
                sentence = ParseSentenceReturn();
                break;

            default:
                AddError("This reserved word cant start a sentence", token);
                break;
            }
            // Devuelve la sentencia
            return(sentence);
        }
示例#7
0
        public NewTranslationViewModel(Contribution original)
        {
            this.Original = original;
            Title         = Resx.AppResources.NewTranslation;
            SaveCommand   = new Command(async() => await ExecuteSaveCommand());
            CancelCommand = new Command(async() => await ExecuteCancelCommand());

            var selectedLanguage = MainService.Languages?.Where(x => x.Iso == LocalSettings.LastIsoTranslation).FirstOrDefault();

            if (selectedLanguage.Iso == null)
            {
                selectedLanguage = MainService.Languages?.Where(x => x.Iso == "eng").FirstOrDefault();
            }


            Item = new SentenceBase
            {
                Text     = "",
                Language = selectedLanguage,
            };
        }
示例#8
0
 /// <summary>
 ///		Llama al procesador principal para ejecutar una sentencia desconocida
 /// </summary>
 protected abstract void Execute(SentenceBase abstractSentence);
示例#9
0
        /// <summary>
        ///		Ejecuta una serie de sentencias
        /// </summary>
        protected override void Execute(SentenceBase abstractSentence)
        {
            switch (abstractSentence)
            {
            case SentenceBlock sentence:
                ExecuteBlock(sentence);
                break;

            case SentenceForEach sentence:
                ExecuteForEach(sentence);
                break;

            case SentenceIfExists sentence:
                ExecuteIfExists(sentence);
                break;

            case SentenceExecute sentence:
                ExecuteDataCommand(sentence);
                break;

            case SentenceExecuteScript sentence:
                ExecuteScriptSql(sentence);
                break;

            case SentenceDataBatch sentence:
                ExecuteDataBatch(sentence);
                break;

            case SentenceBulkCopy sentence:
                ExecuteBulkCopy(sentence);
                break;

            case SentenceAssertExecute sentence:
                ExecuteAssertExecute(sentence);
                break;

            case SentenceAssertScalar sentence:
                ExecuteAssertScalar(sentence);
                break;

            case SentenceImportCsv sentence:
                ExecuteImportCsv(sentence);
                break;

            case SentenceImportCsvSchema sentence:
                ExecuteImportCsvSchema(sentence);
                break;

            case SentenceExportCsv sentence:
                ExecuteExportCsv(sentence);
                break;

            case SentenceExportPartitionedCsv sentence:
                ExecuteExportPartitionedCsv(sentence);
                break;

            case SentenceExportCsvSchema sentence:
                ExecuteExportCsvSchema(sentence);
                break;

            case SentenceExportParquet sentence:
                ExecuteExportParquet(sentence);
                break;

            case SentenceImportParquet sentence:
                ExecuteImportParquet(sentence);
                break;
            }
        }
示例#10
0
 /// <summary>
 ///		Llama al procesador principal para ejecutar una sentencia desconocida
 /// </summary>
 protected abstract Task ExecuteAsync(SentenceBase abstractSentence, CancellationToken cancellationToken);