Exemple #1
0
 public MsSqlServerConnectedSystemManager(
     ConnectedSystem connectedSystem,
     State state,
     TimeSpan maxFileAge,
     ILoggerFactory loggerFactory)
     : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <MsSqlServerConnectedSystemManager>())
 {
     _connectedSystem = connectedSystem;
 }
Exemple #2
0
 public JiraConnectedSystemManager(
     ConnectedSystem connectedSystem,
     State state,
     TimeSpan maxFileAge,
     ILoggerFactory loggerFactory)
     : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <ServiceNowConnectedSystemManager>())
 {
     _jiraClient = Jira.CreateRestClient(
         connectedSystem.Credentials.Account,
         connectedSystem.Credentials.PublicText,
         connectedSystem.Credentials.PrivateText);
 }
Exemple #3
0
 public LogicMonitorConnectedSystemManager(
     ConnectedSystem connectedSystem,
     State state,
     TimeSpan maxFileAge,
     ILoggerFactory loggerFactory)
     : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <LogicMonitorConnectedSystemManager>())
 {
     _logicMonitorClient = new PortalClient(
         connectedSystem.Credentials.Account,
         connectedSystem.Credentials.PublicText,
         connectedSystem.Credentials.PrivateText,
         loggerFactory.CreateLogger <PortalClient>());
     _cache = new QueryCache <JObject>(TimeSpan.FromMinutes(1));
 }
Exemple #4
0
        public CertifyConnectedSystemManager(
            ConnectedSystem connectedSystem,
            State state,
            TimeSpan maxFileAge,
            ILoggerFactory loggerFactory)
            : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <CertifyConnectedSystemManager>())
        {
            _certifyClient = new CertifyClient(connectedSystem.Credentials.PublicText, connectedSystem.Credentials.PrivateText, new CertifyClientOptions {
                Timeout = TimeSpan.FromMinutes(2)
            });

            // FixerSharp for exchange rate conversion, if configured
            if (connectedSystem.Configuration.ContainsKey(FixerApiKey))
            {
                var fixerApiKey = connectedSystem.Configuration[FixerApiKey];
                Fixer.SetApiKey(fixerApiKey);
            }
        }
        public AutoTaskConnectedSystemManager(
            ConnectedSystem connectedSystem,
            State state,
            TimeSpan maxFileAge,
            ILoggerFactory loggerFactory)
            : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <AutoTaskConnectedSystemManager>())
        {
            // Ensure we have what we need
            if (string.IsNullOrWhiteSpace(connectedSystem?.Credentials?.PublicText))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.PublicText)} must be set");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem?.Credentials?.PrivateText))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.PrivateText)} must be set");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem?.Credentials?.ClientSecret))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.ClientSecret)} must be set to the Integration Code");
            }

            // If the user provides an account, it's to set the server Id
            // This avoids the buggy AutoTask getZoneInfo call and improves performance
            ClientOptions?clientOptions = string.IsNullOrWhiteSpace(connectedSystem.Credentials.Account)
                                ? null
                                : new ClientOptions
            {
                ServerId = int.TryParse(connectedSystem.Credentials.Account, out var serverId)
                                                ? serverId
                                                : throw new ConfigurationException("Incorrectly-configured AutoTask Account Server Id")
            };

            _autoTaskClient = new Client(
                connectedSystem.Credentials.PublicText,
                connectedSystem.Credentials.PrivateText,
                connectedSystem.Credentials.ClientSecret,
                loggerFactory.CreateLogger <Client>(),
                clientOptions
                );
            _cache = new QueryCache <JObject>(TimeSpan.FromMinutes(1));
        }
