singrdk/base/Applications/utilities/getsymlink/getsymlink.sg

85 lines
2.5 KiB
Plaintext
Raw Normal View History

2008-03-05 09:52:00 -05:00
////////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Note:
//
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Singularity;
using Microsoft.Singularity.Directory;
using Microsoft.Singularity.V1.Services;
using Microsoft.Singularity.Channels;
using Microsoft.SingSharp;
using Microsoft.SingSharp.Runtime;
using Microsoft.Contracts;
using Microsoft.SingSharp.Reflection;
using Microsoft.Singularity.Applications;
using Microsoft.Singularity.Io;
using Microsoft.Singularity.Configuration;
[assembly: Transform(typeof(ApplicationResourceTransform))]
2008-11-17 18:29:00 -05:00
namespace Microsoft.Singularity.Applications
{
2008-03-05 09:52:00 -05:00
[ConsoleCategory(DefaultAction=true)]
internal class Parameters {
[InputEndpoint("data")]
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
[OutputEndpoint("data")]
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
[Endpoint]
public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
[StringParameter( "path", Position=0, Mandatory=true)]
internal string nsPath;
reflective internal Parameters();
internal int AppMain() {
return GetSymLink.AppMain(this);
}
}
class GetSymLink
{
private static void tell()
{
Console.WriteLine("Getsymlink <link name>.");
Console.WriteLine(" returns value of link located at <link name>");
}
internal static int AppMain(Parameters! config)
{
ErrorCode errorOut;
string link;
2008-11-17 18:29:00 -05:00
DirectoryServiceContract.Imp ds = ((!)config.nsRef).Acquire();
2008-03-05 09:52:00 -05:00
if (ds == null) {
throw new Exception("Unable to acquire handle to the Directory Service root");
}
ds.RecvSuccess();
2008-11-17 18:29:00 -05:00
bool ok = SdsUtils.GetLinkValue((!)config.nsPath, ds, out link, out errorOut);
2008-03-05 09:52:00 -05:00
if (!ok) {
Console.WriteLine("{0} ({1}) failed. reason: {2}\n",
"getsymlink", config.nsPath, SdsUtils.ErrorCodeToString(errorOut) );
delete ds;
return -1;
}
Console.WriteLine("Link: {0} -> {1}", config.nsPath,link);
delete ds;
return 0;
}
}//SymbolicLink
}//namespace