private static void CreateSubItems(CommonDataContract.PollItem parentPollItem, System.Xml.XmlNode parentItemNode)
 {
     CommonDataContract.SubPollItem subPollItem;
     parentPollItem.CreateSubItemCollection();
     foreach (System.Xml.XmlNode subItemNode in parentItemNode.ChildNodes) {
         if (subItemNode.Name == "sub-item") {
             subPollItem = new CommonDataContract.SubPollItem();
             subPollItem.ItemName = subItemNode.Attributes["name"].Value.ToString();
             subPollItem.BitOffset = Convert.ToInt16(subItemNode.Attributes["offset"].Value);
             subPollItem.BitCount = Convert.ToInt16(subItemNode.Attributes["count"].Value);
             parentPollItem.SubItems.Add(subPollItem);
         }
     }
 }
Exemplo n.º 2
0
 private void AddPollItemToHashtable(CommonDataContract.PollItem pollItem)
 {
     if (!_hashtablePollItems.Contains(pollItem.ItemName)) {
         _hashtablePollItems.Add(pollItem.ItemName, pollItem);
     }
 }
 private string CreateLogString(CommonDataContract.PollItemValue currentPollItemValue)
 {
     //return String.Format("{0}\t{1} {2}\t{3}",
     //               currentPollItemValue.ItemID,
     //               currentPollItemValue.Timestamp.ToShortDateString(),
     //               currentPollItemValue.Timestamp.ToLongTimeString(),
     //               currentPollItemValue.Value.ToString());
     return String.Format("<item-value id=\"{0}\" timestamp=\"{1} {2}\"\t value=\"{3}\"/>",
         currentPollItemValue.ItemID,
         currentPollItemValue.Timestamp.ToShortDateString(),
         currentPollItemValue.Timestamp.ToLongTimeString(),
         currentPollItemValue.Value.ToString());
 }
 internal void UpdateValues(CommonDataContract.PollItemValue[] pollItemValues)
 {
     List<CommonDataContract.PollItem> updatedPollItems = null;
     try {
         updatedPollItems = UpdateValuesToDataBuffer(pollItemValues);
     }
     catch (Exception ex) {
         TDInternalLogger.GetLogger().LogException(ex);
     }
     try {
         if (updatedPollItems != null)
             _externalDataStore.SaveValues(updatedPollItems);
     }
     catch (Exception ex) {
         TDInternalLogger.GetLogger().LogException(ex);
     }
     try {
         if (updatedPollItems != null)
             _logDataStore.SaveValues(updatedPollItems);
     }
     catch (Exception ex) {
         TDInternalLogger.GetLogger().LogException(ex);
     }
 }
 /// <summary>
 /// Updates values into data buffer. 
 /// Returning a list of updated poll items
 /// </summary>
 /// <param name="pollItemValues"></param>
 /// <returns></returns>
 private List<CommonDataContract.PollItem> UpdateValuesToDataBuffer(CommonDataContract.PollItemValue[] pollItemValues)
 {
     string itemID;
     List<CommonDataContract.PollItem> resultList = new List<CommonDataContract.PollItem>();
     CommonDataContract.PollItem currentPollItem;
     foreach (CommonDataContract.PollItemValue currentItemValue in pollItemValues) {
         itemID = currentItemValue.ItemID;
         if (CurrentDataBuffer.Contains(itemID)) {
             CurrentDataBuffer.RegisterPollItem(itemID);
         }
         currentPollItem = CurrentDataBuffer.GetPollItemByID(itemID);
         if (currentPollItem.IsPackage) {
             UnpackAndSaveSubItems(currentPollItem, currentItemValue, resultList);
         }
         currentPollItem.AddValue(currentItemValue.Timestamp, currentItemValue);
         resultList.Add(currentPollItem);
     }
     CurrentDataBuffer.LastTimeStamp = DateTime.Now;
     return resultList;
 }
        /// <summary>
        /// Unpack poll item. Save value into buffer. Save item in result list 
        /// </summary>
        /// <param name="currentPollItem">poll item</param>
        /// <param name="currentItemValue">poll item value</param>
        /// <param name="resultItemList">result updated poll item list</param>
        private void UnpackAndSaveSubItems(
            CommonDataContract.PollItem currentPollItem, 
            CommonDataContract.PollItemValue currentItemValue,
            List<CommonDataContract.PollItem> resultItemList)
        {
            Int64 intValue = Convert.ToInt64(currentItemValue.Value);
            bool[] fullBits = new bool[currentPollItem.PackLength];
            char[] bits = Convert.ToString(intValue, 2).ToCharArray();
            for (int i = 1; i <= bits.Length; i++) {
                if (bits[bits.Length-i] == '1')
                    fullBits[fullBits.Length - i] = true;
            }

            CommonDataContract.PollItemValue newPollItemValue;
            int lastIndex = fullBits.Length - 1;
            foreach (var subItem in currentPollItem.SubItems) {
                newPollItemValue = new CommonDataContract.PollItemValue();
                newPollItemValue.ItemID = subItem.ItemName;
                newPollItemValue.Timestamp = currentItemValue.Timestamp;
                /// Берем смещение от конца массива (т.е. при offset = 0 надо взять последний элемент)
                newPollItemValue.Value = fullBits[lastIndex - subItem.BitOffset];
                subItem.AddValue(newPollItemValue.Timestamp, newPollItemValue);
                resultItemList.Add(subItem);
            }
        }
        /*private System.Data.SqlServerCe.SqlCeConnection _connection;

        public InternalDataStore() {
            _connection =
                new System.Data.SqlServerCe.SqlCeConnection("Data Source=./TechDatabase.sdf");
            _connection.Open();
        }

        public void SaveValues(CommonDataContract.PollItemValue[] pollItemValues) {
            System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand();
            cmd.Connection = _connection;
            cmd.CommandType = System.Data.CommandType.Text;
            foreach (var currentPollItemValue in pollItemValues) {
                cmd.CommandText = String.Format("insert into item_values (itemID, Timestamp, Value) values ('{0}','{1}','{2}')",
                    currentPollItemValue.ItemID, currentPollItemValue.Timestamp, currentPollItemValue.Value);
                int rowCount = cmd.ExecuteNonQuery();
            }
        }
         * */
        public void SaveValues(CommonDataContract.PollItemValue[] pollItemValues)
        {
        }
 private void SaveDataToBuffer(CommonDataContract.PollItemValue[] pollItemValues)
 {
     _currentDataManager.UpdateValues(pollItemValues);
 }