Exemple #6
0
        internal TestConnectedSystemManager(
            ConnectedSystem connectedSystem,
            State state,
            TimeSpan maxFileAge,
            ILogger <TestConnectedSystemManager> logger)
            : base(connectedSystem, state, maxFileAge, logger)
        {
            _logger = logger;
            // Initialise the list
            _logger.LogInformation("Populating DataSet1 with initial data");
            var items = new List <JObject>
            {
                new JObject(new JProperty("ConnectedSystemKey", "Key1"), new JProperty("FirstName", "Bob1"), new JProperty("LastName", "Smith1"), new JProperty("Description", "Description1")),
                new JObject(new JProperty("ConnectedSystemKey", "Key2"), new JProperty("FirstName", "Bob2"), new JProperty("LastName", "Smith2"), new JProperty("Description", "Description1")),
                new JObject(new JProperty("ConnectedSystemKey", "Key3"), new JProperty("FirstName", "Bob3"), new JProperty("LastName", "Smith3"), new JProperty("Description", "Description1")),
                new JObject(new JProperty("ConnectedSystemKey", "Key4"), new JProperty("FirstName", "Bob4"), new JProperty("LastName", "Smith4"), new JProperty("Description", "Description1")),
                new JObject(new JProperty("ConnectedSystemKey", "Key5"), new JProperty("FirstName", "Bob5"), new JProperty("LastName", "Smith5"), new JProperty("Description", "Description1"))
            };

            Items.Add("DataSet1", items);
        }
Exemple #7
0
        private void AssertCorrectPermissions(
            Permissions connectedSystemPermissions,
            Permissions connectedSystemDataSetPermissions,
            Dictionary <SyncActionType, DirectionPermissions> expectedActionTypePermissions)
        {
            var connectedSystem = new ConnectedSystem(SystemType.Test, "Test")
            {
                Permissions = connectedSystemPermissions
            };
            var connectedSystemDataSet = new ConnectedSystemDataSet {
                Permissions = connectedSystemDataSetPermissions
            };

            foreach (var item in expectedActionTypePermissions)
            {
                ConnectedSystemManagerBase
                .DeterminePermission(connectedSystem, connectedSystemDataSet, item.Key)
                .Should()
                .BeEquivalentTo(item.Value);
            }
        }
Exemple #8
0
        public SalesforceConnectedSystemManager(
            ConnectedSystem connectedSystem,
            State state,
            TimeSpan maxFileAge,
            ILoggerFactory loggerFactory)
            : base(connectedSystem, state, maxFileAge, loggerFactory.CreateLogger <SalesforceConnectedSystemManager>())
        {
            // Ensure we have what we need
            if (connectedSystem !.Credentials.Account?.Length == 0)
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.Account)} must be set to a url when specified, otherwise omit this configuration item.");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem !.Credentials.ClientId))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.ClientId)} must be set");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem !.Credentials.ClientSecret))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.ClientSecret)} must be set");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem !.Credentials.PublicText))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.PublicText)} must be set");
            }
            if (string.IsNullOrWhiteSpace(connectedSystem !.Credentials.PrivateText))
            {
                throw new ConfigurationException($"ConnectedSystem '{connectedSystem!.Name}'s {nameof(connectedSystem.Credentials)} {nameof(connectedSystem.Credentials.PrivateText)} must be set");
            }

            _salesforceClient = new SalesforceClient(
                connectedSystem.Credentials.Account,
                connectedSystem.Credentials.ClientId,
                connectedSystem.Credentials.ClientSecret,
                connectedSystem.Credentials.PublicText,
                connectedSystem.Credentials.PrivateText);
        }
 public UIComponent(Script state, ConnectedSystem system)
 {
     this.state  = state;
     this.system = system;
 }
