コード例 #1
0
        /*
         * Example activity element in array, notice each entry has profile info as well as "sport" on case RUN and cycling should be sepearte
         *
         * {
         *  id_str: '1234567890',
         *  id: 1234567890,
         *  profileId: 1234567890,
         *  profile: {
         *    id: 1234567890,
         *    publicId: '1234567890-1234567890-1234567890',
         *    firstName: 'Example',
         *    lastName: 'Name',
         *    male: true,
         *    imageSrc: 'https://static-cdn.zwift.com/prod/profile/12345678901234567890',
         *    imageSrcLarge: 'https://static-cdn.zwift.com/prod/profile/12345678901234567890',
         *    playerType: 'NORMAL',
         *    countryAlpha3: 'deu',
         *    countryCode: 276,
         *    useMetric: true,
         *    riding: false,
         *    privacy: [Object],
         *    socialFacts: null,
         *    worldId: null,
         *    enrolledZwiftAcademy: false,
         *    playerTypeId: 1,
         *    playerSubTypeId: null,
         *    currentActivityId: null
         *  },
         *  worldId: 1,
         *  name: 'Zwift Run - Watopia',
         *  description: null,
         *  privateActivity: true,
         *  sport: 'RUNNING',
         *  startDate: '2021-01-01T00:00:00.000+0000',
         *  endDate: '2021-01-01T01:00:00.00+0000',
         *  lastSaveDate: '2021-01-01T01:00:00.00+0000',
         *  autoClosed: false,
         *  duration: '1:00',
         *  distanceInMeters: 1234.56,
         *  fitFileBucket: 's3-fit-prd-uswest2-zwift',
         *  fitFileKey: 'prod/123456/123456-123456123456',
         *  totalElevation: 0,
         *  avgWatts: 0,
         *  rideOnGiven: false,
         *  activityRideOnCount: 42,
         *  activityCommentCount: 0,
         *  snapshotList: null,
         *  calories: 4242.00,
         *  primaryImageUrl: 'https://s3-fit-prd-uswest2-zwift.s3.amazonaws.com/prod/img/123456-123456123456123456',
         *  movingTimeInMs: 123456,
         *  privacy: 'PRIVATE',
         *  topNotableMoment: {
         *    notableMomentTypeId: 1,
         *    activityId: 123456123456123456123456,
         *    incidentTime: 123456,
         *    priority: 8,
         *    aux1: '3',
         *    aux2: '300'
         *  },
         *  avgSpeedInMetersPerSecond: 2.42,
         *  feedImageThumbnailUrl: 'https://s3-fit-prd-uswest2-zwift.s3.amazonaws.com/prod/img/1234561-23456123456123456',
         *  eventSubgroupId: null,
         *  eventId: null,
         *  clubActivity: false
         * },
         *
         */

        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);
            Name = api.GetMeasureName();
            Skin = api.GetSkin();

            user      = api.ReadString("zwiftUser", "");
            password  = api.ReadString("zwiftPass", "");
            pastMonth = api.ReadInt("pastMonth", 0);

            var feedArr = fetchZwiftFeed();

            try
            {
                foreach (var activity in feedArr)
                {
                    CultureInfo provider = CultureInfo.InvariantCulture;
                    DateTime    start    = DateTime.Parse(activity.startDate);
                    var         month    = new DateTime(start.Year, start.Month, 1);
                    if (!distanceDict.ContainsKey(month))
                    {
                        distanceDict[month] = 0;
                    }
                    distanceDict[month] += Convert.ToDouble(activity.distanceInMeters);
                }
            }
            catch (Exception e)
            {
                api.Log(API.LogType.Error, "ZWIFT_RM_API.dll: Reload error:" + e.Message);
            };
        }
コード例 #2
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

            Name = api.GetMeasureName();
            Skin = api.GetSkin();

            Path   = api.ReadString("Path", "");
            Server = api.ReadString("Server", "");
        }
