Beispiel #1
0
        public static SiteSettings GetRemoteSite(string siteName, OnlineVideos.OnlineVideosWebservice.OnlineVideosService ws = null)
        {
            try
            {
                if (ws == null)
                {
                    ws = new OnlineVideosService()
                    {
                        Timeout = 30000, EnableDecompression = true
                    }
                }
                ;
                string siteXml = ws.GetSiteXml(siteName);
                if (siteXml.Length > 0)
                {
                    IList <SiteSettings> sitesFromWeb = SerializableSettings.Deserialize(siteXml);
                    if (sitesFromWeb != null && sitesFromWeb.Count > 0)
                    {
                        // Download images
                        try
                        {
                            string iconPath = Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, @"Icons\" + siteName + ".png");
                            byte[] icon     = ws.GetSiteIconIfChanged(siteName,
                                                                      File.Exists(iconPath) ?
                                                                      BitConverter.ToString(md5Service.ComputeHash(File.ReadAllBytes(iconPath))).Replace("-", "").ToLower()
                                                                        :
                                                                      null);
                            if (icon != null && icon.Length > 0)
                            {
                                File.WriteAllBytes(iconPath, icon);
                            }
                        }
                        catch (Exception ex)
                        {
                            OnlineVideos.OnlineVideoSettings.Instance.Logger.Warn("Error getting Icon for Site '{0}': {1}", siteName, ex.ToString());
                        }
                        try
                        {
                            string bannerPath = Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, @"Banners\" + siteName + ".png");
                            byte[] banner     = ws.GetSiteBannerIfChanged(siteName,
                                                                          File.Exists(bannerPath) ?
                                                                          BitConverter.ToString(md5Service.ComputeHash(File.ReadAllBytes(bannerPath))).Replace("-", "").ToLower()
                                                                        :
                                                                          null);
                            if (banner != null && banner.Length > 0)
                            {
                                File.WriteAllBytes(bannerPath, banner);
                            }
                        }
                        catch (Exception ex)
                        {
                            OnlineVideos.OnlineVideoSettings.Instance.Logger.Warn("Error getting Banner for Site '{0}': {1}", siteName, ex.ToString());
                        }

                        // return the site
                        return(sitesFromWeb[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                OnlineVideos.OnlineVideoSettings.Instance.Logger.Warn("Error getting remote Site {0}: {1}", siteName, ex.ToString());
            }
            return(null);
        }