void IProbeSite.Probe(ProbeContext context) { var scope = context.CreateScope("host"); scope.Set(new { Type = "RabbitMQ", _settings.Host, _settings.Port, _settings.VirtualHost, _settings.Username, Password = new string('*', _settings.Password.Length), _settings.Heartbeat, _settings.Ssl }); if (_settings.Ssl) { scope.Set(new { _settings.SslServerName }); } ConnectionCache.Probe(scope); ReceiveEndpoints.Probe(scope); }
private void Initialize(IDictionary properties, IClientChannelSinkProvider sinkProvider) { if (properties != null) { // read property values foreach (DictionaryEntry property in properties) { switch ((string)property.Key) { case "name": _channelName = Convert.ToString(property.Value); break; case "priority": _channelPriority = Convert.ToInt32(property.Value); break; case "cachedConnections": _cachedConnections = Convert.ToInt32(property.Value); break; } } } // create the chain of the sink providers that will process all messages _sinkProvider = ChannelHelper.ClientChannelCreateSinkProviderChain( sinkProvider, new PipeClientTransportSinkProvider()); // create connection cache _connectionCache = new ConnectionCache(_cachedConnections, new ConnectionFactory(CreateConnection)); }
private void AssertExpectedMostRecent(ConnectionCache cache, ConnectionInfo expectedMostRecent) { ConnectionInfo actualMostRecent = cache.GetMostRecentConnection(); Assert.AreEqual(expectedMostRecent.ServerUri, actualMostRecent.ServerUri); Assert.AreEqual(expectedMostRecent.LastUsage, actualMostRecent.LastUsage); }
public void TestOrder() { ConnectionCache cache = new ConnectionCache(); // set to some high number const int highNumber = ConnectionCache.CAPACITY + 100; ConnectionInfo expectedMostRecentConnection = null; // Full cache with lastUsage values in reverse order (to force sorting). // Intentionally add one more than will fit in the cache for (int i = ConnectionCache.CAPACITY; i >= 0; i--) { ConnectionInfo newConnectionInfo = GetConnectionInfo(i + highNumber); cache.AddToCache(newConnectionInfo); if (expectedMostRecentConnection == null) { expectedMostRecentConnection = newConnectionInfo; } AssertExpectedMostRecent(cache, expectedMostRecentConnection); } // Add a new ConnectionInfo with a newer time--GetMostRecentConnectionInfo should update ConnectionInfo newerConnection = GetConnectionInfo(2 * highNumber); cache.AddToCache(newerConnection); AssertExpectedMostRecent(cache, newerConnection); // Revise a ConnectionInfo with an even newer time--GetMostRecentConnectionInfo should update newerConnection.SetLastUsage(newerConnection.LastUsage.AddDays(1)); cache.AddToCache(newerConnection); AssertExpectedMostRecent(cache, newerConnection); }
public void TestOrder() { ConnectionCache cache = new ConnectionCache(); // set to some issue number int highNumber = ConnectionCache.CAPACITY + 100; // fill up with sequential high last-usage values for (int i = 1; i <= ConnectionCache.CAPACITY; i++) { cache.AddToCache(GetConnectionInfo(i + highNumber)); } var highestExpected = $"http://fake.fake/{highNumber + ConnectionCache.CAPACITY}"; // add connections with low last-usage values, verify that // the most recent connection is still the highest value from the // initial population for (int i = 1; i < ConnectionCache.CAPACITY; i++) { // add connection with low last-usage value cache.AddToCache(GetConnectionInfo(i)); var mostRecent = cache.GetMostRecentConnection(); Assert.IsTrue(mostRecent.ServerUri.Equals(highestExpected)); } // adding one more should bump out original highest value cache.AddToCache(GetConnectionInfo(0)); Assert.IsFalse(cache.GetMostRecentConnection().ServerUri.Equals(highestExpected)); }
/// <summary> /// Creates a new instance of the Dynamics365Entity class from an entity with the specified logical name in the specified Dynamics instance. /// </summary> /// <param name="logicalName"></param> /// <param name="connection"></param> /// <returns></returns> public static Dynamics365Entity Create(string logicalName, Dynamics365Connection connection) { ConnectionCache cache = new ConnectionCache(connection); string cacheKey = string.Format("GetEntity:{0}", logicalName); Dynamics365Entity entity = (Dynamics365Entity)cache[cacheKey]; if (entity == null) { RetrieveEntityRequest request = new RetrieveEntityRequest() { LogicalName = logicalName, EntityFilters = EntityFilters.Attributes, RetrieveAsIfPublished = false }; using (OrganizationServiceProxy proxy = connection.OrganizationServiceProxy) { RetrieveEntityResponse response = (RetrieveEntityResponse)proxy.Execute(request); entity = CreateFromMetadata(response.EntityMetadata, connection, true); } cache[cacheKey] = entity; } return(entity); }
public EntityMetadata GetEntityMetadata(Dynamics365Connection connection) { ConnectionCache cache = new ConnectionCache(connection); string cacheKey = string.Format("GetEntityMetadata:{0}", LogicalName); EntityMetadata entityMetadata = (EntityMetadata)cache[cacheKey]; if (entityMetadata == default(EntityMetadata)) { RetrieveEntityRequest request = new RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = LogicalName, RetrieveAsIfPublished = true }; using (OrganizationServiceProxy proxy = (connection).OrganizationServiceProxy) { RetrieveEntityResponse response = (RetrieveEntityResponse)proxy.Execute(request); entityMetadata = response.EntityMetadata; } cache[cacheKey] = entityMetadata; } return(entityMetadata); }
public void SetCurrentConnection(UserDetails userDetails) { ConnectionCache connectionCache = GetConnectionCache(userDetails, "current"); CurrentConnection = connectionCache.Service; CurrentUserDetails = connectionCache.UserDetails; }
public void SetCurrentConnection(IConnectionStringHelper connectionStringHelper) { ConnectionCache connectionCache = GetConnectionCache(connectionStringHelper, "current"); CurrentConnection = connectionCache.Service; CurrentUserDetails = connectionCache.UserDetails; }
public GameHub(MatchCache matchCache, ConnectionCache connectionCache, HttpClient httpClient, Dictionary <string, UnfinishedMatchResult> timeReported) { _httpClient = httpClient; _timeReported = timeReported; _matchCache = matchCache; _connectionCache = connectionCache; }
public static List <Dynamics365Relationship> GetRelationships(Dynamics365Entity entity, Dynamics365Connection connection) { ConnectionCache cache = new ConnectionCache(connection); string cacheKey = string.Format("GetRelationships:{0}", entity.LogicalName); List <Dynamics365Relationship> relationships = (List <Dynamics365Relationship>)cache[cacheKey]; if (relationships == null) { relationships = new List <Dynamics365Relationship>(); RetrieveEntityRequest request = new RetrieveEntityRequest() { LogicalName = entity.LogicalName, EntityFilters = EntityFilters.Relationships, RetrieveAsIfPublished = false }; using (OrganizationServiceProxy proxy = connection.OrganizationServiceProxy) { RetrieveEntityResponse response = (RetrieveEntityResponse)proxy.Execute(request); foreach (ManyToManyRelationshipMetadata metadata in response.EntityMetadata.ManyToManyRelationships) { Dynamics365Relationship relationship = new Dynamics365Relationship() { SchemaName = metadata.SchemaName, EntityLogicalName = metadata.Entity1LogicalName == entity.LogicalName ? metadata.Entity1LogicalName : metadata.Entity2LogicalName, RelatedEntityLogicalName = metadata.Entity1LogicalName == entity.LogicalName ? metadata.Entity2LogicalName : metadata.Entity1LogicalName }; relationships.Add(relationship); } foreach (OneToManyRelationshipMetadata metadata in response.EntityMetadata.ManyToOneRelationships) { Dynamics365Relationship relationship = new Dynamics365Relationship() { SchemaName = metadata.SchemaName, EntityLogicalName = metadata.ReferencedEntity == entity.LogicalName ? metadata.ReferencedEntity : metadata.ReferencingEntity, RelatedEntityLogicalName = metadata.ReferencedEntity == entity.LogicalName ? metadata.ReferencingEntity : metadata.ReferencedEntity }; relationships.Add(relationship); } foreach (OneToManyRelationshipMetadata metadata in response.EntityMetadata.OneToManyRelationships) { Dynamics365Relationship relationship = new Dynamics365Relationship() { SchemaName = metadata.SchemaName, EntityLogicalName = metadata.ReferencedEntity == entity.LogicalName ? metadata.ReferencedEntity : metadata.ReferencingEntity, RelatedEntityLogicalName = metadata.ReferencedEntity == entity.LogicalName ? metadata.ReferencingEntity : metadata.ReferencedEntity }; relationships.Add(relationship); } } cache[cacheKey] = relationships; } return(relationships); }
/// <summary> /// Creates a Dynamics365Field instance from the field's AttributeMetadata. /// </summary> /// <param name="attributeMetadata">The AttributeMetadata.</param> /// <returns>A Dynamics365Field.</returns> public static Dynamics365Field CreateFromMetadata(AttributeMetadata attributeMetadata, Dynamics365Connection connection) { Dynamics365Field field = null; Dynamics365TypeConverter converter = new Dynamics365TypeConverter(attributeMetadata); if (converter.CanConvertTo(converter.Dynamics365Type) && attributeMetadata.DisplayName.LocalizedLabels.Count > 0) { field = new Dynamics365Field() { LogicalName = attributeMetadata.LogicalName, DisplayName = attributeMetadata.DisplayName.UserLocalizedLabel.Label, EntityLogicalName = attributeMetadata.EntityLogicalName, IsPrimaryId = (bool)attributeMetadata.IsPrimaryId, CanCreate = (bool)attributeMetadata.IsValidForCreate, CanUpdate = (bool)attributeMetadata.IsValidForUpdate, Targets = attributeMetadata is LookupAttributeMetadata ? ((LookupAttributeMetadata)attributeMetadata).Targets : default(string[]) }; // see https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/configure-activity-feeds if ((field.EntityLogicalName == "post" || field.EntityLogicalName == "postfollow") && attributeMetadata is LookupAttributeMetadata && field.Targets?.Length == 0) { using (OrganizationServiceProxy proxy = connection.OrganizationServiceProxy) { ConnectionCache cache = new ConnectionCache(connection); string cacheKey = string.Format("GetPostConfigurations"); string[] targets = (string[])cache[cacheKey]; if (targets == null) { const string ENTITY_NAME_LOGICAL_NAME = "msdyn_entityname"; FilterExpression filter = new FilterExpression(); filter.AddCondition("statecode", ConditionOperator.Equal, 0); filter.AddCondition("statuscode", ConditionOperator.Equal, 1); QueryExpression query = new QueryExpression() { EntityName = "msdyn_postconfig", ColumnSet = new ColumnSet(ENTITY_NAME_LOGICAL_NAME), Criteria = filter, }; EntityCollection response = proxy.RetrieveMultiple(query); field.Targets = new string[response.Entities.Count]; for (int entityIndex = 0; entityIndex < response.Entities.Count; entityIndex++) { field.Targets[entityIndex] = response.Entities[entityIndex].Attributes[ENTITY_NAME_LOGICAL_NAME].ToString(); } cache[cacheKey] = field.Targets; } } } } return(field); }
public static void RunInTransaction(Action <DbConnection> func) { using (TransactionScope scope = GetRequiredTransactionScope()) { DbConnection conn = ConnectionCache.GetConnection(); func(conn); scope.Complete(); } }
public void ToConfigString_MatchesExpectedString() { // Note: This test might break if the serialization order changes ConnectionCache cache = new ConnectionCache(); cache.AddToCache(GetConnectionInfo(1, true)); cache.AddToCache(GetConnectionInfo(2, true)); string configString = cache.ToConfigString(); Assert.AreEqual(KnownConfigString, configString); }
public override void Install() { _services.Settings.SaveSetting(new ShopConnectorSettings()); _services.Localization.ImportPluginResourcesFromXml(PluginDescriptor); InsertProfile(ShopConnectorProductXmlExportProvider.SystemName, true); InsertProfile(ShopConnectorCategoryXmlExportProvider.SystemName, true); base.Install(); ConnectionCache.Remove(); }
public void Ctor_ConfigStringIsValidJson_CacheIsCorrect() { ConnectionCache cache = new ConnectionCache(KnownConfigString); List <Uri> connections = cache.GetCachedConnections().ToList(); Assert.AreEqual(2, connections.Count); ConnectionInfo info1 = GetConnectionInfo(1, true); ConnectionInfo info2 = GetConnectionInfo(2, true); CompareConnectionInfos(info1, cache.GetMostRecentConnection(info1.ServerUri)); CompareConnectionInfos(info2, cache.GetMostRecentConnection(info2.ServerUri)); }
private static object ExecuteCommmand(string spName, SqlCommandExecutor executor, params object[] parameterValues) { object res; using (TransactionScope scope = GetRequiredTransactionScope( )) { DbConnection conn = ConnectionCache.GetConnection( ); using (DbCommand cmd = CreateCommand(conn, spName, parameterValues)) { res = executor(cmd); } scope.Complete( ); } return(res); }
public static T RunInTransaction <T>(Func <DbConnection, T> func) { using (TransactionScope scope = GetRequiredTransactionScope()) { DbConnection conn = ConnectionCache.GetConnection(); var result = func(conn); scope.Complete(); return(result); } }
private static IScheduler _getScheduler(string ip) { if (!ConnectionCache.ContainsKey(ip)) { var properties = new NameValueCollection(); properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = $"{channelType}://{localIp}:{port}/{bindName}"; var schedulerFactory = new StdSchedulerFactory(properties); _scheduler = schedulerFactory.GetScheduler().Result; ConnectionCache[ip] = _scheduler; } return(ConnectionCache[ip]); }
public void LoadFromSerializedString(string serializedConfig) { try { var config = JsonConvert.DeserializeObject <ExtensionConfiguration>(serializedConfig); ZoomLevel = config.ZoomLevel; SavedConnection = config.SavedConnection; CachedConnections = config.CachedConnections; } catch { // don't use serialized data if it can't be parsed } }
public void TestCapacity() { ConnectionCache cache = new ConnectionCache(); for (int i = 0; i < ConnectionCache.CAPACITY; i++) { cache.AddToCache(GetConnectionInfo(i)); Assert.AreEqual(i + 1, cache.GetCachedConnections().Count()); } // add one more over capacity cache.AddToCache(GetConnectionInfo(ConnectionCache.CAPACITY)); Assert.AreEqual(ConnectionCache.CAPACITY, cache.GetCachedConnections().Count()); }
/// <summary> /// Gets entity fields relevant to the operation type. /// </summary> /// <param name="operationType">The operation type.</param> /// <returns>The fields.</returns> public static List <Dynamics365Field> GetFields(Dynamics365Entity entity, Dynamics365Connection connection) { if (entity == default(Dynamics365Entity)) { throw new ArgumentException("Entity cannot be null", nameof(entity)); } if (connection == default(Dynamics365Connection)) { throw new ArgumentException("Connection cannot be null", nameof(connection)); } ConnectionCache cache = new ConnectionCache(connection); string cacheKey = string.Format("GetFields:{0}", entity.LogicalName); List <Dynamics365Field> fields = (List <Dynamics365Field>)cache[cacheKey]; if (fields == default(List <Dynamics365Field>)) { fields = new List <Dynamics365Field>(); RetrieveEntityRequest request = new RetrieveEntityRequest() { LogicalName = entity.LogicalName, EntityFilters = EntityFilters.Attributes, RetrieveAsIfPublished = false }; using (OrganizationServiceProxy proxy = connection.OrganizationServiceProxy) { RetrieveEntityResponse response = (RetrieveEntityResponse)proxy.Execute(request); foreach (AttributeMetadata attributeMetadata in response.EntityMetadata.Attributes) { if ((bool)attributeMetadata.IsValidForRead) { Dynamics365Field field = CreateFromMetadata(attributeMetadata, connection); if (field != null) { fields.Add(field); } } } } fields.Sort((field1, field2) => field1.DisplayName.CompareTo(field2.DisplayName)); cache[string.Format(cacheKey, entity.LogicalName)] = fields; } return(fields); }
public static List <Dynamics365Process> GetProcesses(Dynamics365Connection connection, string entityLogicalName) { ConnectionCache cache = new ConnectionCache(connection); string cacheKey = "GetProcesses"; List <Dynamics365Process> processes = (List <Dynamics365Process>)cache[cacheKey]; if (processes == default(List <Dynamics365Process>)) { processes = new List <Dynamics365Process>(); processes.Sort((process1, process2) => process1.Name.CompareTo(process2.Name)); cache[cacheKey] = processes; } return(processes); }
/// <summary> /// Gets the columns returned by the T-SQL query. /// </summary> /// <returns>The columns.</returns> public override DataColumnCollection GetDataColumns() { // todo - could just be a local variable? ConnectionCache cache = new ConnectionCache(Parent); string cacheKey = string.Format("GetDataColumns:{0}", ID); DataColumnCollection columns = (DataColumnCollection)cache[cacheKey]; if (columns == default(DataColumnCollection)) { columns = GetDataTable(Query, 1).Columns; cache[cacheKey] = columns; } return(columns); }
private void ClearCacheToolStripMenuItem_Click(object sender, EventArgs e) { try { TreeNode connectionNode = ClientUtility.GetContextMenuTreeviewNode(dataSourceTreeView, sender); IConnection connection = ApplicationState.Default.ActiveProject.Connections[connectionNode.Index]; ConnectionCache cache = new ConnectionCache(connection); cache.Clear(); ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Information, string.Format(Properties.Resources.DataSourceFormCacheClearSucceeded, connection.Name))); } catch (Exception ex) { ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex)); } }
public ActionResult ConnectionSelect(GridCommand command, bool isForExport) { var model = new GridModel <ConnectionModel>(); ConnectionCache.ControllingData().UpdatePersistedConnections(); var connections = _connectorService.GetConnections(isForExport, command.Page - 1, command.PageSize); model.Data = connections; model.Total = connections.TotalCount; return(new JsonResult { Data = model }); }
public override DataColumnCollection GetDataColumns() { ConnectionCache cache = new ConnectionCache(Parent); string cacheKey = string.Format("GetDataColumns:{0}", ID.ToString()); DataColumnCollection columns = (DataColumnCollection)cache[cacheKey]; if (columns == default(DataColumnCollection)) { DataSet dataSet = GetExcelDataSet(0); columns = dataSet.Tables[SheetName].Columns; cache[cacheKey] = columns; } // todo - this fails when rendering in comparison data source return(columns); }
void IProbeSite.Probe(ProbeContext context) { var scope = context.CreateScope("host"); scope.Set(new { Type = "AmazonSQS", _settings.Region, _settings.AccessKey, Password = new string('*', _settings.SecretKey.Length) }); ConnectionCache.Probe(scope); ReceiveEndpoints.Probe(scope); }
void IProbeSite.Probe(ProbeContext context) { var scope = context.CreateScope("host"); scope.Set(new { Type = "RabbitMQ", _settings.Host, _settings.Port, _settings.Username, Password = new string('*', _settings.Password.Length) }); ConnectionCache.Probe(scope); ReceiveEndpoints.Probe(scope); }
public ActionResult Configure(ConfigurationModel model, FormCollection form) { if (!ModelState.IsValid) { return(Configure()); } var settings = Services.Settings.LoadSetting <ShopConnectorSettings>(); model.Copy(settings, false); Services.Settings.SaveSetting(settings); ConnectionCache.Remove(); NotifySuccess(T("Admin.Common.DataSuccessfullySaved")); return(Configure()); }
static NetTrafficCache() { Connections = new ConnectionCache(); }
private void Initialize(IDictionary properties, IClientChannelSinkProvider sinkProvider) { if (properties != null) { // read property values foreach (DictionaryEntry property in properties) { switch ((string)property.Key) { case "name": _channelName = Convert.ToString(property.Value); break; case "priority": _channelPriority = Convert.ToInt32(property.Value); break; case "cachedConnections": _cachedConnections = Convert.ToInt32(property.Value); break; } } } // create the chain of the sink providers that will process all messages _sinkProvider = ChannelHelper.ClientChannelCreateSinkProviderChain( sinkProvider, new PipeClientTransportSinkProvider()); // create connection cache _connectionCache = new ConnectionCache(_cachedConnections, CreateConnection); }