AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 03.07.2009, 07:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,626 / 848 (80) +++++++
Регистрация: 28.10.2006
dynamic-ax.co.uk: Dynamics AX: Counting Lines of Code – Mohammed Rasheed
Источник: http://dynamic-ax.spaces.live.com/Bl...4DE3!426.entry
==============

 


It recently downed upon me that I do not have an account of the number of lines of code I have written on my vpc (my Dynamics AX Playground!!).... Unfortunately I could not find an easy way to get an accurate count of the lines of code I wrote.. Hence i wrote some more code :)
Its like writing code to count code!!
Hope this is of help to others out there.. asking themselves the same question.
X++:
class mrCountLinesOfCode 
{ 
Map axTypeCount; 
Map mrTypeCount; 
MapEnumerator axEnumerator; 
MapEnumerator mrEnumerator; 
str fullPath; 
int pos; 
int total; 
int linesOfCode; 
} 
void run() 
{ 
TreeNodeiterator tempNodeIterator; 
TreeNodeiterator treeNodeIterator; 
TreeNodeiterator rootNodeIterator; 
TreeNodeiterator childNodeiterator; 
str type; 
TreeNode treeNode; 
TreeNode rootNode; 
TreeNode childNode; 
TreeNode tempNode; 
; 
#AOT 
rootNode = TreeNode::rootNode(); 
rootNodeIterator = rootNode.AOTiterator(); 
rootNode = rootNodeIterator.next(); 
axTypeCount = new Map(types::String,types::Integer); 
mrTypeCount = new Map(types::String,types::Integer); 
while(rootNode) 
{ 
type = rootNode.treeNodeName(); 
rootNodeIterator = rootNode.AOTiterator(); 
childNode = rootNodeIterator.next(); 
childNodeIterator = childNode.AOTiterator(); 
treeNode = childNodeIterator.next(); 
while(childNode) 
{ 
tempNode = treeNode; 
tempNodeiterator = tempNode.AOTiterator(); 
while(treeNode) 
{ 
// loop till you get to a leaf node - as methods are leafs 
while(treeNode.AOTchildNodeCount() > 0) 
{ 
if(treeNode.AOTiterator().next().AOTchildNodeCount()> 0) 
treeNode = tempNodeiterator.next(); 
if(!treeNode) 
treeNode = tempNode; 
tempNode = treeNode; 
treeNode = treeNode.AOTiterator().next(); 
if(!treeNode) 
treeNode = tempNode; 
} 
// so we found a Lefe. check if its a method 
if(sysTreeNode::hasSource(treeNode)) 
{ 
tempNodeiterator = tempNode.AOTiterator(); 
while(treeNode) 
{ 
treeNode = tempNodeiterator.next(); // iterate first. 
this.setCount(treeNode,type); 
} 
treeNode = tempNodeiterator.next(); 
if(!treeNode) 
{ 
treeNode = childNodeIterator.next(); 
if(!treeNode) 
{ 
childNode = rootNodeIterator.next(); 
childNodeIterator = childNode.AOTiterator(); 
treeNode = childNodeIterator.next(); 
} 
tempNode = treeNode; 
tempNodeiterator = tempNode.AOTiterator(); 
} 
}// end if Has Source 
else 
treeNode = tempNodeiterator.next(); // leaf is not a method.. hence move to the next node 
} 
//childNode = rootNodeIterator.next(); 
treeNode = childNodeIterator.next(); 
if(!treeNode) 
{ 
childNode = rootNodeIterator.next(); 
while(childNode && !this.checkIfNodeMightHaveCode(childNode.sysNodeType())) 
{ 
childNode = rootNodeIterator.next(); 
} 
if(childNode) 
{ 
childNodeIterator = childNode.AOTiterator(); 
treeNode = childNodeIterator.next(); 
} 
} 
} 
childNode = rootNodeIterator.next(); 
rootNode = childNode; 
}// end root while 
this.printitOut(); 
} 
void setCount(treeNode _treeNode,str _type) 
{ 
int tempLines; 
; 
fullPath = sysTreeNode::getPath(_treeNode); 
pos = 0; 
pos = strScan(fullPath,'\mr',1,strlen(fullPath)); //i always prefix any new elements i create with MR 
tempLines = this.getLinesOfCode(_treeNode.AOTgetSource()); 
if(tempLines > 4) 
{ 
if(pos) 
this.countMrLines(tempLines,_type); 
else 
this.countAXLines(tempLines,_type); 
} 
} 
int getLinesOfCode(Source _source) 
{ 
Source tmpSource; 
Line line; 
int ptr; 
int numberOfLines; 
; 
if (_source) 
{ 
tmpSource = _source; 
while (tmpSource) 
{ 
line++; 
ptr = strfind(tmpSource, '\n', 1, maxint()); 
if (!ptr) 
{ 
ptr = strlen(tmpSource); 
} 
numberOfLines++; 
tmpSource = strdel(tmpSource, 1, ptr); 
} 
} 
return numberOfLines; 
} 
int getLinesOfCode(Source _source) 
{ 
Source tmpSource; 
Line line; 
int ptr; 
int numberOfLines; 
; 
if (_source) 
{ 
tmpSource = _source; 
while (tmpSource) 
{ 
line++; 
ptr = strfind(tmpSource, '\n', 1, maxint()); 
if (!ptr) 
{ 
ptr = strlen(tmpSource); 
} 
numberOfLines++; 
tmpSource = strdel(tmpSource, 1, ptr); 
} 
} 
return numberOfLines; 
} 
void countMrLines(int _lines,str _type) 
{ 
; 
linesOfCode = 0; 
if(mrTypeCount.exists(_type)) 
linesOfCode = mrTypeCount.lookup(_type); 
linesOfCode += _lines; 
mrTypeCount.insert(_type,linesOfCode); 
} 
boolean checkIfNodeMightHaveCode(int _sysNodeType) 
{ 
; 
#TreeNodeSysNodeType 
switch(_sysNodeType) 
{ 
case #SysNodeTypeTableCollection : 
case #SysNodeTypeSystemEnum : 
case #NT_DBCOLLECTIONLIST : 
case #NT_DBFIELDGROUPLIST : 
case #NT_DBENUMLIST : 
case #NT_DBREFERENCELIST : 
case #NT_CONFIGURATIONKEYLIST : 
case #NT_SECURITYKEYLIST : 
case #NT_DBLICENSECODELIST : 
case #NT_MENU : 
case #NT_DBLICENSECODE : 
case #NT_CONFIGURATIONKEY : 
case #NT_SECURITYKEY : 
case #NT_TYPE : 
case #NT_REFERENCE : 
case #NT_PERSPECTIVE : 
case #NT_PERSPECTIVEFIELDLIST : 
return false; 
default: 
return true; 
} 
// just in case 
return true; 
}
  Technorati Tags: Dynamics AX 2009,Dynamics AX Code,TreeNode


Источник: http://dynamic-ax.spaces.live.com/Bl...4DE3!426.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
gatesasbait: Dynamics AX 2009 SSRS and SSAS Integration Tips Blog bot DAX Blogs 3 09.07.2009 13:07
Developer for Microsoft Dynamics AX Certification Roadmap Blog bot DAX Blogs 1 13.05.2009 16:17
AX UK: Microsoft Dynamics AX 3.0 to 2009 Data and Code Upgrade Training Blog bot DAX Blogs 1 03.02.2009 11:15
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:30.