Esempio n. 1
0
        static void ValidateArgs(ApplicationArgs args)
        {
            try
            {
                using (var cn = new SqlConnection(args.ConnectionString))
                {
                    cn.Open();
                    cn.Close();
                }
            }
            catch (Exception)
            {
                Console.Error.WriteLine(string.Format("Connection String: {0}", args.ConnectionString));
                throw;
            }

            if (!File.Exists(args.QestlabQesPath))
            {
                throw new FileNotFoundException("File 'qestlab.qes' could not be found", args.QestlabQesPath);
            }

            if (!Directory.Exists(args.ScriptFolder))
            {
                throw new FileNotFoundException("Script folder could not be found", args.ScriptFolder);
            }

            if (!(args.WriteTableStructure || args.WriteForeignKeys || args.WriteQestObjects))
            {
                throw new ArgumentException("Nothing to write");
            }
        }
Esempio n. 2
0
        private static void WriteScripts(ApplicationArgs args)
        {
            var writers = new List <ScriptWriterBase>();

            if (args.WriteTableStructure)
            {
                writers.Add(new TableStructureScriptWriter(args.ConnectionString, Path.Combine(args.ScriptFolder, @"structure\structure.tables.qn.sql")));
            }

            if (args.WriteForeignKeys)
            {
                writers.Add(new ForeignKeysScriptWriter(args.ConnectionString, Path.Combine(args.ScriptFolder, @"structure\structure.foreignkeys.qn.sql")));
            }

            if (args.WriteQestObjects)
            {
                writers.Add(new QestObjectsScriptWriter(args.QestlabQesPath, Path.Combine(args.ScriptFolder, @"data\data.object_types.qn.sql"), Path.Combine(Path.GetDirectoryName(args.QestlabQesPath), "QESTLabObjects.sql")));
            }

            if (writers.Count() == 0)
            {
                return;
            }

            if (!args.Silent)
            {
                foreach (var w in writers)
                {
                    w.ProgressWrite += WriteProgress;
                }
            }

            CancelWrite = new CancellationTokenSource();

            Tasks = writers.Select(w => w.WriteToFileAsync(CancelWrite.Token)).ToList();

            foreach (var t in Tasks)
            {
                t.ContinueWith(WriteComplete);
            }

            Tasks.First().Start();
        }