public override void Analyze()
        {
            this.childScalarNodes.Clear();

            // delegate analyze (don't use enumerator because the child node may change our child collection by e.g. removing or replacing itself)
            for (int i = this.ChildNodes.Count - 1; i >= 0; i--)
            {
                this.ChildNodes[i].Analyze();
            }

            // collect scalar nodes
            foreach (SnmpNode childNode in this.childNodes)
            {
                SnmpScalarNode scalarNode = childNode as SnmpScalarNode;
                if (scalarNode != null)
                {
                    this.childScalarNodes.Add(scalarNode);
                }
            }

            base.Analyze();

            // check if we can merge this node to a scalar array node (all childs need to be scalars)
            if (this.childNodes.Count > 0)
            {
                if (LwipOpts.GenerateScalarArrays && (this.childScalarNodes.Count == this.childNodes.Count) && (this.ParentNode != null))
                {
                    SnmpScalarArrayNode scalarArrayNode = new SnmpScalarArrayNode(this.childScalarNodes, this.ParentNode);
                    scalarArrayNode.Oid  = this.Oid;
                    scalarArrayNode.Name = this.Name;
                    scalarArrayNode.Analyze();

                    for (int i = 0; i < this.ParentNode.ChildNodes.Count; i++)
                    {
                        if (this.ParentNode.ChildNodes[i] == this)
                        {
                            this.ParentNode.ChildNodes.RemoveAt(i);
                            this.ParentNode.ChildNodes.Insert(i, scalarArrayNode);
                            break;
                        }
                    }
                }
                else if (LwipOpts.GenerateSingleAccessMethodsForTreeNodeScalars && (this.childScalarNodes.Count > 1))
                {
                    foreach (SnmpScalarNode scalarNode in this.childScalarNodes)
                    {
                        scalarNode.UseExternalMethods = true;
                        scalarNode.ExternalGetMethod  = this.GetMethodName;
                        scalarNode.ExternalTestMethod = this.TestMethodName;
                        scalarNode.ExternalSetMethod  = this.SetMethodName;
                    }
                }
            }
            else             // if (this.childNodes.Count == 0)
            {
                if (!LwipOpts.GenerateEmptyFolders && (this.ParentNode != null))
                {
                    // do not generate this empty folder because it only waste (static) memory
                    for (int i = 0; i < this.ParentNode.ChildNodes.Count; i++)
                    {
                        if (this.ParentNode.ChildNodes[i] == this)
                        {
                            this.ParentNode.ChildNodes.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
		public override void Analyze()
		{
			this.childScalarNodes.Clear();

			// delegate analyze (don't use enumerator because the child node may change our child collection by e.g. removing or replacing itself)
			for (int i=this.ChildNodes.Count-1; i>=0; i--)
			{
				this.ChildNodes[i].Analyze();
			}

			// collect scalar nodes
			foreach (SnmpNode childNode in this.childNodes)
			{
				SnmpScalarNode scalarNode = childNode as SnmpScalarNode;
				if (scalarNode != null)
				{
					this.childScalarNodes.Add(scalarNode);
				}
			}

			base.Analyze();

			// check if we can merge this node to a scalar array node (all childs need to be scalars)
			if (this.childNodes.Count > 0)
			{
				if (LwipOpts.GenerateScalarArrays && (this.childScalarNodes.Count == this.childNodes.Count) && (this.ParentNode != null))
				{
					SnmpScalarArrayNode scalarArrayNode = new SnmpScalarArrayNode(this.childScalarNodes, this.ParentNode);
					scalarArrayNode.Oid  = this.Oid;
					scalarArrayNode.Name = this.Name;

					for (int i=0; i<this.ParentNode.ChildNodes.Count; i++)
					{
						if (this.ParentNode.ChildNodes[i] == this)
						{
							this.ParentNode.ChildNodes.RemoveAt(i);
							this.ParentNode.ChildNodes.Insert(i, scalarArrayNode);
							break;
						}
					}
				}
				else if (LwipOpts.GenerateSingleAccessMethodsForTreeNodeScalars && (this.childScalarNodes.Count > 1))
				{
					foreach (SnmpScalarNode scalarNode in this.childScalarNodes)
					{
						scalarNode.UseExternalMethods = true;
						scalarNode.ExternalGetMethod  = this.GetMethodName;
						scalarNode.ExternalTestMethod = this.TestMethodName;
						scalarNode.ExternalSetMethod  = this.SetMethodName;
					}
				}
			}
			else // if (this.childNodes.Count == 0)
			{
				if (!LwipOpts.GenerateEmptyFolders && (this.ParentNode != null))
				{
					// do not generate this empty folder because it only waste (static) memory
					for (int i=0; i<this.ParentNode.ChildNodes.Count; i++)
					{
						if (this.ParentNode.ChildNodes[i] == this)
						{
							this.ParentNode.ChildNodes.RemoveAt(i);
							break;
						}
					}
				}
			}
		}