ToString() 공개 메소드

public ToString ( ) : string
리턴 string
예제 #1
0
        /// <summary>
        /// Delete triple with specified parameters.
        /// </summary>
        /// <param name="subjectName">Subject</param>
        /// <param name="predicateName">Predicate</param>
        /// <param name="objectName">Object</param>
        /// <returns>Returns 'True' if operation completed succeful, 'False' otherwise.</returns>
        public bool DeleteTriplet(TripleName subjectName, TripleName predicateName, TripleName objectName)
        {
            subjectName   = EnsurePrefix(subjectName);
            predicateName = EnsurePrefix(predicateName);
            objectName    = EnsurePrefix(objectName);

            var shortSubjectStr   = subjectName.ToString();
            var shortPredicateStr = predicateName.ToString();
            var shortObjectStr    = objectName.ToString();

            var tr = Triples.Where(t => t.Subject == shortSubjectStr && t.Predicate == shortPredicateStr).Include(o => o.Objects).FirstOrDefault();

            if (tr != null)
            {
                var obj = tr.Objects.FirstOrDefault(o => o.Object == shortObjectStr);
                if (obj != null)
                {
                    TripleObjects.Remove(TripleObjects.Find(obj.TripleObject_Id));

                    if (!tr.Objects.Any())
                    {
                        Triples.Remove(tr);
                    }

                    SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Delete triple with specified parameters.
        /// </summary>
        /// <param name="subjectName">Subject</param>
        /// <param name="predicateName">Predicate</param>
        /// <param name="objectName">Object</param>
        /// <returns>Returns 'True' if operation completed succeful, 'False' otherwise.</returns>
        public bool DeleteTriplet(TripleName subjectName, TripleName predicateName, TripleName objectName)
        {
            subjectName = EnsurePrefix(subjectName);
            predicateName = EnsurePrefix(predicateName);
            objectName = EnsurePrefix(objectName);

            var shortSubjectStr = subjectName.ToString();
            var shortPredicateStr = predicateName.ToString();
            var shortObjectStr = objectName.ToString();

            var tr = Triples.Where(t => t.Subject == shortSubjectStr && t.Predicate == shortPredicateStr).Include(o => o.Objects).FirstOrDefault();
            if (tr != null)
            {
                var obj = tr.Objects.FirstOrDefault(o => o.Object == shortObjectStr);
                if (obj != null)
                {
                    TripleObjects.Remove(TripleObjects.Find(obj.TripleObject_Id));

                    if (!tr.Objects.Any())
                        Triples.Remove(tr);

                    SaveChanges();
                    return true;
                }
            }
            return false;
        }
예제 #3
0
        /// <summary>
        /// Add triple with specified parameters.
        /// </summary>
        /// <param name="subjectStr">Subject</param>
        /// <param name="predicateStr">Predicate</param>
        /// <param name="objectStr">Object</param>
        /// <returns>Returns 'True' if operation completed succeful, 'False' otherwise.</returns>
        /// <example>PutTriplet( “czusr:76087518-4f8e-4d3a-9bfb-2fd2332376eb”, “czpred:favorite”, "cztimeline:3a87bb5c-85f7-4305-8b2f-f2002580cd25")</example>
        public bool PutTriplet(TripleName subjectName, TripleName predicateName, TripleName objectName)
        {
            subjectName   = EnsurePrefix(subjectName);
            predicateName = EnsurePrefix(predicateName);
            objectName    = EnsurePrefix(objectName);
            var shortSubjectStr   = subjectName.ToString();
            var shortPredicateStr = predicateName.ToString();
            var shortObjectStr    = objectName.ToString();

            var tr = Triples.Where(t => t.Subject == shortSubjectStr && t.Predicate == shortPredicateStr).Include(o => o.Objects).FirstOrDefault();

            if (tr != null)
            {
                if (tr.Objects.FirstOrDefault(x => x.Object == shortObjectStr) == null)
                {
                    tr.Objects.Add(
                        new TripleObject
                    {
                        Object          = shortObjectStr,
                        TripleObject_Id = Guid.NewGuid()
                    }
                        );
                }
                else
                {
                    return(true);
                }
                SaveChanges();
                return(true);
            }
            var triple = new Triple
            {
                Subject   = shortSubjectStr,
                Predicate = shortPredicateStr,
                Id        = Guid.NewGuid(),
                Objects   = new Collection <TripleObject>
                {
                    new TripleObject
                    {
                        Object          = shortObjectStr,
                        TripleObject_Id = Guid.NewGuid()
                    }
                }
            };

            Triples.Add(triple);
            SaveChanges();
            return(true);
        }
예제 #4
0
 /// <summary>Gets owner of the triplet</summary>
 /// <param name="name">Name of the triplet. Triplets referring to timelines, exhibits, artifacts and bNodes are supported.
 /// In all other cases method returns null.</param>
 /// <param name="bNodes">List of previously examined bNodes to avoid endless recursion</param>
 /// <returns>String representation of owning user ID</returns>
 public string GetSubjectOwner(TripleName name, List<string> bNodes = null)
 {
     name = EnsurePrefix(name);
     switch (name.Prefix)
     {
         case TripleName.UserPrefix:
             return name.Name;
         case TripleName.TimelinePrefix:
             var timelineId = Guid.Parse(name.Name);
             var timeline = Timelines.Where(t => t.Id == timelineId).FirstOrDefault();
             if (timeline == null)
                 return null;
             Entry(timeline).Reference(t => t.Collection).Load();
             return GetCollectionOwner(timeline.Collection);
         case TripleName.ExhibitPrefix:
             var exhibitId = Guid.Parse(name.Name);
             var exhibit = Exhibits.Where(e => e.Id == exhibitId).FirstOrDefault();
             if (exhibit == null)
                 return null;
             Entry(exhibit).Reference(e => e.Collection).Load();
             return GetCollectionOwner(exhibit.Collection);
         case TripleName.ArtifactPrefix:
             var artifactId = Guid.Parse(name.Name);
             var artifact = ContentItems.Where(c => c.Id == artifactId).FirstOrDefault();
             if (artifact == null)
                 return null;
             Entry(artifact).Reference(a => a.Collection).Load();
             return GetCollectionOwner(artifact.Collection);
         case TripleName.TourPrefix:
             var tourId = Guid.Parse(name.Name);
             var tour = Tours.FirstOrDefault(t => t.Id == tourId);
             if (tour == null)
                 return null;
             Entry(tour).Reference(t => t.Collection).Load();
             return GetCollectionOwner(tour.Collection);
         case "_":
             var subject = name.ToString();
             // Guard against infinite loop
             if (bNodes != null && bNodes.Contains(subject))
                 return null;
             // Find subject of any triple that uses passed subject as object
             var linkedSubject = Triples.
                 Include(t => t.Objects).
                 Where(t => t.Objects.Any(o => o.Object == subject)).
                 Select(t => t.Subject).FirstOrDefault();
             if (String.IsNullOrEmpty(linkedSubject))
                 return null;
             // Get owner of linked subject
             if (bNodes == null)
                 bNodes = new List<string>(new string[] { subject });
             else
                 bNodes.Add(subject);
             return GetSubjectOwner(TripleName.Parse(linkedSubject), bNodes);
         default:
             return null;
     }
 }
예제 #5
0
        /// <summary>Gets owner of the triplet</summary>
        /// <param name="name">Name of the triplet. Triplets referring to timelines, exhibits, artifacts and bNodes are supported.
        /// In all other cases method returns null.</param>
        /// <param name="bNodes">List of previously examined bNodes to avoid endless recursion</param>
        /// <returns>String representation of owning user ID</returns>
        public string GetSubjectOwner(TripleName name, List <string> bNodes = null)
        {
            name = EnsurePrefix(name);
            switch (name.Prefix)
            {
            case TripleName.UserPrefix:
                return(name.Name);

            case TripleName.TimelinePrefix:
                var timelineId = Guid.Parse(name.Name);
                var timeline   = Timelines.Where(t => t.Id == timelineId).FirstOrDefault();
                if (timeline == null)
                {
                    return(null);
                }
                Entry(timeline).Reference(t => t.Collection).Load();
                return(GetCollectionOwner(timeline.Collection));

            case TripleName.ExhibitPrefix:
                var exhibitId = Guid.Parse(name.Name);
                var exhibit   = Exhibits.Where(e => e.Id == exhibitId).FirstOrDefault();
                if (exhibit == null)
                {
                    return(null);
                }
                Entry(exhibit).Reference(e => e.Collection).Load();
                return(GetCollectionOwner(exhibit.Collection));

            case TripleName.ArtifactPrefix:
                var artifactId = Guid.Parse(name.Name);
                var artifact   = ContentItems.Where(c => c.Id == artifactId).FirstOrDefault();
                if (artifact == null)
                {
                    return(null);
                }
                Entry(artifact).Reference(a => a.Collection).Load();
                return(GetCollectionOwner(artifact.Collection));

            case TripleName.TourPrefix:
                var tourId = Guid.Parse(name.Name);
                var tour   = Tours.FirstOrDefault(t => t.Id == tourId);
                if (tour == null)
                {
                    return(null);
                }
                Entry(tour).Reference(t => t.Collection).Load();
                return(GetCollectionOwner(tour.Collection));

            case "_":
                var subject = name.ToString();
                // Guard against infinite loop
                if (bNodes != null && bNodes.Contains(subject))
                {
                    return(null);
                }
                // Find subject of any triple that uses passed subject as object
                var linkedSubject = Triples.
                                    Include(t => t.Objects).
                                    Where(t => t.Objects.Any(o => o.Object == subject)).
                                    Select(t => t.Subject).FirstOrDefault();
                if (String.IsNullOrEmpty(linkedSubject))
                {
                    return(null);
                }
                // Get owner of linked subject
                if (bNodes == null)
                {
                    bNodes = new List <string>(new string[] { subject });
                }
                else
                {
                    bNodes.Add(subject);
                }
                return(GetSubjectOwner(TripleName.Parse(linkedSubject), bNodes));

            default:
                return(null);
            }
        }
예제 #6
0
        /// <summary>
        /// Add triple with specified parameters.
        /// </summary>
        /// <param name="subjectStr">Subject</param>
        /// <param name="predicateStr">Predicate</param>
        /// <param name="objectStr">Object</param>
        /// <returns>Returns 'True' if operation completed succeful, 'False' otherwise.</returns>
        /// <example>PutTriplet( “czusr:76087518-4f8e-4d3a-9bfb-2fd2332376eb”, “czpred:favorite”, "cztimeline:3a87bb5c-85f7-4305-8b2f-f2002580cd25")</example>
        public bool PutTriplet(TripleName subjectName, TripleName predicateName, TripleName objectName)
        {
            subjectName = EnsurePrefix(subjectName);
            predicateName = EnsurePrefix(predicateName);
            objectName = EnsurePrefix(objectName);
            var shortSubjectStr = subjectName.ToString();
            var shortPredicateStr = predicateName.ToString();
            var shortObjectStr = objectName.ToString();

            var tr = Triples.Where(t => t.Subject == shortSubjectStr && t.Predicate == shortPredicateStr).Include(o => o.Objects).FirstOrDefault();
            if (tr != null)
            {
                if (tr.Objects.FirstOrDefault(x => x.Object == shortObjectStr) == null)
                {
                    tr.Objects.Add(
                        new TripleObject
                            {
                                Object = shortObjectStr,
                                TripleObject_Id = Guid.NewGuid()
                            }
                    );
                }
                else
                {
                    return true;
                }
                SaveChanges();
                return true;
            }
            var triple = new Triple
                {
                    Subject = shortSubjectStr,
                    Predicate = shortPredicateStr,
                    Id = Guid.NewGuid(),
                    Objects = new Collection<TripleObject>
                        {
                            new TripleObject
                                {
                                    Object = shortObjectStr,
                                    TripleObject_Id = Guid.NewGuid()
                                }
                        }
                };
            Triples.Add(triple);
            SaveChanges();
            return true;
        }