2 using System.Collections.Generic;
5 using System.Xml.Serialization;
6 using System.Collections;
7 using System.Collections.Specialized;
8 using Seci.Definitions;
20 OrderedDictionary
_dict =
new OrderedDictionary();
32 if (!String.IsNullOrEmpty(name))
43 if (!String.IsNullOrEmpty(name))
45 _dict[name.ToLower()] = value;
61 String[] keys = this.GetKeys();
74 String[] keys = this.GetKeys();
76 _dict[keys[index]] = value;
90 if (!String.IsNullOrEmpty(blockName))
92 if (!String.IsNullOrEmpty(block.
Alias) && _dict.Count > 0)
97 throw new Exception(
"Alias is not unique");
103 _dict.Add(blockName.ToLower(), block);
107 throw new Exception(
"Block name already exists");
118 if (!String.IsNullOrEmpty(block.
Alias) && _dict.Count > 0)
123 throw new Exception(
"Alias is not unique");
129 _dict.Insert(index, blockName.ToLower(), block);
133 throw new Exception(
"Block name already exists");
151 List<String> keys =
new List<string>(
GetKeys());
152 for (
int i = 0; i < keys.Count; ++i)
154 if (keys[i] == oldName.ToLower())
163 Remove(oldName.ToLower());
169 _dict.Insert(index, oldName.ToLower(), oldBlock);
170 throw new ArgumentException(
"Block name already exists.");
176 _dict.Insert(index, oldName.ToLower(), oldBlock);
177 throw new ArgumentException(
"Alias name already exists");
180 _dict.Insert(index, newName.ToLower(), newBlock);
189 public int Count {
get {
return _dict.Count; } }
199 if (!String.IsNullOrEmpty(blockName))
201 return _dict.Contains(blockName.ToLower());
215 if (String.IsNullOrEmpty(alias))
222 if (block.
Alias != null && block.
Alias.ToLower() == alias.ToLower())
250 String newName =
"renamed_";
252 for (
int i = 0; i < newDictionary.Count; ++i)
260 if (!
_dict.Contains(newDictionary[i].BlockName.ToLower()))
262 _dict.Add(newDictionary[i].BlockName.ToLower(), newDictionary[i]);
267 newDictionary[i].BlockName = newName + newDictionary[i].BlockName +
"_" + count.ToString();
268 _dict.Add(newDictionary[i].BlockName.ToLower(), newDictionary[i]);
274 Helpers.ErrorLogger.SeciError(
"AddDictionary", err);
285 _dict.Remove(blockName.ToLower());
295 String[] keys = this.GetKeys();
297 _dict.Remove(keys[index]);
305 public void Swap(
int index1,
int index2)
314 if (index1 <
_dict.Count && index2 <
_dict.Count && index1 != index2)
318 _dict.RemoveAt(index2);
319 _dict.RemoveAt(index1);
320 _dict.Insert(index1, temp2.BlockName.ToLower(), temp2);
321 _dict.Insert(index2, temp1.BlockName.ToLower(), temp1);
332 String[] keys = this.GetKeys();
334 List<String> blocksToRemove =
new List<String>();
339 foreach (String key
in keys)
341 if (
this[key].ParentVI.ToLower() == fileName.ToLower())
343 blocksToRemove.Add(key);
348 for (
int i = 0; i < blocksToRemove.Count; ++i)
350 this.Remove(blocksToRemove[i]);
361 if (
_dict.Keys.Count != 0)
363 String[] keys =
new String[_dict.Keys.Count];
365 _dict.Keys.CopyTo(keys, 0);
379 internal List<String> GetEnabledBlocks()
381 if (
_dict.Keys.Count != 0)
384 List<String> keys =
new List<String>();
388 List<String> blocks =
new List<String>();
390 for (
int i = 0; i < keys.Count; ++i)
392 if (
this[keys[i]].BlockEnabled)
394 blocks.Add(
this[keys[i]].BlockName);
410 internal String[] GetAliases()
412 if (
_dict.Keys.Count != 0)
415 List<String> keys =
new List<String>();
419 List<String> aliases =
new List<String>();
421 for (
int i = 0; i < keys.Count; ++i)
423 aliases.Add(
this[keys[i]].Alias);
426 return aliases.ToArray();
439 internal String[,] GetLabVIEWInfo()
441 if (
_dict.Keys.Count != 0)
444 List<String> keys =
new List<String>();
448 String[,] results =
new String[keys.Count, 7];
450 for (
int i = 0; i < keys.Count; ++i)
452 results[i, 0] = keys[i];
453 results[i, 1] =
this[keys[i]].Alias;
454 results[i, 2] =
this[keys[i]].ParentVI;
455 results[i, 3] =
this[keys[i]].ReadControl;
456 results[i, 4] =
this[keys[i]].WriteControl;
457 results[i, 5] =
this[keys[i]].GoButton;
458 results[i, 6] =
this[keys[i]].WaitForControl;
478 internal String[] GetFormattedBlockValues(Boolean visibleOnly, Boolean includeSetpoint, Boolean includeGroup, Boolean includeWaitState)
480 if (
_dict.Keys.Count != 0)
482 List<String> keys =
new List<String>();
486 List<String> values =
new List<String>();
488 for (
int i = 0; i < keys.Count; ++i)
495 values.Add(GetFormattedBlockValue(temp.
BlockName, includeSetpoint, includeGroup, includeWaitState));
499 return values.ToArray();
515 internal String GetFormattedBlockValue(String blockName, Boolean includeSetpoint, Boolean includeGroup, Boolean includeWaitState)
521 String result = temp.BlockName +
": " + temp.FormattedCurrentValue +
" " + temp.BlockUnits;
525 result +=
" [Setpoint = " + temp.FormattedSetPointValue +
"]";
528 if (includeWaitState && !temp.
InRange)
530 result +=
" OUT OF RANGE";
533 if (includeGroup && !String.IsNullOrEmpty(temp.
Group))
535 result +=
" <Group=" + temp.Group +
">";
552 internal String GetBlockValue(String blockName)
554 if (!String.IsNullOrEmpty(blockName))
556 if (
_dict.Keys.Count != 0)
558 String lower = blockName.ToLower();
560 if (
_dict.Contains(lower))
567 return temp.CurrentValue;
582 internal String GetSetpointValue(String blockName)
584 if (!String.IsNullOrEmpty(blockName))
586 if (
_dict.Keys.Count != 0)
588 String lower = blockName.ToLower();
590 if (
_dict.Contains(lower))
597 return temp.SetPointValue;
607 #region IXmlSerializable Members
625 public void ReadXml(System.Xml.XmlReader reader)
629 XmlSerializer Serializer =
new XmlSerializer(typeof(
BlockInfo));
634 if (reader.Name ==
"BlockInfo")
637 while (reader.NodeType != XmlNodeType.EndElement)
641 entity = Serializer.Deserialize(reader) as
BlockInfo;
642 _dict.Add(entity.BlockName.ToLower(), entity);
643 reader.MoveToContent();
663 XmlSerializer Serializer =
new XmlSerializer(typeof(
BlockInfo));
665 foreach (
string key
in _dict.Keys)
669 Serializer.Serialize(writer,
_dict[key]);
677 #region ICloneable Members
687 if (
_dict.Keys.Count > 0)
691 for (
int i = 0; i < _dict.Count; ++i )
694 deepCopy.Add(blockclone.BlockName.ToLower(), blockclone);
Boolean Contains(String blockName)
Wrapper for standard Dictionary "Contains" All keys are lowercase.
void RemoveByVI(String fileName)
Remove block(s) by VI - may be more than one block. Used when a VI is removed from a configuration...
Boolean Replace(String oldName, String newName, BlockInfo newBlock)
Method for replacing a block in the dictionary. Keeps the existing key. First removes the old block...
Boolean Add(String blockName, BlockInfo block)
Wrapper for standard Dictionary "Add", but with additional checks: i) the key is not "" or null...
This class is used for storing the information for any blocks that are created and provides methods f...
void Insert(int index, String blockName, BlockInfo block)
void Clear()
Wrapper for standard Dictionary "Clear"
void ReadXml(System.Xml.XmlReader reader)
ReadXml - Default method of IXmlSerializable Used to read the block information from the configuratio...
object Clone()
Clone - Default method of ICloneable Used to clone (deep copy) the block dictionary. This allows for cancelling when editing the blocks.
void RemoveAt(int index)
Remove a block by index number, like a standard List. Looks up the key then calls remove by key...
void WriteXml(System.Xml.XmlWriter writer)
WriteXml - Default method of IXmlSerializable Used to write the block information to the configuratio...
void Remove(String blockName)
Wrapper for standard Dictionary "Remove" which removes by key.
System.Xml.Schema.XmlSchema GetSchema()
GetSchema - Default method of IXmlSerializable Not used.
Boolean IsAliasUnique(String alias)
Checks that the alias for the Block is unique. Note: Ignores case.
String[] GetKeys()
Gets a list of all the keys in the dictionary.
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
void Swap(int index1, int index2)
Swap the order of two blocks