Exemple #10
0
        public async System.Threading.Tasks.Task TestAsync()
        {
            var connectedSystem = new ConnectedSystem(SystemType.Test, "Test")
            {
                Permissions = new Permissions
                {
                    CanWrite     = true,
                    CanCreateIn  = true,
                    CanUpdateIn  = true,
                    CanDeleteIn  = true,
                    CanCreateOut = true,
                    CanUpdateOut = true,
                    CanDeleteOut = true
                }
            };
            var state = new State();

            state.ItemLists["TestDataSet"] = new StateItemList
            {
                new StateItem(
                    new JObject(
                        new JProperty("Id", "ExistingKey1"),
                        new JProperty("FullName", "Sarah Jane"), new
                        JProperty("Description", "Is lovely")
                        )
                    ),
                new StateItem(
                    new JObject(
                        new JProperty("Id", "Key1"),
                        new JProperty("FullName", "Bob1 Smith1"),
                        new JProperty("Description", "OldDescription1")
                        )
                    )
            };

            var dataSet = new ConnectedSystemDataSet
            {
                CreateDeleteDirection = CreateDeleteDirection.In,
                Name             = "DataSet1",
                StateDataSetName = "TestDataSet",
                Mappings         = new List <Mapping>
                {
                    new Mapping
                    {
                        Direction        = MappingType.Join,
                        SystemExpression = "ConnectedSystemKey",
                        StateExpression  = "Id"
                    },
                    new Mapping
                    {
                        Direction        = MappingType.In,
                        SystemExpression = "ConnectedSystemKey",
                        StateExpression  = "Id"
                    },
                    new Mapping
                    {
                        Direction = MappingType.In,
                        //SystemExpression = "FirstName",
                        SystemExpression = "'' + FirstName + ' ' + LastName",
                        StateExpression  = "FullName"
                    },
                    new Mapping
                    {
                        Direction        = MappingType.In,
                        SystemExpression = "Description",
                        StateExpression  = "Description"
                    }
                },
                Permissions = new Permissions {
                    CanWrite = true, CanCreateIn = true, CanUpdateIn = true, CanDeleteIn = true, CanCreateOut = true, CanUpdateOut = true, CanDeleteOut = true
                }
            };

            using var testConnectedSystemManger = new TestConnectedSystemManager(
                      connectedSystem,
                      state,
                      TimeSpan.FromHours(1),
                      _outputHelper.BuildLoggerFor <TestConnectedSystemManager>()
                      );
            var actionList = await testConnectedSystemManger
                             .TestProcessConnectedSystemItemsAsync(dataSet, testConnectedSystemManger.Items[dataSet.Name])
                             .ConfigureAwait(false);

            actionList.Should().NotBeNullOrEmpty();
            actionList.Should().HaveCount(6);
            var creates = actionList.Where(a => a.Type == SyncActionType.CreateState);

            creates.Should().HaveCount(4);
            creates.All(a => a.Permission.In == DataSetPermission.Allowed).Should().BeTrue();
            creates.All(a => a.Permission.Out == DataSetPermission.InvalidOperation).Should().BeTrue();

            var updates = actionList.Where(a => a.Type == SyncActionType.UpdateBoth);

            updates.Should().HaveCount(1);
            updates.All(a => a.Permission.In == DataSetPermission.Allowed).Should().BeTrue();
            updates.All(a => a.Permission.Out == DataSetPermission.Allowed).Should().BeTrue();

            var deletes = actionList.Where(a => a.Type == SyncActionType.DeleteState);

            deletes.Should().HaveCount(1);
            deletes.All(a => a.Permission.In == DataSetPermission.Allowed).Should().BeTrue();
            deletes.All(a => a.Permission.Out == DataSetPermission.InvalidOperation).Should().BeTrue();

            // Process a second time - should be in stable state
            actionList = await testConnectedSystemManger
                         .TestProcessConnectedSystemItemsAsync(dataSet, testConnectedSystemManger.Items[dataSet.Name])
                         .ConfigureAwait(false);

            actionList.Should().NotBeNullOrEmpty();
            actionList.Should().HaveCount(5);
            actionList.All(a => a.Type == SyncActionType.AlreadyInSync).Should().BeTrue();
            actionList.All(a => a.Permission.In == DataSetPermission.Allowed).Should().BeTrue();
            actionList.All(a => a.Permission.Out == DataSetPermission.Allowed).Should().BeTrue();
        }