public static string ProcesarRegistros(Proceso proceso, List <Abstract> quickbookRecords) { // Access // Procesar Entrada.. StringBuilder mostrarMensaje = new StringBuilder(); var ws = new wClient.WService(); string err = ""; List <List <Par> > data = null; if (proceso.entrada.quickbaseAccessToken != string.Empty) { string resp = ws.doQuery(proceso.entrada.quickbaseAccessToken, null, out err); //El query debe ser los que tengan Quickbook si o si if (err != string.Empty) { mostrarMensaje.Append("Ejecutando accion Error en el servicio:" + err + Environment.NewLine); } var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; try { data = serializer.Deserialize <List <List <Par> > >(resp); } catch (Exception ex) { Console.WriteLine(ex.Message); mostrarMensaje.Append("Ejecutando accion Error des serializando:" + ex.Message + Environment.NewLine); } if (data == null) { mostrarMensaje.Append("Ejecutando accion data:null" + Environment.NewLine); } else { mostrarMensaje.Append("Ejecutando accion cantidad a procesar:" + quickbookRecords.Count + Environment.NewLine); } } if (data != null && data.Count > 0) { // Inicializar Conexion a Quickbook foreach (ProcesoAccion accion in proceso.acciones) { //Revisando si tenemos respuesta creada a esta altura if (accion.tipo == "add_quickbase") { mostrarMensaje.Append("Ejecutando accion " + accion.nombre + Environment.NewLine); Dictionary <string, string> llaveQuickbase = new Dictionary <string, string>(); //procesaremos los registros para actualizar string resultadoActualizacion = HelperTask.UpdateQuickbookToquickbaseVendorCreated(data, accion, llaveQuickbase, ref err, ref quickbookRecords); mostrarMensaje.Append(resultadoActualizacion); //Existen nuevos registros para crear mostrarMensaje.Append("Cantidad de registros a crear:" + quickbookRecords.Count + Environment.NewLine); if (quickbookRecords.Count > 0) { string resultadoCreados = HelperTask.CreateQuickbookToQuickbaseNewVendor(accion, quickbookRecords, ref err); mostrarMensaje.Append(resultadoCreados); } } } return(mostrarMensaje.ToString()); } else { mostrarMensaje.Append("Cantidad de registros a crear:" + quickbookRecords.Count); if (quickbookRecords.Count > 0) { foreach (ProcesoAccion accion in proceso.acciones) { //Revisando si tenemos respuesta creada a esta altura if (accion.tipo == "add_quickbase") { //Existen nuevos registros de quickbook para quickbase string resultadoCreados = HelperTask.CreateQuickbookToQuickbaseNewVendor(accion, quickbookRecords, ref err); mostrarMensaje.Append(resultadoCreados); } } } return(mostrarMensaje.ToString()); } }
public static string GetFieldsToCsv(List <ProcesoParametros> parametros, string keyExternalValue, object obj, ref string err) { try { err = ""; List <String> fieldValues = new List <string>(); for (int i = 0; i < parametros.Count; i++) { if (!parametros[i].isKey) { if (parametros[i].Type == null) { PropertyInfo[] ifnoo = obj.GetType().GetProperties(); PropertyInfo _propertyInfo = obj.GetType().GetProperty(parametros[i].fieldName); if (_propertyInfo == null) { err = "Property with names " + parametros[i].fieldName + " does not exists in " + obj.GetType().ToString() + Environment.NewLine; return(null); } object objectValue = _propertyInfo.GetValue(obj, null); Abstract ObjectQuickbook = objectValue as Abstract; if (ObjectQuickbook != null) { fieldValues.Add(ObjectQuickbook.ListID); } else { fieldValues.Add(Convert.ToString(objectValue).Replace("\"", "\"\"")); } } else { string[] field = parametros[i].Type.ToString().Split('/'); string fieldPropertyCustom = field[0]; //custom string fieldPropertyName = field[1]; //ID if (fieldPropertyCustom == "Custom") { Abstract newValueObject = obj as Abstract; string value = newValueObject.getDataExValue(fieldPropertyName); if (value != null) { fieldValues.Add(value.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } else { if (fieldPropertyCustom == "AdditionalContactRef") { if (((Vendor)obj).AdditionalContactRef == null) { fieldValues.Add(""); } else { AdditionalContact newValue = ((Vendor)obj).AdditionalContactRef.Find(d => d.ContactName == "Main Phone"); if (newValue != null) { fieldValues.Add(newValue.ContactValue.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } } else { ////si es otro dato compuesto obtener el tipo string value = HelperTask.getObjectValue(parametros[i].fieldName, fieldPropertyCustom, obj, fieldPropertyName, ref err); if (value != null) { fieldValues.Add(value.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } } } } else { if (parametros[i].Type == "Configuration") { fieldValues.Add(Config.CompaniaDB); } else { if (keyExternalValue != string.Empty) { fieldValues.Add(keyExternalValue); } else { fieldValues.Add(""); } } } } string fila = "\"" + String.Join("\",\"", fieldValues.ToArray()) + "\""; //fila="\" return(fila); } catch (Exception ex) { err = ex.Message + Environment.NewLine; return(string.Empty); } }
public static string ProcesoEjecutarToQuickBase(Proceso proceso) { // Access // Procesar Entrada.. StringBuilder mostrarMensaje = new StringBuilder(); var ws = new wClient.WService(); string err = ""; string resp = ws.doQuery(proceso.entrada.quickbaseAccessToken, null, out err); Quickbook.Config.App_Name = Properties.Settings.Default.qbook_app_name; Quickbook.Config.File = proceso.file; Quickbook.Config.CompaniaDB = proceso.companiaDB; Quickbook.Config.IsProduction = true; if (err != string.Empty) { mostrarMensaje.Append("Ejecutando accion Error en el servicio:" + err + Environment.NewLine); } var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; List <List <Par> > data = null; try { data = serializer.Deserialize <List <List <Par> > >(resp); } catch (Exception ex) { Console.WriteLine(ex.Message); mostrarMensaje.Append("Ejecutando accion Error des serializando:" + ex.Message + Environment.NewLine); } if (data == null) { mostrarMensaje.Append("Ejecutando accion data:null" + Environment.NewLine); } else { mostrarMensaje.Append("Ejecutando accion cantidad a procesar:" + data.Count + Environment.NewLine); } if (data != null && data.Count > 0) { // Inicializar Conexion a Quickbook Config.quickbooks = new Connector(Quickbook.Config.App_Name, Quickbook.Config.File); if (Config.quickbooks.Connect()) { foreach (ProcesoAccion accion in proceso.acciones) { //Revisando si tenemos respuesta creada a esta altura if (accion.tipo == "add_quickbook") { mostrarMensaje.Append("Ejecutando accion " + accion.nombre + Environment.NewLine); //creando la coleccion que almacenara las respuestas de la accion. List <ProcesoRespuesta> ConfiguracionRespuestaSave = accion.respuestas.FindAll(d => d.categoria == "Save"); List <ProcesoRespuesta> ConfiguracionRespuestaLog = accion.respuestas.FindAll(d => d.categoria == "Log"); Dictionary <string, List <string> > RespuestasSave = new Dictionary <string, List <string> >(); Dictionary <string, List <string> > RespuestasLog = new Dictionary <string, List <string> >(); string llaveQuickbook = ""; Dictionary <string, string> llaveQuickbase = new Dictionary <string, string>(); //obtener los campos de respuesta para los parametros a enviar //el token sera la llave Dictionary <string, string> fieldNameExternals = HelperTask.GetFieldNameKeyExternal(ConfiguracionRespuestaSave); for (int j = 0; j < data.Count; j++) { // Para Key => Value retornado desde Quickbase ; Hashtable pairs = Generic.getPairValues(data[j]); // Obtener la coleccion Fields => Value que se asignara al Objeto List <string> fieldNames = new List <string>(); List <object> fieldValues = new List <object>(); string fieldRiquiered = string.Empty; bool Requiered = false; //Get the Values to add to quickbook HelperTask.GetValuesToAdd(accion, pairs, ref fieldNames, ref fieldValues, ref fieldNameExternals, ref llaveQuickbase, ref fieldRiquiered, ref Requiered, ref mostrarMensaje, ref err); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string xmlSend = string.Empty; string xmlRecived = string.Empty; if (accion.quickbookTabla != string.Empty) { if (Requiered == false) { try { string fullPath = System.IO.Directory.GetCurrentDirectory(); Assembly testAssembly = Assembly.LoadFile(fullPath + "\\Quickbook.dll"); Type difineType = testAssembly.GetType("Quickbook." + accion.quickbookTabla); // create instance of class Calculator object objQuickbookInstance = Activator.CreateInstance(difineType); Abstract ObjectQuickbook = (Abstract)Generic.SetFields(fieldNames, fieldValues, objQuickbookInstance, ref err); if (ObjectQuickbook.HasChild) { if (pairs["CHILDS"] != null) { string pairsDetails = pairs["CHILDS"].ToString(); HelperTask.CargadoDetalle(ObjectQuickbook, accion, pairsDetails, ref err); } } if (ObjectQuickbook != null && ObjectQuickbook.AddRecord(ref err, ref xmlSend, ref xmlRecived)) { if (ConfiguracionRespuestaSave.Count > 0) { HelperTask.AddConfigSave(ConfiguracionRespuestaSave, llaveQuickbase, ObjectQuickbook, ref err, ref RespuestasSave); } } else { if (err == string.Empty) { if (ConfiguracionRespuestaLog.Count > 0) { xmlSend = xmlSend.Replace(",", "."); xmlSend = xmlSend.Replace(Environment.NewLine, ""); xmlRecived = xmlRecived.Replace(",", "."); xmlRecived = xmlRecived.Replace(Environment.NewLine, ""); string accionValue = accion.tipo + proceso.nombre; accionValue = accionValue.Replace(" ", ""); string log = accionValue + "," + xmlSend + "," + xmlRecived + "," + "0"; HelperTask.AddConfigLog(ConfiguracionRespuestaLog, log, ref RespuestasLog); } } else { if (ConfiguracionRespuestaLog.Count > 0) { xmlSend = xmlSend.Replace(",", "."); xmlSend = xmlSend.Replace(Environment.NewLine, ""); err = err.Replace(",", "."); err = err.Replace(Environment.NewLine, ""); string accionValue = accion.tipo + proceso.nombre; accionValue = accionValue.Replace(" ", ""); string log = accionValue + "," + xmlSend + "," + err + "," + "0"; HelperTask.AddConfigLog(ConfiguracionRespuestaLog, log, ref RespuestasLog); } } } } catch (Exception ex) { mostrarMensaje.Append("Error al Procesar los datos: " + ex.Message + Environment.NewLine); } } else { if (ConfiguracionRespuestaLog.Count > 0) { string accionValue = accion.tipo + proceso.nombre; accionValue = accionValue.Replace(" ", ""); string log = accionValue + "," + fieldRiquiered + "," + "Se requiere el campo se encuentra vacio o null" + "," + "0"; HelperTask.AddConfigLog(ConfiguracionRespuestaLog, log, ref RespuestasLog); } } } } mostrarMensaje.Append(HelperTask.ImportToQuickBase(ConfiguracionRespuestaSave, ConfiguracionRespuestaLog, RespuestasSave, RespuestasLog, ref err)); } } Config.quickbooks.Disconnect(); } else { mostrarMensaje.Append("Error no conecto a Quickbooks"); } // Fin conexion a Quickbook } return(mostrarMensaje.ToString()); }