Beispiel #1
0
        internal AsyncMeasure(API api)
        {
            rmAPI = api;
            proxy = new APIProxy(api);

            var rmPSHost = new PSHostProxy();

            rmPSHost.Ui.RainmeterAPI = rmAPI;

            var initSS = CreateSessionState();

            runspace = RunspaceFactory.CreateRunspace(rmPSHost, initSS);

            runspace.Open();

            PrepareEnvironment();

            string filePath = rmAPI.ReadPath("ScriptFile", null);

            if (!string.IsNullOrEmpty(filePath))
            {
                if (!File.Exists(filePath))
                {
                    rmAPI.Log(API.LogType.Error, "Script file does not exist.");
                    return;
                }

                script = new Command(File.ReadAllText(filePath), true);
                return;
            }

            script = GetCommandFromLine();
        }
Beispiel #2
0
        internal ChildMeasure(API api)
        {
            rmAPI = api;
            proxy = new APIProxy(api);

            string parentName = api.ReadString("Parent", "").ToLowerInvariant();
            IntPtr skin       = api.GetSkin();

            parent = null;

            // Find parent using measure name AND the skin pointer to be sure that it's the right one.
            foreach (ParentMeasure parentMeasure in ParentMeasure.ParentMeasures)
            {
                if (parentMeasure.skin.Equals(skin) &&
                    parentMeasure.measureName.Equals(parentName))
                {
                    parent = parentMeasure;
                    break;
                }
            }

            if (parent == null)
            {
                api.Log(API.LogType.Error, "PowershellRM.dll: Parent=" + parentName + " not valid");
                return;
            }

            runspace = parent.runspace;
        }
Beispiel #3
0
        internal ParentMeasure(API api)
        {
            rmAPI = api;
            proxy = new APIProxy(api);

            measureName = api.GetMeasureName().ToLowerInvariant();
            skin        = api.GetSkin();

            var initState = CreateSessionState();

            rmPSHost = new PSHostProxy();

            runspace = RunspaceFactory.CreateRunspace(rmPSHost, initState);
            runspace.Open();

            PrepareEnvironment();

            ParentMeasures.Add(this);

            string filePath = rmAPI.ReadPath("ScriptFile", null);

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!File.Exists(filePath))
            {
                rmAPI.Log(API.LogType.Error, "Script file does not exist.");
                return;
            }

            type = ScriptType.FileNoUpdate;
            string rawScript = File.ReadAllText(filePath);

            Task.Run(() =>
            {
                using (Pipeline pipe = runspace.CreatePipeline())
                {
                    pipe.Commands.AddScript(rawScript);

                    try
                    {
                        pipe.Invoke();

                        CommandInfo updateFuncInfo = runspace.SessionStateProxy
                                                     .InvokeCommand.GetCommand("Update", CommandTypes.Function);

                        if (updateFuncInfo == null)
                        {
                            rmAPI.Log(API.LogType.Debug, "Could not find Update function in script file.");
                        }
                        else
                        {
                            type   = ScriptType.File;
                            script = new Command("Update");
                        }
                    }
                    catch (Exception e)
                    {
                        rmAPI.Log(API.LogType.Error, e.ToString());
                        type = ScriptType.NotValid;
                    }
                }

                state = State.Ready;
            });
        }