Exemplo n.º 1
0
        private void Validate()
        {
            if (SqlConnection == null)
            {
                throw new Exception("Definir la conexión a SQL Server");
            }

            if (ExportToDatabase == null)
            {
                throw new Exception($"El campo '{nameof(ExportToDatabase)}' no puede ser null");
            }
            else if (ExportToDatabase.Trim() == "")
            {
                throw new Exception($"El campo '{nameof(ExportToDatabase)}' no puede ser una cadena vacía");
            }

            if (ExportFromDatabase == null)
            {
                throw new Exception($"El campo '{nameof(ExportFromDatabase)}' no puede ser null");
            }
            else if (ExportFromDatabase.Trim() == "")
            {
                throw new Exception($"El campo '{nameof(ExportFromDatabase)}' no puede ser una cadena vacía");
            }
        }
        public void DoWork()
        {
            WPExportDTO exportDTO = WPExportEngine.RunAllQueries(
                _wpSource,
                _wpConfigurationPluginExportDTO);

            string json = string.Empty;

            if (string.IsNullOrEmpty(_configurationOUTFile.DirtyExportFile) == false)
            {
                DirtyWPToJson dirtyWPToJson = new DirtyWPToJson(exportDTO);
                json = dirtyWPToJson.CreateJSON(Newtonsoft.Json.Formatting.None);
                FileHelper.WriteToFile(_configurationOUTFile.DirtyExportFile, json);
            }

            WPToJson wPToJson = new WPToJson(exportDTO)
            {
                ExportSeoWithYoast = _wpConfigurationPluginExportDTO.Yoast
            };

            json = wPToJson.CreateJSON(Newtonsoft.Json.Formatting.Indented);

            if (string.IsNullOrEmpty(_configurationOUTFile.ExportFile) == false)
            {
                FileHelper.WriteToFile(_configurationOUTFile.ExportFile, json);
            }

            WPExportResult wp     = Newtonsoft.Json.JsonConvert.DeserializeObject <WPExportResult>(json);
            ISQLEngine     engine = null;

            if (string.IsNullOrEmpty(_configurationOUTFile.SQLServerConnection) == false)
            {
                engine = new SQLServerEngine(_configurationOUTFile.SQLServerConnection);
                ExportToDatabase export = new ExportToDatabase(engine);
                var result = export.Run(wp).Result;
            }


            if (string.IsNullOrEmpty(_configurationOUTFile.MySQLServerConnection) == false)
            {
                engine = new MySQLEngine(_configurationOUTFile.MySQLServerConnection);
                ExportToDatabase export = new ExportToDatabase(engine);
                var result = export.Run(wp).Result;
            }
        }
        public async Task <IActionResult> ConvertJSONToSQL(ImportToMySQLDTO values)
        {
            if (values.contents.Length == 0)
            {
                return(null);
            }

            WPExportResult wp = new WPExportResult();

            using (var ms = new MemoryStream())
            {
                values.contents.CopyTo(ms);
                var    fileBytes = ms.ToArray();
                string json      = Encoding.ASCII.GetString(fileBytes);

                wp = Newtonsoft.Json.JsonConvert.DeserializeObject <WPExportResult>(json);
            }

            if (wp == null)
            {
                return(null);
            }


            ISQLEngine       engine = new MySQLEngine(values.ConnectionString);
            ExportToDatabase export = new ExportToDatabase(engine);
            var result = await export.Run(wp);

            StringBuilder sb = new StringBuilder();

            foreach (var item in result)
            {
                sb.AppendFormat("{0}: {1} {2} | ", item.Key, item.Value, Environment.NewLine);
            }

            string log = sb.ToString();

            return(View("Index"));
        }