本文整理汇总了C#中IShellContext.ResolveFile方法的典型用法代码示例。如果您正苦于以下问题:C# IShellContext.ResolveFile方法的具体用法?C# IShellContext.ResolveFile怎么用?C# IShellContext.ResolveFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellContext
的用法示例。
在下文中一共展示了IShellContext.ResolveFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoRun
protected override void DoRun(IShellContext context)
{
string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Input);
var model = ExcelModel.OpenFile(file);
model.DataFormat = DataFormat;
context.SetVariable(GetExcelVariableName(context), model);
}
示例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);
}
示例3: CreateWriter
public ICdlWriter CreateWriter(TableInfo rowFormat, CopyTableTargetOptions options, IShellContext context, DataFormatSettings sourceDataFormat)
{
string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
var fw = new StreamWriter(file);
var provider = GetConnectionProvider(context);
return new SqlFileWriter(fw, provider.Factory);
}
示例4: DoRun
protected override void DoRun(IShellContext context)
{
string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
if (Expression != null && Value != null) throw new Exception("DBSH-00078 SaveToFile: both Expression and Value is set");
if (Expression == null && Value == null) throw new Exception("DBSH-00079 SaveToFile: none of Expression and Value is set");
if (Expression != null)
{
object obj = context.Evaluate(Expression);
if (obj is byte[])
{
var bytes = (byte[]) obj;
using (var fw = System.IO.File.OpenWrite(file))
{
fw.Write(bytes, 0, bytes.Length);
}
}
else
{
using (var fw = new StreamWriter(file, false, Encoding))
{
fw.Write(obj.ToString());
}
}
}
if (Value!=null)
{
string val = context.Replace(Value);
using (var fw = new StreamWriter(file, false, Encoding))
{
fw.Write(val);
}
}
}
示例5: OpenDbfRead
private SocialExplorer.IO.FastDBF.DbfFile OpenDbfRead(IShellContext context)
{
var dbf = new SocialExplorer.IO.FastDBF.DbfFile(Encoding);
var name = context.ResolveFile(context.Replace(Name), ResolveFileMode.Input);
dbf.Open(name, System.IO.FileMode.Open);
return dbf;
}
示例6: DoRun
protected override void DoRun(IShellContext context)
{
string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Input);
var model = ShapeFileModel.OpenFile(file, SpatialTool.GetProjection(Projection, context));
model.DataFormat = DataFormat;
model.AddFileIdentifier = AddFileIdentifier;
context.SetVariable(GetShpVariableName(context), model);
}
示例7: 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);
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: LoadTemplate
protected string LoadTemplate(IShellContext context)
{
string templateData = TemplateData;
if (templateData == null && TemplateFile != null)
{
using (var sr = new StreamReader(context.ResolveFile(context.Replace(TemplateFile), ResolveFileMode.Template)))
{
templateData = sr.ReadToEnd();
}
}
return templateData;
}
示例11: OpenRead
private void OpenRead(out TableInfo table, out BinaryReader br, IShellContext context)
{
string file = GetName(context);
file = context.ResolveFile(file, ResolveFileMode.Input);
var fr = new FileInfo(file).OpenRead();
br = new BinaryReader(fr);
string s = br.ReadString();
var doc = new XmlDocument();
doc.LoadXml(s);
table = new TableInfo(null);
table.LoadFromXml(doc.DocumentElement);
table.AfterLoadLink();
}
示例12: 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;
}
}
示例13: GetInstructions
private List<XmlReadInstructions> GetInstructions(IShellContext context)
{
if (!AnalyseColumns)
{
var res = new List<XmlReadInstructions>();
if (!String.IsNullOrEmpty(XPath) && Columns.Any())
{
res.Add(new XmlReadInstructions
{
Columns = Columns,
XPath = XPath,
});
}
if (Instructions != null) res.AddRange(Instructions);
return res;
}
string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Input);
return XmlTableAnalyser.AnalyseFile(file, true);
}
示例14: LoadTextContent
protected string LoadTextContent(object model, IShellContext context)
{
string templateData = LoadTemplate(context);
if (templateData != null)
{
var sw = new StringWriter();
RazorScripting.ParseRazor(templateData, sw.Write, model);
return sw.ToString();
}
string textData = TextData;
if (textData == null && TextFile != null)
{
using (var sr = new StreamReader(context.ResolveFile(context.Replace(TextFile), ResolveFileMode.Input)))
{
textData = sr.ReadToEnd();
}
}
return textData;
}
示例15: 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();
}
}
}
}