/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShiftOS.Engine
{
///
/// Denotes that the following terminal command or namespace must only be used in an elevated environment.
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
public class KernelModeAttribute : Attribute
{
}
///
/// Denotes that the following public static method is a ShiftOS Terminal command.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class Command : Attribute
{
///
/// The command name.
///
public string name;
///
/// The description of the command.
///
public string description = "";
///
/// The usage flags for the command.
///
public string usage = "";
///
/// Should the command be hidden from the help system?
///
public bool hide = false;
///
/// Creates a new instance of the .
///
/// The name of the command.
public Command(string name)
{
this.name = name;
}
///
/// Creates a new instance of the .
///
/// The name of the command.
/// Whether the command should be hidden from the help system.
public Command(string name, bool hide)
{
this.name = name;
this.hide = hide;
}
public Command(string name, string usage, string description)
{
this.name = name;
this.description = description;
this.usage = usage;
}
}
///
/// Denotes that this function or property is dependent on a Shiftorium upgrade.
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class RequiresUpgradeAttribute : Attribute
{
///
/// Gets or sets the upgrade(s) this attribute requires.
///
public string Upgrade { get; set; }
///
/// Gets whether the dependent upgrade(s) are installed.
///
public virtual bool Installed
{
get
{
if (Upgrade.Contains(";"))
{
string[] split = Upgrade.Split(';');
foreach (var upg in split)
{
if (!Shiftorium.UpgradeInstalled(upg))
return false;
}
return true;
}
else
{
return Shiftorium.UpgradeInstalled(Upgrade);
}
}
}
///
/// Marks this Form or Command as dependant on this upgrade.
///
/// Upgrade ID - See 'shiftorium.json' in resources for all IDs and their metadata.
public RequiresUpgradeAttribute(string upg)
{
Upgrade = upg;
}
}
///
/// Marks a Terminal command as obsolete.
///
[AttributeUsage(AttributeTargets.Method)]
public class CommandObsolete : Attribute
{
///
/// The reason of obsolescence.
///
public string reason;
///
/// If a new command has the same functionality, this is it.
///
public string newcommand;
///
/// Should we warn the user when they run this command?
///
public bool warn;
///
/// Creates a new instance of the class.
///
/// The reason for this command's obsolescence. You can use "%n" in place of the new command name.
/// If a new command is set to take over, specify it here.
/// Whether or not we should warn the user when they run the command.
public CommandObsolete(string reason, string newcommand, bool warn)
{
this.reason = reason; // %n for newcommand
this.newcommand = newcommand;
this.warn = warn;
}
}
///
/// Denotes that this command requires a specified argument to be in its argument dictionary.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class RequiresArgument : Attribute
{
///
/// The argument name
///
public string argument;
///
/// Creates a new instance of the attribute
///
/// The argument name associated with this attribute
public RequiresArgument(string argument)
{
this.argument = argument;
}
public override object TypeId
{
get
{
return this;
}
}
}
///
/// Prevents a command from being run in a remote session.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class RemoteLockAttribute : Attribute
{
}
}