示例#1
0
文件: Helpers.cs 项目: Fox-Alpha/nscp
        public List <string> getKeys(string path)
        {
            List <string> ret = new List <string>();

            SettingsRequestMessage.Builder newMessage = SettingsRequestMessage.CreateBuilder();
            SettingsRequestMessage.Types.Request.Types.Query.Builder newQuery = SettingsRequestMessage.Types.Request.Types.Query.CreateBuilder();
            newQuery.SetNode(Settings.Types.Node.CreateBuilder().SetPath(path).Build());
            newQuery.SetRecursive(false);
            newQuery.SetType(Common.Types.DataType.STRING);
            newMessage.AddPayload(SettingsRequestMessage.Types.Request.CreateBuilder().SetPluginId(plugin_id).SetQuery(newQuery.Build()).Build());
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            newMessage.Build().WriteTo(stream);
            NSCP.Core.Result res = core.settings(stream.ToArray());
            if (!res.result)
            {
                log.error("Failed to get value: " + path);
                return(ret);
            }
            SettingsResponseMessage response_message = SettingsResponseMessage.ParseFrom(res.data);

            if (response_message.GetPayload(0).Result.Code != Common.Types.Result.Types.StatusCodeType.STATUS_OK)
            {
                log.error("Failed to get value: " + path);
                return(ret);
            }
            foreach (string value in response_message.GetPayload(0).Query.Value.ListDataList)
            {
                ret.Add(value);
            }
            return(ret);
        }
示例#2
0
文件: Helpers.cs 项目: Fox-Alpha/nscp
        public long getInt(string path, string key, int defaultValue)
        {
            SettingsRequestMessage.Builder newMessage = SettingsRequestMessage.CreateBuilder();
            SettingsRequestMessage.Types.Request.Types.Query.Builder newQuery = SettingsRequestMessage.Types.Request.Types.Query.CreateBuilder();
            newQuery.SetNode(Settings.Types.Node.CreateBuilder().SetPath(path).SetKey(key).Build());
            newQuery.SetDefaultValue(Common.Types.AnyDataType.CreateBuilder().SetIntData(defaultValue).Build());
            newQuery.SetType(Common.Types.DataType.INT);
            newMessage.AddPayload(SettingsRequestMessage.Types.Request.CreateBuilder().SetPluginId(plugin_id).SetQuery(newQuery.Build()).Build());
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            newMessage.Build().WriteTo(stream);
            NSCP.Core.Result res = core.settings(stream.ToArray());
            if (!res.result)
            {
                log.error("Failed to get value: " + path);
                return(defaultValue);
            }
            SettingsResponseMessage response_message = SettingsResponseMessage.ParseFrom(res.data);

            if (response_message.GetPayload(0).Result.Code != Common.Types.Result.Types.StatusCodeType.STATUS_OK)
            {
                log.error("Failed to get value: " + path);
                return(defaultValue);
            }
            return(response_message.GetPayload(0).Query.Value.IntData);
        }
示例#3
0
文件: Helpers.cs 项目: Fox-Alpha/nscp
        public bool registerKey(string path, string key, int type, string title, string description, string defaultValue, bool advanced)
        {
            SettingsRequestMessage.Builder newMessage = SettingsRequestMessage.CreateBuilder();
            SettingsRequestMessage.Types.Request.Types.Registration.Builder registration_builder = SettingsRequestMessage.Types.Request.Types.Registration.CreateBuilder();
            registration_builder.SetNode(Settings.Types.Node.CreateBuilder().SetPath(path).SetKey(key).Build());
            registration_builder.SetInfo(Settings.Types.Information.CreateBuilder().SetTitle(title).SetDescription(description).Build());
            newMessage.AddPayload(SettingsRequestMessage.Types.Request.CreateBuilder().SetPluginId(plugin_id).SetRegistration(registration_builder.Build()).Build());
            SettingsRequestMessage message = newMessage.Build();

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            message.WriteTo(stream);
            NSCP.Core.Result res = core.settings(stream.ToArray());
            if (!res.result)
            {
                log.error("Failed to describe key: " + path);
                return(false);
            }
            SettingsResponseMessage response_message = SettingsResponseMessage.ParseFrom(res.data);

            if (response_message.GetPayload(0).Result.Code != Common.Types.Result.Types.StatusCodeType.STATUS_OK)
            {
                log.error("Failed to describe key: " + path);
                return(false);
            }
            return(true);
        }
示例#4
0
文件: Helpers.cs 项目: Fox-Alpha/nscp
        public bool reload(string context)
        {
            SettingsRequestMessage.Builder newMessage = SettingsRequestMessage.CreateBuilder();
            SettingsRequestMessage.Types.Request.Types.Control.Builder registration_builder = SettingsRequestMessage.Types.Request.Types.Control.CreateBuilder();
            registration_builder.SetContext(context);
            registration_builder.SetCommand(Settings.Types.Command.RELOAD);
            newMessage.AddPayload(SettingsRequestMessage.Types.Request.CreateBuilder().SetPluginId(plugin_id).SetControl(registration_builder.Build()).Build());
            SettingsRequestMessage message = newMessage.Build();

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            message.WriteTo(stream);
            NSCP.Core.Result res = core.settings(stream.ToArray());
            if (!res.result)
            {
                log.error("Failed to save: " + context);
                return(false);
            }
            SettingsResponseMessage response_message = SettingsResponseMessage.ParseFrom(res.data);

            if (response_message.GetPayload(0).Result.Code != Common.Types.Result.Types.StatusCodeType.STATUS_OK)
            {
                log.error("Failed to save: " + context);
                return(false);
            }
            return(true);
        }
示例#5
0
文件: Helpers.cs 项目: Fox-Alpha/nscp
        public void setBool(string path, string key, bool value)
        {
            SettingsRequestMessage.Builder newMessage = SettingsRequestMessage.CreateBuilder();
            SettingsRequestMessage.Types.Request.Types.Update.Builder newQuery = SettingsRequestMessage.Types.Request.Types.Update.CreateBuilder();
            newQuery.SetNode(Settings.Types.Node.CreateBuilder().SetPath(path).SetKey(key).Build());
            newQuery.SetValue(Common.Types.AnyDataType.CreateBuilder().SetBoolData(value).Build());
            newMessage.AddPayload(SettingsRequestMessage.Types.Request.CreateBuilder().SetPluginId(plugin_id).SetUpdate(newQuery.Build()).Build());
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            newMessage.Build().WriteTo(stream);
            NSCP.Core.Result res = core.settings(stream.ToArray());
            if (!res.result)
            {
                log.error("Failed to set value: " + path);
                return;
            }
            SettingsResponseMessage response_message = SettingsResponseMessage.ParseFrom(res.data);

            if (response_message.GetPayload(0).Result.Code != Common.Types.Result.Types.StatusCodeType.STATUS_OK)
            {
                log.error("Failed to set value: " + path);
                return;
            }
        }