private static void InsertTag(XmlLightElement start, string xpath, ReplaceOption where, string insertName) { XmlLightElement tag = new XmlLightElement(null, SearchNamespacePrefix + ":" + insertName); tag.Attributes["xmlns:" + SearchNamespacePrefix] = SearchNamespaceUri; tag.IsEmpty = false; XmlLightElement node = start.SelectRequiredNode(xpath); if (where == ReplaceOption.Append) { node.Children.Add(tag); tag.Parent = node; } else if (where == ReplaceOption.Replace) { int ordinal = node.Parent.Children.IndexOf(node); node.Parent.Children[ordinal] = tag; tag.Parent = node.Parent; node.Parent = null; tag.Children.Add(node); node.Parent = tag; } else { throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Initializes a new instance of the <see cref="RestoreSqlServerDatabaseDetails"/> class. /// </summary> /// <param name="dataFilePath">The data file path.</param> /// <param name="logFilePath">The log file path.</param> /// <param name="device">The device.</param> /// <param name="restoreFrom">The restore from.</param> /// <param name="credential">The credential.</param> /// <param name="checksumOption">The checksum option.</param> /// <param name="errorHandling">The error handling.</param> /// <param name="recoveryOption">The recovery option.</param> /// <param name="replaceOption">The replace option.</param> /// <param name="restrictedUserOption">The restricted user option.</param> /// <exception cref="System.ArgumentException"> /// Credential cannot be null or whitespace when Device is URL /// or /// ErrorHandling cannot be None when using checksum. /// </exception> public RestoreSqlServerDatabaseDetails( string dataFilePath, string logFilePath, Device device, Uri restoreFrom, string credential, ChecksumOption checksumOption, ErrorHandling errorHandling, RecoveryOption recoveryOption, ReplaceOption replaceOption, RestrictedUserOption restrictedUserOption) { if (!string.IsNullOrWhiteSpace(dataFilePath)) { SqlInjectorChecker.ThrowIfNotValidPath(dataFilePath, nameof(dataFilePath)); } if (!string.IsNullOrWhiteSpace(logFilePath)) { SqlInjectorChecker.ThrowIfNotValidPath(logFilePath, nameof(logFilePath)); } new { restoreFrom }.AsArg().Must().NotBeNull(); if (device == Device.Url) { credential.MustForArg(nameof(credential)).NotBeNullNorWhiteSpace("Credential cannot be null or whitespace when Device is URL").And().BeAlphanumeric(new[] { ' ', '_' }); } if (checksumOption == ChecksumOption.Checksum) { if (errorHandling == ErrorHandling.None) { throw new ArgumentException("ErrorHandling cannot be None when using checksum.", nameof(errorHandling)); } } this.ChecksumOption = checksumOption; this.Credential = credential; this.DataFilePath = dataFilePath; this.Device = device; this.ErrorHandling = errorHandling; this.LogFilePath = logFilePath; this.RecoveryOption = recoveryOption; this.ReplaceOption = replaceOption; this.RestoreFrom = restoreFrom; this.RestrictedUserOption = restrictedUserOption; }
private void OnReplace(object sender, EventArgs e) { if (_procOpt == null) { _procOpt = new ReplaceOption(); _optDlg = new OptionsDlg(); _optDlg.AddOption(_procOpt); } if (_optDlg.ShowDialog() != DialogResult.OK) { return; } StrStreamProvider provider = new StrStreamProvider(_textBoxInput.Text); MemoryStream memstrm = new MemoryStream(); TextReplacer processor = new TextReplacer((new StreamWriter(memstrm)), _procOpt); TextDispatcher dispatcher = new TextDispatcher(provider, processor); dispatcher.Run(); UpdateOutputTextBox(Encoding.Default.GetString(memstrm.GetBuffer())); }
private static void InsertTag(XmlLightElement start, string xpath, ReplaceOption where, string insertName) { XmlLightElement tag = new XmlLightElement(null, SearchNamespacePrefix + ":" + insertName); tag.Attributes["xmlns:" + SearchNamespacePrefix] = SearchNamespaceUri; tag.IsEmpty = false; XmlLightElement node = start.SelectRequiredNode(xpath); if (where == ReplaceOption.Append) { node.Children.Add(tag); tag.Parent = node; } else if (where == ReplaceOption.Replace) { int ordinal = node.Parent.Children.IndexOf(node); node.Parent.Children[ordinal] = tag; tag.Parent = node.Parent; node.Parent = null; tag.Children.Add(node); node.Parent = tag; } else throw new ArgumentOutOfRangeException(); }