/// <summary> /// Get evaluated variable or property value for specified scope. /// </summary> /// <param name="name">Access to property or variable by its name.</param> /// <param name="scope">Where is placed. null value for global or unspecified scope.</param> /// <returns>Evaluated value.</returns> public virtual string GetPropValue(string name, string scope = null) { if (UVars.IsExist(name, scope)) { LSender.Send(this, $"Evaluate: use '{name}:{scope}' from user-variable"); return(GetUVarValue(name, scope)); } if (scope == null) { string slnProp = env.GetMutualPropValue(name); if (slnProp != null) { LSender.Send(this, $"Solution-context for getProperty - '{name}' = '{slnProp}'"); return(slnProp); } } ProjectProperty prop = GetProject(scope).GetProperty(name); if (prop != null) { return(prop.EvaluatedValue); } LSender.Send(this, "getProperty: return default value"); return(UNDEF_VAL); }
/// <summary> /// Magic methods. Invoking. /// </summary> /// <![CDATA[ /// `[result =] name<return_type>([{argument_types}])` /// ]]> /// <param name="binder"></param> /// <param name="args"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { Type[] tArgs; try { tArgs = getArgTypes(binder, args); } catch (ArgumentException ex) { LSender.Send(this, $"Problem with arguments. DLR for '{binder.Name}': {ex.Message}", Message.Level.Warn); tArgs = args.Select(a => a.GetType()).ToArray(); } Type[] tGeneric = getGenericArgTypes(binder).ToArray(); MethodInfo mi = getmi(binder.Name, tGeneric, tArgs); TDyn dyn = provider.bind( mi, provider.Svc.tryAlias(binder.Name), Convention ); // Boxing types, for example: NullType -> null -> NullType object[] unboxed = unbox(args); result = Dynamic.DCast(dyn.returnType, dyn.dynamic.Invoke(null, unboxed)); boxing(unboxed, args); return(true); }
private protected void DefProperty(AVariable variable, string evaluated) { LSender.Send(this, $"Set property: `{variable.name}`:`{variable.scope}`"); //defProperty(uvariable.getVariable(variable.name, variable.scope), getProject(variable.scope)); SetGlobalProperty(GetProject(variable.scope), variable.name, evaluated); }
/// <summary> /// Callback function used with the SetWindowsHookEx function. /// The system calls this function every time a new mouse input event is about to be posted into a thread input queue. /// </summary> /// <param name="nCode">A code the hook procedure uses to determine how to process the message.</param> /// <param name="wParam">The identifier of the mouse message.</param> /// <param name="lParam">A pointer to an MSLLHOOKSTRUCT structure.</param> /// <returns></returns> private LRESULT lowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) { int recode = findReCode(wParam); int idx = 0; foreach (IMouseListener listener in Loader.ActivatedFilters) { if (recode != -1 && idx++ <= recode) { continue; } FilterResult act = listener.msg(nCode, wParam, lParam); if (act == FilterResult.IgnoreFilters) { break; } else if (act == FilterResult.Continue) { continue; } #if DEBUG LSender.Send(this, $"prevent msg({nCode}, {wParam}, {lParam}) by filter {listener.Id}:'{listener.Name}'", Message.Level.Trace); #endif return(stopChainCode); } return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); }
public TrayForm(IBootloader loader, FormWindowState state) { if (loader == null) { throw new ArgumentNullException("Bootloader cannot be null."); } this.loader = loader; svc = new Mokona(loader); fic = listener(typeof(InterruptedClickFilter)); fmc = listener(typeof(MixedClicksFilter)); fdc = listener(typeof(DoubleClicksFilter)); fhs = listener(typeof(HyperactiveScrollFilter)); InitializeComponent(); origin = ClientSize; try { notifyIconMain.Icon = Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch (ArgumentException ex) { notifyIconMain.Icon = Icon; LSender.Send(this, ex.Message, Log.Message.Level.Debug); } hotKeys.KeyPress += onHotKeys; log.Received += onLogMsgReceived; fic.Triggering += (object sender, DataArgs <ulong> e) => { uiAction(() => labelInterruptedClick.Text = e.Data.ToString()); }; fmc.Triggering += (object sender, DataArgs <ulong> e) => { uiAction(() => labelMixedClicks.Text = e.Data.ToString()); }; fdc.Triggering += (object sender, DataArgs <ulong> e) => { uiAction(() => labelDoubleClick.Text = e.Data.ToString()); }; fhs.Triggering += (object sender, DataArgs <ulong> e) => { uiAction(() => labelHyperactiveScroll.Text = e.Data.ToString()); }; WindowState = state; Resize += (object _sender, EventArgs _e) => { visible(WindowState); }; Modifiers mcomb = Modifiers.ControlKey | Modifiers.AltKey | Modifiers.ShiftKey; try { hotKeys.register(mcomb, Keys.Z); hotKeys.register(mcomb, Keys.X); } catch (Exception ex) { log.send(this, ex.Message, Log.Message.Level.Error); } }
/// <summary> /// New position in stream. /// </summary> /// <param name="svc"></param> /// <param name="line">Received line.</param> /// <returns>true if it was processed by current handler, otherwise it means ignoring.</returns> public override bool Positioned(ISvc svc, RawText line) { if (svc.Sln.ExtItems == null) { svc.Sln.ExtItems = new Dictionary <string, string>(); } string _line; while ((_line = svc.ReadLine(this)) != null && _line.Trim() != "EndGlobalSection") { int pos = _line.IndexOf('='); if (pos < 0) // we will use non-strict processing { svc.Sln.ExtItems[_line.Trim()] = null; LSender.Send(this, $"Found extensible null record:{_line}", Message.Level.Info); continue; } string key = _line.Substring(0, pos).Trim(); string val = _line.Substring(pos + 1).Trim(); svc.Sln.ExtItems[key] = val; LSender.Send(this, $"Found extensible key-value: `{key}` = `{val}`", Message.Level.Info); } return(true); }
protected virtual void CopyFile(string destDir, string destFile, bool overwrite, params string[] files) { if (!Directory.Exists(destDir)) { LSender.Send(this, $"Trying to create directory `{destDir}`", MsgLevel.Trace); Directory.CreateDirectory(destDir); } bool isDestFile = !string.IsNullOrWhiteSpace(destFile); if (isDestFile && files.Length > 1) { throw new ArgumentException( string.Format( "The destination path `{0}` cannot contain file name `{1}` if the source has 2 or more files for used mask. End with `{1}\\` or `{1}/` if it directory.", destDir, destFile ) ); } foreach (string file in files) { string dest = Path.Combine(destDir, isDestFile ? destFile : Path.GetFileName(file)); LSender.Send(this, $"Copy file `{file}` to `{dest}` overwrite({overwrite})", MsgLevel.Trace); File.Copy(file, dest, overwrite); } }
/// <summary> /// Prepare, parse, and evaluate mixed data through SobaScript supported syntax. /// </summary> /// <param name="data">Mixed input data.</param> /// <returns>Evaluated end value.</returns> public override string Eval(string data) { var point = EntryPoint(data.Trim()); string subtype = point.Key; string request = point.Value; LSender.Send(this, $"`{ToString()}`: subtype - `{subtype}`, request - `{request}`", MsgLevel.Trace); IPM pm = new PM(request, emsbuild); switch (subtype) { case "cancel": { return(StCancel(pm)); } case "projects": { return(StProjects(pm)); } case "type": { return(StType(pm)); } case "solution": { return(StSolution(pm)); } } throw new SubtypeNotFoundException(subtype); }
protected virtual void CopyDirectory(IEnumerable <string[]> files, string dest, bool force, bool overwrite) { if (!Directory.Exists(dest)) { if (!force) { throw new NotFoundException(dest, "Check path or use `force` flag"); } LSender.Send(this, $"Trying to create directory `{dest}`", MsgLevel.Trace); Directory.CreateDirectory(dest); } foreach (var file in files.ToArray()) { string from = file[0]; string to = file[1]; string subdir = Path.GetDirectoryName(to); if (!Directory.Exists(subdir)) { Directory.CreateDirectory(subdir); } LSender.Send(this, $"Copy directory: file `{from}` to `{to}` overwrite({overwrite})", MsgLevel.Trace); File.Copy(from, to, overwrite); } }
/// <summary> /// New position in stream. /// </summary> /// <param name="svc"></param> /// <param name="line">Received line.</param> /// <returns>true if it was processed by current handler, otherwise it means ignoring.</returns> public override bool Positioned(ISvc svc, RawText line) { string _line; while ((_line = svc.ReadLine(this)) != null && _line.Trim() != "EndGlobalSection") { int pos = _line.IndexOf('='); // Guids: src = dest if (pos < 0) { LSender.Send(this, $"Incorrect NestedProjects records: '{_line}'", Message.Level.Warn); return(false); } string src = _line.Substring(0, pos).Trim(); string dest = _line.Substring(pos + 1).Trim(); LSender.Send(this, $"NestedProjects '{src}' -> '{dest}'", Message.Level.Info); var parent = svc.Sln.SolutionFolderList.Where(f => f.header.pGuid == dest).First(); svc.Sln.SolutionFolderList.Where(f => f.header.pGuid == src) .ForEach(f => f.header.parent.Value = parent); svc.Sln.ProjectItemList.Where(p => p.pGuid == src) .ForEach(p => p.parent.Value = parent); } return(true); }
/// <summary> /// Evaluate user-variable with IEvaluator by using unique identification. /// An evaluated value should be updated for variable. /// </summary> /// <param name="ident">Unique identificator</param> /// <param name="evaluator">IEvaluator objects for evaluating</param> /// <param name="resetting">To reset IEvaluator chain to initial state if true. Otherwise, evaluation can be in the chain of other evaluators.</param> public void Evaluate(string ident, IEvaluator evaluator, bool resetting) { if (evaluator == null) { throw new ArgumentNullException(nameof(evaluator)); } lock (sync) { if (!definitions.ContainsKey(ident)) { throw new DefinitionNotFoundException(ident); } TVariable var = new TVariable(definitions[ident]) { status = ValStatus.Started }; definitions[ident] = var; if (resetting) { var.evaluated = evaluator.Evaluate(var.unevaluated); } else { var.evaluated = evaluator.Evaluate(var.evaluated); } var.status = ValStatus.Evaluated; definitions[ident] = var; LSender.Send(this, $"IEvaluator '{evaluator.GetType().ToString()}': Evaluation of variable '{ident}' is completed.", MsgLevel.Trace); } }
private bool Unload(Project prj) { if (prj == null) { return(false); } try { if (prj.FullPath != null) { ProjectCollection.GlobalProjectCollection.UnloadProject(prj); } else if (prj.Xml != null) { ProjectCollection.GlobalProjectCollection.TryUnloadProject(prj.Xml); } return(true); } catch (Exception ex) { LSender.Send(this, $"Project cannot be unloaded due to error: '{ex.Message}'", MsgLevel.Debug); return(false); } }
protected bool free() { if (!Library.IsActive) { LSender.Send(this, $"Dispose Library: it's not activated.", Message.Level.Trace); return(true); } BeforeUnload(this, new DataArgs <Link>(Library)); try { return(NativeMethods.FreeLibrary(Library.Handle)); } finally { AfterUnload( this, new DataArgs <Link>( new Link(Library.LibName) ) ); if (PE != null) { LSender.Send(this, $"Dispose PE: file ({PE.FileName})", Message.Level.Debug); ((IDisposable)PE).Dispose(); } } }
/// <summary> /// New position in stream. /// </summary> /// <param name="svc"></param> /// <param name="line">Received line.</param> /// <returns>true if it was processed by current handler, otherwise it means ignoring.</returns> public override bool Positioned(ISvc svc, RawText line) { if (svc.Sln.SolutionConfigList == null) { svc.Sln.SolutionConfigList = new List <IConfPlatform>(); } string _line; while ((_line = svc.ReadLine(this)) != null && _line.Trim() != "EndGlobalSection") { string left = _line.Before('=')?.Trim(); // Debug|Win32 = Debug|Win32 if (left == null || String.Compare(left, "DESCRIPTION", StringComparison.OrdinalIgnoreCase) == 0) { LSender.Send(this, $"Solution Configuration has been ignored for line '{_line}'", Message.Level.Debug); continue; } string[] cfg = left.Split('|'); if (cfg.Length < 2) { continue; } LSender.Send(this, $"Solution Configuration ->['{cfg[0]}' ; '{cfg[1]}']", Message.Level.Info); svc.Sln.SolutionConfigList.Add(new ConfigSln(cfg[0], cfg[1])); } return(true); }
private void btnExt_Click(object sender, EventArgs e) { if (extcfg.IsValueCreated) { ((Kit.FilterLineControl)extcfg.Value).Show(); return; } LSender.Send(this, $"Create {nameof(Kit.FilterLineControl)} panel"); var panel = ((Kit.FilterLineControl)extcfg.Value); panel.Left = 0; panel.Top = 0; panel.Width = panelTop.Width; panel.Height = panelTop.Height /* - progressLine.Height*/; panelTop.Controls.Add(panel); panel.Dock = DockStyle.Fill; panel.BringToFront(); progressLine.BringToFront(); panel.Show(); }
public void SendVectorTest1() { LSender.Reset(); LSender.Sent += (object sender, MsgArgs e) => { Assert.True(e.At("LSenderTest")); Assert.True(e.At("DepC", "LSenderTest")); Assert.True(e.At("DepC", "DepB", "LSenderTest")); Assert.True(e.At("DepC", "DepB", "DepA", "LSenderTest")); #if LSR_FEATURE_S_VECTOR Assert.False(e.At("DepB", "DepC", "LSenderTest")); Assert.False(e.At("DepA", "DepB", "LSenderTest")); #else Assert.True(e.At("DepB", "DepC", "LSenderTest")); Assert.True(e.At("DepA", "DepB", "LSenderTest")); #endif Assert.True(e.At("DepB", "DepA", "LSenderTest")); }; DepA.ClassA.SendStatic(string.Empty); DepA.ClassA.SendInstance(string.Empty); }
private static void UnknownFail(Exception ex, bool threadEx) { LSender.Send <Executor>( $"{ex.Message}{(threadEx ? "[TH]" : "[M]")}\n---\n{ex.ToString()}", MvsSln.Log.Message.Level.Fatal ); }
/// <summary> /// Remove all user-variables /// </summary> public void UnsetAll() { lock (sync) { definitions.Clear(); } LSender.Send(this, "Reseted all User-variables", MsgLevel.Trace); }
public void IsInTest1() { LSender.Reset(); LSender.Sent += (object sender, MsgArgs e) => { #if LSR_FEATURE_S_VECTOR Assert.NotEmpty(e.vector); Assert.True(e.At("LSenderTest")); Assert.False(e.At("vsSolutionBuildEvent")); Assert.False(e.At("LSenderTest", "vsSolutionBuildEvent")); Assert.False(e.At("vsSolutionBuildEvent", "LSenderTest")); #else Assert.Empty(e.vector); Assert.True(e.At("LSenderTest")); Assert.True(e.At("vsSolutionBuildEvent")); Assert.True(e.At("LSenderTest", "vsSolutionBuildEvent")); Assert.True(e.At("vsSolutionBuildEvent", "LSenderTest")); #endif }; LSender.Send(this, new MsgArgs("")); }
protected Platform GetPlatform(string value) { if (String.IsNullOrWhiteSpace(value)) { return(Platform.Default); } switch (value.Trim().ToLowerInvariant()) { case "x86": case "x32": case "win32": { return(Platform.x86); } case "x64": { return(Platform.x64); } case "anycpu": case "any cpu": { return(Platform.AnyCPU); } } LSender.Send(this, $"Incorrect platform target: '{value}'. Use '{nameof(Platform.Default)}'", Message.Level.Warn); return(Platform.Default); }
/// <summary> /// Defines user-variable. /// Value setted as unevaluated. /// </summary> /// <param name="name">Variable name.</param> /// <param name="scope">Specified scope for this variable.</param> /// <param name="unevaluated">Mixed string with unevaluated data.</param> public void SetVariable(string name, string scope, string unevaluated) { if (!IsValidName(name) || !IsValidScope(scope)) { throw new ArgumentException($"name - '{name}' or scope - '{scope}' is not valid for variable"); } string defindex = DefIndex(name, scope); if (unevaluated == null) { unevaluated = String.Empty; } lock (sync) { definitions[defindex] = new TVariable() { unevaluated = unevaluated, ident = defindex, name = name, scope = scope, status = ValStatus.Unevaluated, prev = (definitions.ContainsKey(defindex))? definitions[defindex] : new TVariable(), evaluated = null }; LSender.Send(this, $"User-variable: defined '{defindex}' = '{unevaluated}'"); } }
/// <summary> /// Construct data from used components with ISobaCLoader. /// </summary> /// <param name="cLoader"></param> public Inspector(ISobaCLoader cLoader) { this.cLoader = cLoader; foreach (IComponent c in cLoader.Registered) { #if DEBUG LSender.Send(this, $"extracting from '{c.GetType().Name}'", MsgLevel.Trace); #endif Extract(c, data); } if (data.Count < 1) { return; } // Aliases to components foreach (var root in data[new NodeIdent()]) { if (root.Aliases == null) { continue; } foreach (string alias in root.Aliases) { data[new NodeIdent(alias, root.Link.method, root.Link.className)] = data[root.Link]; //shallow copies } } }
/// <summary> /// Prepare, parse, and evaluate mixed data through SobaScript supported syntax. /// </summary> /// <param name="data">Mixed input data.</param> /// <returns>Evaluated end value.</returns> public override string Eval(string data) { var point = EntryPoint(data, RegexOptions.Singleline); string subtype = point.Key; string request = point.Value; LSender.Send(this, $"`{ToString()}`: subtype - `{subtype}`, request - `{request}`", MsgLevel.Trace); switch (subtype) { case "out": { return(StOut(new PM(request))); } case "log": { return(StLog(new PM(request))); } case "item": { return(StItem(new PM(request))); } } throw new SubtypeNotFoundException(subtype); }
protected virtual string DoRepeat(string condition, string block, string iterator, bool silent) { LSender.Send(this, $"DoRepeat: condition `{condition}`; block `{block}`; silent: {silent}"); string ret = string.Empty; #if DEBUG long idx = 0; #endif while (expression.IsTrue(condition)) { if (silent) { Evaluate(block); } else { ret += Evaluate(block); } if (iterator != null) { Evaluate(iterator); } #if DEBUG if (++idx > iterationLimit) { throw new LimitException($"Iteration Limit of '{iterationLimit}' reached. Aborted.", iterationLimit); } #endif } return(ret); }
/// <summary> /// Gets full path to file with environment PATH. /// </summary> /// <returns>null value if file is not found</returns> protected virtual string FindFile(string file) { string lfile = GetLocation(file); if (File.Exists(lfile)) { return(lfile); } LSender.Send(this, $"finding file with environment PATH :: `{file}`({lfile})", MsgLevel.Trace); string[] exts = Environment.GetEnvironmentVariable("PATHEXT").Split(';'); foreach (string dir in EnvPath) { lfile = GetLocation(file, dir); if (File.Exists(lfile) || exts.Any(ext => File.Exists(lfile + ext))) { LSender.Send(this, $"found in: '{dir}' :: '{lfile}'", MsgLevel.Trace); return(lfile); } } return(null); }
protected virtual bool tryIsolateModule(Link l, out string module) { try { if (!l.resolved && !Path.HasExtension(l.module) && GetModuleFileName(l, out string fname)) { module = fname; } else { module = l.module; } var dstDir = Path.Combine(Path.GetTempPath(), CLLI, Guid.NewGuid().ToString()); Directory.CreateDirectory(dstDir); var dst = Path.Combine(dstDir, Path.GetFileName(module)); File.Copy(module, dst, true); module = dst; return(true); } catch (Exception ex) { //TODO: option to throw exception LSender.Send(this, $"Something went wrong when trying to isolate `{l.module}`: {ex.Message}", Message.Level.Debug); module = null; return(false); } }
private void ShowFilterPanel() { if (extcfg.IsValueCreated) { ((FilterLineControl)extcfg.Value).Show(); return; } LSender.Send(this, $"Create {nameof(FilterLineControl)} panel"); var panel = (FilterLineControl)extcfg.Value; panel.Left = 0; panel.Top = 0; panel.Width = panelFilter.Width; panel.Height = panelFilter.Height; panelFilter.Controls.Add(panel); panel.Dock = DockStyle.Fill; panel.BringToFront(); progressLine.BringToFront(); panel.Show(); }
protected virtual void Mkdir(string path) { if (!Directory.Exists(path)) { LSender.Send(this, $"Create empty directory `{path}`", MsgLevel.Trace); Directory.CreateDirectory(path); } }
private protected bool UndefProperty(AVariable variable) { LSender.Send(this, $"Unset property: `{variable.name}`:`{variable.scope}`"); Project project = GetProject(variable.scope); //uvariable.unset(variable.name, variable.scope); //leave for sbe-scripts return(RemoveGlobalProperty(project, variable.name)); }
protected virtual void DeleteFiles(string[] files) { foreach (string file in files) { LSender.Send(this, $"Delete file `{file}`", MsgLevel.Trace); File.Delete(file); } }