Ejemplo n.º 1
0
 /// <summary>
 /// Creates <see cref="PotentiallyAsyncWriterAndObservable{TValue}"/> which will write <see cref="JToken"/>s as character enumerables to given sink.
 /// </summary>
 /// <param name="logic">This <see cref="PotentiallyAsyncWriterLogic{TValue, TSink}"/>.</param>
 /// <param name="sink">The sink to which perform writing.</param>
 /// <returns>An instance of <see cref="PotentiallyAsyncWriterAndObservable{TValue}"/> to be used to serialize <see cref="JToken"/>s to <paramref name="sink"/>.</returns>
 public static PotentiallyAsyncWriterAndObservable <JToken> CreateJTokenWriter <TSink>(
     this PotentiallyAsyncWriterLogic <IEnumerable <Char>, TSink> logic,
     TSink sink
     )
 {
     return(WriterFactory.CreateTransformableWriter <JToken, TSink, IEnumerable <Char> >(
                ArgumentValidator.ValidateNotNullReference(logic),
                sink,
                TransformJToken
                ));
 }
Ejemplo n.º 2
0
        private async Task ExecuteTaskAsync()
        {
            Encoding encoding;
            var      encodingName = this.FileEncoding;

            if (String.IsNullOrEmpty(encodingName))
            {
                encoding = Encoding.UTF8;
            }
            else
            {
                encoding = Encoding.GetEncoding(encodingName);
            }

            var encodingInfo = encoding.CreateDefaultEncodingInfo();
            var vendor       = await this.LoadDynamically <SQLVendor>(this.VendorPackageID, this.VendorPackageVersion, this.VendorAssemblyPath, this.VendorTypeName);

            if (vendor != null)
            {
                var user = await this.LoadDynamically <SQLGeneratorUser>(this.GeneratorPackageID, this.GeneratorPackageVersion, this.GeneratorAssemblyPath, this.GeneratorTypeName);

                if (user != null)
                {
                    var path = Path.GetFullPath(this.OutputFile);
                    using (var fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        var streamWriter = StreamFactory.CreateUnlimitedWriter(fs, this._cancellationSource.Token);
                        var writer       = WriterFactory.CreateTransformableWriter <String, StreamWriterWithResizableBuffer, IEnumerable <Char> >(
                            new StreamCharacterWriter(encodingInfo, 1024),
                            streamWriter,
                            ToCharEnumerable
                            );
                        foreach (var sql in user.GenerateSQL(vendor))
                        {
                            await writer.TryWriteAsync(sql);
                        }
                        await streamWriter.FlushAsync();
                    }

                    this.Log.LogMessage(MessageImportance.High, $"Successfully wrote SQL file \"{path}\".");
                }
            }
        }