当前位置: 首页>>代码示例>>C#>>正文


C# IShellContext.OutputMessage方法代码示例

本文整理汇总了C#中IShellContext.OutputMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IShellContext.OutputMessage方法的具体用法?C# IShellContext.OutputMessage怎么用?C# IShellContext.OutputMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShellContext的用法示例。


在下文中一共展示了IShellContext.OutputMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoRun

 protected override void DoRun(IShellContext context)
 {
     context.OutputMessage("Opening MS Excel");
     var model = ExcelModel.CreateNewWindow();
     model.DataFormat = DataFormat;
     context.SetVariable(GetExcelVariableName(context), model);
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:7,代码来源:NewWindow.cs

示例2: GetName

 ICdlWriter ITabularDataTarget.CreateWriter(TableInfo rowFormat, CopyTableTargetOptions options, IShellContext context, DataFormatSettings sourceDataFormat)
 {
     string file = GetName(context);
     file = context.ResolveFile(file, ResolveFileMode.Output);
     context.OutputMessage("Writing file " + Path.GetFullPath(file));
     return new CdlFileWriter(file, rowFormat);
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:7,代码来源:CdlFile.cs

示例3: DoRun

 protected override void DoRun(IShellContext context)
 {
     string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
     context.OutputMessage("Writing file " + Path.GetFullPath(file));
     var model = ExcelModel.CreateFile(file);
     model.DataFormat = DataFormat;
     context.SetVariable(GetExcelVariableName(context), model);
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:8,代码来源:Create.cs

示例4: DoRun

        protected override void DoRun(IShellContext context)
        {
            context.OutputMessage("DBSH-00152 Importing dataset");

            using (var conn = GetConnectionProvider(context).Connect())
            {
                GetModel(context).ImportIntoDatabase(conn);
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:9,代码来源:Import.cs

示例5: DoRun

 protected override void DoRun(IShellContext context)
 {
     string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
     context.OutputMessage("DBSH-00118 Exporting SQL file Writing " + file);
     using (var fw = new StreamWriter(file))
     {
         GetModel(context).WriteSql(fw);
     }
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:9,代码来源:WriteSql.cs

示例6: DoRun

 protected override void DoRun(IShellContext context)
 {
     string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
     string url = context.Replace(Url);
     context.OutputMessage("Downloading from URL " + url);
     using (var client = new WebClient())
     {
         client.DownloadFile(url, file);
     }
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:10,代码来源:Download.cs

示例7: DoRun

        protected override void DoRun(IShellContext context)
        {
            object model = null;
            IModelProvider provider = null;
            if (Model is string)
            {
                model = context.Evaluate((string) Model);
                if (model is IModelProvider)
                {
                    provider = (IModelProvider) model;
                    model = provider.GetModel(context);
                }
            }
            else if (Model is IModelProvider)
            {
                provider = (IModelProvider)Model;
                model = provider.GetModel(context);
            }
            else
            {
                model = Model;
            }

            _log.InfoFormat("DBSH-00074 Apply template {0}=>{1}", TemplateFile ?? "(inline template)", File);

            string templateData = LoadTemplate(context);

            try
            {
                string fn = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
                context.OutputMessage("Generating file " + fn);
                using (var sw = new StreamWriter(fn))
                {
                    RazorScripting.ParseRazor(templateData, sw.Write, model, 
                        provider != null ? provider.InitializeTemplate : (Action<IRazorTemplate, IShellContext>) null, context);
                }
            }
            catch (RazorEngine.Templating.TemplateCompilationException err)
            {
                _log.ErrorFormat("DBSH-00075 Error compiling template {0}", TemplateFile);
                foreach (var error in err.Errors)
                {
                    _log.Error(error.ToString());
                }
                throw;
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:47,代码来源:Razor.cs

示例8: DoRun

        protected override void DoRun(IShellContext context)
        {
            var model = GetModel(context);
            var sqlModel = new DataSyncSqlModel(model, context, true, context.Replace(GetProviderString(context)));

            var connection = GetConnectionProvider(context);
            using (var conn = connection.Connect())
            {
                var sqlconn = conn as SqlConnection;
                if (sqlconn != null)
                {
                    sqlconn.InfoMessage += (s, e) =>
                    {
                        foreach (SqlError error in e.Errors)
                        {
                            context.OutputMessage(error.Message);
                        }
                    };
                }
                sqlModel.Run(conn, connection.Factory, context, UseTransaction, sqlModel.Parameters, GetParameterValues(context));
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:22,代码来源:Run.cs

示例9: DoRun

        protected override void DoRun(IShellContext context)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FtpDirectory);
            //request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            request.Method = WebRequestMethods.Ftp.ListDirectory;

            string pwd = Password;
            if (!String.IsNullOrEmpty(PasswordEncoded)) pwd = XmlTool.SafeDecodeString(PasswordEncoded);

            //request.KeepAlive = false;
            //request.UseBinary = true;
            request.UsePassive = PassiveMode;
            request.Credentials = new NetworkCredential(Login, pwd);

            var files = new List<string>();

            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                var responseStream = response.GetResponseStream();
                using (var reader = new StreamReader(responseStream))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine()?.Trim();
                        if (String.IsNullOrEmpty(line)) continue;
                        if (line == "." || line == "..") continue;
                        files.Add(line);
                    }
                }
            }

            foreach (string file in files)
            {
                FtpWebRequest requestLength = (FtpWebRequest)WebRequest.Create(FtpDirectory + file);
                requestLength.UsePassive = PassiveMode;
                requestLength.Credentials = new NetworkCredential(Login, pwd);
                requestLength.Method = WebRequestMethods.Ftp.GetFileSize;

                long ftpSize;
                using (FtpWebResponse response = (FtpWebResponse)requestLength.GetResponse())
                {
                    ftpSize = response.ContentLength;
                    response.Close();
                }

                long localSize = 0;
                string localFile = Path.Combine(LocalDirectory, file);
                if (System.IO.File.Exists(localFile)) localSize = new FileInfo(localFile).Length;

                if (localSize != ftpSize)
                {
                    context.OutputMessage($"Downloading file {file}, size={ftpSize}");

                    FtpWebRequest requestFile = (FtpWebRequest)WebRequest.Create(FtpDirectory + file);
                    requestFile.UsePassive = PassiveMode;
                    requestFile.Credentials = new NetworkCredential(Login, pwd);
                    requestFile.Method = WebRequestMethods.Ftp.DownloadFile;

                    using (var response = requestFile.GetResponse())
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            using (BinaryWriter writer = new BinaryWriter(System.IO.File.Open(localFile, FileMode.Create)))
                            {
                                int bytesRead = 0;
                                byte[] buffer = new byte[1024];

                                while (true)
                                {
                                    bytesRead = stream.Read(buffer, 0, buffer.Length);
                                    if (bytesRead == 0) break;
                                    writer.Write(buffer, 0, bytesRead);
                                }
                            }
                        }
                    }
                }
                else
                {
                    context.OutputMessage($"Skipping file {file}");
                }
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:83,代码来源:FtpSyncDirectory.cs

示例10: DoRun

        protected override void DoRun(IShellContext context)
        {
            if (File != null && Command != null) throw new Exception("DBSH-00060 Both Script.File and Script.Command properties are set");
            if (File == null && Command == null && Files == null) throw new Exception("DBSH-00061 None of Script.File and Script.Command and Script.Files properties are set");

            var connection = GetConnectionProvider(context);
            using (var conn = connection.Connect())
            {
                DbTransaction tran = null;
                try
                {
                    if (UseTransactions)
                    {
                        context.OutputMessage("Opening transaction");
                        tran = conn.BeginTransaction();
                    }

                    // execute inline command
                    if (Command != null)
                    {
                        RunScript(new StringReader(Command), conn, tran, UseReplacements == null || UseReplacements == true, true, false, context);
                    }

                    // execute linked file
                    if (File != null)
                    {
                        string fn = context.ResolveFile(File, ResolveFileMode.Input);
                        using (var reader = new StreamReader(fn, FileEncoding))
                        {
                            _log.InfoFormat("DBSH-00067 Executing SQL file {0}", fn);
                            context.OutputMessage(String.Format("Executing SQL file {0}", fn));
                            RunScript(reader, conn, tran, UseReplacements == true, false, true, context);
                        }
                    }
                    if (Files != null)
                    {
                        foreach (string file in Files)
                        {
                            string fn = context.ResolveFile(file, ResolveFileMode.Input);
                            using (var reader = new StreamReader(fn, FileEncoding))
                            {
                                _log.InfoFormat("DBSH-00148 Executing SQL file {0}", fn);
                                context.OutputMessage(String.Format("Executing SQL file {0}", fn));
                                RunScript(reader, conn, tran, UseReplacements == true, false, true, context);
                            }
                        }
                    }

                    if (tran != null)
                    {
                        context.OutputMessage("Commiting transaction");
                        tran.Commit();
                    }
                }
                catch
                {
                    if (tran != null)
                    {
                        context.OutputMessage("Rollbacking transaction");
                        tran.Rollback();
                    }
                    throw;
                }
                finally
                {
                    if (tran != null)
                    {
                        tran.Dispose();
                    }
                }
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:72,代码来源:Script.cs

示例11: DoRun

 protected override void DoRun(IShellContext context)
 {
     var childContext = context.CreateChildContext();
     childContext.CreateScope();
     foreach (var item in Source.GetList(context))
     {
         if (Property == null)
         {
             bool processed = false;
             var dct = item as Dictionary<string, object>;
             if (dct != null)
             {
                 foreach (var tuple in dct)
                 {
                     childContext.SetVariable(tuple.Key, tuple.Value);
                 }
                 processed = true;
             }
             var record = item as ICdlRecord;
             if (record != null)
             {
                 for (int i = 0; i < record.FieldCount; i++)
                 {
                     childContext.SetVariable(record.GetName(i), record.GetValue(i));
                 }
                 processed = true;
             }
             if (!processed) throw new Exception("DBSH-00077 Property is not set and Items collection doesn't return property names");
         }
         else
         {
             childContext.SetVariable(Property, item);
         }
         try
         {
             foreach (var command in Commands)
             {
                 command.Run(childContext);
             }
         }
         catch (Exception err)
         {
             if (!ContinueOnErrors) throw;
             context.OutputMessage(err.Message);
         }
     }
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:47,代码来源:ForEach.cs

示例12: if

        ICdlWriter ITabularDataTarget.CreateWriter(TableInfo rowFormat, CopyTableTargetOptions options, IShellContext context, DataFormatSettings sourceDataFormat)
        {
            string file = context.ResolveFile(context.Replace(Name), ResolveFileMode.Output);
            context.OutputMessage("Writing file " + Path.GetFullPath(file));
            var dbf = new SocialExplorer.IO.FastDBF.DbfFile(Encoding);
            if (File.Exists(file)) File.Delete(file);
            dbf.Create(file);

            foreach (var col in rowFormat.Columns)
            {
                DbfColumn.DbfColumnType type;
                int len = 0, scale = 0;
                switch (col.CommonType.Code)
                {
                    case DbTypeCode.Array:
                    case DbTypeCode.Generic:
                    case DbTypeCode.Text:
                    case DbTypeCode.Xml:
                        type = DbfColumn.DbfColumnType.Memo;
                        break;
                    case DbTypeCode.Blob:
                        type = DbfColumn.DbfColumnType.Binary;
                        break;
                    case DbTypeCode.Datetime:
                        var dtype = (DbTypeDatetime) col.CommonType;
                        if (dtype.SubType == DbDatetimeSubType.Date)
                        {
                            type = DbfColumn.DbfColumnType.Date;
                        }
                        else
                        {
                            type = DbfColumn.DbfColumnType.Character;
                            len = DateTime.UtcNow.ToString("s").Length;
                        }
                        break;
                    case DbTypeCode.Float:
                        type = DbfColumn.DbfColumnType.Number;
                        len = 18;
                        scale = DefaultNumericScale;
                        break;
                    case DbTypeCode.Int:
                        if (AllowFoxProInteger)
                        {
                            type = DbfColumn.DbfColumnType.Integer;
                        }
                        else
                        {
                            type = DbfColumn.DbfColumnType.Number;
                            len = 18;
                        }
                        break;
                    case DbTypeCode.Logical:
                        type = DbfColumn.DbfColumnType.Boolean;
                        break;
                    case DbTypeCode.Numeric:
                        type = DbfColumn.DbfColumnType.Number;
                        len = 18;
                        scale = ((DbTypeNumeric) col.CommonType).Scale;
                        break;
                    case DbTypeCode.String:
                        var stype = (DbTypeString) col.CommonType;
                        if (stype.IsBinary)
                        {
                            type = DbfColumn.DbfColumnType.Binary;
                        }
                        else if (stype.Length <= 254)
                        {
                            type = DbfColumn.DbfColumnType.Character;
                            len = stype.Length;
                            if (len <= 0) len = DefaultStringLength;
                        }
                        else
                        {
                            type = DbfColumn.DbfColumnType.Memo;
                        }
                        break;
                    default:
                        type = DbfColumn.DbfColumnType.Character;
                        len = DefaultStringLength;
                        break;

                }
                dbf.Header.AddColumn(col.Name, type, len, scale);
            }

            return new DbfWriter(dbf, DataFormat);
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:87,代码来源:DbfFile.cs

示例13: DoRun

        protected override void DoRun(IShellContext context)
        {
            ITabularDataSource source;
            ITabularDataTarget target;

            if (Source != null && SourceExpression != null) throw new Exception("DBSH-00087 CopyTable: Both Source and SourceExpression are set");
            if (Source == null && SourceExpression == null) throw new Exception("DBSH-00088 CopyTable: None Source and SourceExpression are set");
            if (Target != null && TargetExpression != null) throw new Exception("DBSH-00089 CopyTable: Both Target and TargetExpression are set");
            if (Target == null && TargetExpression == null) throw new Exception("DBSH-00090 CopyTable: None Target and TargetExpression are set");

            if (SourceExpression != null)
            {
                source = (ITabularDataSource) context.Evaluate(SourceExpression);
            }
            else
            {
                source = Source;
            }

            if (TargetExpression != null)
            {
                target = (ITabularDataTarget) context.Evaluate(TargetExpression);
            }
            else
            {
                target = Target;
            }

            var options = new CopyTableTargetOptions
                {
                    TruncateBeforeCopy = CleanTarget,
                    TargetMapMode = TargetMapMode,
                    AllowBulkCopy = AllowBulkCopy,
                };

            var table = source.GetRowFormat(context);

            _log.InfoFormat("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context));
            context.OutputMessage(String.Format("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context)));

            var transformedInputTable = table;
            var counts = new List<int>();
            if (ColumnMap.Count > 0)
            {
                transformedInputTable = new TableInfo(null);
                foreach (var mapItem in ColumnMap)
                {
                    var newCols = mapItem.GetOutputColumns(table, context);
                    counts.Add(newCols.Length);
                    transformedInputTable.Columns.AddRange(newCols);
                }
            }

            using (var reader = source.CreateReader(context))
            {
                using (var writer = target.CreateWriter(transformedInputTable, options, context, source.GetSourceFormat(context)))
                {
                    int rowNumber = 0;
                    while (reader.Read())
                    {
                        if (ColumnMap.Count > 0)
                        {
                            var outputRecord = new ArrayDataRecord(transformedInputTable);
                            int columnIndex = 0;
                            for (int i = 0; i < ColumnMap.Count; i++)
                            {
                                var map = ColumnMap[i];
                                int count = counts[i];
                                for (int j = 0; j < count; j++, columnIndex++)
                                {
                                    outputRecord.SeekValue(columnIndex);
                                    map.ProcessMapping(j, rowNumber, reader, outputRecord, context);
                                }
                            }
                            writer.Write(outputRecord);
                        }
                        else
                        {
                            writer.Write(reader);
                        }
                        rowNumber++;
                    }
                }
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:85,代码来源:CopyTable.cs

示例14: StreamWriter

 ICdlWriter ITabularDataTarget.CreateWriter(TableInfo rowFormat, CopyTableTargetOptions options, IShellContext context, DataFormatSettings sourceDataFormat)
 {
     string file = context.ResolveFile(GetName(context), ResolveFileMode.Output);
     context.OutputMessage("Writing file " + Path.GetFullPath(file));
     //var fs = System.IO.File.OpenWrite(file);
     var fw = new StreamWriter(file, false, Encoding);
     var writer = new CsvWriter(fw, Delimiter, Quote, Escape, Comment, QuotingMode, EndOfLine, DataFormat);
     if (HasHeaders)
     {
         writer.WriteRow(rowFormat.Columns.Select(c => c.Name));
     }
     return writer;
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:13,代码来源:CsvFile.cs

示例15: DoRun

 protected override void DoRun(IShellContext context)
 {
     string text = context.Replace(Message);
     _log.Info(text);
     context.OutputMessage(text);
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:6,代码来源:Echo.cs


注:本文中的IShellContext.OutputMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。