Exemplo n.º 1
0
        /// <summary>
        /// 定时保存按键统计信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimerTick(object sender, System.EventArgs e)
        {
            //保存数据到数据库
            List <UsageCount> modelList = new List <UsageCount>();

            foreach (var val in DetailUsage.usageList.Values)
            {
                UsageCount count = new UsageCount();
                count.time      = DateTime.Now;
                count.KeyName   = val.KeyName;
                count.Count     = val.Count;
                count.TableName = val.TableName;
                modelList.Add(count);
            }
            sqlhelper.InsertModelData(modelList);
            Dictionary <string, UsageCount> dic = new Dictionary <string, UsageCount>();

            DetailUsage.usageList = dic;
            Dictionary <string, int> totaldic = new Dictionary <string, int>();

            totaldic.Add("TOTAL", TotalUsage.totalCount);
            totaldic.Add("MAIN", TotalUsage.mainCount);
            totaldic.Add("NUMBER", TotalUsage.numberCount);
            totaldic.Add("FUNC", TotalUsage.funcCount);
            totaldic.Add("CTRL", TotalUsage.ctrlCount);
            sqlhelper.UpdateTotalCount(totaldic);
        }
Exemplo n.º 2
0
        private static void UpdateUsageCounts(string usagePath1, string usagePath2, string cryptPassword, int playTime, int noNewClicks, string machineGUID, string userGUID, Logger logger)
        {
            FileStream fileStream = null;
            UsageCount usageCount = null;

            try
            {
                usageCount = (UsageCount)Serializer.Deserialize(typeof(UsageCount), usagePath1, cryptPassword, ref fileStream, false, true);

                logger.WriteMessage(DateTime.Now.ToString() + " successfully read existing usage count from path 1.");
            }
            catch (IOException ex)
            {
                logger.WriteError(ex);

                usageCount = (UsageCount)Serializer.Deserialize(typeof(UsageCount), usagePath2, cryptPassword, ref fileStream, false, true);

                logger.WriteMessage(DateTime.Now.ToString() + " successfully read existing usage count from path 2.");
            }

            // if a new UsageCount was created, its numerical values will be set to 0.
            usageCount.MachineGUID = machineGUID;
            usageCount.UserGUID    = userGUID;
            usageCount.NoClicks   += noNewClicks;
            usageCount.NoScreenSaverSessions++;
            usageCount.TotalPlayTime += playTime;

            logger.WriteMessage(DateTime.Now.ToString() + " successfully updated usage count in memory.");

            Serializer.Serialize(usageCount, cryptPassword, ref fileStream);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully written usage count on disk.");
        }
Exemplo n.º 3
0
 private string ModelToSQL(UsageCount model)
 {
     DateTime oldTime = new DateTime(1970, 1, 1);
     TimeSpan span = model.time.Subtract(oldTime);
     double milliSecondsTime = span.TotalMilliseconds;
     string sql = "INSERT INTO \"" + model.TableName + "\" (\"time\",\"count\") VALUES ( " + milliSecondsTime + "," + model.Count + ");";
     return sql;
 }
Exemplo n.º 4
0
        private void btnEncryptUsage_Click(object sender, EventArgs e)
        {
            UsageCount uc = new UsageCount
            {
                MachineGUID           = "machineGUIDGoesHere",
                UserGUID              = "userGUIDGoesHere",
                NoClicks              = 23,
                NoScreenSaverSessions = 32,
                TotalPlayTime         = 47832
            };

            Serializer.Serialize(uc, @"C:\OxigenData\SettingsData\ss_usg_1.dat", "password");

            MessageBox.Show("UsageCount Serialized", "Message");
        }
Exemplo n.º 5
0
 private void ModifyCountVal(string key, int val)
 {
     if (DetailUsage.usageList.ContainsKey(key))
     {
         UsageCount count = DetailUsage.usageList[key];
         count.Count = val;
         DetailUsage.usageList[key] = count;
     }
     else
     {
         UsageCount count = new UsageCount();
         count.Count     = val;
         count.KeyName   = key;
         count.TableName = key;
         count.time      = DateTime.Now;
         DetailUsage.usageList.Add(key, count);
     }
 }
Exemplo n.º 6
0
        internal virtual string ToString(bool verbose)
        {
            StringBuilder sb = new StringBuilder(512);

            sb.Append("\r\nIsPrivateEntry   = ").Append(IsPrivateEntry);
            sb.Append("\r\nIsPartialEntry   = ").Append(IsPartialEntry);
            sb.Append("\r\nStreamSize       = ").Append(StreamSize);
            sb.Append("\r\nExpires          = ").Append(ExpiresUtc == DateTime.MinValue? "": ExpiresUtc.ToString("r", CultureInfo.CurrentCulture));
            sb.Append("\r\nLastAccessed     = ").Append(LastAccessedUtc == DateTime.MinValue? "": LastAccessedUtc.ToString("r", CultureInfo.CurrentCulture));
            sb.Append("\r\nLastModified     = ").Append(LastModifiedUtc == DateTime.MinValue? "": LastModifiedUtc.ToString("r", CultureInfo.CurrentCulture));
            sb.Append("\r\nLastSynchronized = ").Append(LastSynchronizedUtc == DateTime.MinValue? "": LastSynchronizedUtc.ToString("r", CultureInfo.CurrentCulture));
            sb.Append("\r\nMaxStale(sec)    = ").Append(MaxStale == TimeSpan.MinValue? "": ((int)MaxStale.TotalSeconds).ToString(NumberFormatInfo.CurrentInfo));
            sb.Append("\r\nHitCount         = ").Append(HitCount.ToString(NumberFormatInfo.CurrentInfo));
            sb.Append("\r\nUsageCount       = ").Append(UsageCount.ToString(NumberFormatInfo.CurrentInfo));
            sb.Append("\r\n");
            if (verbose)
            {
                sb.Append("EntryMetadata:\r\n");
                if (m_EntryMetadata != null)
                {
                    foreach (string s in m_EntryMetadata)
                    {
                        sb.Append(s).Append("\r\n");
                    }
                }
                sb.Append("---\r\nSystemMetadata:\r\n");
                if (m_SystemMetadata != null)
                {
                    foreach (string s in m_SystemMetadata)
                    {
                        sb.Append(s).Append("\r\n");
                    }
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 7
0
 private UsageCount DTToModel(DataTable dt)
 {
     UsageCount count = new UsageCount();
     return count;
 }