Пример #1
0
        /// <summary>
        /// 创建一个新的统计账户
        /// </summary>
        /// <returns></returns>
        public StatisticsAccount CreatNewAccount()
        {
            ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>();
            SiteSettings         siteSettings        = siteSettingsManager.Get();

            string key       = EncryptionUtility.MD5(siteSettings.MainSiteRootUrl + "A4ba4oqS").ToLower();
            string creatLink = string.Format("http://wss.cnzz.com/user/companion/spacebuilder.php?domain={0}&key={1}", siteSettings.MainSiteRootUrl, key);
            string webMatter = HttpCollects.GetHTMLContent(creatLink, Encoding.GetEncoding("gb2312"), null);

            string errorMessage = null;

            switch (webMatter.Trim())
            {
            case "":
                errorMessage = "远程站点没有响应";
                break;

            case "-1":
                errorMessage = "key输入有误";
                break;

            case "-2":
                errorMessage = "该域名长度有误(1~64)";
                break;

            case "-3":
                errorMessage = "域名输入有误(比如输入汉字)";
                break;

            case "-4":
                errorMessage = "域名插入数据库有误";
                break;

            case "-5":
                errorMessage = "同一个IP用户调用页面超过阀值,阀值暂定为10";
                break;
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception("创建统计帐号出错,错误信息:" + errorMessage);
            }

            string siteIdStr   = webMatter.Substring(0, webMatter.IndexOf('@'));
            string passwordStr = webMatter.Substring(webMatter.IndexOf('@') + 1);
            long   siteId      = 0;
            long   password    = 0;

            StatisticsAccount account = new StatisticsAccount();

            if (long.TryParse(siteIdStr, out siteId) && long.TryParse(passwordStr, out password))
            {
                account.Password = password.ToString();
                account.UserName = siteId.ToString();
                return(account);
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// 初始化统计信息
        /// </summary>
        public static void Initialize()
        {
            CNZZStatisticsService service = new CNZZStatisticsService();

            StatisticsAccount account = service.GetAccount();

            if (account == null)
            {
                account = service.CreatNewAccount();
            }
            service.SaveStatisticsAccount(account);
        }
Пример #3
0
        /// <summary>
        /// 获取统计账户信息
        /// </summary>
        /// <returns></returns>
        public StatisticsAccount GetAccount()
        {
            SystemDataService systemDataService = new SystemDataService();
            StatisticsAccount account           = new StatisticsAccount();
            long siteId   = systemDataService.GetLong("CNZZStatisticsSiteId");
            long password = systemDataService.GetLong("CNZZStatisticsPassword");

            if (siteId <= 0 || password <= 0)
            {
                return(null);
            }

            account.UserName = siteId.ToString();
            account.Password = password.ToString();
            return(account);
        }
Пример #4
0
        /// <summary>
        /// 保存统计帐号
        /// <param name="account">被保存的统计帐号</param>
        /// </summary>
        public void SaveStatisticsAccount(StatisticsAccount account)
        {
            if (account == null || string.IsNullOrEmpty(account.Password) || string.IsNullOrEmpty(account.UserName))
            {
                return;
            }

            SystemDataService systemDataService = new SystemDataService();
            long siteId   = systemDataService.GetLong("CNZZStatisticsSiteId");
            long password = systemDataService.GetLong("CNZZStatisticsPassword");

            long accountSiteId = 0;

            if (!long.TryParse(account.UserName, out accountSiteId))
            {
                return;
            }

            long accountPassword = 0;

            if (!long.TryParse(account.Password, out accountPassword))
            {
                return;
            }

            if (accountSiteId != siteId)
            {
                systemDataService.Change("CNZZStatisticsSiteId", accountSiteId - siteId);
            }
            if (accountPassword != password)
            {
                systemDataService.Change("CNZZStatisticsPassword", accountPassword - password);
            }

            Enable = true;

            ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>();
            SiteSettings         siteSettings        = siteSettingsManager.Get();

            siteSettings.StatScript = GetStatisticsCode();

            siteSettingsManager.Save(siteSettings);
        }