예제 #1
0
        /// <summary>
        /// Returns a file object based on the format description.
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public DataFileBase CreateFile(FileFormatDescription format)
        {
            var c = format.Type.GetConstructor(Type.EmptyTypes);
            var f = (DataFileBase)c.Invoke(null);

            return f;
        }
예제 #2
0
        /// <summary>
        /// Returns a file object based on the format description.
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public DataFileBase CreateFile(FileFormatDescription format)
        {
            var c = format.Type.GetConstructor(Type.EmptyTypes);
            var f = (DataFileBase)c.Invoke(null);

            return(f);
        }
예제 #3
0
        public JobInstance ScheduleAsJob(TableOrView source, string path, FileFormatDescription format, string queueName, string comments)
        {
            var job = GetInitializedJobInstance(queueName, comments);

            var et = new ExportTable();

            et.Source = source;

            // TODO: change this to support different compression formats
            path = Path.Combine(path, String.Format("{0}_{1}_{2}{3}.gz", Context.UserName, job.JobID, source.ObjectName, format.DefaultExtension));

            var destination = FileFormatFactory.CreateFile(format);
            destination.Uri = new Uri(String.Format("file:///{0}", path));
            destination.FileMode = DataFileMode.Write;
            destination.Compression = CompressionMethod.GZip;

            // special initialization in case of a text file
            if (destination is TextDataFile)
            {
                var tf = (TextDataFile)destination;
                tf.Encoding = Encoding.ASCII;
                tf.Culture = System.Globalization.CultureInfo.InvariantCulture;
                tf.GenerateIdentityColumn = false;
                tf.ColumnNamesInFirstLine = true;
            }

            et.Destination = destination;

            job.Parameters["Parameters"].SetValue(et);

            return job;
        }
예제 #4
0
        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;
        }
예제 #5
0
        public FileFormatDescription GetFileFormatDescription(Uri uri, out string filename, out string extension, out DataFileCompression compression)
        {
            GetExtensionWithoutCompression(uri, out filename, out extension, out compression);

            // FInd file format with the appropriate extensions
            FileFormatDescription format = null;

            foreach (var f in GetFileFormatDescriptions())
            {
                if (StringComparer.InvariantCultureIgnoreCase.Compare(extension, f.Value.DefaultExtension) == 0)
                {
                    format = f.Value;
                    break;
                }
            }

            return(format);
        }