public static void PushGpDataToZudello()
        {
            string Token = ZudelloLogin.Login();



            SQLCredentials           ConnectionString = new SQLCredentials();
            Dictionary <int, string> Connection       = ConnectionString.ConnectionStringBuilder();


            /****
             *
             * Add threading into here for the foreach loop
             * will need to chunk based on amount of connections
             */


            //get the query from mappings table
            foreach (var Mappings in getBody())
            {
                //bool isXml = false;
                //Get the SQL statement
                string mySql = Mappings.Value.Body;
                //Get the Mappings
                dynamic zudelloObject = Mappings.Value;

                string SQLQuery = GpTools.RenderToSql(mySql, zudelloObject);

                //if (mySql.Contains("XML PATH")) isXml = true;
               #warning make this in config also for process method


                string cmd = SQLQuery;

                //Open SQL connection and run the SQL query


                //Get connection details by Key ID
                SqlConnection con           = new SqlConnection(Connection[Mappings.Value.connection_id]);
                SqlCommand    SelectCommand = new SqlCommand(cmd, con);
                // SqlDataReader myreader;
                con.Open();

                var jsonResult = new StringBuilder();

                var myreader = SelectCommand.ExecuteReader();

                if (!myreader.HasRows)
                {
                    //if there is no data then close connection and next loop
                    con.Close();
                    continue;
                }
                else
                {
                    while (myreader.Read())
                    {
                        jsonResult.Append(myreader.GetValue(0).ToString());
                    }
                    dynamic obj;
                    //Console.WriteLine(jsonResult);

                    obj = JsonConvert.DeserializeObject <ExpandoObject>(jsonResult.ToString());

                    foreach (var ObjectType in obj)

                    {
                        foreach (var dataValues in ObjectType.Value)
                        {
                            MyQueueObject dataWrapper = new MyQueueObject();

                            dataWrapper.data = dataValues;

                            string data = JsonConvert.SerializeObject(dataWrapper);
                            Console.WriteLine(data);
                            Console.WriteLine(ZudelloLogin.SendToZudelloQueue(Token, data));
                        }
                    }



                    //Update last sync time for this mapping ID
                    using (var db = new ZudelloContext())
                    {
                        var lastSync = db.Zlastsync.Where(s => s.MappingId == Mappings.Value.Id).FirstOrDefault();

                        lastSync.LastSync = DateTime.Now.ToString();
                        db.SaveChanges();
                    }
                }
                con.Close();
            }
        }
Exemple #2
0
        public static bool ProcessMethod(dynamic queueData)
        {
            string econnectDocument;
            string sXsdSchema;
            string sConnectionString;


            try
            {
                dynamic zudelloObject = JsonConvert.DeserializeObject <ExpandoObject>(queueData.queue.Body);
                string  order         = queueData.map.ProcessOrder.ToString();

                //Created at
                string obj     = queueData.map.DocType.ToString();
                string uuid    = "";//zudelloObject.invoiceUUID.ToString();
                string queueID = queueData.queue.Id.ToString();

                //Generate the eConnectXml
                string xmlRendered = GpTools.RenderXml(queueData.map.Body, zudelloObject);
                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        XmlDocument xmldoc = new XmlDocument();
                        xmldoc.LoadXml(xmlRendered);
                        econnectDocument = xmldoc.OuterXml;

                        //User ID=sa;Password=sa
                        using (var db = new ZudelloContext())
                        {
                            var Connection = db.Zconnections.Where(i => i.Id == 1).FirstOrDefault();

                            sConnectionString = String.Format(@"Data Source={0};Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog ={1};", Connection.DataSource, Connection.InitialCatalog);
                            db.Dispose();
                        }
                        // sConnectionString = @"Data Source=LAPTOP-BUDQ9SBN\DYNAMICGP;Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog = GP_DE;";
                        // Create an XML Document object for the schema
                        XmlDocument XsdDoc = new XmlDocument();

                        // Create a string representing the eConnect schema
                        sXsdSchema = XsdDoc.OuterXml;

                        // Pass in xsdSchema to validate against.
                        bool created = e.CreateEntity(sConnectionString, econnectDocument);
                        if (created == true)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    // The eConnectException class will catch eConnect business logic errors.
                    // display the error message on the console
                    catch (eConnectException exc)
                    {
                        Console.Write(exc.ToString());
                        e.Dispose();
                        return(false);
                    }
                    // Catch any system error that might occurr.
                    // display the error message on the console
                    catch (System.Exception ex)
                    {
                        Console.Write(ex.ToString());
                        e.Dispose();
                        return(false);
                    }
                }
            }


            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }