Exemplo n.º 1
0
 private void LoadKeyTable(GXXmlReader reader)
 {
     KeyTable.Clear();
     if (reader.IsStartElement("KeyTable", true))
     {
         while (reader.IsStartElement("Item", true))
         {
             byte   k = (byte)reader.ReadElementContentAsInt("Key");
             byte[] d = GXDLMSTranslator.HexToBytes(reader.ReadElementContentAsString("Data"));
             KeyTable.Add(new GXKeyValuePair <byte, byte[]>(k, d));
         }
         reader.ReadEndElement("KeyTable");
     }
 }
Exemplo n.º 2
0
        static private KeyTable HashToKeyTable(KeyHash hash)
        {
            KeyTable result = new KeyTable();

            foreach (string key in hash.Keys)
            {
                List <List <KeyCode> > outMethods = new List <List <KeyCode> >();

                // 書式:A,B|C,D|E|F,G
                string keyMethod = hash[key] as string;

                List <string> keyMethodItems = new List <string>(keyMethod.Split(','));
                foreach (var methodItem in keyMethodItems)
                {
                    List <KeyCode> outCodes = new List <KeyCode>();
                    var            keyCodes = methodItem.Split('|');
                    foreach (var k in keyCodes)
                    {
                        // 文字列をKeyCodeに変換
                        if (k != "")
                        {
                            outCodes.Add((KeyCode)Enum.Parse(typeof(KeyCode), k));
                        }
                    }

                    if (outCodes.Count != 0)
                    {
                        outMethods.Add(outCodes);
                    }
                }

                result.Add(key.ToLower(), outMethods);
            }

            return(result);
        }