コード例 #3
0
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;

            string type = api.ReadString("Type", "");

            measure.Type = typeof(Control)
                           .Assembly
                           .GetTypes()
                           .Where(x => x.GetBaseTypes().Contains(typeof(Control)))
                           .FirstOrDefault(x => x.Name == type);

            if (measure.Type == default(Type))
            {
                measure.log.LogParameterNotValid(type, "Type");
                measure.Invalid = true;
                return;
            }

            if (measure.Control == null || measure.Type.GetType() != measure.Type || measure.Invalid)
            {
                measure.Control = (Control)measure.Type.GetConstructor(Type.EmptyTypes).Invoke(null);
            }

            PropertyParser.ParseProperties(api, measure.Control);

            measure.TabName = api.ReadString("TabName", "");

            if (measure.Control.GetType() != typeof(Form))
            {
                // Find parent using name AND the skin handle to be sure that it's the right one.
                string parentName = api.ReadString("ParentName", "");
                foreach (Measure parentMeasure in Measure.Measures)
                {
                    if (parentMeasure.Skin.Equals(measure.Skin) && parentMeasure.Name.Equals(parentName))
                    {
                        measure.Parent = parentMeasure;
                    }
                }

                if (measure.Parent == null)
                {
                    measure.log.LogError("RainForms.dll: " + measure.Type.ToString() + " needs a parent.");
                    measure.Invalid = true;
                    return;
                }
                measure.AddControlToParent();
            }
        }
コード例 #4
0
        internal void Reload(Rainmeter.API api, ref double maxValue)
        {
            try
            {
                number = api.ReadInt("Value", 0);
            }
            catch (Exception e) {}
            try
            {
                Arc.Thickness = Convert.ToSingle(api.ReadDouble("Width", Arc.Thickness));
            }
            catch (Exception e) {}
            try
            {
                Digit.Size = Convert.ToInt32(api.ReadInt("Size", Digit.Size) * ScaleFactor);
            }
            catch (Exception e) {}
            try
            {
                outFilePath = api.ReadString("Out", string.Format("{0}.png", number.ToString()));
            }
            catch (Exception e) {}
            try
            {
                var colorVals = api.ReadString("Color", string.Format("{0},{1},{2},{3}", Arc.Red, Arc.Green, Arc.Blue, Arc.Opacity)).Split(',').Select(n => Int32.Parse(n)).ToArray();
                switch (colorVals.Length)
                {
                case 4:
                {
                    Arc.Opacity = colorVals[3];
                    goto case 3;
                }

                case 3:
                {
                    Arc.Red   = colorVals[0];
                    Arc.Green = colorVals[1];
                    Arc.Blue  = colorVals[2];
                    break;
                }
                }
            }
            catch (Exception e) {}
            try
            {
                Digit.GlobalAngle = Convert.ToSingle(api.ReadDouble("Angle", Digit.GlobalAngle));
            }
            catch (Exception e) { }
        }
コード例 #5
0
        internal void Reload(Rainmeter.API rm, ref double maxValue)
        {
            SkinHandle     = rm.GetSkin();
            FinishAction   = rm.ReadString("FinishAction", "");
            ConnectionType = rm.ReadString("ConnectionType", "INTERNET").ToUpperInvariant();
            if (ConnectionType != "NETWORK" && ConnectionType != "INTERNET")
            {
                API.Log(API.LogType.Error, "CheckNet.dll: ConnectionType=" + ConnectionType + " not valid");
            }

            UpdateRate = rm.ReadInt("UpdateRate", 20);
            if (UpdateRate <= 0)
            {
                UpdateRate = 20;
            }
        }
