Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
   public class Channel : BindableBase
    {
        private string Name = "";
        public string name
        {
            get { return this.Name; }
            set { this.SetProperty(ref this.Name, value); }
        }

        private string Logo = "";
        public string logo
        {
            get { return this.Logo; }
            set { this.SetProperty(ref this.Logo, value); }
        }

        private Dictionary<System.DateTime,Programs> Programs2Date;
        public Dictionary<System.DateTime, Programs> programs2Date
        {
            get { return this.Programs2Date; }
            set { this.SetProperty(ref this.Programs2Date, value); }
        }

        private Program NowProgram;
        public Program nowProgram
        {
            get { return this.NowProgram; }
            set { this.SetProperty(ref this.NowProgram, value); }
        }

        public int order;

         private bool IsSelected = true;
         public bool isSelected
         {
             get { return this.IsSelected; }
             set { this.SetProperty(ref this.IsSelected, value); }
         }


      
        public void parseJson(JToken token)
        {
            this.Name = ((Newtonsoft.Json.Linq.JProperty)token).Name;
            this.Logo = "Assets/loghi/" + this.Name + ".png";
           // this.Logo = "Assets/loghi/Rai 1.png";

            this.Programs2Date = new Dictionary<DateTime, Programs>();
            Program program;

            foreach (var p in token.First.Children())
            {
                program = new Program();
                program.parseJson((JToken)p);
                if(!programs2Date.ContainsKey(program.startDate.Date)){
                    programs2Date.Add(program.startDate.Date, new Programs());
                    programs2Date[program.startDate.Date].parent = this;
                }
                
                program.parent = this;
                this.Programs2Date[program.startDate.Date].Add(program);


            }
            

            //filler iniziale nel caso il primo programma crei un buco tra le 00:00 e il suo inizio
            TimeSpan lastmidnight = new TimeSpan(0,0,0);
            foreach (KeyValuePair<DateTime, Programs> pair in Programs2Date)
            {
                if (pair.Value[0].startDate.TimeOfDay > lastmidnight) {
                    TimeSpan dif = pair.Value[0].startDate.TimeOfDay - lastmidnight;
                    Program filler = new Program(){duration=dif.TotalMinutes};
                    filler.setWidth();
                    pair.Value.Insert(0, filler);
                }
            }

            //sega la durata oltre le 24:00
            
            foreach (KeyValuePair<DateTime, Programs> pair in Programs2Date)
            {
                DateTime thismidnight =pair.Key.AddDays(1);
                DateTime end = pair.Value.Last().startDate.Add(new TimeSpan(0, (int)pair.Value.Last().duration,0));
                if ( end > thismidnight)
                {
                    TimeSpan dif = end - thismidnight;
                    pair.Value.Last().duration -= dif.TotalMinutes;
                    pair.Value.Last().setWidth();
                    
                }
            }

            highlightNowProgram();

        }
        private object lockObject = new Object();
        public void highlightNowProgram()
        {
            lock (lockObject)
            {
                if (Programs2Date.ContainsKey(DateTime.Now.Date))
                {
                    foreach (Program p in Programs2Date[DateTime.Now.Date])
                    {
                        if (p.startDate <= DateTime.Now && p.endDate >= DateTime.Now)
                        {
                            p.isNow = true;
                            this.NowProgram = p;
                        }
                        else
                        {
                            p.isNow = false;
                        }
                    }
                }
            }

           
        }





    }
}

Commits for Nextrek/Windows8/GuidaTv/ClassLibrary1/Channel.cs

Diff revisions: vs.
Revision Author Commited Message
21 JMBauan picture JMBauan Wed 26 Jun, 2013 10:48:36 +0000