// Tests if a file exists. The result is true if the file // given by the specified path exists; otherwise, the result is // false. Note that if path describes a directory, // Exists will return true. // // Your application must have Read permission for the target directory. // //| <include file='doc\File.uex' path='docs/doc[@for="File.Exists"]/*' /> public static bool Exists(String !path) { DirectoryServiceContract.Imp dsRoot = DirectoryService.NewClientEndpoint(); if (dsRoot == null) { throw new Exception("No directory service endpoint."); } bool ok = Exists(dsRoot, path); delete dsRoot; return(ok); }
private static int RunProcess(DirectoryServiceContract.Imp !ds, string[] args, PipeMultiplexer !outputMux) { Process child = Binder.CreateProcess(ds, args, outputMux); if (child != null) { child.Start(); child.Join(); return(0); } return(-1); }
// Must be balanced with a call to ReleaseDnsConnection()! internal static DNSContract.Imp !GetDnsConnection() { LocalDataStoreSlot slot = SafeSlotFetchOrInitialize(ref DnsSlot, DnsSlotLock); if (Thread.GetData(slot) == null) { // We haven't created a channel for this thread yet. Create one. DNSContract.Imp !dnsImp; DNSContract.Exp !dnsExp; DirectoryServiceContract.Imp epNS = DirectoryService.NewClientEndpoint(); DNSContract.NewChannel(out dnsImp, out dnsExp); try { epNS.SendBind(Bitter.FromString2(DNSContract.ModuleName), dnsExp); switch receive { case epNS.NakBind(ServiceContract.Exp: Start rejectedEP, error) : if (rejectedEP != null) { delete rejectedEP; } delete dnsImp; // Do nothing; we will return null below. break; case epNS.AckBind(): // Success; put our remaining end of the channel // into thread-local storage. dnsImp.RecvReady(); TRef <DNSContract.Imp : ReadyState> dnsConnHolder = new TRef <DNSContract.Imp : ReadyState>(dnsImp); Thread.SetData(slot, dnsConnHolder); break; } } finally { delete epNS; } } // By now there should definitely be a channel in our thread-local storage. TRef <DNSContract.Imp : ReadyState> !connHolder = (TRef <DNSContract.Imp : ReadyState> !)Thread.GetData(slot); return(connHolder.Acquire()); }
//[ShellCommand("StartProcess", "tests lib routine to start process with Manifest")] internal static int AppMain(Parameters !config) { DirectoryServiceContract.Imp ds = null; if (config.nsRef != null) { ds = config.nsRef.Acquire(); } if (ds == null) { throw new Exception("Unable to acquire handle to the Directory Service root"); } ds.RecvSuccess(); // Make ourselves a new output pipe UnicodePipeContract.Exp !newOutputExp; UnicodePipeContract.Imp !newOutputImp; UnicodePipeContract.NewChannel(out newOutputImp, out newOutputExp); // Retrieve our real stdOut and start using the one we just created // instead UnicodePipeContract.Imp stdOut = ConsoleOutput.Swap(newOutputImp); if (stdOut == null) { Console.WriteLine("runtests expects a STDOUT pipe"); delete newOutputExp; delete ds; return(1); } // Use a mux to splice our own output together with the child // processes we will run. PipeMultiplexer !outputMux = PipeMultiplexer.Start(stdOut, newOutputExp); string[] args = config.Args; if (args != null && args[0] != null) { RunProcess(ds, args, outputMux); } outputMux.Dispose(); delete ds; return(0); }
public static KeyboardDeviceContract.Imp OpenKeyboard(string! devName) { KeyboardDeviceContract.Exp! exp; KeyboardDeviceContract.Imp! imp; KeyboardDeviceContract.NewChannel(out imp, out exp); // get NS endpoint DirectoryServiceContract.Imp ns = DirectoryService.NewClientEndpoint(); bool success = false; ns.SendBind(Bitter.FromString2(devName),exp); switch receive { case ns.AckBind(): success = true; break; case ns.NakBind(exp): delete exp; break; case ns.ChannelClosed(): break; } if (!success) { DebugStub.Print("OpenKeyboard lookup of {0} failed.\n", __arglist(devName); delete imp; delete ns; return null; } switch receive { case imp.Success(): break; case unsatisfiable: throw new Exception("Didn't imp.RecvAckConnect"); break; } delete ns; return imp; }
public static bool ConnectEndPoint(string !lookupName, [Claims] ServiceContract.Exp !ep) { DirectoryServiceContract.Imp epNS = DirectoryService.NewClientEndpoint(); try { ErrorCode errorOut; bool ok = SdsUtils.Bind(lookupName, epNS, ep, out errorOut); if (!ok) { return(false); } else { return(true); } // // epNS.SendBind(Microsoft.Singularity.Bitter.FromString2(lookupName), ep); // // switch receive { // case epNS.NakBind(ServiceContract.Exp:Start rejectedEP, error) : // // failure // delete rejectedEP; // return false; // break; // // case epNS.AckBind() : // // success // return true; // break; // // case epNS.ChannelClosed() : // // failure // return false; // } // } finally { delete epNS; } }
public static bool Exists(DirectoryServiceContract.Imp : Ready !dsRoot, String !path)
private static ConsoleDeviceContract.Imp OpenConsoleInternal(DirectoryServiceContract.Imp !nsImp, [Claims] char[] !in ExHeap deviceName)