public void runQuery(List<xFerParamater> _vars)
        {
            string packageName = _vars[0].Value.ToString();
            string dbName = _vars[1].Value.ToString();
            string xQuery = _vars[2].Value.ToString();
            string collection = string.Empty;
            List<xFerParamater> _params = new List<xFerParamater>();
            if (_vars.Count > 3)
            {
                string paramtext = string.Empty;
                try
                {
                    collection = _vars[3].Value.ToString().Trim();

                    if (collection.IndexOf("[") > -1)
                    {
                        collection = string.Empty;
                        paramtext = _vars[3].Value.ToString().Trim();
                    }


                }
                catch
                {
                }

                if(_vars.Count > 4)
                try
                {
                    paramtext = _vars[4].Value.ToString().Trim();
                }
                catch
                {
                }

                if (paramtext != string.Empty)
                {
                    _params = getParametersPassed(paramtext);
                }
            }


             xFerCalls call = new xFerCalls();
             xFer xMe = new xFer();
             xMe.MongoCollection = collection;
             foreach (xFerPackage p in _xFerPackages)
             {
                 if (p.PackageName == packageName)
                 {
                     foreach (xFerQuery q in p.Queries)
                     {
                         if (q.QueryName == xQuery)
                         {

                             xMe.SourceQuery = q;
                             if (_params.Count > 0)
                             {
                                 xMe.SourceQuery.Paramaters = _params;
                             }
                         }
                     }
                 }

                 foreach (xFerDb db in _dbs)
                 {
                     if (db.DbName == dbName)
                     {
                         xMe.SourceDb = db;
                     }
                 }

             }

             if (xMe.SourceDb.ConnectionString != string.Empty && xMe.SourceQuery.QueryText.ToString() != string.Empty)
             {
                 DataTable dt = call.transfer(xMe);

                 if (dt != null)
                 {
                     if (dt.Rows.Count > 0)
                     {
                         StringBuilder sbHeader = new StringBuilder();
                         StringBuilder sbSubHeader = new StringBuilder();
                         foreach (DataColumn dc in dt.Columns)
                         {
                             sbHeader.Append(dc.ColumnName.ToString() + "\t");
                             sbSubHeader.Append(returnDots(dc.ColumnName.ToString()) + "\t");
                         }

                         Console.WriteLine(sbHeader.ToString());
                         Console.WriteLine(sbSubHeader.ToString());

                         foreach (DataRow dr in dt.Rows)
                         {
                             StringBuilder sbRow = new StringBuilder();

                             for (int i = 0; i < dt.Columns.Count; i++)
                             {
                                 sbRow.Append(dr[i].ToString() + "\t");
                             }

                             Console.WriteLine(sbRow.ToString());
                         }
                     }
                 }

             }


        }
Example #2
0
        public DataTable transfer(xFer x)
        {
            //TEST CONNECTIONS
            bool sourceConn = testConnection(x.SourceDb.ConnectionString, x.SourceDb.DbType);
            bool destConn = false;
            if (x.DestinationDb.ConnectionString.Trim().Length > 0)
            {
                destConn = testConnection(x.DestinationDb.ConnectionString, x.DestinationDb.DbType);
            }
            DataTable dt = new DataTable();

            if (!sourceConn)
            {
                _errors.Add("Source Connection Failed.");
                Console.WriteLine("Source Connection Failed: " + x.SourceDb.DbName);
            }
            if (!destConn && x.DestinationDb.ConnectionString.Trim().Length > 0)
            {
                _errors.Add("Destination Connection Failed.");
                Console.WriteLine("Destination Connection Failed: " + x.SourceDb.DbName);
            }

            if(sourceConn)
            {

                dt = getData(x.SourceDb, x.SourceQuery, x.MongoCollection);


                if (destConn)
                {
                    if (dt.Rows.Count > 0)
                    {
                        putData(x.DestinationDb, dt, x.xFerType, x.DestinationQuery, x.MongoCollection);
                    }
                }
                else
                {
                    
                }

            }
            return dt;
        }
        public void createxFer(List<xFerParamater> _vars)
        {

            string packageName = _vars[0].Value.ToString();
            string xFerName = _vars[1].Value.ToString();
            string sourcedb = _vars[2].Value.ToString();
            string destinationdb = _vars[3].Value.ToString();
            string xFerType = _vars[4].Value.ToString();
            string sourceQuery = _vars[5].Value.ToString();
            string destinationQuery = string.Empty;
            string mongoCollection = _vars[6].Value.ToString();

            if (_vars.Count > 7)
            {
                destinationQuery = _vars[7].Value.ToString();
            }


            xFer _x = new xFer();
            //SEE IF PACKAGE EXISTS
            foreach (xFerPackage p in _xFerPackages)
            {
                if (p.PackageName == packageName)
                {
                    bool isUpdate = false;
                    foreach (xFer xin in p.XFers)
                    {
                        if (xin.XFerName == xFerName)
                        {
                            isUpdate = true;
                            foreach (xFerDb db in _dbs)
                            {
                                if (db.DbName == sourcedb)
                                {
                                    xin.SourceDb = db;
                                }
                                else if (db.DbName == destinationdb)
                                {
                                    xin.DestinationDb = db;
                                }
                            }

                            xin.xFerType = getTransferType(xFerType);
                            //_x.SourceQuery

                            foreach (xFerQuery q in p.Queries)
                            {
                                if (q.QueryName == sourceQuery)
                                {
                                    xin.SourceQuery = q;
                                }
                                else if (q.QueryName == destinationQuery)
                                {
                                    xin.DestinationQuery = q;
                                }
                            }

                            xin.MongoCollection = mongoCollection;

                            //save pacakge
                            xFerFiles.createFile(LitJson.JsonMapper.ToJson(p), _initPath + "\\package_" + p.PackageName + ".txt");
                        }
                    }

                    if (!isUpdate)
                    {
                        _x.XFerName = xFerName;

                        foreach (xFerDb db in _dbs)
                        {
                            if (db.DbName == sourcedb)
                            {
                                _x.SourceDb = db;
                            }
                            else if (db.DbName == destinationdb)
                            {
                                _x.DestinationDb = db;
                            }
                        }

                        _x.xFerType = getTransferType(xFerType);
                        //_x.SourceQuery

                        foreach (xFerQuery q in p.Queries)
                        {
                            if (q.QueryName == sourceQuery)
                            {
                                _x.SourceQuery = q;
                            }
                            else if (q.QueryName == destinationQuery)
                            {
                                _x.DestinationQuery = q;
                            }
                        }
                        _x.MongoCollection = mongoCollection;
                        p.XFers.Add(_x);
                        //save pacakge
                        xFerFiles.createFile(LitJson.JsonMapper.ToJson(p), _initPath + "\\package_" + p.PackageName + ".txt");
                    }
                }
            }



        }