コード例 #6
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            Name = api.GetMeasureName();
            API.Log(API.LogType.Debug, "Mediamonkey.dll: Reloading ChildMeasure=" + Name);

            base.Reload(api, ref maxValue);

            string parentName = api.ReadString("PlayerName", "", false).Replace("[", "").Replace("]", "");
            IntPtr skin       = api.GetSkin();

            API.Log(API.LogType.Debug, "Mediamonkey.dll: Looking for ParentMeasure" + parentName + "in skin " + skin + "for ChildMeasure " + Name);

            // Find parent using name AND the skin handle to be sure that it's the right one.
            ParentMeasure = null;
            foreach (ParentMeasure parentMeasure in ParentMeasure.ParentMeasures)
            {
                if (parentMeasure.Skin.Equals(skin) && parentMeasure.Name.Equals(parentName))
                {
                    API.Log(API.LogType.Debug, "Mediamonkey.dll: Found ParentMeasure " + parentMeasure.Name + " for ChildMeasure " + Name);
                    ParentMeasure = parentMeasure;
                }
            }

            if (ParentMeasure == null)
            {
                API.Log(API.LogType.Error, "Mediamonkey.dll: PlayerName=" + parentName + " not valid");
            }
        }
コード例 #7
0
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "name":
                this.Type = MeasureType.SongName;
                break;

            case "artists":
                this.Type = MeasureType.Artists;
                break;

            case "album":
                this.Type = MeasureType.Album;
                break;

            case "lyric":
                this.Type = MeasureType.Lyric;
                break;

            case "islyrictranslated":
                this.Type = MeasureType.IsLyricTranslated;
                break;

            case "translatedlyric":
                this.Type = MeasureType.TranslatedLyric;
                break;

            default:
                api.Log(API.LogType.Error, "ParentChild.dll: Type=" + type + " not valid");
                break;
            }
        }
コード例 #8
0
ファイル: Plugin.cs プロジェクト: ayousuf23/PrayerTimePlugin
        public static void Initialize(ref IntPtr data, IntPtr rm)
        {
            string path = Rainmeter.API.GetSettingsFile();

            Rainmeter.API api       = (Rainmeter.API)rm;
            string        latitude  = api.ReadString("Latitude", "21.3891", false);
            string        longitude = api.ReadString("Longitude", "39.8579", false);
            int           method    = api.ReadInt("Method", 4);
            int           school    = api.ReadInt("School", 0);
            int           latitudeAdjustmentMethod = api.ReadInt("LatitudeAdjustmentMethod", 1);
            int           hijriAdjustment          = api.ReadInt("HijriAdjustment", 0);
            int           midnightMode             = api.ReadInt("MidnightMode", 0);
            bool          _12hourmode = api.ReadInt("12HourClockMode", 24) == 12;

            data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure(path, latitude, longitude, method, school, latitudeAdjustmentMethod, hijriAdjustment, midnightMode, _12hourmode)));
        }
コード例 #9
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

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

            // Find parent using name AND the skin handle to be sure that it's the right one
            RuntimeTypeHandle parentType = typeof(ParentMeasure).TypeHandle;

            foreach (KeyValuePair <uint, Measure> pair in Plugin.Measures)
            {
                if (System.Type.GetTypeHandle(pair.Value).Equals(parentType))
                {
                    ParentMeasure parentMeasure = (ParentMeasure)pair.Value;
                    if (parentMeasure.Name.Equals(parentName) &&
                        parentMeasure.Skin.Equals(skin))
                    {
                        HasParent = true;
                        ParentID  = pair.Key;
                        return;
                    }
                }
            }

            HasParent = false;
            API.Log(API.LogType.Error, "ParentChild.dll: ParentName=" + parentName + " not valid");
        }
コード例 #10
0
        internal void Reload(Rainmeter.API rm, ref double maxValue)
        {
            string type = rm.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "major":
                Type = MeasureType.Major;
                break;

            case "minor":
                Type = MeasureType.Minor;
                break;

            case "number":
                Type = MeasureType.Number;
                break;

            case "string":
                Type = MeasureType.String;
                break;

            default:
                API.Log(API.LogType.Error, "SystemVersion.dll: Type=" + type + " not valid");
                break;
            }
        }
