Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }