Storage implementation for ChronoZoom based on Entity Framework.
Inheritance: DbContext
Example #1
0
 public void DeleteTriplet(SingleTriple triple)
 {
     #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(GetSubjectOwner(storage, triple.Subject) == user.Id.ToString())
             {
     #else
             using(var storage = new Storage())
     #endif
                 try
                 {
                     SetStatusCode(storage.DeleteTriplet(triple.Subject, triple.Predicate, triple.Object) ? HttpStatusCode.OK : HttpStatusCode.NotModified, "");
                 }
                 catch (ArgumentException exc)
                 {
                     SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
                 }
     #if RELEASE
             }
             else
             {
                 SetStatusCode(HttpStatusCode.Unauthorized, "Only subject owners can delete triple");
             }
         }
     });
     #endif
 }
Example #2
0
        public ExportImport()
        {
            // persist storage
            _storage = new Storage();

            // persist user object
            _user = GetUser();
        }
Example #3
0
        public Dictionary<string, string> GetPrefixes()
        {
            using(var storage = new Storage())
            {
                var d = new Dictionary<string,string>();

                foreach (var p in storage.TriplePrefixes)
                    d.Add(p.Prefix, p.Namespace);

                foreach (var p in TripleName.PrefixesAndNamespaces)
                    d.Add(p.Key, p.Value);
                return d;
            }
        }
Example #4
0
 public IEnumerable<Entities.Triple> GetTriplets(string subject, string predicate, string @object)
 {
     try
     {
         using (var storage = new Storage())
             return storage.GetTriplet(
                 HttpUtility.UrlDecode(subject),
                 predicate == null ? null : HttpUtility.UrlDecode(predicate),
                 @object == null ? null : HttpUtility.UrlDecode(@object));
     }
     catch (ArgumentException exc)
     {
         SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
         return null;
     }
 }
        /// <summary></summary>
        /// <param name="descendant"></param>
        /// <returns>A list of all ancestor timelines which also includes the current timeline.</returns>
        public static List<Guid> Ancestors(this Timeline descendant)
        {
            List<Guid> rv = new List<Guid>();

            Timeline timeline = descendant;
            Guid[] searchTerm;

            using (Storage storage = new Storage())
            {
                while (timeline != null)
                {
                    rv.Add(timeline.Id);
                    searchTerm = new Guid[] { timeline.Id };
                    timeline = storage.Timelines.Where(t => t.ChildTimelines.Any(ct => searchTerm.Contains(ct.Id))).FirstOrDefault(); // get parent if exists
                }
            }

            return rv;
        }
Example #6
0
        public ActionResult Success(FormCollection forms)
        {
            if (Request.IsAuthenticated)
            {
                var user = (Microsoft.IdentityModel.Claims.IClaimsIdentity)HttpContext.User.Identity;

                if (user != null)
                {
                    string nameIdentifier = "";
                    string identityProvider = "";

                    foreach (var item in user.Claims)
                    {
                        if (item.ClaimType.EndsWith("nameidentifier"))
                        {
                            nameIdentifier = item.Value;
                        }
                        else if (item.ClaimType.EndsWith("identityprovider"))
                        {
                            identityProvider = item.Value;
                        }
                    }

                    using (Storage storage = new Storage())
                    {
                        Entities.User storedUser = storage.Users.FirstOrDefault(candidate => candidate.IdentityProvider == identityProvider && candidate.NameIdentifier == nameIdentifier);
                        if (storedUser != null)
                            return Redirect("/" + storedUser.DisplayName);
                    }
                }
            }

            return Redirect("/");
        }
Example #7
0
        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);
            }
        }
Example #8
0
 private string GetSubjectOwner(Storage storage, string subject)
 {
     var name = storage.EnsurePrefix(TripleName.Parse(subject));
     switch(name.Prefix) {
         case TripleName.UserPrefix:
             return name.Name;
         case TripleName.TimelinePrefix:
             var collection = RetrieveCollection(storage, storage.GetCollectionFromTimeline(Guid.Parse(name.Name)));
             return collection != null && collection.User != null ? collection.User.Id.ToString() : null;
         case TripleName.ExhibitPrefix:
             collection = RetrieveCollection(storage, storage.GetCollectionFromExhibitGuid(Guid.Parse(name.Name)));
             return collection != null && collection.User != null ? collection.User.Id.ToString() : null;
         case TripleName.ArtifactPrefix:
             collection = RetrieveCollection(storage, storage.GetCollectionFromContentItemGuid(Guid.Parse(name.Name)));
             return collection != null && collection.User != null ? collection.User.Id.ToString() : null;
         default:
             return null;
     }
 }