public void Execute(InstallEnvironment env) { Service service = new Service(Name, autoStart); service.ApplicationPath = ApplicationPath; Node <object> theNode = databaseManager.Find("/System/Runtime/Services"); if (!theNode.TypedStreamExists <Service>()) { theNode.AddTypedStream <Service>(StreamOptions.Indexed | StreamOptions.AllowDerivedTypes); } using (TypedStream <Service> ts = theNode.OpenForWriting <Service>()) { ts.Write(ts.Count, service); } }
public static int WriteObject(ExecutionContext context, object[] values, out object[] inlineParameters) { inlineParameters = EmptyParameters; if (values.Length < 2 || values.Length > 5) { context.Error.WriteLine("Invalid syntax: WriteObject @object NodePath [TypedStream [Index]]"); return(-1); } object obj = values[0]; string path = values[1].ToString(); Type type = null; uint index = 0; // We first get type. if (values.Length > 2) { type = Type.GetType(values[2].ToString()); if (type == null) { context.Error.WriteLine("Type '{0}' not resolved.", values[2].ToString()); return(-1); } } if (values.Length > 3) { if (values[3] is uint) { index = (uint)values[3]; } else if (values[3] is int) { index = (uint)((int)values[3]); } else if (!uint.TryParse(values[3].ToString(), out index)) { context.Error.WriteLine("The index is not a number: {0}", values[3].ToString()); return(-1); } } Node <object> node = context.ShellApp.WorkingDirectory.Find(path); if (node == null) { context.Error.WriteLine("Path '{0}' does not exist", path); return(-1); } TypedStream <object> typedStream = null; try { if (type == null) { typedStream = node.OpenForWriting(); } else { typedStream = node.Open(type, OpenMode.Write); } if (typedStream == null) { context.Error.WriteLine("Typed stream '{0}' does not exist on path '{1}'", type, path); return(-1); } // We write it. typedStream.Write(index, obj); } finally { if (typedStream != null) { typedStream.Dispose(); } } return(1); }