Пример #1
0
 public void Initialize()
 {
     base.Initialize();
     Random rand = new Random();
     Console.WriteLine("adding " + num_timelines + " random timelines");
     for (int i = 0; i < num_timelines; ++i)
     {
         Int64 start = (Int64)Math.Floor(rand.NextDouble() * (max_time - 1));
         Int64 end = (Int64)Math.Floor(rand.NextDouble() * (max_time - start)) + start;
         Timeline t = new Timeline();
         t.Id = Guid.NewGuid();
         t.FromYear = (decimal)start - 13700000001;
         t.ToYear = (decimal)end - 13700000001;
         t.ForkNode = Storage.ForkNode((Int64)t.FromYear, (Int64)t.ToYear);
         t.Regime = "RITreeTestTimeline";
     }
     _storage.SaveChanges();
 }
Пример #2
0
        /// <summary>
        /// Get TimelineShortctu from Timeline
        /// </summary>
        /// <param name="timeline">Timeline object</param>
        /// <returns>TimelineShortcut</returns>
        public TimelineShortcut GetTimelineShortcut(Timeline timeline)
        {
            var ts = new TimelineShortcut()
            {
                Title = timeline.Title
            };

            if (timeline.Collection.Title == "Beta Content")
            {
                ts.TimelineUrl = String.Format("/#{0}", GetContentPath(timeline.Collection.Id, timeline.Id, null));
                ts.Author = "Chronozoom";
            }
            else
            {
                ts.TimelineUrl = String.Format("/{0}/{1}/#{2}", timeline.Collection.User.DisplayName, timeline.Collection.Title, GetContentPath(timeline.Collection.Id, timeline.Id, null));
                ts.Author = timeline.Collection.User.DisplayName;
            }
            ts.ImageUrl = GetTimelineImageUrl(timeline);
            return ts;
        }
Пример #3
0
 public TimelineRaw(Timeline t)
 {
     Id = t.Id;
     Depth = t.Depth;
     SubtreeSize = t.SubtreeSize;
     Title = t.Title;
     Regime = t.Regime;
     FromYear = t.FromYear;
     ToYear = t.ToYear;
     ForkNode = t.ForkNode;
     Height = t.Height;
 }
Пример #4
0
        public Timeline GetRootTimelines(Guid collectionId)
        {
            IEnumerable<Timeline> rootCollectionTimeline = new Timeline[0];
            try
            {
                retryPolicy.ExecuteAction(
                  () =>
                  {
                      rootCollectionTimeline = Database.SqlQuery<Timeline>("SELECT * FROM Timelines WHERE Timeline_ID is NULL and Collection_ID = {0}", collectionId);
                  });
            }
            catch (Exception e)
            {
                throw e;
            }

            return rootCollectionTimeline.FirstOrDefault();
        }
Пример #5
0
 public TimelineRaw(Timeline t)
 {
     Id = t.Id;
     RootId = t.RootId;
     Depth = t.Depth;
     SubtreeSize = t.SubtreeSize;
     Title = t.Title;
     Regime = t.Regime;
     FromYear = t.FromYear;
     ToYear = t.ToYear;
     ForkNode = t.ForkNode;
     Height = t.Height;
     FirstNodeInSubtree = t.FirstNodeInSubtree;
     Predecessor = t.Predecessor;
     Successor = t.Successor;
 }
Пример #6
0
        private static string GetTimelineImageUrl(Timeline timeline)
        {
            if (timeline.Exhibits != null)
            {
                foreach (var exhibit in timeline.Exhibits)
                {
                    foreach (var contentItem in exhibit.ContentItems)
                    {
                        var mediaType = contentItem.MediaType.ToLower();
                        if (mediaType.Equals("picture") || mediaType.Equals("image"))
                        {
                            return contentItem.Uri;
                        }
                    }
                }
            }

            return "/images/default-tile.png";
        }
