本文整理汇总了C#中Args类的典型用法代码示例。如果您正苦于以下问题:C# Args类的具体用法?C# Args怎么用?C# Args使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Args类属于命名空间,在下文中一共展示了Args类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLiveNamespace1
public void TestLiveNamespace1()
{
Service service = Connect();
String username = "sdk-user";
String password = "changeme";
String savedSearch = "sdk-test1";
String searchString = "search index=main * | 10";
// Setup a namespace
Args splunkNameSpace = new Args();
splunkNameSpace.Add("owner", username);
splunkNameSpace.Add("app", "search");
// Get all users, scrub and make our test user
UserCollection users = service.GetUsers();
if (users.ContainsKey(username))
{
users.Remove(username);
}
Assert.IsFalse(users.ContainsKey(username), "Expected users to not contain: " + username);
users.Create(username, password, "user");
Assert.IsTrue(users.ContainsKey(username), "Expected users to contain: " + username);
// Get saved searches for our new namespace, scrub and make our test saved searches
SavedSearchCollection savedSearches = service.GetSavedSearches(splunkNameSpace);
if (savedSearches.ContainsKey(savedSearch))
{
savedSearches.Remove(savedSearch);
}
Assert.IsFalse(savedSearches.ContainsKey(savedSearch), "Expected the saved search to not contain " + savedSearch);
}
示例2: ParseCmdType
private static bool ParseCmdType(string[] strArgs, Args args)
{
switch (strArgs[0])
{
case "list":
args.CmdType = CommandType.ListPasses;
break;
case "update":
args.CmdType = CommandType.Update;
break;
case "add":
args.CmdType = CommandType.AddPass;
args.PassItem = ParsePassItem(strArgs);
break;
case "del":
args.CmdType = CommandType.RemovePass;
args.FindPassById = ParseId(strArgs);
break;
case "edit":
args.CmdType = CommandType.EditPass;
args.FindPassById = ParseId(strArgs);//to be sure that i have id
args.PassItem = ParsePassItem(strArgs);
break;
case "info":
args.CmdType = CommandType.ShowPassInfo;
args.FindPassById = ParseId(strArgs);
break;
case "reset":
args.CmdType = CommandType.ResetPsd;
break;
default:
return false;
}
return true;
}
示例3: Execute
protected override void Execute(Args args)
{
var entries = ScriptLogEntry.Load(Database);
var version = VersionNumber.Parse(args.GetValue("version"));
if (entries.Any(x => x.Version == version.ToString() && !x.ScriptNumber.HasValue))
{
switch (args.GetValueOrDefault("conflict", ConflictStrategy.Fail))
{
case ConflictStrategy.Fail:
throw new ApplicationException("Version already exists.");
case ConflictStrategy.Notify:
using (TemporaryConsoleColorWarning())
Console.WriteLine("Version already exists.");
return;
case ConflictStrategy.Ignore:
return;
default:
throw new ArgumentOutOfRangeException();
}
}
const string sql = "insert [dbo].[ScriptLog] ([Version], [User], [Date]) values (@version, @user, @date)";
var entry = new
{
Date = DateTimeOffset.UtcNow,
User = Environment.UserName,
Version = version.ToString()
};
Database.Execute(sql, entry);
}
示例4: Resource
/// <summary>
/// Initializes a new instance of the <see cref="Resource"/> class,
/// adding optional arguments for namespace and other endpoint
/// arguments.
/// </summary>
/// <param name="service">The service.</param>
/// <param name="path">The path of this resource.</param>
/// <param name="args">The variable arguments.</param>
public Resource(Service service, string path, Args args)
{
this.Service = service;
/* Pull out namespace items (app, owner, sharing) from the args, and
* then use to create the full path.
*/
Args clonedArgs = new Args(args);
Args splunkNamespace = new Args();
if (args.ContainsKey("app"))
{
splunkNamespace.Set("app", args["app"].ToString());
clonedArgs.Remove("app");
}
if (args.ContainsKey("owner"))
{
splunkNamespace.Set("owner", args["owner"].ToString());
clonedArgs.Remove("owner");
}
if (args.ContainsKey("sharing"))
{
splunkNamespace.Set(
"sharing", args["sharing"].ToString());
clonedArgs.Remove("sharing");
}
if (!clonedArgs.ContainsKey("count"))
{
clonedArgs.Set("count", "-1");
}
this.RefreshArgs = clonedArgs;
this.Path = service.Fullpath(
path, splunkNamespace.Count == 0 ? null : splunkNamespace);
this.MaybeValid = false;
}
示例5: FillUserPassword
private static void FillUserPassword(Args args)
{
if (args.UserPassword != null)
return;
Console.WriteLine("Enter user password:");
args.UserPassword = Console.ReadLine();
}
示例6: ParseArgs
private static Args ParseArgs(string[] argArray)
{
var args = new Args{Repeat = 1};
Action<string> nextArg = null;
foreach (var a in argArray)
{
if (nextArg != null)
{
nextArg(a);
nextArg = null;
continue;
}
if (a.StartsWith("-") || a.StartsWith("/"))
{
switch (a.Substring(1))
{
case "r":
nextArg = s => args.Repeat = int.Parse(s);
break;
default:
throw new ArgumentOutOfRangeException("unknown arg: " + a);
}
}
}
return args;
}
示例7: Test_Creating
public void Test_Creating()
{
var args = new Args("path", "mask", ProgramAction.FileRename);
Assert.AreEqual(args.Path, "path");
Assert.AreEqual(args.Mask, "mask");
Assert.AreEqual(args.Action, ProgramAction.FileRename);
}
示例8: SimpleIntPresent
public void SimpleIntPresent()
{
var args = new Args("x#", "-x", "42");
args.Has('x').ShouldBeTrue();
args.Get<int>('x').ShouldBe(42);
args.NextArgument().ShouldBe(2);
}
示例9: GetActionKey
public static NamedAction GetActionKey(Args arguments, NamedAction defaultAction)
{
NamedAction actionKey = arguments.IsDefault ?
defaultAction : arguments.GetActionKey();
return actionKey;
}
示例10: TestUsge
public void TestUsge()
{
var args = new Args(1, "abc", new DateTime(2013, 10, 15), this);
Assert.That(args.Get<int>(0), Is.EqualTo(1));
Assert.That(args.Get<string>(1), Is.EqualTo("abc"));
Assert.That(args.Get<DateTime>(2), Is.EqualTo(new DateTime(2013, 10, 15)));
Assert.That(args.Get<ArgsTest>(3), Is.SameAs(this));
}
示例11: FillPcPath
private static void FillPcPath(Args args)
{
if (args.PcPath != null)
return;
Console.WriteLine("Enter path to PC base:");
args.PcPath = Console.ReadLine();
}
示例12: BotChatConnection_ChatMessageReceived
private static void BotChatConnection_ChatMessageReceived(object o, Args.ChatMessageReceivedEventArgs e)
{
if(e.Message.Message == Command)
{
StartRaidGame();
enteredViewers.Add(new Viewer(e.Message.Author));
}
}
示例13: ExtraArguments
public void ExtraArguments()
{
var args = new Args("x,y*", "-x", "-y", "alpha", "beta");
args.Has('x').ShouldBeTrue();
args.Has('y').ShouldBeTrue();
args.Get<bool>('x').ShouldBeTrue();
args.Get<string>('y').ShouldBe("alpha");
args.NextArgument().ShouldBe(3);
}
示例14: CreateNamespace
/// <summary>
/// Establishes and returns a namespace.
/// </summary>
public Args CreateNamespace(String username, String appname)
{
Args splunkNamespace = new Args();
splunkNamespace.Add("owner", username);
splunkNamespace.Add("app", appname);
return splunkNamespace;
}
示例15: Execute
protected override void Execute(Args args)
{
var count = int.Parse(args.GetValueOrDefault("count", "10"));
var entries = ScriptLogEntry.Load(Database, count).ToList();
Console.WriteLine();
Console.WriteLine(ScriptLogEntry.Format(entries));
Console.WriteLine();
}