コード例 #11
0
ファイル: Plugin.cs プロジェクト: ayousuf23/PrayerTimePlugin
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api       = (Rainmeter.API)rm;
            string        latitude  = api.ReadString("Latitude", "21.3891", false);
            string        longitude = api.ReadString("Longitude", "39.8579", false);
            int           method    = api.ReadInt("Method", 4);
            int           school    = api.ReadInt("School", 0);
            int           latitudeAdjustmentMethod = api.ReadInt("LatitudeAdjustmentMethod", 1);
            int           hijriAdjustment          = api.ReadInt("HijriAdjustment", 0);
            int           midnightMode             = api.ReadInt("MidnightMode", 0);
            bool          _12hourmode = api.ReadInt("12HourClockMode", 24) == 12;

            measure.Reload(latitude, longitude, method, school, latitudeAdjustmentMethod, hijriAdjustment, midnightMode, _12hourmode);
        }
コード例 #12
0
        // this is for initial "parent" type,
        // sent down inheritenace chain, overidden though?
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "rank":
                Type = MeasureType.Rank;
                break;

            case "won":
                Type = MeasureType.Won;
                break;

            case "lost":
                Type = MeasureType.Lost;
                break;

            case "wontoday":
                Type = MeasureType.WonToday;
                break;

            case "losttoday":
                Type = MeasureType.LostToday;
                break;

            case "highestrank":
                Type = MeasureType.HighestRank;
                break;

            default:
                API.Log(API.LogType.Error, "Type=" + type + " is not valid");
                break;
            }
        }
コード例 #13
0
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "current");

            switch (type.ToLowerInvariant())
            {
            case "current":
                Type = MeasureType.current;
                break;

            case "lastx":
                Type = MeasureType.lastX;
                break;

            case "min":
                Type = MeasureType.min;
                break;

            case "max":
                Type = MeasureType.max;
                break;

            default:
                api.Log(API.LogType.Error, "ZWIFT_RM_API.dll: Type=" + type + " not valid");
                break;
            }
        }
コード例 #14
0
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;

            //Read measure for an Input string
            measure.myString = api.ReadString("Input", "");
        }
コード例 #15
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

            Name = api.GetMeasureName();
            Skin = api.GetSkin();

            this.HistoryJsonPath = api.ReadString("HistoryJsonPath", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Netease/CloudMusic/webdata/file/history"));
        }
コード例 #16
0
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;

            measure.updateRate = api.ReadInt("Timer", 1);
            //We dont have to replace measures here as they will be replaced during Execute so we can pass false.
            //Note though that doing that measures will always then have their current info in update but variables will not. See the commented out code below to have both always act like DynamicVariables=1
            measure.myCommand = api.ReadString("OnTimer", "", false);
        }
コード例 #17
0
        public static unsafe void Initialize(void** data, void* rm)
        {
            uint id = (uint)((void*)*data);

            RM.API api = new RM.API((IntPtr)rm);

            string parentName = api.ReadString("Parent", null);
            if (string.IsNullOrEmpty(parentName))
                Measures.Add(id, new XmlParserParent());
            else
                Measures.Add(id, new XmlParserChild());
        }
コード例 #18
0
        public void Setup(Rainmeter.API api)
        {
            // Init members
            SendAsync             = (api.ReadInt("SendAsync", 0) > 0);
            TryToReconnect        = false;
            KeepConnectionAlive   = (api.ReadInt("KeepAlive", 1) > 0);
            PingServer            = (api.ReadInt("PingServer", 0) > 0);
            MaxReconnectAttempts  = api.ReadInt("MaxReconnectAttempts", 0);
            CurrentAttempt        = 0;
            LastConnectionAttempt = DateTime.Now;
            LastPing = LastConnectionAttempt;

            // Setup WebSocket
            String Address = api.ReadString("Address", "");

            if (!Address.IsNullOrEmpty())
            {
                ws            = new WebSocket(Address);
                ws.NoDelay    = true;
                ws.OnOpen    += OnOpen;
                ws.OnMessage += OnMessage;
                ws.OnError   += OnError;
                ws.OnClose   += OnClose;
                ws.ConnectAsync();
            }

            // Get Commands
            Skin         = api.GetSkin();
            cmdOnOpen    = api.ReadString("OnOpen", "");
            cmdOnMessage = api.ReadString("OnMessage", "");
            cmdOnError   = api.ReadString("OnError", "");
            cmdOnClose   = api.ReadString("OnClose", "");

            // Get Parsable Commands

            // Ex: ParseCommands="AA:|BB:|CMD:"
            // OnAA:=[Some Bang]
            // OnBB:=[Some Bang]
            // OnCMD:=[Some Bang]

            Commands = new List <Command>();
            String cmds = api.ReadString("ParseCommands", "");

            if (!cmds.IsNullOrEmpty())
            {
                var tags = cmds.Split('|');
                foreach (var tag in tags)
                {
                    String c = api.ReadString("On" + tag, "");
                    Commands.Add(new Command {
                        Tag = tag, cmdOnTag = c
                    });
                }
            }
        }
