コード例 #1
0
ファイル: Triples.svc.cs プロジェクト: zmahdavi/ChronoZoom
        public void PutTriplet(SingleTriple triple)
        {
            try
            {
                var subjectName = TripleName.Parse(triple.Subject);
                var predicateName = TripleName.Parse(triple.Predicate);
                var objectName = TripleName.Parse(triple.Object);
#if RELEASE
                ApiOperation(delegate(User user, Storage storage)
                {
                    if (user == null)
                    {
                        SetStatusCode(HttpStatusCode.Unauthorized, "Anonymous users cannot modify triple");
                    }
                    else
                    {
                        objectName = storage.EnsurePrefix(objectName);
                        if (objectName.Prefix == "_")
                        {
                            var tripleOwner = storage.GetSubjectOwner(objectName);
                            if (tripleOwner != null && tripleOwner != user.Id.ToString())
                                SetStatusCode(HttpStatusCode.BadRequest, "Object bNode belongs to another user");
                        }

                        if (storage.GetSubjectOwner(subjectName) == user.Id.ToString())
                        {
#else
                            using(var storage = new Storage()) 
#endif
                            {

                                SetStatusCode(storage.PutTriplet(subjectName, predicateName, objectName) ? HttpStatusCode.OK : HttpStatusCode.NotModified, "");
                            }
#if RELEASE
                        }
                        else
                        {
                            SetStatusCode(HttpStatusCode.Unauthorized, "Only subject owners can modify triple");
                        }
                    }
                });
#endif
            }
            catch (ArgumentException exc)
            {
                SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
            }            
        }
コード例 #2
0
ファイル: Triples.svc.cs プロジェクト: zmahdavi/ChronoZoom
        public void DeleteTriplet(SingleTriple triple)
        {
            try
            {
                var subjectName = TripleName.Parse(triple.Subject);
                var predicateName = TripleName.Parse(triple.Predicate);
                var objectName = TripleName.Parse(triple.Object); 
#if RELEASE // Authenticate only in RELEASE mode 
                ApiOperation(delegate(User user, Storage storage)
                {
                    if (user == null)
                    {
                        SetStatusCode(HttpStatusCode.Unauthorized, "Anonymous users cannot delete triple");
                    } 
                    else 
                    {
                        if(storage.GetSubjectOwner(TripleName.Parse(triple.Subject)) == user.Id.ToString())
                        {
#else
                            using(var storage = new Storage()) 
#endif
                                SetStatusCode(storage.DeleteTriplet(subjectName, predicateName, objectName) ? HttpStatusCode.OK : HttpStatusCode.NotModified, "");
#if RELEASE
                        }
                        else
                        {
                            SetStatusCode(HttpStatusCode.Unauthorized, "Only subject owners can delete triple");
                        }
                    }
                });
#endif
            }
            catch (ArgumentException exc)
            {
                SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
            }
        }