示例#1
0
        private static int GetIntValue(string field)
        {
            int i = 0;

            string json = GetData(DateTime.Now);
            if (String.Compare(json, defaultJson, true) != 0)
            {
                JsonAnalyzer js = new JsonAnalyzer(json);
                int.TryParse(js.GetValue(field), out i);
            }
            return i;
        }
示例#2
0
        /// <summary>
        /// 记录IP信息
        /// </summary>
        /// <param name="ip"></param>
        public static void Record(string ip)
        {
            new Thread(() =>
            {

                try
                {
                    string key = String.Format("{0:yyyyMMdd}", DateTime.Now);
                    string data;                                   //流量数据
                    int todayIP = 0, todayPV = 0,
                        totalIP = 0, totalPV = 0;

                    string ips = String.Empty;                     //IP库

                    //获取累计的IP和PV,如果不存在,则创建字段
                    if (trafficFile.Contains("totalIP"))
                    {
                        int.TryParse(trafficFile["totalIP"], out totalIP);
                    }
                    else
                    {
                        trafficFile.Add("totalIP", "0");
                    }

                    if (trafficFile.Contains("totalPV"))
                    {
                        int.TryParse(trafficFile["totalPV"], out totalPV);
                    }
                    else
                    {
                        trafficFile.Add("totalPV", "0");
                    }

                    data = GetData(DateTime.Now);
                    JsonAnalyzer js = new JsonAnalyzer(data);

                    int.TryParse(js.GetValue("ip"), out todayIP);
                    int.TryParse(js.GetValue("pv"), out todayPV);

                    //检测是否是独立访客,如果是则增加IP并记录
                    if (trafficFile.Contains("ips"))
                    {
                        ips = trafficFile["ips"];
                    }
                    else
                    {
                        trafficFile.Add("ips", "");
                    }

                    if (ips.IndexOf(ip) == -1)
                    {
                        ips = String.Format("{0}{1}|", ips, ip);
                        trafficFile["ips"] = ips;
                        ++todayIP;
                        ++totalIP;

                        //更新今日IP数据并返回新的JSON
                        js = new JsonAnalyzer(js.SetValue("ip", todayIP.ToString()));

                        //保存总的IP数据
                        if (trafficFile.Contains("totalIP"))
                        {
                            trafficFile["totalIP"] = totalIP.ToString();
                        }
                        else
                        {
                            trafficFile.Add("totalIP", totalIP.ToString());
                        }
                    }
                    ++todayPV;
                    ++totalPV;

                    //保存今日PV
                    trafficFile[key] = js.SetValue("pv", todayPV.ToString());

                    //保存总的PV数据
                    trafficFile["totalPV"] = totalPV.ToString();
                }
                catch (Exception ex)
                {
                    //
                    //Catch error
                    //

                    trafficFile.Flush();
                }
            }).Start();

        }
示例#3
0
 /// <summary>
 /// 获取标签的字典形式
 /// </summary>
 /// <param name="flags"></param>
 /// <returns></returns>
 public static Dictionary<string, bool> GetFlagsDict(string flags)
 {
     IDictionary<string, string> dict = new JsonAnalyzer(flags).ConvertToDictionary();
     Dictionary<string, bool> flagDict = new Dictionary<string, bool>();
     foreach (KeyValuePair<string, string> pair in dict)
     {
         flagDict.Add(pair.Key, pair.Value == "1");
     }
     return flagDict;
 }
示例#4
0
        /// <summary>
        /// 获取标签值
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static BuiltInArchiveFlags GetBuiltInFlags(string flags)
        {
            JsonAnalyzer json = new JsonAnalyzer(flags);
            BuiltInArchiveFlags flag = BuiltInArchiveFlags.None;


            if (json.GetValue(internalFlagTexts[(int)BuiltInArchiveFlags.AsPage]) == "1")
            {
                flag |= BuiltInArchiveFlags.AsPage;
            }
            if (json.GetValue(internalFlagTexts[(int)BuiltInArchiveFlags.IsSpecial]) == "1")
            {
                flag |= BuiltInArchiveFlags.IsSpecial;
            }

            if (json.GetValue(internalFlagTexts[(int)BuiltInArchiveFlags.IsSystem]) == "1")
            {
                flag |= BuiltInArchiveFlags.IsSystem;
            }
            if (json.GetValue(internalFlagTexts[(int)BuiltInArchiveFlags.Visible]) == "1")
            {
                flag |= BuiltInArchiveFlags.Visible;
            }

            return flag;

        }
示例#5
0
 /// <summary>
 /// 获取标签值
 /// </summary>
 /// <param name="flags"></param>
 /// <param name="flagKey"></param>
 /// <returns></returns>
 public static bool GetFlag(string flags, string flagKey)
 {
     JsonAnalyzer json = new JsonAnalyzer(flags);
     return json.GetValue(flagKey) == "1";
 }
示例#6
0
        /// <summary>
        /// 校验激活状态
        /// </summary>
        internal static void VerifyActivation()
        {

        	if(DateTime.Now<new DateTime(2014,02,16)){
        		return;
        	}
            //
            // 如果异步方式调用
            // 或在本地调试则不校验
            //
            if (Cms.Cache.Get(checkKey) != null || CheckIsHostOnLocalhost())
            {
                return;
            }
            


            //
            // 异步从服务器读取激活状态
            //
            /*
            new Thread(() =>
            {
                lock (activeInfo)
                {
                    CheckActiveState();
                }

            }).Start();*/


            CheckActiveState();

            //=====分析获得的数据并返回到客户端=====//
            if (!String.IsNullOrEmpty(activeInfo))
            {
                lock (activeInfo)
                {
                    try
                    {
                        JsonAnalyzer js = new JsonAnalyzer(activeInfo);
                        string result = js.GetValue("state");

                        if (result != "ok")
                        {
                            activiveIsNormal = false;                           //设置状态

                            string content = js.GetValue("content");
                            HttpContext.Current.Response.ClearContent();
                            HttpContext.Current.Response.Write(content);

                            //返回字符串
                            if (result == "end")
                            {
                                HttpRuntime.UnloadAppDomain();
                                HttpContext.Current.Response.End();
                                return;
                            }
                            else if (result == "go")
                            {
                                return;
                            }
                        }
                        else
                        {
                            activiveIsNormal = true;                           //设置状态
                            //如果通过校验,则缓存1日激活状态

                            Cms.Cache.Insert(checkKey, "1", DateTime.Now.AddDays(7));

                        }
                    }
                    catch
                    {
                        //如果发生异常
                        //则创建缓存3天候过期来避免频繁向服务器发送校验请求
                         Cms.Cache.Insert(checkKey, "1", DateTime.Now.AddDays(3));
                    }
                }
            }
        }