00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stdafx.h"
00023 #include <Console.h>
00024 #include <Formatter.h>
00025 #include "BON2Component.h"
00026 #include "networkingBonX.h"
00027
00028 namespace BON
00029 {
00030
00031
00032
00033
00034
00035
00036
00037 Component::Component()
00038 : m_bIsInteractive( false )
00039 {
00040 }
00041
00042 Component::~Component()
00043 {
00044 if ( m_project ) {
00045 m_project->finalizeObjects();
00046 finalize( m_project );
00047 m_project = NULL;
00048 }
00049 }
00050
00051
00052
00053
00054
00055 void Component::initialize( Project& project )
00056 {
00057 }
00058
00059 static CString operator+(const CString& A, const std::string& B)
00060 {
00061 return A + B.c_str();
00062 }
00063
00064 static CString MakeHyperlink(BON::Object& obj)
00065 {
00066 return GMEConsole::Formatter::MakeObjectHyperlink(obj->getName().c_str(), obj->getID().c_str());
00067 }
00068
00069 void Component::ProcessDiagram(Networking::NetDiagram& diagram)
00070 {
00071 using namespace GMEConsole;
00072
00073 Console::Out::WriteLine(CString("Network ") + diagram->getName());
00074
00075 std::set<Networking::NetDiagram> childDiagrams = diagram->getNetDiagram();
00076 for (std::set<Networking::NetDiagram>::iterator it = childDiagrams.begin(); it != childDiagrams.end(); it++) {
00077 ProcessDiagram(*it);
00078 }
00079
00080 std::set<Networking::Router> childRouters = diagram->getRouter();
00081 for (std::set<Networking::Router>::iterator it = childRouters.begin(); it != childRouters.end(); it++) {
00082 ProcessRouter(*it);
00083 }
00084 Console::Out::WriteLine(CString());
00085 }
00086
00087 void Component::ProcessRouter(Networking::Router& router) {
00088 using namespace GMEConsole;
00089
00090 Console::Out::WriteLine(CString(" Router ") + MakeHyperlink(router));
00091
00092 std::set<Networking::Port> ports = router->getPort();
00093 for (std::set<Networking::Port>::iterator it = ports.begin(); it != ports.end(); it++) {
00094 Networking::Port port = *it;
00095
00096 std::string iftype = (*it)->getAttribute("IFType")->getStringValue();
00097 double ifspeed = port->getIFSpeed();
00098 std::string ipaddr = port->getIPAddress();
00099 Console::Out::WriteLine(CString(" Port ") + MakeHyperlink(port) +
00100 "(" + iftype + "; " + CComVariant(ifspeed) + "Kbps), Addr: " + ipaddr );
00101
00102 std::multiset<Networking::GenNet> dsts = port->getConnectionDsts();
00103 for (std::multiset<Networking::GenNet>::iterator it2 = dsts.begin(); it2 != dsts.end(); it2++) {
00104 Console::Out::WriteLine(CString(" Connected to ") +
00105 (*it2)->getObjectMeta().name() + " " + MakeHyperlink(*it2));
00106 }
00107 }
00108
00109 }
00110
00111
00112
00113
00114
00115
00116 void Component::finalize( Project& project )
00117 {
00118
00119
00120 }
00121
00122
00123
00124
00125
00126 void Component::invoke( Project& project, const std::set<FCO>& setModels, long lParam )
00127 {
00128 #ifdef SUPPORT_OLD_INVOKE
00129 Object focus;
00130 invokeEx( project, focus, setModels, lParam );
00131 #else
00132 if ( m_bIsInteractive )
00133 AfxMessageBox("This BON2 Component does not support the obsolete invoke mechanism!");
00134 #endif
00135 }
00136
00137
00138
00139
00140
00141 void Component::invokeEx( Project& project, FCO& currentFCO, const std::set<FCO>& setSelectedFCOs, long lParam )
00142 {
00143 #ifdef GME_ADDON
00144 project->setAutoCommit( false);
00145 #endif
00146 using namespace GMEConsole;
00147 Console::Out::WriteLine("Interpreter started...");
00148
00149 Console::Out::WriteLine(CString("Router list for network ") + project->getRootFolder()->getName());
00150 std::set<BON::Object> diagrams = project->getRootFolder()->getChildObjects("NetDiagram");
00151 for (std::set<BON::Object>::iterator it = diagrams.begin(); it != diagrams.end(); it++) {
00152 Networking::NetDiagram diagram = *it;
00153 ProcessDiagram(diagram);
00154 }
00155
00156 Console::Out::WriteLine("Interpreter completed...");
00157 }
00158
00159
00160
00161
00162
00163 void Component::objectInvokeEx( Project& project, Object& currentObject, const std::set<Object>& setSelectedObjects, long lParam )
00164 {
00165 if ( m_bIsInteractive )
00166 AfxMessageBox("This BON2 Component does not support objectInvokeEx method!");
00167 }
00168
00169
00170
00171
00172 Util::Variant Component::getParameter( const std::string& strName )
00173 {
00174
00175
00176
00177 return Util::Variant();
00178 }
00179
00180 void Component::setParameter( const std::string& strName, const Util::Variant& varValue )
00181 {
00182
00183
00184 }
00185
00186 #ifdef GME_ADDON
00187
00188
00189
00190
00191 void Component::globalEventPerformed( globalevent_enum event )
00192 {
00193
00194
00195 }
00196
00197
00198
00199
00200 void Component::objectEventPerformed( Object& object, unsigned long event, VARIANT v )
00201 {
00202
00203
00204 }
00205
00206 #endif // GME_ADDON
00207
00208 };
00209