checkpoint

This commit is contained in:
2020-04-29 23:47:06 -04:00
parent 64f7dd4b7d
commit 19a9fc06ba
31 changed files with 678 additions and 360 deletions

View File

@@ -1,39 +1,103 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using Foodsoft.Alpm;
// ReSharper disable once UnusedType.Global
namespace Samples
{
class Program
[Example("installed")]
internal class Installed : IExample
{
static void Other()
public int Run(string[] args)
{
using var h = new Handle("/", "/home/luebsj/db");
using var db = h.RegisterSyncDB("jkl-repo", SigLevel.SIG_PACKAGE_OPTIONAL | SigLevel.SIG_USE_DEFAULT);
db.AddServer("http://arch.johnluebs.com/x86_64");
db.Update(false);
foreach (var a in db.Servers)
{
Console.WriteLine("Hello {0}", a);
}
using var h = new Handle("/", "/var/lib/pacman");
using var db = h.LocalDB;
var servers = db.Servers;
var b = new string[3];
var l = db.Servers.ToImmutableList();
foreach (var pkg in db.PackageCache)
using (pkg)
{
Console.WriteLine("{0} {1}", pkg.Name, pkg.Version);
}
using var cache = db.PackageCache;
foreach ( var p in cache) using(p)
{
Console.WriteLine("Hello: {0} {1} {2}", p.Name, p.Filename, p.BuildDate);
}
Console.WriteLine("Hello World! {0} {1} {2}", db.Name, API.Version,
l[0]);
return 0;
}
static void Main(string[] args)
}
[Example("search")]
internal class Search : IExample
{
public int Run(string[] args)
{
Other();
using var h = new Handle("/", "/var/lib/pacman");
using var db = h.RegisterSyncDB("core");
db.Servers = new[]{"http://www.google.com"};
db.Update(true);
foreach (var pkg in db.PackageCache)
using (pkg)
{
Console.WriteLine("{0} {1} {2}", pkg.Name, pkg.Version, pkg.Description);
}
return 0;
}
}
}
namespace Samples
{
internal static class Program
{
private static int Main(string[] args)
{
var examples = (from t in Assembly.GetExecutingAssembly().GetTypes()
let attribute = (Example?) t.GetCustomAttribute(typeof(Example))
where attribute != null
select new {Name = attribute.Name, Type = t}).ToImmutableDictionary((e) => e.Name);
if (args.Length < 1)
{
Console.Error.WriteLine("Sample");
foreach (var example in examples.Values)
{
Console.Error.WriteLine("{0}", example.Name);
}
return 1;
}
int ret;
try
{
ret = ((IExample) Activator.CreateInstance(examples[args[0]].Type)!).Run(args);
}
catch (AlpmException e)
{
Console.Error.WriteLine("{0}", e.Message);
return 1;
}
return ret;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
public class Example : Attribute
{
public string Name { get; }
public Example(string name)
{
Name = name;
}
}
public interface IExample
{
public int Run(string[] args);
}
}