Exemple #1
0
 public bool Execute(Tag tag, int permissionLevel, string name, params object[] args)
 {
     lock (CommandsLock) {
         foreach (Command command in Commands)
         {
             if (!CommandAPI.NameEquals(name, command.Name, IgnoreCase))
             {
                 continue;
             }
             int argsLength = command.Parameters.Length - 1;
             if (args.Length < argsLength)
             {
                 continue;
             }
             if (argsLength == 0 && args.Length > argsLength)
             {
                 continue;
             }
             try {
                 for (int i = 0; i < command.Parameters.Length; i++)
                 {
                     if (i == 0)
                     {
                         command.Parameters[i] = tag;
                         continue;
                     }
                     Type parameterType = command.ParameterInfos[i].ParameterType;
                     if (i == command.Parameters.Length - 1 && args.Length >= argsLength && parameterType.IsArray)
                     {
                         Type  elementType = parameterType.GetElementType();
                         Array array       = Array.CreateInstance(elementType, args.Length - argsLength + 1);
                         for (int n = 0; n < array.Length; n++)
                         {
                             array.SetValue(Convert.ChangeType(args[argsLength + n - 1], elementType), n);
                         }
                         command.Parameters[i] = array;
                         continue;
                     }
                     command.Parameters[i] = Convert.ChangeType(args[i - 1], parameterType);
                 }
             } catch {
                 continue;
             }
             if (permissionLevel < command.PermissionLevel)
             {
                 NoPermission?.Invoke(tag);
                 continue;
             }
             command.Invoke();
             return(true);
         }
         return(false);
     }
 }
        private async void LeftPole_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            if (GetPermission)
            {
                if (args.IsSettingsSelected)
                {
                    // not implemented
                    ContentFrame.Navigate(typeof(SettingsPage));
                }
                else
                {
                    selecteditem = (NavigationViewItem)args.SelectedItem;
                    string typeName = selecteditem.Tag.ToString();

                    ContentFrame.Navigate(Type.GetType(typeName));
                }
            }
            else
            {
                NoPermission.Visibility = Visibility.Visible;
                await NoPermission.Fade(value : 1.0f, duration : 500, delay : 0, easingType : EasingType.Default).StartAsync();
            }
        }