Exemplo n.º 3
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ShortAddress = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 3)
     {
         RcCoord = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 4)
     {
         PANId = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 5)
     {
         KeyTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 KeyTable.Add(new GXKeyValuePair <byte, byte[]>(Convert.ToByte(tmp[0]), (byte[])tmp[1]));
             }
         }
     }
     else if (e.Index == 6)
     {
         FrameCounter = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         ToneMask = (string)e.Value;
     }
     else if (e.Index == 8)
     {
         TmrTtl = Convert.ToByte(e.Value);
     }
     else if (e.Index == 9)
     {
         MaxFrameRetries = Convert.ToByte(e.Value);
     }
     else if (e.Index == 10)
     {
         NeighbourTableEntryTtl = Convert.ToByte(e.Value);
     }
     else if (e.Index == 11)
     {
         List <GXDLMSNeighbourTable> list = new List <GXDLMSNeighbourTable>();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[]             tmp = (object[])v;
                 GXDLMSNeighbourTable it  = new GXDLMSNeighbourTable();
                 it.ShortAddress       = Convert.ToUInt16(tmp[0]);
                 it.Enabled            = Convert.ToBoolean(tmp[1]);
                 it.ToneMap            = (string)tmp[2];
                 it.Modulation         = (Modulation)Convert.ToInt32(tmp[3]);
                 it.TxGain             = Convert.ToSByte(tmp[4]);
                 it.TxRes              = (GainResolution)Convert.ToInt32(tmp[5]);
                 it.TxCoeff            = (string)tmp[6];
                 it.Lqi                = Convert.ToByte(tmp[7]);
                 it.PhaseDifferential  = Convert.ToSByte(tmp[8]);
                 it.TMRValidTime       = Convert.ToByte(tmp[9]);
                 it.NeighbourValidTime = Convert.ToByte(tmp[10]);
                 list.Add(it);
             }
         }
         NeighbourTable = list.ToArray();
     }
     else if (e.Index == 12)
     {
         HighPriorityWindowSize = Convert.ToByte(e.Value);
     }
     else if (e.Index == 13)
     {
         CscmFairnessLimit = Convert.ToByte(e.Value);
     }
     else if (e.Index == 14)
     {
         BeaconRandomizationWindowLength = Convert.ToByte(e.Value);
     }
     else if (e.Index == 15)
     {
         A = Convert.ToByte(e.Value);
     }
     else if (e.Index == 16)
     {
         K = Convert.ToByte(e.Value);
     }
     else if (e.Index == 17)
     {
         MinCwAttempts = Convert.ToByte(e.Value);
     }
     else if (e.Index == 18)
     {
         CenelecLegacyMode = Convert.ToByte(e.Value);
     }
     else if (e.Index == 19)
     {
         FccLegacyMode = Convert.ToByte(e.Value);
     }
     else if (e.Index == 20)
     {
         MaxBe = Convert.ToByte(e.Value);
     }
     else if (e.Index == 21)
     {
         MaxCsmaBackoffs = Convert.ToByte(e.Value);
     }
     else if (e.Index == 22)
     {
         MinBe = Convert.ToByte(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Exemplo n.º 4
0
        private void EnsureChildSiteMapProviderUpToDate(SiteMapProvider childProvider)
        {
            SiteMapNode oldNode = (SiteMapNode)ChildProviderTable[childProvider];

            SiteMapNode newNode = childProvider.GetRootNodeCore();

            if (newNode == null)
            {
                throw new ProviderException(SR.GetString(SR.XmlSiteMapProvider_invalid_sitemapnode_returned, childProvider.Name));
            }

            // child providers have been updated.
            if (!oldNode.Equals(newNode))
            {
                // If the child provider table has been updated, simply return null.
                // This will happen when the current provider's sitemap file is changed or Clear() is called;
                if (oldNode == null)
                {
                    return;
                }

                lock (_lock) {
                    oldNode = (SiteMapNode)ChildProviderTable[childProvider];
                    // If the child provider table has been updated, simply return null. See above.
                    if (oldNode == null)
                    {
                        return;
                    }

                    newNode = childProvider.GetRootNodeCore();
                    if (newNode == null)
                    {
                        throw new ProviderException(SR.GetString(SR.XmlSiteMapProvider_invalid_sitemapnode_returned, childProvider.Name));
                    }

                    if (!oldNode.Equals(newNode))
                    {
                        // If the current provider does not contain any nodes but one child provider
                        // ie. _siteMapNode == oldNode
                        // the oldNode needs to be removed from Url table and the new node will be added.
                        if (_siteMapNode.Equals(oldNode))
                        {
                            UrlTable.Remove(oldNode.Url);
                            KeyTable.Remove(oldNode.Key);

                            UrlTable.Add(newNode.Url, newNode);
                            KeyTable.Add(newNode.Key, newNode);

                            _siteMapNode = newNode;
                        }

                        // First find the parent node
                        SiteMapNode parent = (SiteMapNode)ParentNodeTable[oldNode];

                        // parent is null when the provider does not contain any static nodes, ie.
                        // it only contains definition to include one child provider.
                        if (parent != null)
                        {
                            // Update the child nodes table
                            SiteMapNodeCollection list = (SiteMapNodeCollection)ChildNodeCollectionTable[parent];

                            // Add the newNode to where the oldNode is within parent node's collection.
                            int index = list.IndexOf(oldNode);
                            if (index != -1)
                            {
                                list.Remove(oldNode);
                                list.Insert(index, newNode);
                            }
                            else
                            {
                                list.Add(newNode);
                            }

                            // Update the parent table
                            ParentNodeTable[newNode] = parent;
                            ParentNodeTable.Remove(oldNode);

                            // Update the Url table
                            UrlTable.Remove(oldNode.Url);
                            KeyTable.Remove(oldNode.Key);

                            UrlTable.Add(newNode.Url, newNode);
                            KeyTable.Add(newNode.Key, newNode);
                        }
                        else
                        {
                            // Notify the parent provider to update its child provider collection.
                            XmlSiteMapProvider provider = ParentProvider as XmlSiteMapProvider;
                            if (provider != null)
                            {
                                provider.EnsureChildSiteMapProviderUpToDate(this);
                            }
                        }

                        // Update provider nodes;
                        ChildProviderTable[childProvider] = newNode;
                        _childProviderList = null;
                    }
                }
            }
        }