Jay5962

AFsdk a tad bit slower than i was expecting

Discussion created by Jay5962 on Dec 11, 2009
Latest reply on Dec 11, 2009 by spilon

I've got an interesting one here, I've put together a pretty stock webservice that extracts all attributes and elements to an associated GUID. The problem is the first time I connect to a element it takes a long time to traverse the structure and return the values. Why does the ADSKF take in excess of 20 seconds to return a 50element/attribute list. I noticed a similar problem in the PI system explorer, it takes a long time when you view all the attributes in a element for the first time. Any Ideas on why AF’s performance is not as slick as I expect it to be? Or even better does someone have some routines to optimize AF?

public Service ()  
{
    ConnectAF();
}

private void ConnectAF()
{
    try
    {
        NetworkCredential myCred = new NetworkCredential(".....................", "..............");
        myPISystems.DefaultPISystem.PISystem.Connect(myCred);
        myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase;
        TextLogger.WriteLine("ConnectAF: " + DateTime.Now + " [Information] WebService Connected to AF Server");
    }
    catch (Exception ex)
    {
        TextLogger.WriteLine("ConnectAF: " + DateTime.Now + " [Error] " + ex.Message);
    }
}

Now the function that extracts elements and attributes

[WebMethod(CacheDuration=500)]
[XmlInclude(typeof(AFnode))]
public  ArrayList  GetAFgroups(string  _GUID)
{
    try
    {
        Guid GUID = new Guid(_GUID); 
        myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase;
        const int MaxCount = 100;
        AFNamedCollectionList<AFElement> myElements;
        AFElement myRoot1 = AFElement.FindElement(myDB.PISystem, GUID);
        myElements = AFElement.FindElements(myDB, myRoot1, "*", AFSearchField.Name, false,
                AFSortField.Name, AFSortOrder.Descending, MaxCount);
        ArrayList newList =   GetAFelement(myElements);

        try
        {
            string AttributeParent = myRoot1.Attributes["ObjectName"].GetValue().ToString();
            newList = GetAFattribute(myRoot1.Attributes, AttributeParent, newList);
        }
        catch (Exception ex)
        {
            //TextLogger.WriteLine("GetAFelement: " + A1.Text + " - " + ex.Message);  
            newList = GetAFattribute(myRoot1.Attributes, "", newList);
        }

        return newList; 
        //myPISystems.DisconnectAll();
    }
    catch (Exception ex)
    {
        TextLogger.WriteLine("GetAFgroups: " + DateTime.Now + " [Error] " + ex.Message);
        return null; 
    }
}

private ArrayList GetAFelement(IEnumerable<AFElement> myElements)
{
    ArrayList AFroot = new ArrayList();
    AFnode AFNode;
    foreach (AFElement CurElement in myElements)
    {
        AFNode = new AFnode();
        AFNode.Type = "G";
        AFNode.Name = CurElement.Name;
        AFNode.ID = CurElement.ID.ToString() ;
        AFNode.Description = CurElement.Description;
        if (CurElement.HasChildren == false)
        {
            AFNode.HasChildren = HasAFattribute(CurElement.Attributes);
        }
        else
        {
            AFNode.HasChildren = CurElement.HasChildren;
        }

        AFroot.Add(AFNode);

    }

    return AFroot;
}

private  ArrayList GetAFattribute(AFAttributes CurElement, string AttributeParent, ArrayList TagsGroups)
{
    AFnode AFNode;
    foreach (AFAttribute CurAttribute in CurElement)
    {
        if (CurAttribute.DataReference != null)
        {
            if (CurAttribute.DataReference.Name.ToString() == "PI Point")
            {
                AFNode = new AFnode();
                AFNode.Name = AttributeParent + CurAttribute.Name;
                AFNode.ID = CurAttribute.ID.ToString();
                AFNode.Description = CurAttribute.Description;
                AFNode.HasChildren = false;
                AFNode.Type = "T";
                TagsGroups.Add(AFNode);    
            }
        }
    }

    return TagsGroups;
}

Outcomes