Example #1
0
        /// <summary>
        /// Refresh Complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e)
        {
            try
            {
                // Success / Failure
                if (e.Error != null)
                {
                    Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString());

                    // Start the timer so that we expire
                    base.RenderMedia();
                }
                else
                {
                    // Ammend the resource file so that we can open it directly from the library (this is better than using a tempoary file)
                    string cachedFile = e.Result;

                    // Handle the background
                    String bodyStyle;

                    if (_options.backgroundImage == null || _options.backgroundImage == "")
                    {
                        bodyStyle = "background-color:" + _options.backgroundColor + " ;";
                    }
                    else
                    {
                        bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
                    }

                    string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>");
                    html = html.Replace("[[ViewPortWidth]]", _width.ToString());

                    // Write to the library
                    using (StreamWriter sw = new StreamWriter(File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read)))
                    {
                        sw.Write(html);
                        sw.Close();
                    }

                    // Read the control meta back out
                    ReadControlMeta();

                    // Handle Navigate in here because we will not have done it during first load
                    _webBrowser.Navigate(_filePath);
                }
            }
            catch (ObjectDisposedException)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Retrived the data set, stored the document but the media has already expired."), LogType.Error.ToString());
            }
            catch (Exception ex)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Unknown exception " + ex.Message), LogType.Error.ToString());

                // This should exipre the media
                Duration = 5;
                base.RenderMedia();
            }
        }
Example #2
0
        /// <summary>
        /// Refresh Complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e)
        {
            try
            {
                // Success / Failure
                if (e.Error != null)
                {
                    Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Info.ToString());

                    // We have failed to update from XMDS
                    // id we have been asked to reload on XmdsRefresh, check to see if we have a file to load,
                    // if not expire on a short timer.
                    if (_reloadOnXmdsRefresh)
                    {
                        if (File.Exists(_filePath))
                        {
                            // Cached file to revert to
                            UpdateCacheIfNecessary();

                            // Navigate to the file
                            HtmlUpdatedEvent?.Invoke(_localWebPath);
                        }
                        else
                        {
                            // No cache to revert to
                            Trace.WriteLine(new LogMessage("xmds_GetResource", "We haven't been able to download this widget and there isn't a pre-cached one to use. Skipping."), LogType.Info.ToString());

                            // Start the timer so that we expire
                            Duration = 2;
                            base.RenderMedia(0);
                        }
                    }
                }
                else
                {
                    // Ammend the resource file so that we can open it directly from the library (this is better than using a tempoary file)
                    string cachedFile = e.Result;

                    // Handle the background
                    string html = MakeHtmlSubstitutions(cachedFile);

                    // Comment in to write out the update date at the end of the file (in the body)
                    // This is useful if you want to check how frequently the file is updating
                    //html = html.Replace("<body>", "<body><h1 style='color:white'>" + DateTime.Now.ToString() + "</h1>");

                    // Write to the library
                    using (FileStream fileStream = File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        using (StreamWriter sw = new StreamWriter(fileStream))
                        {
                            sw.Write(html);
                            sw.Close();
                        }
                    }

                    if (_reloadOnXmdsRefresh)
                    {
                        // Read the control meta back out
                        ReadControlMeta();

                        // Handle Navigate in here because we will not have done it during first load
                        HtmlUpdatedEvent?.Invoke(_localWebPath);
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Retrived the resource, stored the document but the media has already expired."), LogType.Error.ToString());
            }
            catch (Exception ex)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Unknown exception " + ex.Message), LogType.Error.ToString());

                // This should exipre the media
                Duration = 5;
                base.RenderMedia(0);
            }
        }
Example #3
0
        /// <summary>
        /// Refresh Complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e)
        {
            try
            {
                // Success / Failure
                if (e.Error != null)
                {
                    Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Info.ToString());

                    // We have failed to update from XMDS
                    // id we have been asked to reload on XmdsRefresh, check to see if we have a file to load,
                    // if not expire on a short timer.
                    if (_reloadOnXmdsRefresh)
                    {
                        if (File.Exists(_filePath))
                        {
                            // Cached file to revert to
                            UpdateCacheIfNecessary();

                            // Navigate to the file
                            _webBrowser.Navigate(_localWebPath);
                        }
                        else
                        {
                            // No cache to revert to
                            Trace.WriteLine(new LogMessage("xmds_GetResource", "We haven't been able to download this widget and there isn't a pre-cached one to use. Skipping."), LogType.Info.ToString());

                            // Start the timer so that we expire
                            Duration = 2;
                            base.RenderMedia();
                        }
                    }
                }
                else
                {
                    // Ammend the resource file so that we can open it directly from the library (this is better than using a tempoary file)
                    string cachedFile = e.Result;

                    // Handle the background
                    String bodyStyle;
                    String backgroundColor = _options.Dictionary.Get("backgroundColor", _options.backgroundColor);

                    if (_options.backgroundImage == null || _options.backgroundImage == "")
                    {
                        bodyStyle = "background-color:" + backgroundColor + " ;";
                    }
                    else
                    {
                        bodyStyle = "background-image: url('" + _options.backgroundImage + "'); background-attachment:fixed; background-color:" + backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
                    }

                    string html = cachedFile.Replace("</head>", "<!--START_STYLE_ADJUST--><style type='text/css'>body {" + bodyStyle + " }</style><!--END_STYLE_ADJUST--></head>");
                    html  = html.Replace("[[ViewPortWidth]]", _width.ToString());
                    html += "<!--VIEWPORT=" + _width.ToString() + "x" + _height.ToString() + "-->";
                    html += "<!--CACHEDATE=" + DateTime.Now.ToString() + "-->";

                    // Comment in to write out the update date at the end of the file (in the body)
                    // This is useful if you want to check how frequently the file is updating
                    //html = html.Replace("<body>", "<body><h1 style='color:white'>" + DateTime.Now.ToString() + "</h1>");

                    // Write to the library
                    using (FileStream fileStream = File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        using (StreamWriter sw = new StreamWriter(fileStream))
                        {
                            sw.Write(html);
                            sw.Close();
                        }
                    }

                    if (_reloadOnXmdsRefresh)
                    {
                        // Read the control meta back out
                        ReadControlMeta();

                        // Handle Navigate in here because we will not have done it during first load
                        _webBrowser.Navigate(_localWebPath);
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Retrived the resource, stored the document but the media has already expired."), LogType.Error.ToString());
            }
            catch (Exception ex)
            {
                Trace.WriteLine(new LogMessage("WebMedia", "Unknown exception " + ex.Message), LogType.Error.ToString());

                // This should exipre the media
                Duration = 5;
                base.RenderMedia();
            }
        }