~alexharrington/xibo/pyclient-1.1.0a22

« back to all changes in this revision

Viewing changes to client/dotNET/WebContent.cs

  • Committer: Alex Harrington
  • Date: 2009-12-31 11:38:50 UTC
  • Revision ID: alex@longhill.org.uk-20091231113850-bz5flhqq2gsw0qxf
Converted to 2.0 repo format and fixed lineendings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Xibo - Digitial Signage - http://www.xibo.org.uk
3
 
 * Copyright (C) 2006,2007,2008 Daniel Garner and James Packer
4
 
 *
5
 
 * This file is part of Xibo.
6
 
 *
7
 
 * Xibo is free software: you can redistribute it and/or modify
8
 
 * it under the terms of the GNU Affero General Public License as published by
9
 
 * the Free Software Foundation, either version 3 of the License, or
10
 
 * any later version. 
11
 
 *
12
 
 * Xibo is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU Affero General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Affero General Public License
18
 
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
using System;
21
 
using System.Collections.Generic;
22
 
using System.Text;
23
 
using System.Windows.Forms;
24
 
 
25
 
namespace XiboClient
26
 
{
27
 
    class WebContent : Media
28
 
    {
29
 
        int scheduleId;
30
 
        int layoutId;
31
 
        string mediaId;
32
 
        string type;
33
 
 
34
 
        public WebContent(RegionOptions options)
35
 
            : base(options.width, options.height, options.top, options.left)
36
 
        {
37
 
            duration        = options.duration;
38
 
            scheduleId      = options.scheduleId;
39
 
            layoutId        = options.layoutId;
40
 
            mediaId         = options.mediaid;
41
 
            type = options.type;
42
 
 
43
 
            webBrowser = new WebBrowser();
44
 
 
45
 
            webBrowser.Size = this.Size;
46
 
            webBrowser.ScrollBarsEnabled = false;
47
 
            webBrowser.ScriptErrorsSuppressed = true;
48
 
 
49
 
            // Attach event
50
 
            webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
51
 
 
52
 
            Controls.Add(webBrowser);
53
 
 
54
 
            if (!Properties.Settings.Default.powerpointEnabled && options.type == "powerpoint")
55
 
            {
56
 
                webBrowser.DocumentText = "<html><body><h1>Powerpoint not enabled on this display</h1></body></html>";
57
 
                System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Powerpoint is not enabled on this display", scheduleId, layoutId, mediaId));
58
 
            }
59
 
            else
60
 
            {
61
 
                try
62
 
                {
63
 
                    // Try to make a URI out of the file path
64
 
                    try
65
 
                    {
66
 
                        this.filePath = Uri.UnescapeDataString(options.uri);
67
 
                    }
68
 
                    catch (Exception ex)
69
 
                    {
70
 
                        System.Diagnostics.Debug.WriteLine(ex.Message, "WebContent");
71
 
                    }
72
 
 
73
 
                    // Navigate
74
 
                    webBrowser.Navigate(this.filePath);
75
 
                }
76
 
                catch (Exception ex)
77
 
                {
78
 
                    System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", ex.Message, scheduleId, layoutId, mediaId));
79
 
 
80
 
                    webBrowser.DocumentText = "<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>";
81
 
 
82
 
                    System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Unable to show the powerpoint, cannot be located", scheduleId, layoutId, mediaId));
83
 
                }
84
 
            }
85
 
        }
86
 
 
87
 
        public override void RenderMedia()
88
 
        {
89
 
            //do nothing
90
 
            return;
91
 
        }
92
 
 
93
 
        void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
94
 
        {
95
 
            base.Duration = duration;
96
 
            base.RenderMedia();
97
 
 
98
 
            // Get ready to show the control
99
 
            Application.DoEvents();
100
 
            Show();
101
 
        }
102
 
 
103
 
        protected override void Dispose(bool disposing)
104
 
        {
105
 
            if (disposing)
106
 
            {
107
 
                System.Diagnostics.Debug.WriteLine(String.Format("Disposing {0}", filePath));
108
 
 
109
 
                try
110
 
                {
111
 
                    if (webBrowser != null)
112
 
                    {
113
 
                        if (webBrowser.Document != null) webBrowser.Document.Body.InnerHtml = "";
114
 
                        webBrowser.Dispose();
115
 
                    }
116
 
                }
117
 
                catch { }
118
 
            }
119
 
 
120
 
            base.Dispose(disposing);
121
 
 
122
 
            System.Diagnostics.Debug.WriteLine(String.Format("Disposed {0}", filePath));
123
 
        }
124
 
 
125
 
        string filePath;
126
 
        WebBrowser webBrowser;
127
 
        int duration;
128
 
    }
 
1
/*
 
2
 * Xibo - Digitial Signage - http://www.xibo.org.uk
 
3
 * Copyright (C) 2006,2007,2008 Daniel Garner and James Packer
 
4
 *
 
5
 * This file is part of Xibo.
 
6
 *
 
7
 * Xibo is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Affero General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * any later version. 
 
11
 *
 
12
 * Xibo is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU Affero General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Affero General Public License
 
18
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
using System;
 
21
using System.Collections.Generic;
 
22
using System.Text;
 
23
using System.Windows.Forms;
 
24
 
 
25
namespace XiboClient
 
26
{
 
27
    class WebContent : Media
 
28
    {
 
29
        int scheduleId;
 
30
        int layoutId;
 
31
        string mediaId;
 
32
        string type;
 
33
 
 
34
        public WebContent(RegionOptions options)
 
35
            : base(options.width, options.height, options.top, options.left)
 
36
        {
 
37
            duration        = options.duration;
 
38
            scheduleId      = options.scheduleId;
 
39
            layoutId        = options.layoutId;
 
40
            mediaId         = options.mediaid;
 
41
            type = options.type;
 
42
 
 
43
            webBrowser = new WebBrowser();
 
44
 
 
45
            webBrowser.Size = this.Size;
 
46
            webBrowser.ScrollBarsEnabled = false;
 
47
            webBrowser.ScriptErrorsSuppressed = true;
 
48
 
 
49
            // Attach event
 
50
            webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
 
51
 
 
52
            Controls.Add(webBrowser);
 
53
 
 
54
            if (!Properties.Settings.Default.powerpointEnabled && options.type == "powerpoint")
 
55
            {
 
56
                webBrowser.DocumentText = "<html><body><h1>Powerpoint not enabled on this display</h1></body></html>";
 
57
                System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Powerpoint is not enabled on this display", scheduleId, layoutId, mediaId));
 
58
            }
 
59
            else
 
60
            {
 
61
                try
 
62
                {
 
63
                    // Try to make a URI out of the file path
 
64
                    try
 
65
                    {
 
66
                        this.filePath = Uri.UnescapeDataString(options.uri);
 
67
                    }
 
68
                    catch (Exception ex)
 
69
                    {
 
70
                        System.Diagnostics.Debug.WriteLine(ex.Message, "WebContent");
 
71
                    }
 
72
 
 
73
                    // Navigate
 
74
                    webBrowser.Navigate(this.filePath);
 
75
                }
 
76
                catch (Exception ex)
 
77
                {
 
78
                    System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", ex.Message, scheduleId, layoutId, mediaId));
 
79
 
 
80
                    webBrowser.DocumentText = "<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>";
 
81
 
 
82
                    System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Unable to show the powerpoint, cannot be located", scheduleId, layoutId, mediaId));
 
83
                }
 
84
            }
 
85
        }
 
86
 
 
87
        public override void RenderMedia()
 
88
        {
 
89
            //do nothing
 
90
            return;
 
91
        }
 
92
 
 
93
        void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 
94
        {
 
95
            base.Duration = duration;
 
96
            base.RenderMedia();
 
97
 
 
98
            // Get ready to show the control
 
99
            Application.DoEvents();
 
100
            Show();
 
101
        }
 
102
 
 
103
        protected override void Dispose(bool disposing)
 
104
        {
 
105
            if (disposing)
 
106
            {
 
107
                System.Diagnostics.Debug.WriteLine(String.Format("Disposing {0}", filePath));
 
108
 
 
109
                try
 
110
                {
 
111
                    if (webBrowser != null)
 
112
                    {
 
113
                        if (webBrowser.Document != null) webBrowser.Document.Body.InnerHtml = "";
 
114
                        webBrowser.Dispose();
 
115
                    }
 
116
                }
 
117
                catch { }
 
118
            }
 
119
 
 
120
            base.Dispose(disposing);
 
121
 
 
122
            System.Diagnostics.Debug.WriteLine(String.Format("Disposed {0}", filePath));
 
123
        }
 
124
 
 
125
        string filePath;
 
126
        WebBrowser webBrowser;
 
127
        int duration;
 
128
    }
129
129
}
 
 
b'\\ No newline at end of file'