public static void FindDuplicates(String[] args) { bool subDirectoriesRecursion = false; if (args.Length < 1) { GiveHelp(); return; } int rootDirectoryIndex = 0; if (args.Length > 1) { if (args[0] == "/recurse") { if (args.Length < 2) { GiveHelp(); return; } subDirectoriesRecursion = true; rootDirectoryIndex = 1; } } var dirsToSearch = args.Skip(rootDirectoryIndex); List<FileInfosGroup> fileGroups = IterateFolders(subDirectoriesRecursion, dirsToSearch); Console.ReadKey(); }
/// <summary> /// Initializes a new instance of the <see cref="FontGenerationParameters"/> class. /// </summary> /// <param name="args">The application's command line arguments.</param> public FontGenerationParameters(String[] args) { if (args == null || !args.Any()) throw new InvalidCommandLineException(); var parser = new CommandLineParser(args.Skip(1)); if (parser.IsParameter(args.First())) { throw new InvalidCommandLineException(); } NoBold = parser.HasArgument("nobold"); NoItalic = parser.HasArgument("noitalic"); FontName = args.First(); FontSize = parser.GetArgumentOrDefault<Single>("fontsize", 16f); Overhang = parser.GetArgumentOrDefault<Int32>("overhang", 0); PadLeft = parser.GetArgumentOrDefault<Int32>("pad-left", 0); PadRight = parser.GetArgumentOrDefault<Int32>("pad-right", 0); SuperSamplingFactor = parser.GetArgumentOrDefault<Int32>("supersample", 2); if (SuperSamplingFactor < 1) SuperSamplingFactor = 1; SourceText = parser.GetArgumentOrDefault<String>("sourcetext"); SourceFile = parser.GetArgumentOrDefault<String>("sourcefile"); SourceCulture = parser.GetArgumentOrDefault<String>("sourceculture"); if (SourceText != null && SourceFile != null) throw new InvalidCommandLineException("Both a source text and a source file were specified. Pick one!"); SubstitutionCharacter = parser.GetArgumentOrDefault<Char>("sub", '?'); }
public void Run(String[] arguments) { if (arguments.Length == 0) { return; } String taskArgument = arguments[0]; String[] eventArguments = new String[] { String.Empty }; char[] trimChars = new char[] { '-', '/' }; if (arguments.Length > 1) { eventArguments = arguments.Skip(1).ToArray(); } taskArgument = taskArgument.TrimStart(trimChars); foreach (var kvp in RemotingTaskMethods.Methods.Where(k => k.Key.TrimStart(trimChars) == taskArgument)) { String argument = kvp.Key.TrimStart(trimChars); RemoteTaskMethod handler = kvp.Value; if (Program.Form != null && Program.Form.InvokeRequired) { Program.Form.Invoke(handler, new object[] { eventArguments }); } else { handler(eventArguments); } } }
public void RunDllUpdate(String[] args) { if (args.Length < 2) { Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -dllupdate mode"); return; } if (args.Length > 2) { if (!this.SetOptions(args.Skip(2).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: DLL Update aborted since one/more options were not valid"); return; } } String appFolder; if (!this._noLocalIIS) { //Open the Configuration File System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site); Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application"); appFolder = Path.GetDirectoryName(config.FilePath); } else { appFolder = Path.GetDirectoryName(args[1]); } //Detect Folders String binFolder = Path.Combine(appFolder, "bin\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } //Copy all required DLLs are in the bin directory of the application String sourceFolder = RdfWebDeployHelper.ExecutablePath; foreach (String dll in RdfWebDeployHelper.RequiredDLLs) { if (File.Exists(Path.Combine(sourceFolder, dll))) { File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true); Console.WriteLine("rdfWebDeploy: Updated " + dll + " in the web applications bin directory"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found"); return; } } Console.WriteLine("rdfWebDeploy: OK - All required DLLs are now up to date"); }
private static void StartDirect(String[] args) { try { Common.Initialize(); switch (args.First()) { case "-game": Common.StartGame(args.Skip(1).ToArray()); break; case "-editor": Common.StartEditor(args.Skip(1).ToArray()); break; default: throw new ArgumentException(@"Invalid start argument: """ + args[0] + @""", valid arguments are ""-game"" or ""-editor"""); } } catch (Exception e) { MessageBox.Show(e.ToString(), e.GetType().Name); } }
public void Verify(String[] args) { if (args.Length < 2) { Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -dllverify mode"); return; } if (args.Length > 2) { if (!this.SetOptions(args.Skip(2).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: DLL Verify aborted since one/more options were not valid"); return; } } String appFolder; if (!this._noLocalIIS) { //Open the Configuration File System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site); Console.Out.WriteLine("rdfWebDeploy: Opened the Web.Config file for the specified Web Application"); appFolder = Path.GetDirectoryName(config.FilePath); } else { appFolder = Path.GetDirectoryName(args[1]); } //Detect Folders String binFolder = Path.Combine(appFolder, "bin\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } //Verify all required DLLs are in the bin directory of the application IEnumerable<String> dlls = RdfWebDeployHelper.RequiredDLLs; if (this._sql) dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs); if (this._virtuoso) dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs); if (this._fulltext) dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs); foreach (String dll in dlls) { if (!File.Exists(Path.Combine(binFolder, dll))) { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory is not present, suggest you use the -dllupdate mode to rectify this"); return; } } Console.WriteLine("rdfWebDeploy: OK - All required DLLs are present"); }
public void Execute(String[] args) { if (ShowHelpFor(args)) { ShowHelp(); ShowAvailableModules(); } else { String moduleName = args[0]; String[] moduleArgs = args.Skip(1).ToArray(); GennyModuleDescriptor[] descriptors = Locator.Find(moduleName).ToArray(); switch (descriptors.Length) { case 0: Logger.Write($"Could not find a genny module named: {moduleName}"); ShowAvailableModules(); break; case 1: GennyModuleLoaderResult result = Loader.Load(descriptors[0], moduleArgs); if (result.Errors.Any()) { foreach (String error in result.Errors) Logger.Write(error); result.Module.ShowHelp(Logger); } else { result.Module.Run(); } break; default: Logger.Write($"Found more than one genny module named: {moduleName}, try using longer identifiers"); foreach (GennyModuleDescriptor descriptor in descriptors) Logger.Write($" {descriptor.FullName} - {descriptor.Description ?? "{No description}"}"); break; } } }
/// <summary> /// Processes user-specified parameters for the list command. /// </summary> /// <param name="args">The application's command line arguments.</param> /// <param name="parser">The command line argument parser.</param> private void ProcessListParameters(String[] args, CommandLineParser parser) { ListInput = args.Skip(1).Take(1).Single(); }
/// <summary> /// Processes user-specified parameters for the pack command. /// </summary> /// <param name="args">The application's command line arguments.</param> /// <param name="parser">The command line argument parser.</param> private void ProcessPackParameters(String[] args, CommandLineParser parser) { PackOutput = args.Skip(1).Take(1).Single(); PackDirectories = args.Skip(2).ToList(); }
public void RunDeploy(String[] args) { if (args.Length < 3) { Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -deploy mode, type rdfWebDeploy -help to see usage summary"); return; } if (args.Length > 3) { if (!this.SetOptions(args.Skip(3).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid"); return; } } if (this._noLocalIIS) { Console.WriteLine("rdfWebDeploy: No Local IIS Server available so switching to -xmldeploy mode"); XmlDeploy xdeploy = new XmlDeploy(); xdeploy.RunXmlDeploy(args); return; } //Define the Server Manager object Admin.ServerManager manager = null; try { //Connect to the Server Manager if (!this._noIntegratedRegistration) manager = new Admin.ServerManager(); //Open the Configuration File System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site); Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application"); //Detect Folders String appFolder = Path.GetDirectoryName(config.FilePath); String binFolder = Path.Combine(appFolder, "bin\\"); String appDataFolder = Path.Combine(appFolder, "App_Data\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application"); } //Deploy dotNetRDF and required DLLs to the bin directory of the application String sourceFolder = RdfWebDeployHelper.ExecutablePath; foreach (String dll in RdfWebDeployHelper.RequiredDLLs) { if (File.Exists(Path.Combine(sourceFolder, dll))) { File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true); Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found"); return; } } //Deploy the configuration file to the App_Data directory if (File.Exists(args[2])) { File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true); Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory"); } else if (!File.Exists(Path.Combine(appDataFolder, args[2]))) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder"); return; } //Set the AppSetting for the configuration file config.AppSettings.Settings.Remove("dotNetRDFConfig"); config.AppSettings.Settings.Add("dotNetRDFConfig", "~/App_Data/" + Path.GetFileName(args[2])); Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\""); //Now load the Configuration Graph from the App_Data folder Graph g = new Graph(); FileLoader.Load(g, Path.Combine(appDataFolder, args[2])); Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings"); Console.WriteLine(); //Get the sections of the Configuration File we want to edit HttpHandlersSection handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection; if (handlersSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Handlers section of the web applications Web.Config file"); return; } //Detect Handlers from the Configution Graph and deploy IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "type")); IUriNode httpHandler = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "HttpHandler")); //Deploy for IIS Classic Mode if (!this._noClassicRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode"); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration handlersSection.Handlers.Remove("*", handlerPath); //Then add the new registration handlersSection.Handlers.Add(new HttpHandlerAction(handlerPath, handlerType, "*")); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { HttpModulesSection modulesSection = config.GetSection("system.web/httpModules") as HttpModulesSection; if (modulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } modulesSection.Modules.Remove("NegotiateByExtension"); modulesSection.Modules.Add(new HttpModuleAction("NegotiateByExtension", "VDS.RDF.Web.NegotiateByFileExtension")); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode"); } //Save the completed Configuration File config.Save(ConfigurationSaveMode.Minimal); Console.WriteLine(); //Deploy for IIS Integrated Mode if (!this._noIntegratedRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode"); Admin.Configuration adminConfig = manager.GetWebConfiguration(this._site, args[1]); Admin.ConfigurationSection newHandlersSection = adminConfig.GetSection("system.webServer/handlers"); Admin.ConfigurationElementCollection newHandlers = newHandlersSection.GetCollection(); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration foreach (Admin.ConfigurationElement oldReg in newHandlers.Where(el => el.GetAttributeValue("name").Equals(handlerPath)).ToList()) { newHandlers.Remove(oldReg); } //Then add the new registration Admin.ConfigurationElement reg = newHandlers.CreateElement("add"); reg["name"] = handlerPath; reg["path"] = handlerPath; reg["verb"] = "*"; reg["type"] = handlerType; newHandlers.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { Admin.ConfigurationSection newModulesSection = adminConfig.GetSection("system.webServer/modules"); if (newModulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } //First remove the Old Module Admin.ConfigurationElementCollection newModules = newModulesSection.GetCollection(); foreach (Admin.ConfigurationElement oldReg in newModules.Where(el => el.GetAttribute("name").Equals("NegotiateByExtension")).ToList()) { newModules.Remove(oldReg); } //Then add the new Module Admin.ConfigurationElement reg = newHandlers.CreateElement("add"); reg["name"] = "NegotiateByFileExtension"; reg["type"] = "VDS.RDF.Web.NegotiateByFileExtension"; newModules.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } } manager.CommitChanges(); Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode"); } } catch (ConfigurationException configEx) { Console.Error.Write("rdfWebDeploy: Configuration Error: " + configEx.Message); } catch (Exception ex) { Console.Error.Write("rdfWebDeploy: Error: " + ex.Message); } finally { if (manager != null) manager.Dispose(); } }
public static void StartEditor(String[] args) { if (!Common.IsInitialized) Common.Initialize(); if (!File.Exists(Common.EditorPath)) throw new FileNotFoundException("Could not find worldedit.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "worldedit.exe"); if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll"))) throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll"); Boolean kill = false; Boolean debug = false; Boolean valid = true; while (valid && args.Length > 0) { switch (args[0]) { case "-kill": kill = true; args = args.Skip(1).ToArray(); break; case "-debug": debug = true; args = args.Skip(1).ToArray(); break; default: valid = false; break; } } var worldedits = Process.GetProcessesByName("worldedit"); if (worldedits.Count() > 0) { if (kill) { foreach (var worldedit in worldedits) worldedit.Kill(); } else throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it."); } Console.Write("Creating and injecting into World Editor . . . "); var cmd = '"' + Common.EditorPath + '"'; if (args.Length > 0) cmd += ' ' + args.Aggregate((a, b) => a + ' ' + b); Int32 processId; RemoteHooking.CreateAndInject(Common.EditorPath, cmd, 0, "SharpCraft.dll", "SharpCraft.dll", out processId, PluginContext.Editor, debug, Environment.CurrentDirectory, Common.InstallPath); Console.WriteLine("Done!"); }
public void RunXmlDeploy(String[] args) { if (args.Length < 3) { Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -xmldeploy mode, type rdfWebDeploy -help to see usage summary"); return; } if (args.Length > 3) { if (!this.SetOptions(args.Skip(3).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid"); return; } } try { //Determine the path to the Web.config file if possible if (args[1].Equals(".")) { args[1] = Path.Combine(".", "Web.config"); } else if (Path.GetFileName(args[1]).Equals(String.Empty)) { //If we were given a Folder Path then add Web.config to the end args[1] = Path.Combine(args[1], "Web.config"); } else if (!Path.GetFileName(args[1]).Equals("Web.config", StringComparison.OrdinalIgnoreCase)) { //If out path was to a file and it wasn't a Web.config file we error Console.Error.WriteLine("rdfWebDeploy: Error: You must specify a Web.config file for the web application you wish to deploy to"); return; } //Open the Configuration File XmlDocument config = new XmlDocument(); if (File.Exists(args[1])) { //If the File exists open it config.Load(args[1]); //Verify this does appear to be a Web.config file if (!config.DocumentElement.Name.Equals("configuration")) { Console.Error.WriteLine("rdfWebDeploy: Error: The Web.Config file for the Web Application does not appear to be a valid Web.Config file"); return; } } else { //If the Web.Config file doesn't exist then create one XmlDeclaration decl = config.CreateXmlDeclaration("1.0", "utf-8", null); config.AppendChild(decl); XmlElement docEl = config.CreateElement("configuration"); config.AppendChild(docEl); config.Save(args[1]); } Console.Out.WriteLine("rdfWebDeploy: Opened the Web.Config file for the specified Web Application"); XmlNode reg = null; //Detect Folders String appFolder = Path.GetDirectoryName(args[1]); String binFolder = Path.Combine(appFolder, "bin\\"); String appDataFolder = Path.Combine(appFolder, "App_Data\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application"); } //Deploy dotNetRDF and required DLLs to the bin directory of the application String sourceFolder = RdfWebDeployHelper.ExecutablePath; IEnumerable<String> dlls = RdfWebDeployHelper.RequiredDLLs; if (this._sql) dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs); if (this._virtuoso) dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs); if (this._fulltext) dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs); foreach (String dll in dlls) { if (File.Exists(Path.Combine(sourceFolder, dll))) { File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true); Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found"); return; } } //Deploy the configuration file to the App_Data directory if (File.Exists(args[2])) { File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true); Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory"); } else if (!File.Exists(Path.Combine(appDataFolder, args[2]))) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder"); return; } //Set the AppSetting for the configuration file XmlNodeList appSettingsNodes = config.DocumentElement.GetElementsByTagName("appSettings"); XmlNode appSettings; if (appSettingsNodes.Count == 0) { appSettings = config.CreateElement("appSettings"); config.DocumentElement.AppendChild(appSettings); } else if (appSettingsNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <appSettings> node exists"); return; } else { appSettings = appSettingsNodes[0]; } XmlNode configFileSetting = null; foreach (XmlNode setting in appSettings.ChildNodes) { if (setting.Attributes.GetNamedItem("key") != null) { if (setting.Attributes["key"].Value.Equals("dotNetRDFConfig")) { configFileSetting = setting; break; } } } if (configFileSetting == null) { configFileSetting = config.CreateElement("add"); XmlAttribute attr = config.CreateAttribute("key"); attr.Value = "dotNetRDFConfig"; configFileSetting.Attributes.Append(attr); attr = config.CreateAttribute("value"); attr.Value = "~/App_Data/" + Path.GetFileName(args[2]); configFileSetting.Attributes.Append(attr); appSettings.AppendChild(configFileSetting); } else { configFileSetting.Attributes["value"].Value = "~/App_Data/" + Path.GetFileName(args[2]); } Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\""); //Now load the Configuration Graph from the App_Data folder Graph g = new Graph(); FileLoader.Load(g, Path.Combine(appDataFolder, args[2])); Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings"); config.Save(args[1]); Console.WriteLine(); //Detect Handlers from the Configution Graph and deploy IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "type")); IUriNode httpHandlerType = g.CreateUriNode(new Uri(ConfigurationLoader.ConfigurationNamespace + "HttpHandler")); //Deploy for IIS Classic Mode if (!this._noClassicRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode"); //Get the appropriate section of the Config File XmlNodeList systemWebNodes = config.DocumentElement.GetElementsByTagName("system.web"); XmlElement systemWeb; if (systemWebNodes.Count == 0) { systemWeb = config.CreateElement("system.web"); config.DocumentElement.AppendChild(systemWeb); } else if (systemWebNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <system.web> node exists"); return; } else { systemWeb = (XmlElement)systemWebNodes[0]; } XmlNodeList httpHandlersNodes = systemWeb.GetElementsByTagName("httpHandlers"); XmlElement httpHandlers; if (httpHandlersNodes.Count == 0) { httpHandlers = config.CreateElement("httpHandlers"); systemWeb.AppendChild(httpHandlers); } else if (httpHandlersNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <httpHandlers> node exists"); return; } else { httpHandlers = (XmlElement)httpHandlersNodes[0]; } foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandlerType).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //Add XML to register the Handler reg = null; foreach (XmlNode existingReg in httpHandlers.ChildNodes) { if (existingReg.Attributes.GetNamedItem("path") != null) { if (existingReg.Attributes["path"].Value.Equals(handlerPath)) { reg = existingReg; break; } } } if (reg == null) { reg = config.CreateElement("add"); XmlAttribute attr = config.CreateAttribute("path"); attr.Value = handlerPath; reg.Attributes.Append(attr); attr = config.CreateAttribute("verb"); attr.Value = "*"; reg.Attributes.Append(attr); attr = config.CreateAttribute("type"); attr.Value = handlerType; reg.Attributes.Append(attr); httpHandlers.AppendChild(reg); } else { reg.Attributes["type"].Value = handlerType; } Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } } //Deploy Negotiate by File Extension if (this._negotiate) { XmlNodeList httpModulesNodes = systemWeb.GetElementsByTagName("httpModules"); XmlElement httpModules; if (httpModulesNodes.Count == 0) { httpModules = config.CreateElement("httpModules"); systemWeb.AppendChild(httpModules); } else if (httpModulesNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <httpModules> node exists"); return; } else { httpModules = (XmlElement)httpModulesNodes[0]; } reg = null; foreach (XmlNode existingReg in httpModules.ChildNodes) { if (existingReg.Attributes.GetNamedItem("name") != null) { if (existingReg.Attributes["name"].Value.Equals("NegotiateByExtension")) { reg = existingReg; break; } } } if (reg == null) { reg = config.CreateElement("add"); XmlAttribute name = config.CreateAttribute("name"); name.Value = "NegotiateByExtension"; reg.Attributes.Append(name); XmlAttribute type = config.CreateAttribute("type"); type.Value = "VDS.RDF.Web.NegotiateByFileExtension"; reg.Attributes.Append(type); httpModules.AppendChild(reg); } Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } config.Save(args[1]); Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode"); } Console.WriteLine(); //Deploy for IIS Integrated Mode if (!this._noIntegratedRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode"); //Get the appropriate section of the Config File XmlNodeList systemWebServerNodes = config.DocumentElement.GetElementsByTagName("system.webServer"); XmlElement systemWebServer; if (systemWebServerNodes.Count == 0) { systemWebServer = config.CreateElement("system.webServer"); config.DocumentElement.AppendChild(systemWebServer); } else if (systemWebServerNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <system.webServer> node exists"); return; } else { systemWebServer = (XmlElement)systemWebServerNodes[0]; } //Set the <validation validateIntegratedModeConfiguration="false" /> element XmlNodeList validateNodes = systemWebServer.GetElementsByTagName("validation"); if (validateNodes.Count > 0) { foreach (XmlNode validate in validateNodes) { if (validate.Attributes.GetNamedItem("validateIntegratedModeConfiguration") != null) { validate.Attributes["validateIntegratedModeConfiguration"].Value = "false"; } else { XmlAttribute valAttr = config.CreateAttribute("validateIntegratedModeConfiguration"); valAttr.Value = "false"; validate.Attributes.Append(valAttr); } } } else { XmlElement valEl = config.CreateElement("validation"); XmlAttribute valAttr = config.CreateAttribute("validateIntegratedModeConfiguration"); valAttr.Value = "false"; valEl.Attributes.Append(valAttr); systemWebServer.AppendChild(valEl); } //Find <handlers> element XmlNodeList httpHandlersNodes = systemWebServer.GetElementsByTagName("handlers"); XmlElement httpHandlers; if (httpHandlersNodes.Count == 0) { httpHandlers = config.CreateElement("handlers"); systemWebServer.AppendChild(httpHandlers); } else if (httpHandlersNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <handlers> node exists"); return; } else { httpHandlers = (XmlElement)httpHandlersNodes[0]; } foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandlerType).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //Add XML to register the Handler reg = null; foreach (XmlNode existingReg in httpHandlers.ChildNodes) { if (existingReg.Attributes.GetNamedItem("path") != null) { if (existingReg.Attributes["path"].Value.Equals(handlerPath)) { reg = existingReg; break; } } } if (reg == null) { reg = config.CreateElement("add"); XmlAttribute attr = config.CreateAttribute("name"); attr.Value = handlerPath; reg.Attributes.Append(attr); attr = config.CreateAttribute("path"); attr.Value = handlerPath; reg.Attributes.Append(attr); attr = config.CreateAttribute("verb"); attr.Value = "*"; reg.Attributes.Append(attr); attr = config.CreateAttribute("type"); attr.Value = handlerType; reg.Attributes.Append(attr); httpHandlers.AppendChild(reg); } else { reg.Attributes["type"].Value = handlerType; } Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } } //Deploy Negotiate by File Extension if (this._negotiate) { XmlNodeList httpModulesNodes = systemWebServer.GetElementsByTagName("modules"); XmlElement httpModules; if (httpModulesNodes.Count == 0) { httpModules = config.CreateElement("modules"); systemWebServer.AppendChild(httpModules); } else if (httpModulesNodes.Count > 1) { Console.Error.WriteLine("rdfWebDeploy: Error: The Configuration File for the Web Application appears to be invalid as more than one <modules> node exists"); return; } else { httpModules = (XmlElement)httpModulesNodes[0]; } reg = null; foreach (XmlNode existingReg in httpModules.ChildNodes) { if (existingReg.Attributes.GetNamedItem("name") != null) { if (existingReg.Attributes["name"].Value.Equals("NegotiateByExtension")) { reg = existingReg; break; } } } if (reg == null) { reg = config.CreateElement("add"); XmlAttribute name = config.CreateAttribute("name"); name.Value = "NegotiateByExtension"; reg.Attributes.Append(name); XmlAttribute type = config.CreateAttribute("type"); type.Value = "VDS.RDF.Web.NegotiateByFileExtension"; reg.Attributes.Append(type); httpModules.AppendChild(reg); } Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } config.Save(args[1]); Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode"); } } catch (ConfigurationException configEx) { Console.Error.Write("rdfWebDeploy: Configuration Error: " + configEx.Message); } catch (Exception ex) { Console.Error.Write("rdfWebDeploy: Error: " + ex.Message); } }
protected String FormatGuid(String guid) { return String.Format("{0}..{1}", new String(guid.Take(5).ToArray()), new String(guid.Skip(Math.Max(0, guid.Count() - 3)).Take(3).ToArray())); }
/// <summary> /// /// </summary> /// <param name="timestamp"></param> /// <param name="date"></param> /// <param name="time"></param> /// <returns></returns> private static String TryExtractingDateAndTime(String[] timestamp, ref DateTime date, ref DateTime time) { if (timestamp == null) return null; if (DateTime.TryParse(timestamp[1], out time)) { // Rabo format DateTime dummy; if (!DateTime.TryParse(timestamp[0], out dummy)) { date = date.AddTicks(time.Ticks); return String.Join(" ", timestamp[0], timestamp.Skip(2)); } } // ING format if (timestamp != null && (DateTime.TryParse(timestamp[0], out date) || DateTime.TryParseExact(timestamp[0], "yyyyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out date))) { date = date.AddTicks(time.Ticks); return String.Join(" ", timestamp.Skip(2)); } return null; }
static void Main(String[] args) { if (args != null && args.Length == 1 && args[0].Length > 1 && (args[0][0] == '-' || args[0][0] == '/')) { switch (args[0].Substring(1).ToLower()) { default: Console.WriteLine("Huh?!"); break; case "uninstall": case "u": { ServiceController[] scServices = ServiceController.GetServices(); foreach (ServiceController sc in scServices) if (sc.ServiceName == name) if (sc.Status != ServiceControllerStatus.Stopped && sc.Status != ServiceControllerStatus.StopPending) sc.Stop(); ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); break; } case "console": case "c": { TelnetPerfmonServer program = new TelnetPerfmonServer(); program.Run(args.Skip(1).ToArray()); break; } /* case "p": { TelnetPerfmonServer program = new TelnetPerfmonServer(); Thread t =new Thread(() => program.Run(new String[]{})); t.Start(); Thread.Sleep(5000); program.Stop(); break; }*/ } } else { bool found = false; foreach (ServiceController sc in ServiceController.GetServices()) if (sc.ServiceName == name) found = true; if (!found) install(); else ServiceBase.Run(new ServiceBase[] { new TelnetPerfmonService() }); } }