public LocalDeleteFrame(AVSValue args, ScriptEnvironment env) : base(args, env) { vi = GetVideoInfo(); int[] skips = GetSkipFrames(args, env); List<int> f = new List<int>(); int length = vi.num_frames; int skipIdx = 0; for (int i = 0; i < length; i++) { if (skips[skipIdx] == i) { skipIdx++; if (skips.Length <= skipIdx) { skipIdx = 0; } vi.num_frames--; continue; } f.Add(i); } this.frames = f.ToArray(); SetVideoInfo(ref vi); }
public override void Execute(ScriptEnvironment env) { Object obj = null; Type type = null; if(!IsIntermediate) { ArgumentCount = (int)env.Pop(); Method = (string)env.Pop(); } if (IsStatic) { type = (Type)env.Pop(); } else { obj = env.Pop(); type = obj.GetType(); } var args = new object[ArgumentCount]; for (var i = 0; i < args.Length; i++) { args[i] = env.Pop(); } var allMethods = type.GetMethods(); var methods = GetInvokableMethods(allMethods, Method, GetTypes(args)); var method = methods.First(); var ret = method.Invoke(obj, args); if (method.ReturnType != typeof(void)) { env.Push(ret); } }
public void ShouldSetScriptEnvironment() { var environment = new ScriptEnvironment(new string[0]); var scriptHost = new ScriptHost(new Mock<IScriptPackManager>().Object, environment); scriptHost.Env.ShouldEqual(environment); }
public void ShouldSetScriptEnvironment() { var environment = new ScriptEnvironment(new string[0]); var scriptHost = new ScriptHost(null, environment); scriptHost.Env.ShouldEqual(environment); }
protected override int[] GetSkipFrames(AVSValue args, ScriptEnvironment env) { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); string filename = args[1].AsString(); HashSet<int> f = new HashSet<int>(); int lineNo = 0; string line = "xx"; try { using (StreamReader sr = new StreamReader(filename)) { while ((line = sr.ReadLine()) != null) { lineNo++; f.Add(int.Parse(line)); } } } catch (Exception ex) { env.ThrowError(string.Format("line: {0:4} | {1} {2}\n", lineNo, ex.Message, line)); } return f.Distinct().OrderBy(key => key).ToArray<int>(); }
public override void Execute(ScriptEnvironment env) { Type type = null; if(!IsIntermediate) { if (!UseDefaulConstructor) { ArgumentCount = (int)env.Pop(); } type = (Type)env.Pop(); } else { type = TypeOf.GetType(TypeName); } var args = new object[ArgumentCount]; for (var i = 0; i < args.Length; i++) { args[i] = env.Pop(); } var obj = Activator.CreateInstance(type, args); env.Push(obj); }
public override void Execute(ScriptEnvironment env) { var v1 = env.Pop(); var v2 = env.Pop(); env.Push(v1); env.Push(v2); }
public override void Execute(ScriptEnvironment env) { var val = env.Pop(); if((bool)val) { env.JumpToLabel(Name); } }
public override void Execute(ScriptEnvironment env) { if(!IsVoid) { env.ReturnValue = env.Pop(); } env.IsReturning = true; }
public override void Execute(ScriptEnvironment env) { var args = new object[ArgumentCount]; for (var i = 0; i < args.Length; i++) { args[i] = env.Pop(); } env.Push(Operate(args)); }
public override void Execute(ScriptEnvironment env) { var obj = env.Pop(); if(Peek) { env.Push(obj); } env.Push(obj == null); }
public override void Execute(ScriptEnvironment env) { var name = TypeName; if(!IsIntermediate) { name = (string)env.Pop(); } var type = GetType(name); env.Push(type); }
public override void Execute(ScriptEnvironment env) { var robot = env.SpecialArgument as Robot; if (robot.Cooldown == 0) { Execute(env, robot); } else { robot.Cooldown--; env.ProgramCounter--; } }
public override void Execute(ScriptEnvironment env) { var newEnv = env.Split(); var args = new object[ArgumentCount]; for (var i = 0; i < ArgumentCount; i++) { args[i] = env.Pop(); } for(var i = ArgumentCount - 1; i >= 0; i--) { newEnv.Push(args[i]); } newEnv.JumpToLabel(Label); newEnv.ProgramCounter++; var exec = new ScriptExecution(newEnv); env.ExecutionManager.Add(exec); }
private ScriptTestRunner() { _scriptEnvironment = ScriptEnvironment.Default; }
public ScriptPackagesTests(ITestOutputHelper testOutputHelper) { testOutputHelper.Capture(); _scriptEnvironment = ScriptEnvironment.Default; }
public ScriptPublisherTests(ITestOutputHelper testOutputHelper) { testOutputHelper.Capture(); _scriptEnvironment = ScriptEnvironment.Default; _commandRunner = new CommandRunner(GetLogFactory()); }
public CompilationDependencyResolverTests(ITestOutputHelper testOutputHelper) { testOutputHelper.Capture(); _scriptEnvironment = ScriptEnvironment.Default; }
public ScriptParserTests(ITestOutputHelper testOutputHelper) { testOutputHelper.Capture(minimumLogLevel: 0); _scriptEnvironment = ScriptEnvironment.Default; }
public override void Execute(ScriptEnvironment env) { action(env); }
private RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, ScriptDependencyInfoProvider scriptDependencyInfoProvider, ScriptFilesDependencyResolver scriptFilesDependencyResolver, LogFactory logFactory, ScriptEnvironment scriptEnvironment, bool useRestoreCache) { _scriptProjectProvider = scriptProjectProvider; _scriptDependencyInfoProvider = scriptDependencyInfoProvider; _scriptFilesDependencyResolver = scriptFilesDependencyResolver; _logger = logFactory.CreateLogger <RuntimeDependencyResolver>(); _scriptEnvironment = scriptEnvironment; _runtimeMatcher = new Regex($"{_scriptEnvironment.PlatformIdentifier}.*-{_scriptEnvironment.ProccessorArchitecture}"); }
public ScriptPackagesFixture() { _scriptEnvironment = ScriptEnvironment.Default; ClearGlobalPackagesFolder(); BuildScriptPackages(); }
public override void Execute(ScriptEnvironment env) { throw new Exception(); }
public override AVSValue ExecuteAfter(AVSValue clip, ScriptEnvironment env) { return(env.Invoke("FlipVertical", new AVSValue(clip))); }
public override void Execute(ScriptEnvironment env) { var pc = (int)env.CallPop(); env.ProgramCounter = pc; }
public ScriptParserTests(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; _scriptEnvironment = ScriptEnvironment.Default; }
public override void Execute(ScriptEnvironment env) { env[Name] = env.Pop(); }
/// <summary> /// Initializes a new instance of the <see cref="EnvironmentReporter"/> class. /// </summary> /// <param name="versionProvider">The <see cref="IVersionProvider"/> that is /// responsible for providing the current and latest version.</param> /// <param name="scriptConsole">The <see cref="ScriptConsole"/> to write to.</param> /// <param name="scriptEnvironment">The <see cref="ScriptEnvironment"/> providing environmental information.</param> public EnvironmentReporter(IVersionProvider versionProvider, ScriptConsole scriptConsole, ScriptEnvironment scriptEnvironment) { _versionProvider = versionProvider; _scriptConsole = scriptConsole; _scriptEnvironment = scriptEnvironment; }
public RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, LogFactory logFactory, ScriptEnvironment scriptEnvironment, bool useRestoreCache) { _scriptProjectProvider = scriptProjectProvider; _scriptEnvironment = scriptEnvironment; _dependencyContextReader = new ScriptDependencyContextReader(logFactory); _restorer = CreateRestorer(logFactory, useRestoreCache); }
public ScriptPublisherTests() { _scriptEnvironment = ScriptEnvironment.Default; _commandRunner = new CommandRunner(GetLogFactory()); }
public override void Execute(ScriptEnvironment env) { env.Push(env[Variable]); }
public override void Execute(ScriptEnvironment env) { env.Push(env[Argument]); }
public override void Execute(ScriptEnvironment env) { }
public ScaffoldingTests() { _scriptEnvironment = ScriptEnvironment.Default; }
public override VideoFrame GetFrame(int n, ScriptEnvironment env) { if (noRotate) { return(base.GetFrame(n, env)); } var res = NewVideoFrame(env); var frame = Child.GetFrame(n, env); var vi = Child.GetVideoInfo(); Parallel.ForEach(planes, plane => { var zero = plane == YUVPlanes.PLANAR_U || plane == YUVPlanes.PLANAR_V ? 128 : 0; OverlayUtils.MemSet(res.GetWritePtr(plane), zero, res.GetPitch(plane) * res.GetHeight(plane)); // get source image size var height = frame.GetHeight(plane); var width = vi.width / (vi.height / height); var oldXradius = (width - 1) / 2.0; var oldYradius = (height - 1) / 2.0; var pixelSize = frame.GetRowSize(plane) / width; // get destination image size var newWidth = GetVideoInfo().width; var newHeight = GetVideoInfo().height; var newXradius = (newWidth - 1) / 2.0; var newYradius = (newHeight - 1) / 2.0; // angle's sine and cosine var angleRad = -angle * Math.PI / 180; var angleCos = Cos(angleRad); var angleSin = Sin(angleRad); var ymax = height - 1; var xmax = width - 1; var srcStride = frame.GetPitch(plane); var dstOffset = res.GetPitch(plane) - res.GetRowSize(plane); unsafe { var src = (byte *)frame.GetReadPtr(plane); var dst = (byte *)res.GetWritePtr(plane); var cy = -newYradius; for (int y = 0; y < newHeight; y++, cy++) { // do some pre-calculations of source points' coordinates // (calculate the part which depends on y-loop, but does not // depend on x-loop) var tx = angleSin * cy + oldXradius; var ty = angleCos * cy + oldYradius; var cx = -newXradius; for (int x = 0; x < newWidth; x++, dst += pixelSize, cx++) { // coordinates of source point var ox = tx + angleCos * cx; var oy = ty - angleSin * cx; // top-left coordinate var ox1 = (int)ox; var oy1 = (int)oy; // validate source pixel's coordinates if (ox1 >= 0 && oy1 >= 0 && ox1 < width && oy1 < height) { // bottom-right coordinate var ox2 = ox1 == xmax ? ox1 : ox1 + 1; var oy2 = oy1 == ymax ? oy1 : oy1 + 1; var dx1 = ox - ox1; if (dx1 < 0) { dx1 = 0; } var dx2 = 1.0f - dx1; var dy1 = oy - oy1; if (dy1 < 0) { dy1 = 0; } var dy2 = 1.0f - dy1; // get four points byte *p1, p2; p1 = p2 = src + oy1 * srcStride; p1 += ox1 * pixelSize; p2 += ox2 * pixelSize; byte *p3, p4; p3 = p4 = src + oy2 * srcStride; p3 += ox1 * pixelSize; p4 += ox2 * pixelSize; // interpolate using 4 points for (var z = 0; z < pixelSize; z++) { dst[z] = (byte)( dy2 * (dx2 * p1[z] + dx1 * p2[z]) + dy1 * (dx2 * p3[z] + dx1 * p4[z])); } } } dst += dstOffset; } } }); return(res); }
public PvcScriptHost(IScriptPackManager scriptPackManager, ScriptEnvironment environment) : base(scriptPackManager, environment) { }
public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory) { _commandRunner = commandRunner; _logger = logFactory.CreateLogger <DotnetRestorer>(); _scriptEnvironment = ScriptEnvironment.Default; }
public Scaffolder(ScriptLogger logger) { _scriptEnvironment = ScriptEnvironment.Default; _logger = logger; }
public void Execute(ScriptContext context, System.Windows.Window window, ScriptEnvironment environment) { // Retrieve the count of plans displayed in Scope Window int scopePlanCount = context.PlansInScope.Count(); if (scopePlanCount == 0) { MessageBox.Show("Scope Window does not contain any plans."); return; } // Retrieve names for different types of plans List <string> externalPlanIds = new List <string>(); List <string> brachyPlanIds = new List <string>(); List <string> protonPlanIds = new List <string>(); foreach (var ps in context.PlansInScope) { if (ps is BrachyPlanSetup) { brachyPlanIds.Add(ps.Id); } else if (ps is IonPlanSetup) { protonPlanIds.Add(ps.Id); } else { externalPlanIds.Add(ps.Id); } } // Construct output message string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.", context.CurrentUser.Name, scopePlanCount); if (externalPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds)); } if (brachyPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds)); } if (protonPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds)); } // Display additional information. Use the active plan if available. PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0); message += string.Format("\n\nAdditional details for plan {0}:", plan.Id); // TODO Show fraction message message += string.Format("Number of fractions : {0}\n", plan.NumberOfFractions); message += string.Format("Dose per fraction : {0}\n", plan.PlannedDosePerFraction.ToString()); // Access the structure set of the plan if (plan.StructureSet != null) { Image image = plan.StructureSet.Image; var structures = plan.StructureSet.Structures; message += string.Format("\n* Image ID: {0}", image.Id); message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.\n", structures.Count()); // TODO show structure info each foreach (var structureSingle in plan.StructureSet.Structures) { // check validation if (!structureSingle.IsEmpty) { message += string.Format("{0} in volume {1:F2} cc" + Environment.NewLine, structureSingle.Name, structureSingle.Volume); } } } // message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions); // Handle brachytherapy plans separately from external beam plans if (plan is BrachyPlanSetup) { BrachyPlanSetup brachyPlan = (BrachyPlanSetup)plan; var catheters = brachyPlan.Catheters; var seedCollections = brachyPlan.SeedCollections; message += string.Format("\n* Number of Catheters: {0}.", catheters.Count()); message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count()); } else { var beams = plan.Beams; message += string.Format("\n* Number of Beams: {0}." + Environment.NewLine, beams.Count()); // TODO show info of beams foreach (Beam beamSingle in plan.Beams.OrderBy(x => x.BeamNumber)) { message += string.Format("Beam name equal to {0} , ", beamSingle.Id); message += string.Format("and MeterSet = {0}" + Environment.NewLine, beamSingle.Meterset.Value.ToString() + " " + beamSingle.Meterset.Unit.ToString()); } } if (plan is IonPlanSetup) { IonPlanSetup ionPlan = plan as IonPlanSetup; IonBeam beam = ionPlan.IonBeams.FirstOrDefault(); if (beam != null) { message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count()); message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count()); message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count()); } } // MessageBox.Show(message); window.Content = message; }
public override VideoFrame GetFrame(int n, ScriptEnvironment env) { int nn = GetCacheSkipCount(n); return Child.GetFrame(nn, env); }
public override void Execute(ScriptEnvironment env) { env.TryLabel = null; }
protected virtual int[] GetSkipFrames(AVSValue args, ScriptEnvironment env) { int n = args[1].ArraySize(); HashSet<int> f = new HashSet<int>(); int max = vi.num_frames; for (int i = 0; i < n; ++i) { int skipFrm = args[1][i].AsInt(); if (vi.num_frames > skipFrm) { f.Add(skipFrm); } } return f.Distinct().OrderBy(key => key).ToArray<int>(); }
public override void Execute(ScriptEnvironment env) { var robot = env.GetSpecialArgument <Robot>(); robot.Data[Argument] = env.Pop(); }
public ApplyDelFrm(AVSValue args, ScriptEnvironment env) : base(args, env) { }
public ScriptCompiler(ScriptLogger logger, RuntimeDependencyResolver runtimeDependencyResolver) { Logger = logger; RuntimeDependencyResolver = runtimeDependencyResolver; _scriptEnvironment = ScriptEnvironment.Default; }
internal ScriptExecution(ScriptEnvironment env) { Environment = env; }
public override VideoFrame GetFrame(int n, ScriptEnvironment env) { var frame = NewVideoFrame(env); if (realPlanar) { OverlayUtils.ResetChroma(frame); } OverlayUtils.MemSet(frame.GetWritePtr(), byte.MaxValue, frame.GetHeight() * frame.GetPitch()); var stride = frame.GetPitch(); var pixelSize = frame.GetRowSize() / GetVideoInfo().width; var random = new Random(seed == int.MaxValue ? n : seed); unsafe { void LeftRight(int length, Func <int, int> offset) { if (length > 0) { for (var x = 0; x < length; x++) { var data = (byte *)frame.GetWritePtr() + offset(x) * pixelSize; var gradientVal = GradientVal(x, length); for (var y = 0; y < height; y++, data += stride) { var val = gradientVal; if (noise && random.Next(length + 1) > x && random.Next(length + 1) > x) { val = 0; } if (val != byte.MaxValue) { for (var i = 0; i < pixelSize; i++) { data[i] = val; } } } } } } void TopBottom(int length, Func <int, int> offset) { if (length > 0) { for (var y = 0; y < length; y++) { var data = (byte *)frame.GetWritePtr() + offset(rgb ? (height - y - 1) : y) * stride; var gradientVal = GradientVal(y, length); for (var x = 0; x < width; x++, data += pixelSize) { var val = gradientVal; if (noise && random.Next(length + 1) > y && random.Next(length + 1) > y) { val = 0; } if (val != byte.MaxValue && data[0] > val) { for (var i = 0; i < pixelSize; i++) { data[i] = val; } } } } } } LeftRight(left, x => x); LeftRight(right, x => width - x - 1); TopBottom(top, y => y); TopBottom(bottom, y => height - y - 1); } return(frame); }
private ScriptProjectProvider(ScriptParser scriptParser, ScriptFilesResolver scriptFilesResolver, LogFactory logFactory, ScriptEnvironment scriptEnvironment) { _logger = logFactory.CreateLogger <ScriptProjectProvider>(); _scriptParser = scriptParser; _scriptFilesResolver = scriptFilesResolver; _scriptEnvironment = scriptEnvironment; }
public override void Execute(ScriptEnvironment env) { var robot = env.GetSpecialArgument<Robot>(); env.Push(robot.Data.ContainsKey(Argument)); }
public Scaffolder(LogFactory logFactory) { _commandRunner = new CommandRunner(logFactory); _scriptEnvironment = ScriptEnvironment.Default; }
protected abstract void Execute(ScriptEnvironment env, Robot robot);
public OwinScriptHost(IScriptPackManager scriptPackManager, ScriptEnvironment environment) : base(scriptPackManager, environment) { }
protected override void Initialize() { base.Initialize(); Options.LanguageProvider = ScriptEnvironment.GetEnvironment().GetLanguageProvider(typeof(IronSchemeLanguageProvider)); }
public NetFxAnalyzer(ScriptEnvironment script_env, string name, object modules, IConfiguration configuration, Dictionary <string, object> application_options) : base(script_env, name, modules, configuration, application_options) { this.Module = (ModuleDefinition)this._Modules; }
public ScaffoldingTests(ITestOutputHelper testOutputHelper) { _scriptEnvironment = ScriptEnvironment.Default; testOutputHelper.Capture(); }
public static void Initialize() { if (initialized) { return; } initialized = true; instance = new Wrapper(); serverasm = Assembly.GetAssembly(typeof(CitizenMP.Server.Resources.Resource)); if (serverasm != null) { PlayerScriptFunctions = serverasm.GetType("CitizenMP.Server.Resources.PlayerScriptFunctions"); if (PlayerScriptFunctions != null) { PSFDropPlayer = PlayerScriptFunctions.GetMethod("DropPlayer", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); PSFTempBanPlayer = PlayerScriptFunctions.GetMethod("TempBanPlayer", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); PSFGetHostId = PlayerScriptFunctions.GetMethod("GetHostId", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } EventScriptFunctions = serverasm.GetType("CitizenMP.Server.Resources.EventScriptFunctions"); if (EventScriptFunctions != null) { ESFTriggerClientEvent = EventScriptFunctions.GetMethod("TriggerClientEvent_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); ESFRegisterServerEvent = EventScriptFunctions.GetMethod("RegisterServerEvent_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); ESFTriggerEvent = EventScriptFunctions.GetMethod("TriggerEvent_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); ESFCancelEvent = EventScriptFunctions.GetMethod("CancelEvent_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); ESFWasEventCanceled = EventScriptFunctions.GetMethod("WasEventCanceled_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } ScriptEnvironment = serverasm.GetType("CitizenMP.Server.Resources.ScriptEnvironment"); if (ScriptEnvironment != null) { SESetTimeout = ScriptEnvironment.GetMethod("SetTimeout_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); SEAddEventHandler = ScriptEnvironment.GetMethod("AddEventHandler_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); SEGetInstanceId = ScriptEnvironment.GetMethod("GetInstanceId", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); SECurrentEnvironment = ScriptEnvironment.GetProperty("CurrentEnvironment", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(null); EventHandlers = (Dictionary <string, List <Delegate> >)ScriptEnvironment.GetField("m_eventHandlers", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(SECurrentEnvironment); SELuaEnvironment = ScriptEnvironment.GetField("m_luaEnvironment", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(SECurrentEnvironment); SEScriptTimer = ScriptEnvironment.GetNestedType("ScriptTimer", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (SEScriptTimer != null) { SEScriptTimerList = (IList)ScriptEnvironment.GetField("m_timers", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(SECurrentEnvironment); SEScriptTimerFunction = SEScriptTimer.GetProperty("Function", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); SEScriptTimerTickFrom = SEScriptTimer.GetProperty("TickFrom", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); } } ClientInstances = serverasm.GetType("CitizenMP.Server.ClientInstances"); if (ClientInstances != null) { Clients = (ReadOnlyDictionary <string, Client>)ClientInstances.GetProperty("Clients", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(null); ClientsByNetId = (ReadOnlyDictionary <ushort, Client>)ClientInstances.GetProperty("ClientsByNetId", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(null); } ResourceScriptFunctions = serverasm.GetType("CitizenMP.Server.Resources.ResourceScriptFunctions"); if (ResourceScriptFunctions != null) { RSFStopResource = ScriptEnvironment.GetMethod("StopResource_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); RSFStartResource = ScriptEnvironment.GetMethod("StartResource_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); RSFSetGameType = ScriptEnvironment.GetMethod("SetGameType_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); RSFSetMapName = ScriptEnvironment.GetMethod("SetMapName_f", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } /*foreach (Type t in serverasm.GetTypes()) * { * foreach (MethodInfo mi in t.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) * { * foreach (object attr in mi.GetCustomAttributes()) if (attr.GetType().ToString().Contains("LuaMember")) instance.Print(t + " (" + mi.ReturnType + ") " + mi.Name, string.Join(", ", mi.GetParameters().Select(pi => "(" + pi.ParameterType + ") " + pi.Name))); * * //instance.Print(t + " (" + mi.ReturnType + ") " + mi.Name, string.Join(", ", mi.GetParameters().Select(pi => "(" + pi.ParameterType + ") " + pi.Name))); * } * * //foreach (FieldInfo fi in t.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) instance.Print(t + " (" + fi.FieldType + ") " + fi.Name); * * //foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) instance.Print(t + " (" + pi.PropertyType + ") " + pi.Name); * }*/ } ScriptsFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "resources", "ServerWrapper", "Scripts"); if (!Directory.Exists(ScriptsFolder)) { Directory.CreateDirectory(ScriptsFolder); } /*AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => * { * if (!assemblies.ContainsKey(e.Name)) * { * try * { * foreach (string file in Directory.GetFiles(path, "*.dll")) * { * if (e.Name == AssemblyName.GetAssemblyName(file).FullName) * { * assemblies.Add(AssemblyName.GetAssemblyName(file).FullName, Assembly.Load(File.ReadAllBytes(file))); * * break; * } * } * } * catch (Exception ex) * { * instance.PrintException(ex); * } * } * * return assemblies.ContainsKey(e.Name) ? assemblies[e.Name] : null; * };*/ Load(ScriptsFolder); instance.AddEventHandler("rconCommand", new Action <string, object>((command, args) => { string c = command.ToLower(); if (c == "reloadscripts") { instance.CancelEvent(); if (_scripts.Count > 0) { Reload(ScriptsFolder); } } else if (c == "loadscripts") { instance.CancelEvent(); if (_scripts.Count == 0) { Load(ScriptsFolder); } } else if (c == "unloadscripts") { instance.CancelEvent(); if (_scripts.Count > 0) { Unload(ScriptsFolder); } } else if (c == "swupdate") { instance.CancelEvent(); Process.Start("explorer.exe", "https://forum.fivem.net/t/release-c-net-wrapper-for-server-side-scripts/20325"); } else { lock (scripteventhandlers) foreach (IServerScript script in scripteventhandlers.Keys) { if (scripteventhandlers[script].ContainsKey("rconCommand")) { foreach (Delegate handler in scripteventhandlers[script]["rconCommand"]) { handler.DynamicInvoke(command, args); } } } } /*new Action<string, List<object>>((c, a) => * { * if (c == "reloadscripts") * { * instance.CancelEvent(); * * if (_scripts.Count > 0) Reload(ScriptsFolder); * } * else if (c == "loadscripts") * { * instance.CancelEvent(); * * if (_scripts.Count == 0) Load(ScriptsFolder); * } * else if (c == "unloadscripts") * { * instance.CancelEvent(); * * if (_scripts.Count > 0) Unload(ScriptsFolder); * } * else if (c == "swupdate") * { * instance.CancelEvent(); * * Process.Start("explorer.exe", "https://forum.fivem.net/t/release-c-net-wrapper-for-server-side-scripts/20325"); * } * })(command, (List<object>)ConvertArgsFromNLua(args)[0]);*/ })); new Thread(() => { int CurrentMajor, CurrentMinor, CurrentBuild, CurrentRevision, NewMajor, NewMinor, NewBuild; string[] currentver = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); if (currentver.Length < 1 || !int.TryParse(currentver[0], out CurrentMajor)) { CurrentMajor = 1; } if (currentver.Length < 2 || !int.TryParse(currentver[1], out CurrentMinor)) { CurrentMinor = 2; } if (currentver.Length < 3 || !int.TryParse(currentver[2], out CurrentBuild)) { CurrentBuild = 0; } if (currentver.Length < 4 || !int.TryParse(currentver[3], out CurrentRevision)) { CurrentRevision = 0; } string current = CurrentMajor + "." + CurrentMinor + "." + CurrentBuild, latest = ""; //CurrentMajor = 0; bool update = false; while (true) { try { if (!update) { using (WebClient w = new WebClient()) { w.Proxy = null; w.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); // Fails without a user-agent header. JObject json = JObject.Parse(w.DownloadString("https://api.github.com/repos/DorCoMaNdO/FiveMServerWrapper/releases/latest")); string[] ver = json["tag_name"].ToString().Split('.'); if (ver.Length < 1 || !int.TryParse(ver[0], out NewMajor)) { NewMajor = 1; } if (ver.Length < 2 || !int.TryParse(ver[1], out NewMinor)) { NewMinor = 2; } if (ver.Length < 3 || !int.TryParse(ver[2], out NewBuild)) { NewBuild = 0; } latest = NewMajor + "." + NewMinor + "." + NewBuild; update = NewMajor > CurrentMajor || NewMajor == CurrentMajor && NewMinor > CurrentMinor || NewMajor == CurrentMajor && NewMinor == CurrentMinor && NewBuild > CurrentBuild; } } if (update) { instance.Print("---------------------------------------------------------------------------------------------------"); instance.Print("A ServerWrapper update is available!"); instance.Print("Current version: " + current + ", latest version: " + latest + "."); instance.Print("For more info, visit https://forum.fivem.net/t/release-c-net-wrapper-for-server-side-scripts/20325."); instance.Print("Enter the command \"swupdate\" to open the link above in your default browser."); instance.Print("---------------------------------------------------------------------------------------------------"); } } catch (Exception e) { instance.Print(PrintType.Error, "Update check failed, will try again in 10 minutes."); instance.PrintException(e); } Thread.Sleep(600000); } }).Start(); }
public void Execute(ScriptContext context, System.Windows.Window window, ScriptEnvironment environment) { // Retrieve the count of plans displayed in Scope Window int scopePlanCount = context.PlansInScope.Count(); if (scopePlanCount == 0) { MessageBox.Show("Scope Window does not contain any plans."); return; } // Retrieve names for different types of plans List <string> externalPlanIds = new List <string>(); List <string> brachyPlanIds = new List <string>(); List <string> protonPlanIds = new List <string>(); foreach (var ps in context.PlansInScope) { // KK: "is" compares the type. Equiv to ps.GetType() == typeof(BrachyPlanSetup)) if (ps is BrachyPlanSetup) { brachyPlanIds.Add(ps.Id); } else if (ps is IonPlanSetup) { protonPlanIds.Add(ps.Id); } else { externalPlanIds.Add(ps.Id); } } // Construct output message string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.", context.CurrentUser.Name, scopePlanCount); if (externalPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds)); } if (brachyPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds)); } if (protonPlanIds.Count > 0) { message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds)); } // Display additional information. Use the active plan if available. PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0); message += string.Format("\n\nAdditional details for plan {0}:", plan.Id); // Access the structure set of the plan if (plan.StructureSet != null) { Common.Model.API.Image image = plan.StructureSet.Image; var structures = plan.StructureSet.Structures; message += string.Format("\n* Image ID: {0}", image.Id); message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.", structures.Count()); string structureNames = ""; foreach (var s in structures) { structureNames += String.Format("\n\t{0}: volume is {1:F2} cc.", s.Id, s.Volume); } message += structureNames; } message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions); message += string.Format("\n \t Dose per Fraction: {0}.", plan.DosePerFraction); // Handle brachytherapy plans separately from external beam plans if (plan is BrachyPlanSetup) { BrachyPlanSetup brachyPlan = (BrachyPlanSetup)plan; var catheters = brachyPlan.Catheters; var seedCollections = brachyPlan.SeedCollections; message += string.Format("\n* Number of Catheters: {0}.", catheters.Count()); message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count()); } else { var beams = plan.Beams; message += string.Format("\n* Number of Beams: {0}.", beams.Count()); string beamNames = ""; foreach (var b in beams.OrderBy(x => x.BeamNumber)) { beamNames += String.Format("\n\t{0} has {1} MU.", b.Id, b.Meterset.Value); } message += beamNames; } if (plan is IonPlanSetup) { IonPlanSetup ionPlan = plan as IonPlanSetup; IonBeam beam = ionPlan.IonBeams.FirstOrDefault(); if (beam != null) { message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count()); message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count()); message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count()); } } //MessageBox.Show(message); window.Background = Brushes.Blue; window.Content = new TextBlock { Foreground = Brushes.White, FontFamily = new FontFamily("Ariel"), FontSize = 18, Text = message }; //window.Content = message; }
private void HandleException(ScriptException e, ScriptEnvironment env) { if (env.TryLabel == null) { e.Environment = env; throw e; } env.Push(e.InnerException); env.JumpToLabel(env.TryLabel); env.TryLabel = null; }