コード例 #19
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            Topic = api.ReadString("Topic", "");

            Debug("Reloading", 1);
            base.Reload(api, ref maxValue);
            Debug("Reloaded", 1);

            if (OnReloadBangs.Length > 0)
            {
                Log(API.LogType.Notice, "Executing OnReload Bangs");
                ExecuteBangs(OnReloadBangs);
            }
        }
コード例 #20
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            Rainmeter = api;
            base.Reload(api, ref maxValue);

            Topic    = api.ReadString("Topic", "defaulttopic");
            Property = api.ReadString("Property", "");
            var qos = api.ReadInt("Qos", 0);

            ParentName = api.ReadString("ParentName", "");
            Skin       = api.GetSkin();

            // Find parent using name AND the skin handle to be sure that it's the right one.
            ParentMeasure = null;
            foreach (MqttClientMeasure parentMeasure in MqttClientMeasure.ParentMeasures)
            {
                if (parentMeasure.Skin.Equals(Skin) && parentMeasure.Name.Equals(ParentName))
                {
                    ParentMeasure = parentMeasure;
                    try
                    {
                        DebugLevel = parentMeasure.DebugLevel;
                        ParentMeasure.Subscribe(Topic, (byte)qos);
                    }
                    catch
                    {
                        Debug("Error Subscribing !", 1);
                    }
                }
            }

            if (ParentMeasure == null)
            {
                Log(API.LogType.Error, "ParentChild.dll: ParentName=" + ParentName + " not valid");
            }
        }
コード例 #21
0
ファイル: VKPlugin.cs プロジェクト: Aragas/VKPlugin
        internal void Reload(Rainmeter.API rm, ref double maxValue)
        {
            string type = rm.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "Value":
                Type = MeasureType.Value;
                break;

            default:
                API.Log(API.LogType.Error, "VKPlugin.dll: Type=" + type + " not valid");
                break;
            }
        }
コード例 #22
0
 public static void Initialize(ref IntPtr data, IntPtr rm)
 {
     Rainmeter.API api = new Rainmeter.API(rm);
     string parentname = api.ReadString("ParentName", "");
     Measure measure;
     if (string.IsNullOrEmpty(parentname))
     {
         measure = new ParentMeasure();
     }
     else
     {
         measure = new ChildMeasure();
     }
     measure.Initialize(api);
     data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
 }
コード例 #23
0
        public static void Initialize(ref IntPtr data, IntPtr rm)
        {
            Rainmeter.API api    = new Rainmeter.API(rm);
            string        parent = api.ReadString("ParentName", "");
            Measure       measure;

            if (String.IsNullOrEmpty(parent))
            {
                measure = new MqttClientMeasure(api);
            }
            else
            {
                measure = new MqttTopicMeasure(api);
            }

            data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
        }
コード例 #24
0
        public unsafe static void Initialize(void **data, void *rm)
        {
            uint id = (uint)((void *)*data);

            Rainmeter.API api = new Rainmeter.API((IntPtr)rm);

            string parent = api.ReadString("ParentName", "");

            if (String.IsNullOrEmpty(parent))
            {
                Measures.Add(id, new ParentMeasure());
            }
            else
            {
                Measures.Add(id, new ChildMeasure());
            }
        }
コード例 #25
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

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

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

            if (ParentMeasure == null)
            {
                api.Log(API.LogType.Error, "ParentChild.dll: ParentName=" + parentName + " not valid");
            }
        }
