Esempio n. 1
0
        public ThingProfile()
        {
            CreateMap <Entities.IThing, Model.IThing>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => ThingIdHelper.Create(src.Fqdn, src.US, true)))
            ;
            CreateMap <Model.IThing, Entities.IThing>()
            .ForMember(dest => dest.Id, opt => opt.Ignore())
            .ForMember(dest => dest.Fqdn, opt => opt.MapFrom(src => src.Id != null ? ThingIdHelper.GetFQDN(src.Id) : null))
            .ForMember(dest => dest.US, opt => opt.MapFrom(src => src.Id != null ? ThingIdHelper.GetUniqueString(src.Id) : null))
            ;

            CreateMap <Model.BaseThing, Entities.BaseThing>()
            .IncludeBase <Model.IThing, Entities.IThing>()
            .ForMember(dest => dest.Id, opt => opt.Ignore())
            ;

            CreateMap <Entities.BaseThing, Model.BaseThing>()
            .IncludeBase <Entities.IThing, Model.IThing>()
            ;

            CreateMap <Entities.RegularThing, Model.RegularThing>()
            .IncludeBase <Entities.IThing, Model.IThing>()
            ;

            CreateMap <Model.RegularThing, Entities.RegularThing>()
            .IncludeBase <Model.IThing, Entities.IThing>()
            .ForMember(dest => dest.Id, opt => opt.Ignore())
            ;
        }
Esempio n. 2
0
 private TThingEntity Find(TThingModel value)
 {
     if (value == null || value.Id == null)
     {
         throw new ArgumentNullException("value", "Thing or Thing Id is null.");
     }
     return(Find(ThingIdHelper.GetFQDN(value.Id), ThingIdHelper.GetUniqueString(value.Id)));
 }
Esempio n. 3
0
        public IActionResult GetRelations([FromBody] GetRelationsRequest value)
        {
            var session = this.GetSession(value.Session, true);

            T2D.Entities.BaseThing thing =
                this.Find(value.ThingId)
                .Include(t => t.ThingAttributes)
                .Include(t => t.ThingRelations)
                .FirstOrDefault()
            ;

            if (thing == null)
            {
                return(BadRequest($"Thing '{value.ThingId}' do not exists."));
            }

            var role = this.RoleMapper.EnumToEntity(value.Role);

            //TODO: check that session has right to
            if (!AttributeSecurity.QueryRelationsRight(thing, session, role))
            {
                return(BadRequest($"Not enough priviledges to query relations for thing {value.ThingId}."));
            }


            var ret = new GetRelationsResponse();

            ret.RelationThings = new List <GetRelationsResponse.RelationsThings>();

            foreach (var group in thing.ThingRelations.GroupBy(tr => tr.RelationId))
            {
                var rt = new GetRelationsResponse.RelationsThings
                {
                    Relation = RelationMapper.FromEntityId(group.Key).ToString(),
                    Things   = new List <GetRelationsResponse.RelationsThings.IdTitle>(),
                };
                foreach (var th in group)
                {
                    var thingIdTitle = new GetRelationsResponse.RelationsThings.IdTitle {
                        ThingId = ThingIdHelper.Create(th.Thing2_Fqdn, th.Thing2_US)
                    };
                    var thing2 = this.Find(th.Thing2_Fqdn, th.Thing2_US);
                    if (thing2 != null)
                    {
                        thingIdTitle.Title = thing2.Title;
                    }
                    rt.Things.Add(thingIdTitle);
                }
                ret.RelationThings.Add(rt);
            }
            return(Ok(ret));
        }
Esempio n. 4
0
        public IActionResult Post([FromBody] AuthenticationRequest value)
        {
            // mock, AuthenticationThing is created if not exists
            if (string.IsNullOrWhiteSpace(value.ThingId))
            {
                value.ThingId = "inventory1.sovelto.fi/Teemu Testaaja";
            }
            var T0 = dbc.AuthenticationThings.SingleOrDefault(t => t.Fqdn == ThingIdHelper.GetFQDN(value.ThingId) && t.US == ThingIdHelper.GetUniqueString(value.ThingId));

            if (T0 == null)
            {
                T0 = new T2D.Entities.AuthenticationThing
                {
                    Fqdn  = ThingIdHelper.GetFQDN(value.ThingId),
                    US    = ThingIdHelper.GetUniqueString(value.ThingId),
                    Title = $"User {ThingIdHelper.GetUniqueString(value.ThingId)}",
                };
                dbc.AuthenticationThings.Add(T0);
                dbc.SaveChanges();
            }

            //Create SessionEntity
            var session = new Session
            {
                EntryPoint_ThingId = T0.Id,
                StartTime          = DateTime.UtcNow,
            };

            dbc.Sessions.Add(session);
            dbc.SaveChanges();

            var ret = new AuthenticationResponse
            {
                Session = session.Id.ToString(),
            };

            return(Ok(ret));
        }
Esempio n. 5
0
 private IQueryable <T2D.Entities.BaseThing> Find(string thingId)
 {
     return(dbc.Things.Where(t => t.Fqdn == ThingIdHelper.GetFQDN(thingId) && t.US == ThingIdHelper.GetUniqueString(thingId)));
 }