public void ConnectionPreferencesRoundTrip() { var cred = new ExplicitCredentials("db", "user", "pass"); var pref = new ConnectionPreferences() { Credentials = cred, DefaultTimeout = 1000, Name = "ConnName", Url = "http://example.com" }; pref.Headers.Locale = "en-gb"; var saved = new SavedConnections(); saved.Add(pref); var newPref = saved.First(); var newCred = newPref.Credentials as ExplicitCredentials; Assert.AreEqual(cred.Database, newCred.Database); Assert.AreEqual(cred.Username, newCred.Username); Assert.AreEqual(pref.DefaultTimeout, newPref.DefaultTimeout); Assert.AreEqual(pref.Name, newPref.Name); Assert.AreEqual(pref.Url, newPref.Url); Assert.AreEqual(pref.Headers.Locale, newPref.Headers.Locale); }
private void SaveConnectionToBeBuilt(SavedConnection connection) { App.Config.SavedConnections.Add(connection); App.Config.Save(); SelectedConnection = SavedConnections.FirstOrDefault(r => r.NickName == connection.NickName); }
private void SaveConnections(SavedConnections connections) { var json = JsonConvert.SerializeObject(connections); var directory = Path.GetDirectoryName(FilePath); Directory.CreateDirectory(directory); File.WriteAllText(FilePath, json); }
private void GetLastSavedConnectionAndDetermineIfCanConnect() { if (App.Config.LastUsedSavedConnection.Instance != null) { SelectedConnection = SavedConnections.FirstOrDefault(r => r.NickName == App.Config.LastUsedSavedConnection.NickName); CanConnect = true; } else { CanConnect = false; } }
protected override void ProcessRecord() { IEnumerable <ConnectionPreferences> prefs = string.IsNullOrEmpty(FilePath) ? SavedConnections.Load() : SavedConnections.Load(FilePath); if (!string.IsNullOrEmpty(Name)) { prefs = prefs.Where(p => p.Name.IndexOf(Name, StringComparison.OrdinalIgnoreCase) >= 0); } foreach (var conn in prefs.Select(p => new SavedConnection(p))) { WriteObject(conn); } }
public ConnectionSelectionViewModel(SavedConnections model) { _model = model ?? throw new ArgumentNullException(nameof(model)); if (model.Connections == null) { model.Connections = new Connection[] { }; } foreach (var connection in model.Connections) { Connections.Add(new ConnectionViewModel(connection)); } SelectedConnection = Connections.FirstOrDefault(); RefreshPortNames(); OkCommand = new RelayCommand(Ok, CanOk); AddConnectionCommand = new RelayCommand(AddConnection); DeleteConnectionCommand = new RelayCommand(DeleteConnection); RefreshPortNamesCommand = new RelayCommand(RefreshPortNames); }
public void UpdateSavedConnections() { if (_savedConnections == null) { return; } XmlNode parentNode = _settingsRootNode; XmlNodeList nodes = _settingsRootNode.GetElementsByTagName("SavedSettings"); var nodesToHack = new ArrayList(); foreach (XmlNode node in nodes) { if (!SavedConnections.ContainsKey(XmlHelper.GetAttribute(node, "name", MISSING))) { nodesToHack.Add(node); } } foreach (XmlNode node in nodesToHack) { parentNode.RemoveChild(node); } foreach (ConnectionInfo inf in _savedConnections.Values) { var xPath = @"SavedSettings[@name='" + inf.Name.Replace("'", "'") + "']"; XmlNode connectionNode = _settingsRootNode.SelectSingleNode(xPath, null); if (connectionNode == null) { connectionNode = parentNode.AppendChild(_settingsRootNode.OwnerDocument.CreateNode(XmlNodeType.Element, "SavedSettings", null)); } else { if (_databaseUserMetaMappings != null) { nodesToHack.Clear(); foreach (XmlNode childNode in connectionNode.ChildNodes) { if (childNode.Name == "SavedXmlUserMetaAlias") { nodesToHack.Add(childNode); } } foreach (XmlNode node2kill in nodesToHack) { connectionNode.RemoveChild(node2kill); } } } XmlHelper.SetAttribute(connectionNode, "name", inf.Name); XmlHelper.SetAttribute(connectionNode, "driver", inf.Driver); XmlHelper.SetAttribute(connectionNode, "connstr", inf.ConnectionString); XmlHelper.SetAttribute(connectionNode, "dbtargetpath", inf.DbTargetPath); XmlHelper.SetAttribute(connectionNode, "languagepath", inf.LanguagePath); XmlHelper.SetAttribute(connectionNode, "usermetapath", inf.UserMetaDataPath); XmlHelper.SetAttribute(connectionNode, "language", inf.Language); XmlHelper.SetAttribute(connectionNode, "dbtarget", inf.DbTarget); XmlHelper.SetAttribute(connectionNode, "defaultdatabaseonly", inf.ShowDefaultDatabaseOnly.ToString()); if (_databaseUserMetaMappings != null) { foreach (string dbkey in inf.DatabaseUserDataXmlMappings.Keys) { XmlNode mapXmlNode = connectionNode.AppendChild(_settingsRootNode.OwnerDocument.CreateNode(XmlNodeType.Element, "SavedXmlUserMetaAlias", null)); XmlHelper.SetAttribute(mapXmlNode, "database", dbkey); XmlHelper.SetAttribute(mapXmlNode, "alias", inf.DatabaseUserDataXmlMappings[dbkey]); } } } _savedConnections = null; }
public DataMigrator(SavedConnections savedConnections) { _savedConnections = savedConnections; }
static void Main(string[] args) { Console.WriteLine("Starting..."); var prefs = SavedConnections.Load().Default; var conn = Factory.GetConnection(prefs); var savedSearches = conn.Apply(@"<Item type='SavedSearch' action='get' select='criteria'> <is_email_subscription>0</is_email_subscription> <auto_saved>0</auto_saved> <criteria condition='is not null'></criteria> </Item>").Items().Select(i => i.Property("criteria").Value).ToArray(); var settings = new ConnectedAmlSqlWriterSettings(conn) { PermissionOption = AmlSqlPermissionOption.None }; var parser = new SimpleSearchParser() { Context = conn.AmlContext.LocalizationContext }; parser.OrDelimiters.Add('\t'); parser.OrDelimiters.Add('\r'); parser.OrDelimiters.Add('\n'); parser.String.DefaultSearchIsContains = true; parser.String.IsPercentWildcard = false; var ignoreActions = new[] { "ApplySubSelect", "ExcelOrgChartReport", "Finished Goods Open Concern Qry", "Gcs_DesignDateReport", "Gcs_Report_ConcernMfgOrg", "Gcs_Report_CustStagnantIssue", "Gcs_Report_EaConcernTracking", "Gcs_Report_SupplierQtyToReport", "Gcs_Report_SupplierQualityExport", "Get Where Used Parts", "GetChargeTimeEntered", "GetChargeTimeRaw", "GetByPerson", "GntxPartNumberXrefRpt", "LinkSearch", "Mco_Report_CreatedToday", "Mdm_Report_HtsCodes", "PcbProgramCostReport", "ProtoOrder_QueryNoRouting", "ProtoOrder_QueryOrderBuildDates", "ProtoOrder_QueryShouldBeClosed", "ProtoOrderQueryWeek", "QualityGcsPriorityReport", "SearchLumen", "TimeTrack_EmployeeAssignRpt", "TimeTrack_EscalationsReport", }; var noErrorCnt = 0; var errorCnt = 0; var total = 0; Console.WriteLine("Testing queries..."); foreach (var search in savedSearches) { try { if (ignoreActions.Any(a => search.IndexOf(a) > 0)) { continue; } if (Regex.IsMatch(search, @"condition=""in"">\s*\(\s*SELECT", RegexOptions.IgnoreCase)) { continue; } var query = QueryItem.FromXml(search); var countQuery = conn.AmlContext.FromXml(search).AssertItem(); countQuery.Attribute("returnMode").Set("countOnly"); var trueCount = conn.Apply(countQuery.ToAml()).ItemMax(); var sql = query.ToArasSql(settings); if (conn.ApplySql(sql).Items().Count() != trueCount) { throw new InvalidOperationException(); } var newAml = query.ToAml(); if (conn.Apply(newAml).Items().Count() != trueCount) { throw new InvalidOperationException(); } var oData = query.ToOData(settings, conn.AmlContext.LocalizationContext); var criteria = query.ToCriteria(parser); noErrorCnt++; } catch (Exception) { //Console.WriteLine(ex.ToString()); errorCnt++; } total++; if ((total % 20) == 0) { Console.WriteLine($"{total} queries tested"); } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"{errorCnt} errors"); Console.WriteLine($"{noErrorCnt} successes"); Console.ReadLine(); }