コード例 #26
0
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

            Name = api.GetMeasureName();
            Skin = api.GetSkin();

            string DisableLeadingZeroString = api.ReadString("DisableLeadingZero", "false");

            if (DisableLeadingZeroString == "1")
            {
                DisableLeadingZero = true;
            }
            else if (DisableLeadingZeroString == "0")
            {
                DisableLeadingZero = false;
            }
            else
            {
                API.Log(API.LogType.Error, "MediaMonkey.dll: Invalid parameter for DisableLeadingZero =" + DisableLeadingZeroString);
            }
        }
コード例 #27
0
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            //@TODO Use this port
            int port = api.ReadInt("Port", 58932);

            string playerTypeString = api.ReadString("PlayerType", "Status");

            try
            {
                playerType = (InfoTypes)Enum.Parse(typeof(InfoTypes), playerTypeString, true);

                if (playerType == InfoTypes.Cover)
                {
                    //Unused @TODO Implement using this. Probably would be cleanest to null all other music info locations during write to disk
                    //defaultCoverLocation = api.ReadPath("DefaultPath", "");
                    string temp = api.ReadPath("CoverPath", null);
                    if (temp.Length > 0)
                    {
                        CoverOutputLocation = temp;
                    }
                    temp = api.ReadPath("DefaultPath", null);
                    if (temp.Length > 0)
                    {
                        CoverDefaultLocation = temp;
                    }
                }
                else if (playerType == InfoTypes.Progress)
                {
                    maxValue = 100;
                }
            }
            catch (Exception e)
            {
                API.Log(API.LogType.Error, "WebNowPlaying.dll - Unknown PlayerType:" + playerTypeString);
                API.Log(API.LogType.Debug, "Error:" + e.ToString());
                playerType = InfoTypes.Status;
            }
        }
コード例 #28
0
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "a":
                Type = MeasureType.A;
                break;

            case "b":
                Type = MeasureType.B;
                break;

            case "c":
                Type = MeasureType.C;
                break;

            default:
                api.Log(API.LogType.Error, "ParentChild.dll: Type=" + type + " not valid");
                break;
            }
        }
コード例 #29
0
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            //@TODO Use this port
            int port = api.ReadInt("Port", 58932);

            myService = api.ReadString("Name", "");
            //If my service does not start with a slash
            if (myService.Substring(0, 1) != "/")
            {
                myService = "/" + myService;
            }

            string newCommandOnOpen    = api.ReadString("OnOpen", "");
            string newCommandOnClose   = api.ReadString("OnClose", "");
            string newCommandOnMessage = api.ReadString("OnMessage", "");

            mySkin = api.GetSkin();
            string myMeasure = api.GetMeasureName();

            bool isNewService = true;
            int  serviceLoc   = 0;

            foreach (string service in services)
            {
                //If new service already exists
                if (myService == service)
                {
                    isNewService = false;
                    bool isNewSkin = true;
                    myServiceID = serviceLoc;

                    //Check if a skin with the same ID already exists if it does then just update instead of making a new skin
                    //Note: we just compare against onOpen, so make sure it is safe to assume they are always in the same loc from same skin @TODO Actually lets just merge execute command to have an open and a close command Edit: Mostly done
                    foreach (ExecuteCommand command in commands[serviceLoc])
                    {
                        //Check if from the same skin
                        if (command.Skin == mySkin)
                        {
                            //Check if from the same measure (No one really should be using two measures in the same service but since I did it for testing I might as well check for it as well)
                            if (command.Measure == myMeasure)
                            {
                                isNewSkin                = false;
                                command.CommandOnOpen    = newCommandOnOpen;
                                command.CommandOnClose   = newCommandOnClose;
                                command.CommandOnMessage = newCommandOnMessage;
                            }
                        }
                    }

                    if (isNewSkin)
                    {
                        commands[serviceLoc].Add(new ExecuteCommand(mySkin, myMeasure, newCommandOnOpen, newCommandOnClose, newCommandOnMessage));
                    }
                }
                serviceLoc++;
            }

            //If new service is actually new service
            if (isNewService)
            {
                services.Add(myService);

                //Add a new item in the top level (Services) of the list that contains a list of one command
                commands.Add(new List <ExecuteCommand>(new ExecuteCommand[] { new ExecuteCommand(mySkin, myMeasure, newCommandOnOpen, newCommandOnClose, newCommandOnMessage) }));

                //Start new service
                wssv.AddWebSocketService <MessagePassing>(myService);
            }
        }
