OPC Foundation Tree structure - treeview

I've been searching the web, but I can't figure out how to get a tree view of the items on an OPC server. I used the following code:
using Opc.Da;
using Server=Opc.Da.Server;
using Factory=OpcCom.Factory;
string urlstring = string.Format("opcda://{0}/{1}/{{{2}}}", _hostName, _serverName, serverid);
Server s = new Server(new Factory(), new URL(urlstring));
ItemIdentifier itemId = null;
BrowsePosition position;
BrowseFilters filters = new BrowseFilters() {BrowseFilter = browseFilter.item};
BrowseElement[] elements = s.Browse(itemId, filters, out position);

You do not state what precisely does not work. However, the main problems is probably in the fact that you are using BrowseFilter = browseFilter.item. The nodes in the tree are either leaves (sometimes called items), or branches. Your code only asks for the leafs, under the root of the tree. There may be no items under the root whatsoever, and you need to obtain the branches as well, and then dwelve deeper into the branches, recursively.
Start by changing your code to use BrowseFilter = browseFilter.all. This should give you all nodes under the root. Then, call the Browse recursively for the branches (just branches, not items) you receive, using the item ID of each branch as the starting point for the new browse.

Related

tfs How to Get Area Path (as string) from Area Id value

When i save workItem for the first time, I'm using TeamFoundationRequestContext to see values of some fields and do some validation.
Also i need to check AreaPath, but in RequestContext there is only areaId comes. So, maybe there is a TFS API to get AreaPath as string using Area ID. Thanks
You can simply get the Area Path by creating a query like:
Then select Area Path from query result.
Or you can query Area Path field for a work item with API:
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("URL"));
tfs.EnsureAuthenticated();
WorkItemStore workitemstore = tfs.GetService<WorkItemStore>();
var wr = workitemstore.GetWorkItem(ID);
foreach(Field f in wr.Fields)
{
if (f.Name == "Area Path")
{
Console.WriteLine(f.Value);
}
}
There isn't any easy way to get Area Path via Area ID.
The method you may use is query the Area Path via Area ID from SQL Database, however accessing to TFS SQL Database directly is not recommended.
And if you are using TFS2015, you can also use Rest API to get the node information. The information include the Area ID, you can then search the Area ID in it.
There are several ways to enumerate areas using the API:
This link describes accessing the areas using Project.AreaRootNodes (section 4).
This link describes enumerating the areas using the underlying XML structure.
The first approach returns a Node object that has both an Id property as a Path property, so you can map these.

Getting a level of an ALV tree node?

I created an ALV TREE report, using cl_gui_alv_tree, that has 3 levels. I'm also implementing an event handler for when he double clicks a node.
My problem is that I want to take some actions only when he double clicks a node that is a root node. The event 'node_double_click' gives a node_key, but that's the index of the displayed table. How could I achieve this?
The node ID is not an index, it's the ID you assigned to the node when adding it to the tree.
If possible, I'd suggest switching to CL_SALV_TREE - not only because it is documented
and supported by SAP, but also because it comes with some query methods that are quite handy. These methods are documented as well. You can use, for example, GET_NODE to retrieve a node by its ID and then use GET_PARENT to check whether the node in question is a top-level node or has a parent node it is attached to.
I created a pattern for myself, which i am using.
lv_parent1 = node_key.
while lv_parent1 ne go_Main_tree->C_VIRTUAL_ROOT_NODE.
CALL METHOD go_main_tree->get_parent
EXPORTING
i_node_key = lv_parent1
IMPORTING
e_parent_node_key = lv_parent1.
lv_hierlevel = lv_hierlevel + 1 .
ENDWHILE.
if lv_hierlevel > 2.
“ do what You want to do
endif.

can I manually set nodeId in neo4j graph on creation of a node?

