Exemplo n.º 1
0
        public static Topic TopicWithJObject(JObject json, FlickrGroup group)
        {
            // Get topic id
            string topicId = json["id"].ToString();
            Topic topic = null;
            if (group.TopicCache.ContainsKey(topicId))
            {
                topic = group.TopicCache[topicId];
            }
            else
            {
                topic = new Topic();
                topic.ResourceId = topicId;
                group.TopicCache[topicId] = topic;
            }

            // Parse user
            topic.Author = UserFactory.UserWithTopicJObject(json);
            topic.IsAdmin = (json["role"].ToString() == "admin");
            topic.CreationDate = json["datecreate"].ToString().ToDateTime();

            // Subject
            topic.Subject = json["subject"].ToString();

            // Message
            topic.Message = json["message"]["_content"].ToString();

            // Replies
            topic.CanReply = (json["can_reply"].ToString() == "1");
            topic.LastReplyDate = json["datelastpost"].ToString().ToDateTime();
            topic.ReplyCount = int.Parse(json["count_replies"].ToString());

            return topic;
        }
Exemplo n.º 2
0
        public static TopicReply TopicReplyWithJObject(JObject json, Topic topic)
        {
            // Get reply id
            string replyId = json["id"].ToString();
            TopicReply reply = null;
            if (topic.ReplyCache.ContainsKey(replyId))
            {
                reply = topic.ReplyCache[replyId];
            }
            else
            {
                reply = new TopicReply();
                reply.ResourceId = replyId;
                topic.ReplyCache[replyId] = reply;
            }

            // Parse user
            reply.Author = UserFactory.UserWithTopicJObject(json);
            reply.IsAdmin = (json["role"].ToString() == "admin");
            reply.CreationDate = json["datecreate"].ToString().ToDateTime();

            // Message
            reply.Message = json["message"]["_content"].ToString();

            // Replies
            reply.CanDelete = (json["can_delete"].ToString() == "1");

            return reply;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string groupId = NavigationContext.QueryString["group_id"];
            group = Cinderella.CinderellaCore.GroupCache[groupId];

            string topicId = NavigationContext.QueryString["topic_id"];
            topic = group.TopicCache[topicId];

            // Reply list
            ReplyCollection = new ObservableCollection<ModelBase>();
            ReplyListView.ItemsSource = ReplyCollection;

            // Add topic as first item
            ReplyCollection.Add(topic);

            foreach (var reply in topic.Replies)
            {
                ReplyCollection.Add(reply);
            }

            // Config app bar
            ApplicationBar = Resources["ReplyListAppBar"] as ApplicationBar;

            // Events
            Cinderella.CinderellaCore.TopicRepliesUpdated += OnRepliesUpdated;
            Anaconda.AnacondaCore.AddTopicReplyException += OnAddReplyException;
            Cinderella.CinderellaCore.AddTopicReplyCompleted += OnAddReplyComplete;

            SystemTray.ProgressIndicator = new ProgressIndicator();
            SystemTray.ProgressIndicator.IsIndeterminate = true;
            SystemTray.ProgressIndicator.Text = AppResources.DiscussionRetrievingRepliesText;
            SystemTray.ProgressIndicator.IsVisible = true;

            // Refresh reply list
            Anaconda.AnacondaCore.GetTopicRepliesAsync(topicId, groupId, new Dictionary<string, string> { { "page", "1" }, { "per_page", Anaconda.DefaultItemsPerPage.ToString() } });
        }
        private void OnTopicAdded(object sender, AddTopicEventArgs e)
        {
            FlickrGroup group = Cinderella.CinderellaCore.GroupCache[e.GroupId];

            JObject rawJson = JObject.Parse(e.Response);
            string newTopicId = rawJson["topic"]["id"].ToString();

            Topic newTopic = new Topic();
            newTopic.ResourceId = newTopicId;
            newTopic.Subject = e.Subject;
            newTopic.Message = e.Message;
            newTopic.Author = CurrentUser;
            newTopic.CreationDate = DateTime.Now;

            group.TopicCache[newTopicId] = newTopic;
            group.Topics.Insert(0, newTopic);
            group.TopicCount++;

            AddTopicCompleteEventArgs evt = new AddTopicCompleteEventArgs();
            evt.SessionId = e.SessionId;
            evt.GroupId = group.ResourceId;
            evt.newTopic = newTopic;
            AddTopicCompleted.DispatchEvent(this, evt);
        }