Beispiel #1
0
 private static void AssertEntity(EndpointEntity entity, string name, string address, string group, string monitor)
 {
     Assert.Equal(name, entity.Name);
     Assert.Equal(address, entity.Address);
     Assert.Equal(group, entity.Group);
     Assert.Equal(monitor, entity.MonitorType);
 }
        public async Task <EndpointLinkEntity> CreateLinkAsync(EndpointEntity sourceEndpoint,
                                                               EndpointEntity associatedEndpoint,
                                                               CancellationToken ct)
        {
            /* The assumption here is that we have already check that a link from sourceEndpoint to
             * associatedEndpoint doesn't exist so we can just go ahead and create a link. */
            var link = new EndpointLinkEntity
            {
                SourceEndpoint     = sourceEndpoint,
                AssociatedEndpoint = associatedEndpoint,
                Confirmed          = false
            };

            _context.Links.Add(link);

            var created = await _context.SaveChangesAsync(ct);

            if (created < 1)
            {
                return(null);
            }

            link = await _context.Links
                   .Where(r => (r.SourceEndpoint.EndpointId == sourceEndpoint.EndpointId && r.AssociatedEndpoint.EndpointId == associatedEndpoint.EndpointId))
                   .Include(r => r.SourceEndpoint).ThenInclude(r => r.Owner)
                   .Include(r => r.AssociatedEndpoint).ThenInclude(r => r.HubConnection)
                   .FirstOrDefaultAsync(ct);

            return(link);
        }
 private void When_client_requests_endpoint_details()
 {
     _details = _client.GetEndpointDetails(_identifier);
 }
Beispiel #4
0
        protected override void Seed(DataContext context)
        {
            // Records
            var record1 = new RecordEntity()
            {
                Id          = 1,
                VariableId  = 1,
                Value       = "566",
                ArchiveTime = DateTime.Now
            };

            var record2 = new RecordEntity()
            {
                Id          = 2,
                VariableId  = 2,
                Value       = "20",
                ArchiveTime = DateTime.Now
            };

            var record3 = new RecordEntity()
            {
                Id          = 3,
                VariableId  = 3,
                Value       = "1500",
                ArchiveTime = DateTime.Now
            };

            var record4 = new RecordEntity()
            {
                Id          = 4,
                VariableId  = 1,
                Value       = "576",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(30)
            };

            var record5 = new RecordEntity()
            {
                Id          = 5,
                VariableId  = 2,
                Value       = "26",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(30)
            };

            var record6 = new RecordEntity()
            {
                Id          = 6,
                VariableId  = 3,
                Value       = "1566",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(30)
            };

            var record7 = new RecordEntity()
            {
                Id          = 7,
                VariableId  = 1,
                Value       = "586",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(60)
            };

            var record8 = new RecordEntity()
            {
                Id          = 8,
                VariableId  = 2,
                Value       = "33",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(60)
            };

            var record9 = new RecordEntity()
            {
                Id          = 9,
                VariableId  = 3,
                Value       = "1570",
                ArchiveTime = DateTime.Now + TimeSpan.FromSeconds(60)
            };

            context.Records.AddOrUpdate(x => x.Id, record1, record2, record3, record4, record5, record6, record7, record8, record9);

            // Variables
            var var1 = new VariableEntity()
            {
                Id        = 1,
                ProjectId = new Guid("db93cbda-e293-41db-ad54-bee5a4c254a3"),
                Name      = "ns=2;s=Demo.Dynamic.Scalar.Int16",
                Archive   = ArchiveInterval.ThirtySecond,
                DataType  = BuiltInType.Int16,
            };

            var var2 = new VariableEntity()
            {
                Id        = 2,
                ProjectId = new Guid("db93cbda-e293-41db-ad54-bee5a4c254a3"),
                Name      = "ns=2;s=Demo.Dynamic.Scalar.SByte",
                Archive   = ArchiveInterval.ThirtySecond,
                DataType  = BuiltInType.SByte,
            };

            var var3 = new VariableEntity()
            {
                Id        = 3,
                ProjectId = new Guid("db93cbda-e293-41db-ad54-bee5a4c254a3"),
                Name      = "ns=2;s=Demo.Dynamic.Scalar.UInt64",
                Archive   = ArchiveInterval.ThirtySecond,
                DataType  = BuiltInType.UInt64,
            };

            context.Variables.AddOrUpdate(x => x.Id, var1, var2, var3);


            var endpoint = new EndpointEntity()
            {
                Id  = 1,
                Url = "opc.tcp://A05-226b:48010",
                MessageSecurityMode = MessageSecurityMode.None,
                SecurityPolicyUri   = SecurityPolicies.None,
                TransportProfileUri = Profiles.UaTcpTransport
            };

            context.Endpoints.AddOrUpdate(x => x.Id, endpoint);


            var project = new ProjectEntity()
            {
                Id          = new Guid("db93cbda-e293-41db-ad54-bee5a4c254a3"),
                Name        = "TestProject",
                EndpointId  = 1,
                UserId      = null,
                SessionName = "TestProjectSession"
            };

            context.Projects.AddOrUpdate(x => x.Id, project);

            context.SaveChanges();
        }
        public async Task <EndpointEntity> CreateEndpointAsync(string name,
                                                               EndpointClientEntity client,
                                                               EndpointOwnerEntity owner,
                                                               HubConnectionEntity hubConnection,
                                                               CancellationToken ct)
        {
            var endpoint = await _context.Endpoints.FirstOrDefaultAsync(
                r => (r.Owner.IdentityId == owner.IdentityId && r.Name == name),
                ct);

            /* Endpoint already exists so return null to indicate we failed to create new endpoint. */
            if (endpoint != null)
            {
                return(null);
            }

            var existingClient = await _context.Clients.FirstOrDefaultAsync(
                r => (r.ClientId == client.ClientId && r.ClientType == client.ClientType),
                ct);

            /* Ensure client exist */
            if (existingClient == null)
            {
                _context.Clients.Add(client);
            }

            var existingOwner = await _context.Owners.FirstOrDefaultAsync(
                r => (r.IdentityId == owner.IdentityId && r.OwnerName == owner.OwnerName),
                ct);

            /* Ensure owner exist */
            if (existingOwner == null)
            {
                _context.Owners.Add(owner);
            }

            if (existingClient == null || existingOwner == null)
            {
                var createdNavigationPropertiesResult = await _context.SaveChangesAsync(ct);

                if (createdNavigationPropertiesResult < 1)
                {
                    return(null);
                }

                if (existingClient == null)
                {
                    existingClient = await _context.Clients.FirstOrDefaultAsync(
                        r => (r.ClientId == client.ClientId && r.ClientType == client.ClientType),
                        ct);
                }

                if (existingOwner == null)
                {
                    existingOwner = await _context.Owners.FirstOrDefaultAsync(
                        r => (r.IdentityId == owner.IdentityId && r.OwnerName == owner.OwnerName),
                        ct);
                }
            }

            endpoint = new EndpointEntity
            {
                Name          = name,
                Description   = "No description.",
                Client        = existingClient,
                Owner         = existingOwner,
                HubConnection = hubConnection
            };

            _context.Endpoints.Add(endpoint);

            var created = await _context.SaveChangesAsync(ct);

            if (created < 1)
            {
                return(null);
            }

            /* Everything should be up to date now, so let's try again and return the endpoint. */
            endpoint = await _context.Endpoints
                       .Where(r => r.Name == name && r.Owner.IdentityId == existingOwner.IdentityId)
                       .Include(r => r.Owner)
                       .Include(r => r.Client)
                       .FirstOrDefaultAsync();

            return(endpoint);
        }