I am developing a Facebook app in which I login with my Facebook account and Facebook returns me a JSON with my Facebook data as a JSON which I project into a User.class (me) like so:
#NodeEntity public class User{ #GraphId Long NodeId; String facebook_id; String facebook_name; }
and then I do a template.save(me);
this creates a node in the graph with 2 properties: Example: facebook_id="1000023453464" and name="John Smith" and the nodeId is set automatically by neo4j: Example nodeId:1.
The problem is that when I login again, it creates another node with same properties and nodeId:2.
I avoided this by checking if the user already exists in the graph before I saved it in the graph like so:
User retrieved_user = userRepository.findByFacebook_id(me.getFacebook_id());
if(retrieved_user != null) { me.setNodeId(retrieved_user.getNodeId()); }
Now, whenever I login, it doesn't create a duplicate node, it just updates the properties on the existing node.
But this is not what I'm looking for because when I import other data such as list of friends which can be about 1000 nodes to create, I don't want my app to check each individual node for his existence in the database before it saves it.
My point is: If there is a way in which I can manually set the nodeId before I template.save(me) the problem would be solved and my app would not have to check if the node exists in the graph. So if this is doable please help me achieve it. I tried for example the setHighId(215431323), but I get exceptions. I tried to #Override the IdGenerator, EntityIdGenerator, etc. but no success.
If there is another way in which I can save users without having to check if they exist and avoid duplicate nodes, please let me know.
I don't think there is a way to manually set the id. But even if there was, you still had to check if your node exists. Checking for the existence of a node is not that expensive anyway, it's just an index check, so it should be O(log n).

storing links of a site in a tree

I am trying to store the links that I scrape from a site in a non binary tree. The links are laid out hierarchically (obviously). The question is how do I generate the tree ? I mean, how am I going to work my way through the pages provided by the link so that I know who is who's child.
For now I can get the first and the second level of links, but have no idea how to go from here besides that I have to recursively have to build it and have a way to stop when I get to a leaf (which I have).
What I was thinking was something like (code in Python):
def buildTree(root):
for node in root.children:
if <end condition here>:
continue
else:
nodes = getNodes(urllib2.urlopen(node.url).read())
node.addChildren(nodes)
buildTree(node)
where root and nodes are a user defined Node class
Obviously, the links in a site are not a tree, but a graph. You should have a Page object, which is identified by a URL, and a Link object, which points from one page to another (and Page A can point to page B, while page B is pointing to Page A, making it a graph, instead of a tree).
Scanning algorithm pseudo-code:
process_page(current_page):
for each link on the current_page:
if target_page is not already in your graph:
create a Page object to represent target_page
add it to to_be_scanned set
add a link from current_page to target_page
scan_website(start_page)
create Page object for start_page
to_be_scanned = set(start_page)
while to_be_scanned is not empty:
current_page = to_be_scanned.pop()
process_page(current_page)

Column Tree Model doesn't expand node after EXPAND_NO_CHILDREN event

I am displaying a list of items using a SAP ABAP column tree model, basically a tree of folder and files, with columns.
I want to load the sub-nodes of folders dynamically, so I'm using the EXPAND_NO_CHILDREN event which is firing correctly.
Unfortunately, after I add the new nodes and items to the tree, the folder is automatically collapsing again, requiring a second click to view the sub-nodes.
Do I need to call a method when handling the event so that the folder stays open, or am I doing something else wrong?
* Set up event handling.
LS_EVENT-EVENTID = CL_ITEM_TREE_CONTROL=>EVENTID_EXPAND_NO_CHILDREN.
LS_EVENT-APPL_EVENT = GC_X.
APPEND LS_EVENT TO LT_EVENTS.
CALL METHOD GO_MODEL->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = LT_EVENTS
EXCEPTIONS
ILLEGAL_EVENT_COMBINATION = 1
UNKNOWN_EVENT = 2.
SET HANDLER GO_APPLICATION->HANDLE_EXPAND_NO_CHILDREN
FOR GO_MODEL.
...
* Add new data to tree.
CALL METHOD GO_MODEL->ADD_NODES
EXPORTING
NODE_TABLE = PTI_NODES[]
EXCEPTIONS
ERROR_IN_NODE_TABLE = 1.
CALL METHOD GO_MODEL->ADD_ITEMS
EXPORTING
ITEM_TABLE = PTI_ITEMS[]
EXCEPTIONS
NODE_NOT_FOUND = 1
ERROR_IN_ITEM_TABLE = 2.
It's been a while since I've played with SAP, but I always found the SAP Library to be particularly helpful when I got stuck...
I managed to come up with this one for you:
http://help.sap.com/saphelp_nw04/helpdata/en/47/aa7a18c80a11d3a6f90000e83dd863/frameset.htm, specifically:
When you add new nodes to the tree model, set the flag ITEMSINCOM to 'X'.
This informs the tree model that you want to load the items for that node on demand.
Hope it helps?
Your code looks fine,
I would use the method ADD_NODES_AND_ITEMS myself if I were to add nodes and items ;)
Beyond that, try to call EXPAND_NODE after you added the items/nodes and see if that helps.

Resources