I have legacy code and I would like to know what is the best way to create a AFSite programmatically in C# using AFSDK v4.
Do you mean a website using AF SDK? If so, here is a link.
ASP.NET MVC 5 with PI AF SDK: Part 1 - Introduction
My bad, I meant to say an AF hierarchy.
Would you like to create a whole new hierarchy programmatically or import programmatically from an XML file a hierarchy that you already have?
I am actually want to create the whole hierarchy programmatically, I have been trying to use Automapper, since I have a several legacy classes that hold the AFElement.Attraibute[x] values, but I have not been able to map my existing Objects to AFElement.Attributes.
Your question is similar to what is discussed in this thread
How to create a AF Hierarchy from a Business Production Hierarchy in SQL Server.
I would also recommend this workshop if you want to familiarize yourself with AF SDK.
Also, I suppose that your legacy code is in PI SDK?
Retrieving data ...