Beispiel #1
0
        public string javaSet([FromBody] filepath csv_file_path)
        {
            var count = data.Database.SqlQuery <int>(@"select exam_set_counts from Exam_List where exam_id=1").FirstOrDefault <int>();

            if (count <= 2)
            {
                var       free      = data.Database.SqlQuery <string>(@"select top 1 table_name from Java_Sets where availability = 'yes'").FirstOrDefault <string>();
                string    tableName = free;
                CSVtoSQL  c         = new CSVtoSQL();
                DataTable csvData   = FileReader.CSVtoSQL.GetDataTabletFromCSVFile(csv_file_path.csv_file_path);
                Console.WriteLine("Rows count:" + csvData.Rows.Count);

                c.InsertDataIntoSQLServerUsingSQLBulkCopy(csvData, tableName);
                foreach (var column in csvData.Columns)
                {
                    Console.WriteLine(column);
                }
                data.Database.ExecuteSqlCommand(@"update Java_Sets set availability = 'no' where table_name=@tablename", new SqlParameter("@tablename", free));
                data.Database.ExecuteSqlCommand(@"update Exam_List set exam_set_counts = exam_set_counts + 1 where exam_id =1");
                return("Added Successfully");
            }
            else
            {
                return("No More Set Can be Added");
            }
        }
Beispiel #2
0
        public void Execute(Arguments cmdLine)
        {
            this.CommandLine = cmdLine;
            // Conversion des paramètres entrées (ANSI to format FR)
            //ConvertANSI(ref args);

            Thread oThread = null;

            // lecture de la configuration
            now = DateTime.Now;

            // Affichage de la version du batch
            IntegratorBatch.InfoLogger.Debug(now + " DEBUT PROGRAMME");
#if !DEBUG
            Assembly     assem     = Assembly.GetEntryAssembly();
            Assembly     execAssem = Assembly.GetExecutingAssembly();
            AssemblyName assemName = assem.GetName();
            Version      ver       = assemName.Version;
            Version      execVer   = execAssem.GetName().Version;

            String message = "Application " + assemName.Name + " , Version(entry,exec,public) " + ver.ToString() + " " + execVer.ToString();
            try
            {
                Version publishVer = ApplicationDeployment.CurrentDeployment.CurrentVersion;
                message += " " + publishVer.ToString();
            }
            catch
            {
                message += " non disponible";
            }
            IntegratorBatch.InfoLogger.Info(message);
#endif

            string[] inutile = CommandLine.Intercept(new string[] { "csvTransfer", "bondPricer", "dbCopy", "csv", "oxlsx", "sql", "paramsql", "xls", "bp2s", "bp2sregex", "ini", "datastore", "nogui" });
            // afficher les parametres passés et inutiles
            // prendre ceux qui commencent par @xxx ou #xxx qui représentent les variables des connecteurs Producers/consumers
            if (inutile.Length > 0)
            {
                if (IntegratorBatch.InfoLogger.IsInfoEnabled)
                {
                    string liste = "(";
                    foreach (string s in inutile)
                    {
                        if (!s.StartsWith("@") && !s.StartsWith("#"))
                        {
                            liste += s + " ";
                        }
                    }
                    liste += ")";
                    if (liste.Length > 2)
                    {
                        IntegratorBatch.InfoLogger.Info("Les parametres suivants ne sont pas exploitees: " + liste);
                    }
                }
            }

            //------------------------------------------------------------------------------------------
            // programme executé avec des traces en lignes de commande
            if (CommandLine["nogui"] == null)
            {
                Console.WriteLine("FGA Automate: Execution d une extraction :");
                Console.WriteLine(CommandLine.ToString());

                oThread = new Thread(new ThreadStart(ConsoleSpiner.Go));
                oThread.Start();
            }

            //------------------------------------------------------------------------------------------
            // fichier de configuration des paramètres de base
            if (CommandLine["ini"] != null)
            {
                IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de configuration " + CommandLine["ini"]);
                InitFile.loginIni = CommandLine["ini"];
            }
            else
            {
                IntegratorBatch.InfoLogger.Debug("Lecture d un fichier de configuration par defaut " + InitFile.loginIni);
            }

            //------------------------------------------------------------------------------------------
            // fichier de configuration des paramètres de base
            string datastore = "OMEGA";
            if (CommandLine["datastore"] != null)
            {
                IntegratorBatch.InfoLogger.Debug("La base de donnees utilisee " + CommandLine["datastore"]);
                datastore = CommandLine["datastore"];
            }
            //------------------------------------------------------------------------------------------
            // option -@xxxx=yyyy : recueillir les parametres personnalises
            string[] keys, values;
            // tester si il y a des pararametres personnalise
            if (CommandLine.GetStartsWith("@", out keys, out values) > 0)
            {
                IntegratorBatch.InfoLogger.Debug("Lecture d une requete avec parametres : " + keys);
            }
            //------------------------------------------------------------------------------------------
            // option -paramsql : executer la requete fournie afin de recuperer une liste de parametres/valeurs sous la forme d 'un tableau
            string   paramsql    = CommandLine["paramsql"];
            object[] paramsValue = null;
            string   paramsName  = null;
            if (paramsql != null)
            {
                DataSet DS_Params = new DataSet();
                try
                {
                    SQLrequest p_1 = null;
                    // tester si il y a des pararametres personnalise
                    if (keys != null && keys.Length > 0)
                    {
                        p_1 = new SQLrequest(paramsql, datastore, keys, values);
                    }
                    else
                    {
                        p_1 = new SQLrequest(paramsql, datastore);
                    }
                    p_1.Execute(out DS_Params);
                    // transformer le dataset en tableau pour le reutiliser sur la requete SQL principale
                    paramsValue = getParamsArray(DS_Params, out paramsName);
                }
                catch (Exception e)
                {
                    IntegratorBatch.ExceptionLogger.Fatal("Impossible d executer la requete " + paramsql, e);
                    throw e;
                }
            }


            //------------------------------------------------------------------------------------------
            // lire un fichier csv et le mettre dans une table BDD
            string csvTransfer = CommandLine["csvTransfer"];
            if (csvTransfer != null)
            {
                string nomTable  = CommandLine["#nomTable"];
                string nomSchema = CommandLine["#nomSchema"] ?? "dbo";
                CSVtoSQL.DataBaseIntegrate(csvTransfer, datastore, nomSchema, nomTable);
            }
            //------------------------------------------------------------------------------------------


            if (paramsValue != null)
            {
                foreach (object extraValue in paramsValue)
                {
                    System.Collections.ArrayList _Keys = new System.Collections.ArrayList(keys);
                    _Keys.Add('@' + paramsName);
                    System.Collections.ArrayList _Values = new System.Collections.ArrayList(values);
                    _Values.Add(FGA.Automate.Helpers.Helper.ValueToSQLField(extraValue));
                    output(datastore,
                           (string[])_Keys.ToArray(typeof(string)),
                           (string[])_Values.ToArray(typeof(string)),
                           paramsName, extraValue.ToString());
                }
            }
            else
            {
                output(datastore,
                       keys,
                       values);
            }



            //------------------------------------------------------------------------------------------
            // programme executé avec des traces en lignes de commande
            if (CommandLine["nogui"] == null)
            {
                // Le traitement est terminé : arreter propremen la gauge
                ConsoleSpiner.go = false;
                oThread.Join();

                Console.WriteLine("Pressez une touche pour terminer");
                Console.ReadKey();
            }


            IntegratorBatch.InfoLogger.Debug(now + " FIN PROGRAMME");
        }