コード例 #30
0
        public static unsafe void Initialize(void** data, void* rm)
        {
            uint id = (uint)((void*)*data);
            Rainmeter.API api = new Rainmeter.API((IntPtr)rm);

            string parent = api.ReadString("ParentName", "");
            if (String.IsNullOrEmpty(parent))
            {
                Measures.Add(id, new ParentMeasure());
            }
            else
            {
                Measures.Add(id, new ChildMeasure());
            }
        }
コード例 #31
0
 public void Reload(Rainmeter.API rm, ref double maxValue)
 {
     measureType = rm.ReadString("Type", "").ToLowerInvariant();
 }
コード例 #32
0
        internal MqttClientMeasure(Rainmeter.API api)
        {
            ParentMeasures.Add(this);
            ParentRainmeterApis.Add(api);
            this.Rainmeter = api;
            this.Name      = api.GetMeasureName();
            Skin           = api.GetSkin();
            DebugLevel     = (ushort)api.ReadInt("DebugLevel", 0);

            Server        = api.ReadString("Server", "localhost");
            Port          = (ushort)api.ReadInt("Port", 1883);
            RetryInterval = (ushort)api.ReadDouble("RetryInterval", 5.0);
            ClientId      = api.ReadString("ClientId", Guid.NewGuid().ToString());
            Username      = api.ReadString("Username", "");
            Password      = new SecureString();
            foreach (char ch in api.ReadString("Password", ""))
            {
                Password.AppendChar(ch);
            }

            /* Mqtt Server Bangs */
            OnConnectBangs    = SplitBangs(api.ReadString("OnConnect", ""));
            OnDisconnectBangs = SplitBangs(api.ReadString("OnConnect", ""));
            OnReloadBangs     = SplitBangs(api.ReadString("OnReload", ""));
            OnMessageBangs    = SplitBangs(api.ReadString("OnMessage", ""));

            MqttClient = Factory.CreateManagedMqttClient();

            /* Setup Event Handlers */
            MqttClient.UseConnectedHandler(e =>
            {
                if (!MqttClientMeasure.ParentRainmeterApis.Contains(Rainmeter))
                {
                    return;
                }

                Log(API.LogType.Notice, "Connected to " + Server + " : " + Port);

                if (OnConnectBangs.Length > 0)
                {
                    Log(API.LogType.Notice, "Executing OnConnect Bangs");
                    ExecuteBangs(OnConnectBangs);
                }
            });

            MqttClient.UseApplicationMessageReceivedHandler(e =>
            {
                if (!MqttClientMeasure.ParentRainmeterApis.Contains(Rainmeter))
                {
                    return;
                }

                e.GetType();
                String topic   = e.ApplicationMessage.Topic;
                String payload = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                try
                {
                    Debug("### RECEIVED APPLICATION MESSAGE ###", 3);
                    Debug($" >> Topic = {e.ApplicationMessage.Topic}", 4);
                    Debug($" >> Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}", 4);
                    Debug($" >> QoS = {e.ApplicationMessage.QualityOfServiceLevel}", 5);
                    Debug($" >> Retain = {e.ApplicationMessage.Retain}", 5);

                    if (Topics.Contains(topic))
                    {
                        Topics[topic] = payload;
                        Log(API.LogType.Notice, "Received update for " + topic);
                    }
                    else
                    {
                        Topics.Add(topic, payload);
                        Log(API.LogType.Warning, "Received payload for unknown topic " + topic);
                    }

                    if (OnMessageBangs.Length > 0)
                    {
                        Log(API.LogType.Notice, "Executing OnMessage Bangs");
                        ExecuteBangs(OnMessageBangs);
                    }
                }
                catch
                {
                    // Error Application
                }
            });

            MqttClient.UseDisconnectedHandler(e =>
            {
                if (!MqttClientMeasure.ParentRainmeterApis.Contains(Rainmeter))
                {
                    return;
                }

                Log(API.LogType.Error, e.Exception?.Message);
                Log(API.LogType.Error, e.AuthenticateResult?.ReasonString);
                Log(API.LogType.Error, e.ClientWasConnected.ToString());

                if (!MqttClient.IsConnected)
                {
                    Log(API.LogType.Warning, "Lost previous connection to " + Server + " : " + Port);
                }

                if (OnDisconnectBangs.Length > 0)
                {
                    Log(API.LogType.Notice, "Executing OnDisconnect Bangs");
                    ExecuteBangs(OnDisconnectBangs);
                }
            });

            try
            {
                Log(API.LogType.Warning, "Connecting to " + Server + " : " + Port + "...");
                ConnectAsync(Server, Port, Username, Password, ClientId).Wait();
            }
            catch (Exception ex)
            {
                Log(API.LogType.Error, "Exception trying to connect: " + ex);
                return;
            }
        }
