Esempio n. 1
0
 protected void ReadTable(DataFileBase source, DestinationTable destination)
 {
     // Import the file by wrapping it into a dummy command
     using (var cmd = new FileCommand(source))
     {
         ImportTable(cmd, destination);
     }
 }
Esempio n. 2
0
        private void WriteTable(IDbCommand cmd, DataFileBase destination)
        {
            // Wrap command into a cancellable task
            var guid = Guid.NewGuid();
            var ccmd = new CancelableDbCommand(cmd);

            RegisterCancelable(guid, ccmd);

            // Pass data reader to the file formatter
            ccmd.ExecuteReader(dr =>
            {
                destination.WriteFromDataReader(dr);
            });

            UnregisterCancelable(guid);
        }
        public JobInstance ScheduleAsJob(Federation federation, TableOrView[] sources, string path, FileFormatDescription format, string queueName, string comments)
        {
            var job = GetInitializedJobInstance(queueName, comments);

            var settings = new ExportTablesJobSettings(job.JobDefinition.Settings);

            path = path ?? settings.OutputDirectory;
            path = Path.Combine(path, String.Format("{0}_{1}{2}", Context.UserName, job.JobID, Jhu.Graywulf.IO.Constants.FileExtensionZip));

            var destinations = new DataFileBase[sources.Length];

            for (int i = 0; i < sources.Length; i++)
            {
                var ff = FileFormatFactory.Create(federation.FileFormatFactory);

                var destination = ff.CreateFile(format);
                destination.Uri = Util.UriConverter.FromFilePath(String.Format("{0}{1}", sources[i].ObjectName, format.DefaultExtension));

                // special initialization in case of a text file
                // TODO: move this somewhere else, maybe web?
                if (destination is TextDataFileBase)
                {
                    var tf = (TextDataFileBase)destination;
                    tf.Encoding = Encoding.ASCII;
                    tf.Culture  = System.Globalization.CultureInfo.InvariantCulture;
                    tf.GenerateIdentityColumn = false;
                    tf.ColumnNamesInFirstLine = true;
                }

                destinations[i] = destination;
            }

            var et = new ExportTables()
            {
                Sources               = sources,
                Destinations          = destinations,
                Archival              = DataFileArchival.Zip,
                Uri                   = Util.UriConverter.FromFilePath(path),
                FileFormatFactoryType = federation.FileFormatFactory,
                StreamFactoryType     = federation.StreamFactory,
            };

            job.Parameters["Parameters"].Value = et;

            return(job);
        }
Esempio n. 4
0
 public void Catch(DataFileBase file, int line)
 {
     if (file.Filename != null)
     {
         NonfatalError.NotifyBackground(string.Format(ToolsStrings.SyntaxError_Unpacked, Path.GetFileName(file.Filename), line),
                                        ToolsStrings.SyntaxError_Commentary, null, new[] {
             new NonfatalErrorSolution(ToolsStrings.SyntaxError_Solution, null, token => {
                 WindowsHelper.OpenFile(file.Filename);
                 return(Task.Delay(0, token));
             })
         });
     }
     else
     {
         NonfatalError.NotifyBackground(string.Format(ToolsStrings.SyntaxError_Packed,
                                                      $"{file.Name} ({Path.GetFileName(file.Data?.Location ?? "?")})", line), ToolsStrings.SyntaxError_Commentary);
     }
 }
Esempio n. 5
0
        protected void WriteTable(SourceTableQuery source, DataFileBase destination)
        {
            // Create command that reads the table
            using (var cmd = source.CreateCommand())
            {
                using (var cn = source.OpenConnection())
                {
                    using (var tn = cn.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        cmd.Connection     = cn;
                        cmd.Transaction    = tn;
                        cmd.CommandTimeout = Timeout;

                        WriteTable(cmd, destination);
                    }
                }
            }
        }
Esempio n. 6
0
 private void CopyMembers(ImportTable old)
 {
     this.source      = old.source;
     this.destination = old.destination;
 }
Esempio n. 7
0
 private void InitializeMembers()
 {
     this.source      = null;
     this.destination = null;
 }