public static MemberInfo GetMemberInfo(this PathToken token, object source) { IPathNode node = token.Current; var typeNode = node as TypeNode; if (typeNode != null) { return(null); } var indexedNode = node as IndexedNode; if (indexedNode != null) { return(source.GetType().GetProperty("Item")); } var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name); } return(memberInfo); }
private static DynValue OpenFile(ScriptExecutionContext context, CallbackArguments args) { var options = args.AsType(0, nameof(OpenFile), DataType.Table).Table; var type = options.Get("type").CastToString(); var title = options.Get("title").CastToString(); var filter = ParseFiltersTable(options.Get("filters")); var suggestedNameValue = options.Get("suggestedName"); var suggestedName = !suggestedNameValue.IsNil() ? suggestedNameValue.CastToString() : ""; bool accepted; string selectedFile; switch (type) { case "open": accepted = Dialogs.OpenFile(title, filter, out selectedFile); break; case "save": accepted = Dialogs.SaveFile(title, filter, suggestedName, out selectedFile); break; default: throw new ScriptRuntimeException($"Unsupported OpenFile dialog type \"{type}\""); } if (!accepted) { return(DynValue.Nil); } var token = PathToken.Generate(selectedFile); return(DynValue.NewString(token)); }
private static DynValue OpenFolder(ScriptExecutionContext context, CallbackArguments args) { var options = args.AsType(0, nameof(OpenFolder), DataType.Table).Table; var message = options.Get("message").CastToString(); var allowCreate = options.Get("allowCreate").CastToBool(); string selectedPath; while (true) { if (!Dialogs.OpenFolder(message, allowCreate, out selectedPath)) { return(DynValue.Nil); } if ( Dialogs.YesNoQuestion( $"You are about to give the script access to every file and folder in {selectedPath}.\n\nMalicious scripts could use this to harm your computer. Continue?")) { break; } } var token = PathToken.Generate(selectedPath); return(DynValue.NewString(token)); }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { if (log.IsWarnEnabled) { log.Warn("Unable to bind: an empty path node list!."); } return(false); } PathToken token = path.AsPathToken(); if (path.Count == 1) { proxy = this.Create(source, token); if (proxy != null) { return(true); } return(false); } proxy = new ChainedObjectSourceProxy(source, token, this); return(true); }
public void Run(ICommandInteraction writer, PathToken path) { if (IncludeCommand.Run(writer, path)) { EmulationManager.Instance.CurrentEmulation.StartAll(); } }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { if (log.IsWarnEnabled) { log.Warn("Unable to bind: an empty path node list!."); } return(false); } if (path.IsStatic && path.Count < 2) { if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: the \"{0}\" path be unsupported.", path.ToString()); } return(false); } PathToken token = description.Path.AsPathToken(); proxy = CreateProxy(source, token); if (proxy != null) { return(true); } return(false); }
public ChainedObjectSourceProxy(object source, PathToken token, INodeProxyFactory factory) : base(source) { this.factory = factory; count = token.Path.Count; proxies = new ProxyEntry[count]; Bind(source, token); }
public bool Run(ICommandInteraction writer, PathToken path) { if (!File.Exists(path.Value)) { writer.WriteError(String.Format("No such file {0}.", path.Value)); return(false); } using (var progress = EmulationManager.Instance.ProgressMonitor.Start("Including script: " + path.Value)) { bool result = false; switch (Path.GetExtension(path.Value)) { case ".py": result = PythonExecutor(path.Value, writer); break; case ".cs": result = CsharpExecutor(path.Value, writer); break; default: result = ScriptExecutor(path.Value); break; } return(result); } }
public bool TryCreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory, out IObjectSourceProxy proxy) { proxy = null; if (source == null || token.HasNext() || !(token.Current is MemberNode)) { return(false); } MemberInfo memberInfo = token.GetMemberInfo(source); if (memberInfo == null) { return(false); } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null && typeof(IInteractionRequest).IsAssignableFrom(fieldInfo.FieldType)) { proxy = new InteractionRequestFieldObjectSourceProxy(source, fieldInfo); return(true); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null && typeof(IInteractionRequest).IsAssignableFrom(propertyInfo.PropertyType)) { proxy = new InteractionRequestPropertyObjectSourceProxy(source, propertyInfo); return(true); } return(false); }
protected override bool TryCreateProxy(object source, ObjectSourceDescription description, out ISourceProxy proxy) { proxy = null; var path = description.Path; if (path.Count <= 0) { throw new ProxyException("The path nodes of the ObjectSourceDescription \"{0}\" is empty.", description.ToString()); } PathToken token = path.AsPathToken(); if (path.Count == 1) { proxy = this.Create(source, token); if (proxy != null) { return(true); } return(false); } proxy = new ChainedObjectSourceProxy(source, token, this); return(true); }
public override ParserState Accept(PathToken token) { switch (token.Type) { case PathTokenType.StartToken: return(new StartParseState()); default: throw new InvalidOperationException("Unexpected token"); } }
//private static readonly ILog log = LogManager.GetLogger(typeof(ILRuntimeNodeProxyFactory)); public ISourceProxy Create(object source, PathToken token) { IPathNode node = token.Current; if (source == null || !(source is ILTypeInstance || source is CrossBindingAdaptorType)) { return(null); } return(CreateProxy(source, node)); }
public void PathToken_SimplePath_FirstSegmentRemoved() { Request request = new Request(new Uri(@"http://test.com/part1/part2"), HttpMethod.Get); request.Content = ""; PathToken token = new PathToken(0, "name", "none", Types.String); token.DeleteToken(request); Assert.Equal(@"http://test.com/part2", request.Url.ToString()); }
public void PathToken_SimplePath_LastSegmentReplaced() { Request request = new Request(new Uri(@"http://test.com/part1/part2"), HttpMethod.Get); request.Content = ""; PathToken token = new PathToken(1, "name", "none", Types.String); token.ReplaceValue(request, "replacement"); Assert.Equal(@"http://test.com/part1/replacement", request.Url.ToString()); }
public override ParserState Accept(PathToken token) { switch (token.Type) { case PathTokenType.ParentDirectory: case PathTokenType.Subdirectory: return(new EnterToDirectoryState()); case PathTokenType.RootDirectory: return(new EnterRootDirectoryState()); default: throw new InvalidOperationException("Unexpected token"); } }
public ISourceProxy Create(object source, PathToken token) { if (source == null || !(source is LuaTable) || token.Path.IsStatic) { return(null); } IPathNode node = token.Current; LuaTable table = (LuaTable)source; //if (!Contains(table, node)) // return null; return(CreateProxy(table, node)); }
/// <summary> /// Returns the path to access the entity set. /// </summary> /// <returns>Returns a <see cref="string"/> that contains the path to access the entity set.</returns> public string Path() { List <string> properties = new List <string>(); QueryToken token = entitySet; PathToken pathToken = token as PathToken; while (pathToken != null) { properties.Add(pathToken.Identifier); pathToken = pathToken.NextToken as PathToken; } properties.Reverse(); return(String.Join("/", properties.ToArray())); }
//private static readonly ILog log = LogManager.GetLogger(typeof(UniversalNodeProxyFactory)); public ISourceProxy Create(object source, PathToken token) { IPathNode node = token.Current; if (source == null && !node.IsStatic) { return(null); } if (node.IsStatic) { return(this.CreateStaticProxy(node)); } return(CreateProxy(source, node)); }
public override ParserState Accept(PathToken token) { switch (token.Type) { case PathTokenType.EndToken: return(new ParsingComplete()); case PathTokenType.PathDelimiter: return(new OutOfDirectoryState()); case PathTokenType.Subdirectory: throw new InvalidOperationException("Invalid path: subdiricotry contains unexpected symbol"); default: throw new InvalidOperationException("Unexpected token"); } }
public virtual IObjectSourceProxy CreateStaticProxy(Type type, PathToken token, IObjectSourceProxyFactory factory) { var node = token.Current; var proxy = token.HasNext() ? this.CreateStaticChainedProxy(type, node, token.NextToken(), factory) : this.CreateStaticLeafProxy(type, node); if (proxy != null) { return(proxy); } if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: Not found the \"{0}\" member on the \"{1}\" type.", (node as MemberNode).Name, type.Name); } return(null); }
public void Accept(PathToken token) { switch (token.Type) { case PathTokenType.Subdirectory: _visitor.AddSubdirectory(token.Value); break; case PathTokenType.RootDirectory: _visitor.CreateRootDirectory(); break; case PathTokenType.ParentDirectory: _visitor.AddParentDirectory(); break; } }
public override ParserState Accept(PathToken token) { switch (token.Type) { case PathTokenType.ParentDirectory: case PathTokenType.Subdirectory: return(new EnterToDirectoryState()); case PathTokenType.EndToken: throw new InvalidOperationException("Path cannot end with path delimiter"); case PathTokenType.PathDelimiter: throw new InvalidOperationException("Invalid path: subdirectory is missing"); default: throw new InvalidOperationException("Unexpected token"); } }
public IObjectSourceProxy CreateProxy(object source, PathToken token) { IObjectSourceProxy proxy = null; foreach (PriorityFactoryPair pair in this.factories) { var factory = pair.factory; if (factory == null) { continue; } if (factory.TryCreateProxy(source, token, this, out proxy)) { return(proxy); } } return(proxy); }
public void Run(ICommandInteraction writer, PathToken pathToImage) { if (!File.Exists(pathToImage.Value)) { writer.WriteError($"No such file {pathToImage.Value}"); return; } using (var file = new FileStream(pathToImage.Value, FileMode.Open)) { if (!CheckFormat(file)) { writer.WriteError("Bad image format. Supported formats: jpeg, png"); return; } writer.WriteRaw(InlineImage.Encode(file)); } }
public virtual ISourceProxy Create(object source, PathToken token) { ISourceProxy proxy = null; foreach (PriorityFactoryPair pair in this.factories) { var factory = pair.factory; if (factory == null) { continue; } proxy = factory.Create(source, token); if (proxy != null) { return(proxy); } } return(proxy); }
public bool TryCreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory, out IObjectSourceProxy proxy) { proxy = null; IPathNode node = token.Current; if (node is TypeNode) { TypeNode typeNode = (node as TypeNode); Type type = typeNode.Type; if (type == null) { type = TypeFinderUtils.FindType(typeNode.Name); } if (type == null || !token.HasNext()) { if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: not found the \"{0}\" type.", typeNode.Name); } return(false); } proxy = CreateStaticProxy(type, token.NextToken(), factory); if (proxy != null) { return(true); } } else { proxy = CreateProxy(source, token, factory); if (proxy != null) { return(true); } } return(false); }
public virtual IObjectSourceProxy CreateProxy(object source, PathToken token, IObjectSourceProxyFactory factory) { if (source == null) { return(new EmptyObjectSourceProxy()); } var node = token.Current; var proxy = token.HasNext() ? this.CreateChainedProxy(source, node, token.NextToken(), factory) : this.CreateLeafProxy(source, node); if (proxy != null) { return(proxy); } if (log.IsWarnEnabled) { log.WarnFormat("Unable to bind: Not found the \"{0}\" member on the \"{1}\" type.", (node as MemberNode).Name, source.GetType().Name); } return(null); }
public void Run(ICommandInteraction writer, PathToken pathToImage) { if (!File.Exists(pathToImage.Value)) { writer.WriteError($"No such file {pathToImage.Value}"); return; } try { var image = new Bitmap(pathToImage.Value); if (!ImageFormat.Jpeg.Equals(image.RawFormat) && !ImageFormat.Png.Equals(image.RawFormat)) { writer.WriteError("Bad image format. Supported formats: jpeg, png"); return; } writer.WriteRaw(InlineImage.Encode(image)); } catch (Exception e) { writer.WriteError($"There was an error when loading the image: {(e.Message)}"); } }
public bool ParseTokens(IEnumerable <Token> tokensToParse, ICommandInteraction writer) { var reParse = false; var result = new List <Token>(); var tokens = tokensToParse.ToList(); foreach (var token in tokens) { Token resultToken = token; if (token is CommentToken) { continue; } if (token is ExecutionToken) { resultToken = ExecuteWithResult((string)token.GetObjectValue(), writer); if (resultToken == null) { return(false); //something went wrong with the inner command } reParse = true; } var pathToken = token as PathToken; if (pathToken != null) { string fileName; if (TryGetFilenameFromAvailablePaths(pathToken.Value, out fileName)) { resultToken = new PathToken("@" + fileName); } else { Uri uri; string filename; string fname = pathToken.Value; try { uri = new Uri(fname); if (uri.IsFile) { throw new UriFormatException(); } var success = Emulation.FileFetcher.TryFetchFromUri(uri, out filename); if (!success) { writer.WriteError("Failed to download {0}, see log for details.".FormatWith(fname)); filename = null; if (breakOnException) { return(false); } } resultToken = new PathToken("@" + filename); } catch (UriFormatException) { //Not a proper uri, so probably a nonexisting local path } } } result.Add(resultToken); } if (!result.Any()) { return(true); } if (reParse) { return(Parse(String.Join(" ", result.Select(x => x.OriginalValue)), writer)); } try { if (!ExecuteCommand(result.ToArray(), writer) && breakOnException) { return(false); } } catch (Exception e) { var ex = e as AggregateException; if (ex != null) { if (ex.InnerExceptions.Any(x => !(x is RecoverableException))) { throw; } } else if (!(e is RecoverableException)) { throw; } if (swallowExceptions) { if (ex != null) { foreach (var inner in ex.InnerExceptions) { PrintException(String.Join(" ", result.Select(x => x.OriginalValue)), inner, writer); } } else { PrintException(String.Join(" ", result.Select(x => x.OriginalValue)), e, writer); } if (breakOnException) { return(false); } } else { throw; } } return(true); }
public void SetOrAdd(ICommandInteraction writer, [Values("set", "add")] LiteralToken action, PathToken path) { switch (action.Value) { case "set": monitorPath.Path = path.Value; break; case "add": monitorPath.Append(path.Value); break; } PrintCurrentPath(writer); }