Пример #7
0
        private static void ParseJIssues(JArray issuesArray)
        {
            if (issuesArray != null && issuesArray.Count > 0)
            {

                    foreach (JObject obj in issuesArray)
                    {
                      try
                         {
                        Collection new_coll = null;
                        JObject temp = (JObject)obj["title"];
                        String coll_title = (string)temp["name"];
                        String title = (string)temp["name"] + "," + (String)obj["date_issued"];
                        var coll = dbInst.Collections.Where(c => c.Title == coll_title);
                        foreach (Collection c in coll)
                        {
                            new_coll = c;
                        }
                        //adding this newspapers collection if it does not already exist
                        if (new_coll == null)
                        {

                            new_coll = new Collection();
                            new_coll.Id = Guid.NewGuid();
                            new_coll.Title = coll_title;
                            dbInst.Collections.Add(new_coll);
                            if (my_sc.Collections == null) my_sc.Collections = new System.Collections.ObjectModel.Collection<Collection>();
                            my_sc.Collections.Add(new_coll);
                            dbInst.SaveChanges();
                        }
                        string pagesurl = basebatchurl + (string)obj["local_url"];

                        StreamReader reader = new StreamReader(pagesurl);
                        string s = reader.ReadToEnd();
                        reader.Close();
                        JObject jobj = JObject.Parse(s);
                        JArray pagesArray = (JArray)jobj["pages"];

                        //Creating the parent timeline
                        Timeline parent = new Timeline();
                        parent.Id = Guid.NewGuid();
                        parent.Height = null; //todo
                        parent.Regime = "Humanity"; //todo
                        parent.Sequence = 100; //todo
                        parent.Threshold = "8. Origins of modern world"; //todo
                        parent.Title = title;
                        parent.Collection = new_coll;
                        parent.UniqueId = my_timeline_count++;

                        parent.ChildTimelines = new System.Collections.ObjectModel.Collection<Timeline>();
                        //Creating the child timelines
                        for (int i = 0; i < pagesArray.Count; i++)
                        {
                            Timeline j = new Timeline();
                            j.Id = Guid.NewGuid();
                            j.Title = title + ", Pg" + (i + 1); //Newspaper name,date,pagenumber
                            j.Threshold = "8. Origins of modern world"; //todo
                            j.Regime = "Humanity"; //todo
                            j.Sequence = null; //todo
                            j.FromTimeUnit = "ce"; //to be changed for a different source
                            String dateString = (string)obj["date_issued"];
                            Decimal year = Decimal.Parse(dateString.Substring(0, 4));
                            j.FromMonth = int.Parse(dateString.Substring(5, 2));
                            j.FromDay = int.Parse(dateString.Substring(8, 2));
                            j.FromYear = convertToDecimalYear(j.FromDay, j.FromMonth, year, j.FromTimeUnit);
                            j.ToTimeUnit = j.FromTimeUnit;
                            j.ToDay = j.FromDay;
                            j.ToMonth = j.FromMonth;
                            j.ToYear = j.FromYear;
                            j.Start = j.FromYear;
                            j.End = j.ToYear;
                            j.UniqueId = my_timeline_count++;
                            if (parent.FromYear == 0)
                            {
                                parent.FromTimeUnit = "ce";
                                parent.ToTimeUnit = "ce";
                                parent.FromDay = j.FromDay;
                                parent.FromMonth = j.FromMonth;
                                parent.FromYear = j.FromYear;
                                parent.ToDay = j.ToDay;
                                parent.ToMonth = j.ToMonth;
                                parent.ToYear = j.ToYear;
                                parent.Start = parent.FromYear;
                                parent.End = parent.ToYear;
                            }
                            j.Sequence = 100; //todo
                            j.Height = null; //todo
                            j.Collection = new_coll;
                            String temp2 = (String)(pagesArray[i])["url"];
                            String URLofData = temp2.Remove(temp2.LastIndexOf(".json")) + "/seq-" + (i + 1);
                            j.Exhibits = new System.Collections.ObjectModel.Collection<Exhibit>();
                            j.Exhibits.Add(createExhibit(j, URLofData, new_coll));
                            parent.ChildTimelines.Add(j);
                            //adding j to db
                            dbInst.Timelines.Add(j);
                            if ((my_timeline_count % 10000) == 0)
                                Console.WriteLine("Timelines completed  " + my_timeline_count + "  " + DateTime.Now.ToShortTimeString());
                        }

                        //adding parent to db
                        dbInst.Timelines.Add(parent);
                        dbInst.SaveChanges();

                       }
                      catch (Exception e)
                      {
                          continue;
                      }
                }

            }
        }
Пример #8
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;
 }
Пример #9
0
        public void TestTimelinePutDelete()
        {
            string endPoint = String.Format(endpointLocator, serviceUrl, "sandbox/sandbox/timeline");
            HttpWebRequest request = CreateRequest(endPoint, "PUT");

            var newTimelineRequest = new TimelineRaw
            {
                Timeline_ID = new Guid("bdc1ceff-76f8-4df4-ba72-96b353991314"),
                Title = "Test Timeline",
                FromYear = -11000000000m,
                ToYear = -5000000000m,
                Regime = "Cosmos"
            };
            DataContractJsonSerializer putSerializer = new DataContractJsonSerializer(typeof(TimelineRaw));

            Stream requestStream = request.GetRequestStream();
            putSerializer.WriteObject(requestStream, newTimelineRequest);

            WebResponse response = request.GetResponse();
            Stream responseStream = response.GetResponseStream();

            //string responseText = new StreamReader(response.GetResponseStream()).ReadToEnd();
            DataContractJsonSerializer guidSerializer = new DataContractJsonSerializer(typeof(Guid));
            Guid timelineId = (Guid)guidSerializer.ReadObject(responseStream);

            Assert.IsNotNull(timelineId);

            var deleteTimelineRequest = new Timeline

            {
                Id = timelineId
            };

            request = CreateRequest(endPoint, "DELETE");

            DataContractJsonSerializer deleteSerializer = new DataContractJsonSerializer(typeof(Timeline));

            requestStream = request.GetRequestStream();
            deleteSerializer.WriteObject(requestStream, deleteTimelineRequest);

            request.GetResponse();
        }
Пример #10
0
 public TimelineRaw(Timeline t)
 {
     Id = t.Id;
     Depth = t.Depth;
     SubtreeSize = t.SubtreeSize;
     Title = t.Title;
     Regime = t.Regime;
     FromYear = t.FromYear;
     FromIsCirca = t.FromIsCirca;
     ToYear = t.ToYear;
     ToIsCirca = t.ToIsCirca;
     ForkNode = t.ForkNode;
     Height = t.Height;
     BackgroundUrl = t.BackgroundUrl;
     AspectRatio = t.AspectRatio;
 }
Пример #11
0
 public void UpdateFirstNodeInSubtree(Timeline currentTimeline, Guid firstTimelineId)
 {
     TimelineRaw parent = GetParentTimelineRaw(currentTimeline.Id);
     currentTimeline.FirstNodeInSubtree = firstTimelineId;
     if (parent != null)
     {
         UpdateFirstNodeInSubtree(parent, firstTimelineId);
     }
 }
Пример #12
0
 private Timeline PostOrderTraversal(Timeline root)
 {
     if (root.ChildTimelines != null)
     {
         int count = root.ChildTimelines.Count;
         if (count > 0)
         {
             Timeline rs = PostOrderTraversal(root.ChildTimelines[0]);
             root.FirstNodeInSubtree = rs.Id;
             for (int i = 0; i < count - 1; ++i)
             {
                 Timeline s = PostOrderTraversal(root.ChildTimelines[i + 1]);
                 root.ChildTimelines[i].Successor = s.Id;
                 s.Predecessor = root.ChildTimelines[i].Id;
             }
             root.ChildTimelines[count - 1].Successor = root.Id;
             root.Predecessor = root.ChildTimelines[count - 1].Id;
             return rs;
         }
         else
         {
             root.FirstNodeInSubtree = root.Id;
             return root;
         }
     }
     else
     {
         root.FirstNodeInSubtree = root.Id;
         return root;
     }
 }
Пример #13
0
        public TimelineShortcut GetTimelineShortcut(Timeline timeline)
        {
            string superCollectionPath  = "/" + timeline.Collection.SuperCollection.Title;
            string collectionPath       = "/" + timeline.Collection.Path;
            string contentPath          = "#" + GetContentPath(timeline.Collection.Id, timeline.Id, null);

            if (timeline.Collection.Default)
            {
                collectionPath = "";

                if (timeline.Collection.SuperCollection.Title == ConfigurationManager.AppSettings["DefaultSuperCollection"])
                {
                    superCollectionPath = "/";
                }
            }

            var timelineShortcut = new TimelineShortcut()
            {
                Title       = timeline.Title,
                TimelineUrl = superCollectionPath + collectionPath + contentPath,
                Author      = timeline.Collection.User == null ? "" : timeline.Collection.User.DisplayName,
                ImageUrl    = GetTimelineImageUrl(timeline)
            };

            return timelineShortcut;
        }