本文整理汇总了C#中IronRuby.Builtins.RubyFile类的典型用法代码示例。如果您正苦于以下问题:C# RubyFile类的具体用法?C# RubyFile怎么用?C# RubyFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RubyFile类属于IronRuby.Builtins命名空间,在下文中一共展示了RubyFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMainTopLevelScope
public static RubyTopLevelScope/*!*/ CreateMainTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language,
out object self, out RuntimeFlowControl/*!*/ rfc, string dataPath, int dataOffset) {
Assert.NotNull(locals, globalScope, language);
GlobalScopeExtension rubyGlobalScope = (GlobalScopeExtension)language.EnsureScopeExtension(globalScope);
RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals);
scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject);
scope.SetDebugName(rubyGlobalScope.IsHosted ? "top-primary-hosted" : "top-primary");
// define TOPLEVEL_BINDING constant:
if (!rubyGlobalScope.IsHosted) {
var objectClass = rubyGlobalScope.Context.ObjectClass;
objectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope));
if (dataOffset >= 0) {
RubyFile dataFile;
if (File.Exists(dataPath)) {
dataFile = new RubyFile(rubyGlobalScope.Context, dataPath, RubyFileMode.RDONLY);
dataFile.Seek(dataOffset, SeekOrigin.Begin);
} else {
dataFile = null;
}
objectClass.SetConstant("DATA", dataFile);
}
}
self = scope.SelfObject;
rfc = scope.RuntimeFlowControl;
return scope;
}
示例2: CreateMainTopLevelScope
public static RubyTopLevelScope/*!*/ CreateMainTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language,
out object self, out RuntimeFlowControl/*!*/ rfc, string dataPath, int dataOffset) {
Assert.NotNull(locals, globalScope, language);
RubyContext context = (RubyContext)language;
RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false);
RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals);
scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject);
scope.SetDebugName("top-main");
var objectClass = context.ObjectClass;
objectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope));
if (dataOffset >= 0) {
RubyFile dataFile;
if (context.DomainManager.Platform.FileExists(dataPath)) {
dataFile = new RubyFile(context, dataPath, RubyFileMode.RDONLY);
dataFile.Seek(dataOffset, SeekOrigin.Begin);
} else {
dataFile = null;
}
objectClass.SetConstant("DATA", dataFile);
}
self = scope.SelfObject;
rfc = scope.RuntimeFlowControl;
return scope;
}
示例3: SetDataConstant
public static void SetDataConstant(RubyScope/*!*/ scope, string/*!*/ dataPath, int dataOffset) {
Debug.Assert(dataOffset >= 0);
RubyFile dataFile;
RubyContext context = scope.RubyContext;
if (context.DomainManager.Platform.FileExists(dataPath)) {
dataFile = new RubyFile(context, dataPath, RubyFileMode.RDONLY);
dataFile.Seek(dataOffset, SeekOrigin.Begin);
} else {
dataFile = null;
}
context.ObjectClass.SetConstant("DATA", dataFile);
}
示例4: Reinitialize
public static RubyFile/*!*/ Reinitialize(
ConversionStorage<int?>/*!*/ toInt,
ConversionStorage<IDictionary<object, object>>/*!*/ toHash,
ConversionStorage<MutableString>/*!*/ toPath,
ConversionStorage<MutableString>/*!*/ toStr,
RubyFile/*!*/ self,
object descriptorOrPath,
[Optional]object optionsOrMode,
[Optional]object optionsOrPermissions,
[DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) {
var context = self.Context;
Protocols.TryConvertToOptions(toHash, ref options, ref optionsOrMode, ref optionsOrPermissions);
var toIntSite = toInt.GetSite(TryConvertToFixnumAction.Make(toInt.Context));
IOInfo info = new IOInfo();
if (optionsOrMode != Missing.Value) {
int? m = toIntSite.Target(toIntSite, optionsOrMode);
info = m.HasValue ? new IOInfo((IOMode)m) : IOInfo.Parse(context, Protocols.CastToString(toStr, optionsOrMode));
}
int permissions = 0;
if (optionsOrPermissions != Missing.Value) {
int? p = toIntSite.Target(toIntSite, optionsOrPermissions);
if (!p.HasValue) {
throw RubyExceptions.CreateTypeConversionError(context.GetClassName(optionsOrPermissions), "Integer");
}
permissions = p.Value;
}
if (options != null) {
info = info.AddOptions(toStr, options);
}
// TODO: permissions
// descriptor or path:
int? descriptor = toIntSite.Target(toIntSite, descriptorOrPath);
if (descriptor.HasValue) {
RubyIOOps.Reinitialize(self, descriptor.Value, info);
} else {
Reinitialize(self, Protocols.CastToPath(toPath, descriptorOrPath), info, permissions);
}
return self;
}
示例5: Reinitialize
public static RubyFile/*!*/ Reinitialize(RubyFile/*!*/ self,
[DefaultProtocol, NotNull]Union<int, MutableString> descriptorOrPath, int mode, [Optional]int permission) {
// TODO: remove duplicity (constructors vs initializers)
if (descriptorOrPath.IsFixnum()) {
RubyIOOps.Reinitialize(self, descriptorOrPath.Fixnum(), mode);
} else {
var path = self.Context.DecodePath(descriptorOrPath.Second);
var stream = RubyFile.OpenFileStream(self.Context, path, (IOMode)mode);
self.Path = path;
self.Mode = (IOMode)mode;
self.SetStream(stream);
self.SetFileDescriptor(self.Context.AllocateFileDescriptor(stream));
}
// TODO: permission
return self;
}
示例6: SysOpen
public static int SysOpen(RubyClass/*!*/ self, [NotNull]MutableString path, [Optional]MutableString mode, [Optional]int perm) {
if (FileTest.DirectoryExists(self.Context, path)) {
// TODO: What file descriptor should be returned for a directory?
return -1;
}
RubyIO io = new RubyFile(self.Context, path.ToString(), IOModeEnum.Parse(mode));
int fileDesc = io.GetFileDescriptor();
io.Close();
return fileDesc;
}
示例7: Binread
public static MutableString/*!*/ Binread(RubyClass/*!*/ self,
[DefaultProtocol, NotNull]MutableString/*!*/ path,
[DefaultProtocol, Optional]int? length,
[DefaultProtocol, Optional]int? offset)
{
if (offset.HasValue && offset.Value < 0) {
throw RubyExceptions.CreateEINVAL();
}
if (length.HasValue && length.Value < 0) {
throw RubyExceptions.CreateArgumentError("negative length {0} given", length);
}
using (RubyIO io = new RubyFile(self.Context, path.ToString(), IOMode.ReadOnly)) {
if (offset.HasValue && offset.Value > 0) {
io.Seek(offset.Value, SeekOrigin.Begin);
}
return (length.HasValue) ? Read(io, length.Value, null) : Read(io);
}
}
示例8: Open
public static object Open(BlockParam block, RubyClass/*!*/ self,
[DefaultProtocol, NotNull]MutableString/*!*/ path,
[DefaultParameterValue(0)]int level,
[DefaultParameterValue(DEFAULT_STRATEGY)]int strategy)
{
var strPath = self.Context.DecodePath(path);
var file = new RubyFile(self.Context, strPath, IOMode.WriteOnly | IOMode.Truncate | IOMode.CreateIfNotExists);
var gzipWriter = Create(self, file, level, strategy);
return gzipWriter.Do(block);
}
示例9: Create
// TODO: should work for IO and files w/o paths:
internal static FileSystemInfo/*!*/ Create(RubyFile/*!*/ file) {
file.RequireInitialized();
if (file.Path == null) {
throw new NotSupportedException("TODO: cannot get file info for files without path");
}
return Create(file.Context, file.Path);
}
示例10: Inspect
public static MutableString/*!*/ Inspect(RubyFile/*!*/ self) {
return MutableString.CreateMutable(self.Context.GetPathEncoding()).
Append("#<").
Append(self.Context.GetClassOf(self).GetName(self.Context)).
Append(':').
Append(self.Path).
Append(self.Closed ? " (closed)" : "").
Append('>');
}
示例11: ModifiedTime
public static RubyTime ModifiedTime(RubyContext/*!*/ context, RubyFile/*!*/ self) {
return RubyStatOps.ModifiedTime(RubyStatOps.Create(self));
}
示例12: LoadFile
public static object LoadFile(RubyScope/*!*/ scope, RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) {
using (RubyFile file = new RubyFile(self.Context, path.ConvertToString(), IOMode.Default)) {
foreach (object obj in MakeConstructor(scope.GlobalScope, file.GetReadableStream())) {
return obj;
}
}
return null;
}
示例13: GetPath
public static MutableString GetPath(RubyFile/*!*/ self) {
return self.Path != null ? self.Context.EncodePath(self.Path) : null;
}
示例14: Inspect
public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, RubyFile/*!*/ self) {
return MutableString.CreateMutable(context.GetPathEncoding()).
Append("#<File:").
Append(self.Path).
Append(self.Closed ? " (closed)" : "").
Append('>');
}
示例15: Stat
public static FileSystemInfo Stat(RubyContext/*!*/ context, RubyFile/*!*/ self) {
return RubyStatOps.Create(context, self.Path);
}