コード例 #33
0
        internal void Reload(Rainmeter.API rm)
        {
            api = rm;

            try
            {
                string hwType  = rm.ReadString("HardwareType", "");
                string hwName  = rm.ReadString("HardwareName", "");
                int    hwIndex = rm.ReadInt("HardwareIndex", 0);

                string sType  = rm.ReadString("SensorType", "");
                string sName  = rm.ReadString("SensorName", "");
                int    sIndex = rm.ReadInt("SensorIndex", 0);

                api.Log(API.LogType.Debug, String.Format("Hardware(type, name, index): ({0}, {1}, {2}), Sensor(type, name, index): ({3}, {4}, {5})", hwType, hwName, hwIndex, sType, sName, sIndex));

                this.ns = wmiROOT + "\\" + rm.ReadString("Namespace", DefaultNamespace);

                WMIQuery hwQuery = new WMIQuery(this.ns, HardwareClass);
                if (hwType.Length > 0)
                {
                    hwQuery.Where("HardwareType", hwType);
                }
                if (hwName.Length > 0)
                {
                    hwQuery.Where("name", hwName);
                }

                api.Log(API.LogType.Debug, "Hardware Query: " + hwQuery.ToString());

                string hardwareID;
                using (var hardware = hwQuery.GetAt(hwIndex))
                {
                    if (hardware == null)
                    {
                        api.Log(API.LogType.Error, "can't find hardware -> check hardware filter, check if OHM/LHM is running");
                        this.sensorID = null;
                        return;
                    }
                    hardwareID = (string)hardware.GetPropertyValue("Identifier");
                    api.Log(API.LogType.Debug, "Hardware Identifier: " + hardwareID.ToString());
                }

                WMIQuery sQuery = new WMIQuery(this.ns, SensorClass);
                sQuery.Where("Parent", hardwareID);
                if (sType.Length > 0)
                {
                    sQuery.Where("SensorType", sType);
                }
                if (sName.Length > 0)
                {
                    sQuery.Where("name", sName);
                }

                api.Log(API.LogType.Debug, "Sensor Query: " + sQuery.ToString());
                using (var sensor = sQuery.GetAt(sIndex))
                {
                    if (sensor == null)
                    {
                        api.Log(API.LogType.Error, "can't find sensor -> check sensor filter");
                        this.sensorID = null;
                        return;
                    }
                    this.sensorID = sensor.GetPropertyValue("Identifier").ToString();
                    api.Log(API.LogType.Debug, "Sensor Identifier: " + sensorID.ToString());
                }
            }
            catch (Exception ex)
            {
                api.Log(API.LogType.Error, "Fatal Error: " + ex.Message);
                api.Log(API.LogType.Debug, ex.ToString());
            }
        }