Пример #1
0
        // Deletes every content item and reference from exhibit with given guid.
        public void DeleteExhibit(Guid id)
        {
            var exhibitsIDs = GetChildContentItemsIds(id); // list of ids of content items

            // delete content items
            while (exhibitsIDs.Count != 0)
            {
                var e = this.ContentItems.Find(exhibitsIDs.First());
                this.ContentItems.Remove(e);
                exhibitsIDs.RemoveAt(0);
            }

            Exhibit deleteExhibit = this.Exhibits.Find(id);

            this.Exhibits.Remove(deleteExhibit);
        }
Пример #2
0
        public string ImportExhibit(Guid intoTimelineId, Exhibit newExhibit)
        {
            Timeline target = _storage.Timelines.Where(t => t.Id == intoTimelineId).Include("Collection").FirstOrDefault();
            DateTime timestamp = DateTime.UtcNow;

            try
            {
                if (target == null) { return "The destination timeline, \"" + intoTimelineId.ToString() + "\", where you want to paste to, does not exist."; }

                if (_user == null) { return "In order to change a timeline, you must first be logged in."; }

                if (!UserIsMember(target.Collection.Id)) { return "You do not have permission to alter the \"" + target.Title + "\" timeline."; }

                if (newExhibit.Year < target.FromYear || newExhibit.Year > target.ToYear)
                {
                    return "Unable to paste \"" + newExhibit.Title + "\" into \"" + target.Title + "\", since " +
                            newExhibit.Title + "'s date exceeds that of " + target.Title + ".";
                }

                // replace GUIDs with new ones since we're cloning rather than moving - and set collection ids to target collection

                // keep cross-reference between old and new timelineIds so child timelines can maintain a pointer to their parents
                Guid newGUID = Guid.NewGuid();

                newExhibit.Id = newGUID;
                newExhibit.Collection = target.Collection;

                newExhibit.UpdatedBy = _user;
                newExhibit.UpdatedTime = timestamp;
                if (target.Exhibits == null)
                {
                    target.Exhibits = new System.Collections.ObjectModel.Collection<Exhibit>();
                }

                for (int eachItem = 0; eachItem < newExhibit.ContentItems.Count; eachItem++)
                {
                    newExhibit.ContentItems[eachItem].Id = Guid.NewGuid();
                    newExhibit.ContentItems[eachItem].Collection = target.Collection;
                }

                target.Exhibits.Add(newExhibit);
                _storage.SaveChanges();
                }

            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return "Unable to import the exhibit. An unexpected error has occured. " +
                        "Please feel free to try again.";

            }

            return "\"" + newExhibit.Title + "\" has been pasted into \"" + target.Title + "\". " +
                   "You may need to refresh your browser in order to see any new content.";
        }
Пример #3
0
 //used if creating timeline objects instead of flat json objects
 private static Exhibit createExhibit(Timeline j, String URL, Collection col)
 {
     Exhibit e = new Exhibit();
     e.Id = Guid.NewGuid();
     e.Title = j.Title + " - Exhibit"; //todo
     e.Threshold = "8. Origins of modern world"; //todo
     e.Regime = "Humanity";  //todo
     e.TimeUnit = "ce";
     e.Day = j.FromDay;
     e.Month = j.FromMonth;
     e.Year = j.FromYear;
     e.Sequence = 100;
     e.UniqueId = my_exhibit_count++;
     e.Collection = col;
     e.ContentItems = new System.Collections.ObjectModel.Collection<ContentItem>();
     for (int i = 0; i < 4; i++)
     {
         ContentItem c = new ContentItem();
         c.Id = Guid.NewGuid();
         c.UniqueId = my_contentitem_count++;
         c.Title = j.Title + "- ContentItem";
         c.Threshold = "8. Origins of modern world";
         c.Regime = "Humanity";
         c.TimeUnit = "ce";
         c.Year = j.ToYear;
         c.Order = 1; //todo
         c.HasBibliography = false; //todo
         c.MediaSource = "Library of Congress"; //todo
         c.Attribution = "Library of Congress";  //todo
         c.Collection = col;
         switch (i)
         {
             case 0:
                 {
                     c.Caption = j.Title + "- JP2";
                     c.MediaType = "JP2";
                     c.Uri = URL + ".jp2";
                     break;
                 }
             case 1:
                 {
                     c.Caption = j.Title + "- TXT";
                     c.MediaType = "TXT";
                     c.Uri = URL + "/ocr.txt";
                     break;
                 }
             case 2:
                 {
                     c.Caption = j.Title + "- PDF";
                     c.MediaType = "PDF";
                     c.Uri = URL + ".pdf";
                     break;
                 }
             case 3:
                 {
                     c.Caption = j.Title + "- OCR";
                     c.MediaType = "OCR";
                     c.Uri = URL + "/ocr.xml";
                     break;
                 }
         }
         // Insert into db here
         dbInst.ContentItems.Add(c);
         e.ContentItems.Add(c);
     }
     dbInst.Exhibits.Add(e);
     return e;
 }