コード例 #1
0
ファイル: ProtocolChatView.cs プロジェクト: RAOF/smuxi
        void CheckIcon()
        {
            Trace.Call();

            var cachePath = Platform.CachePath;
            var iconPath  = SysPath.Combine(cachePath, "server-icons");
            // REMOTING CALL
            var protocol = ProtocolManager.Protocol;

            iconPath = SysPath.Combine(iconPath, protocol);
            if (!Directory.Exists(iconPath))
            {
                Directory.CreateDirectory(iconPath);
            }
            iconPath = SysPath.Combine(iconPath,
                                       String.Format("{0}.ico", ID));
            var iconFile = new FileInfo(iconPath);

            if (iconFile.Exists && iconFile.Length > 0)
            {
                // cached icon, use right away
                UpdateServerIcon(iconPath);
            }

            string websiteUrl = null;

            lock (NetworkWebsiteUrls) {
                if (!NetworkWebsiteUrls.TryGetValue(ID, out websiteUrl) &&
                    !NetworkWebsiteUrls.TryGetValue(protocol, out websiteUrl))
                {
                    // unknown network and protocol, nothing to download
                    return;
                }
                // download in background so Sync() doesn't get slowed down
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        DownloadServerIcon(websiteUrl, iconFile);
                        iconFile.Refresh();
                        if (!iconFile.Exists || iconFile.Length == 0)
                        {
                            return;
                        }
                        UpdateServerIcon(iconPath);
                    } catch (Exception ex) {
#if LOG4NET
                        f_Logger.Error("CheckIcon(): Exception", ex);
#endif
                    }
                });
            }
        }
コード例 #2
0
        void CheckIcon()
        {
            Trace.Call();

            var iconCache = new IconCache("server-icons");
            // REMOTING CALL
            var protocol = ProtocolManager.Protocol;

            string iconName = String.Format("{0}.ico", ID);
            string iconPath;

            if (iconCache.TryGetIcon(protocol, iconName, out iconPath))
            {
                UpdateServerIcon(iconPath);
            }

            string websiteUrl = null;

            lock (NetworkWebsiteUrls) {
                if (!NetworkWebsiteUrls.TryGetValue(ID, out websiteUrl) &&
                    !NetworkWebsiteUrls.TryGetValue(protocol, out websiteUrl))
                {
                    // unknown network and protocol, nothing to download
                    return;
                }

                // download in background so Sync() doesn't get slowed down
                WebProxy proxy = null;
                // ignore the proxy settings of remote engines
                if (Frontend.IsLocalEngine)
                {
                    proxy = ProxySettings.GetWebProxy(websiteUrl);
                    if (proxy == null)
                    {
                        // HACK: WebClient will always use the system proxy if set to
                        // null so explicitely override this by setting an empty proxy
                        proxy = new WebProxy();
                    }
                }
                iconCache.Proxy = proxy;
                iconCache.BeginDownloadIcon(protocol, iconName, websiteUrl, UpdateServerIcon, null);
            }
        }