I am trying to automate and create a Canoe simulation.
My usecase :
I have a configuration (LibraryTest.cfg) with a CAN Network and a node ACAN in the network. I want to create another node BCAN automatically into the existing configuration along with ACAN. I am trying this using C# .NET Canoe Library for this.
CANoe.Application mApp;
CANoe.Measurement mMsr;
CANoe.Networks mNet;
mApp = new CANoe.Application();
string ConfigFile=
"C:\\Users\\deepasreeraj\\Desktop\\GAC\\TestUnit1\\LibraryTest.cfg";
try
{
mApp.Open(ConfigFile, true, true);
mMsr = (CANoe.Measurement)mApp.Measurement;
mNet = mApp.Networks;
CANoe.Simulation mSim = mApp.Simulation;
if (mNet != null)
{
if(mNet != null)
{
int count = mNet.Count;
for (int i = 0; i < count; i++)
{
mNet.Add("BCAN");
string Nodename = mNet[i].NetworkInterfaces;
}
}
}
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
In this, while the code reaches mNet.Add("BCAN"); it gives an exception "The method or operation is not implemented." Can someone please help me with this?
If you want to add a node, the Networks property is wrong.
You have to use mApp.Configuration.SimulationSetup.Buses.Nodes. There you can call Add to add a new node.
Just check the page Technical References -> COM Interface -> Object Hierarchy in the CANoe help for the complete API Reference.
Related
I am trying to loop through all shapes in a document and check their "Alternate Text" which has had the source filename for that image recorded as it's alternate text. I need to read specific source images and convert them to a different image format.
I am able to get to the point of reading the AlternateText of the shape but it throws an exception:
'((Microsoft.Office.Interop.Word.Shape)(s)).AlternativeText' threw an exception of type 'System.Runtime.InteropServices.COMException'
When I set a breakpoint and view the "s" object, the majority of properties are throwing this exception, however some are not, for example I can read the LinkFormat property and a few others without issue, but the majority of properties throw an error.
Here is the code I am using:
Word.Application WordApp = new Word.Application();
d = WordApp.Documents.Open(#strFilename, ReadOnly: true, Visible: false);
int iReplacements = 0;
int iReplacementNoLink = 0;
foreach (Word.Shape s in d.Shapes)
{
Application.DoEvents();
try
{
if (s.LinkFormat.SourceName.ToString().Contains(".eps") || s.LinkFormat.SourceName.ToString().Contains(".png"))
{
iReplacements++;
}
if (s.AlternativeText != "")
{
iReplacementNoLink++;
}
}
catch (Exception fff)
{
Console.Write(fff);
}
}
The if statement checking the s.AlternateText always ends up in the catch.
I am using Visual Studio 2013 and I have Office 2007, I am not sure if that is relevant or not.
Can anyone tell me what I need to do to be able to read the Alternate Text of the shapes? If I am going about it in the wrong way or need to include a library or if I need to upgrade VS or Office? It seems like it should be really straight forward.
Thank you for any assistance you can provide.
I am unsure why this worked, but I was able to resolve this issue by using the "Select" method of the shape. Once the shape is selected the majority of the properties that previously were throwing errors are populated. There are still approximately 20 properties that thow the error, but I am now able to access things like "AlternativeText","Name","Callout" which were previously throwing the error.
Word.Application WordApp = new Word.Application();
d = WordApp.Documents.Open(#strFilename, ReadOnly: true, Visible: false);
int iReplacements = 0;
int iReplacementNoLink = 0;
foreach (Word.Shape s in d.Shapes)
{
Application.DoEvents();
try
{
//if (s.Type == Microsoft.Office.Core.MsoShapeType.msoLinkedPicture)
if (s.LinkFormat.SourceName.ToString().Contains(".eps") || s.LinkFormat.SourceName.ToString().Contains(".png"))
{
iReplacements++;
}
s.Select();
if (s.AlternativeText != "" && s.AlternativeText != null)
{
iReplacementNoLink++;
}
}
catch (Exception fff)
{
Console.Write(fff);
}
}
I have an mxd file that I've loaded into ArcMap. When finished loading, there are several layers; some of which that have multiple feature classes. The end result is listing all the filepaths/locations/source of each feature class, but for now, I just need to know how to list all the feature classes that are loaded. And when I say list, they can really just be output to the screen via message boxes. I know I'll need to loop through each layer, but utilizing the right interface and accessing ArcMaps properties is where I get lost.
Any help on this would be greatly appreciated. I'm still learning ArcObjects and how it all works and in desperate need of help. Thanks in advance.
This would be an example in C# to loop through all layers and if it's a feature layer, get until the workspace to get the path or whatever from it:
/* Make a list of all feature classes. */
List<ILayer> layers_list = new List<ILayer>();
IMap map = get_map();
IEnumLayer enumLayer = map.get_Layers(null, true);
ILayer layer = null;
while (layer = enumLayer.Next() != null) {
// we're looking for a feature class only
if (layer is IFeatureLayer) {
try {
IFeatureClass fclass = ((IFeatureLayer)layer).FeatureClass;
IFeatureLayer featureLayer = (IFeatureLayer)layer;
// Get the dataset and workspace of the feature class
IDataset ds = (IDataset)fclass;
IWorkspace ws = (IWorkspace)ds.Workspace;
// Do something with the workspace, like getting the path or
// whatever...
} catch (Exception e) {
MessageBox.Show("Layer ' " + layer.Name + "': \n\n" + e.Message);
}
}
}
We're creating a WPF app in which we execute python scripts from different Test Stations and show the output in its corresponding output panel, To run the scripts in parallel we are using Task but when we run the scripts in parallel from the stations, We are getting the output of other stations also into the station that is started first, we're using the following code,
private void ZmqStatusListener(string endPoint)
{
using (Context context = new Context())
{
StatusPort = string.Empty;
TestResultPort = string.Empty;
using (Socket server = context.Socket(SocketType.REP))
{
try
{
if (isStatusContextActive == false || isPortChanged == true)
{
server.Bind(endPoint);
isStatusContextActive = true;
}
}
catch (ZMQ.Exception ex)
{
if (ex.Errno != 100)
{
string IPCPort = _globalParameters.GlbParam.GlbParamIpcStartPort;
if (IPCPort == string.Empty)
{
IPCPort = "0";
}
if (endPoint == EditorConstants.PortAddress.PortPrefix + IPCPort)
{
StatusPort = endPoint;
TestReultError = EditorConstants.CommonMessageTypes.TestReultError + ex.Message + EditorConstants.CommonMessageTypes.StackTraceMessage + ex.StackTrace;
}
StopExecOfScript(default(object));
isCancelledtask = true;
ScriptStatusDesc = new ScriptStatusDesc()
{
Status = "Failed",
statusDescription = "Failed"
};
}
}
while (true)
{
string message = server.Recv(Encoding.UTF8);
UpdateTestResults(message);
server.Send(" ACK", Encoding.UTF8);
// if (message == "Test Passed")
//break;
}
}
}
}
and for testing purpose we're breaking the while loop in this code based on a test message we kept in the python script, then we are able to get the output in the respective station correctly but this way we can only run in a synchronous fashion which we don't want as we require to run the test stations in parallel and the while loop should not break as it should be listening for the response.
We were able to solve the issue by getting clues doing a sample app to reproduce the issue and to first know whether our ClrZmq pattern was correct for us or not and it is correct. The resolution we followed is that when we needed to bind that data to its corresponding View's Model object in its ViewModel so had to retrieve View's DataContext which is of Type ISomeXViewModel for the particular TestStation using an Id of that TestStation we did this cos all of our TestStations are dynamically added and we even store it to be accessed wherever necessary. This issue was caused to due multiple instances of UserControls so we explicitly needed to update the TestStation manually with a little more effort.
Sample Code Snippet
private void BindTestResult(string xmlPayLoad)
{
// converting xmlPalLoad to a class/model object
ITestStationViewModel viewModel = (ITestStationViewModel)((IView)DynamicTestStationsGrid.Children[StationNumber].Content).DataContext;
// IView class has DataContext property so I am type casting the Content which is ContentControl to IView type first and later to ITestStationViewModel
viewModel.TestStationModel = xmlPayLoadModel;
}
Thanks.
I've searched far and wide, and I haven't found a proper solution yet.
First off, this is a WinForms application using .NET 4.0 and DevExpress.
I've been attempting to retrieve Building Blocks (Watermarks, Cover Pages etc) from Word documents (.docx), or at least user generated template files (.dotx), that a user uploads to my application, which will then be saved to a database.
I must be able to retrieve all the Building Blocks used in that file.
I have tried a lot of different ways of retrieving them, but I can only retrieve them from the Built-In Building Blocks.dotx file, located in:
C:\Users\<username>\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Built-In Building Blocks.dotx
I haven't figured out how to extract them from a user generated file.
Here is work in progress code I've been using (many iterations so I can easily debug it):
private void SaveBuildingBlock(string savedFile)
{
try
{
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = null;
wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDocument = wordApplication.Documents.OpenNoRepairDialog(savedFile);
object missing = System.Type.Missing;
Database.ToolbarItemsWordInsertFileData.FileData = FileHandler.FileByteLocked(savedFile);
Database.ToolbarItemsWordInsertFileData.Id = 0;
Database.ToolbarItemsWordInsertFileData.ToolbarItemId = ToolbarId;
Database.ToolbarItemsWordInsertFileData.Save();
ListBuildingBlocks(wordApplication, wordPage);
}
catch (Exception err)
{
Logger.Log(err);
}
}
Next method:
private void ListBuildingBlocks(Microsoft.Office.Interop.Word.Application wordApplication, WordPages wordPage)
{
Microsoft.Office.Interop.Word.WdBuildingBlockTypes type = wordPage == WordPages.CoverPage ? type = Microsoft.Office.Interop.Word.WdBuildingBlockTypes.wdTypeCoverPage : type = Microsoft.Office.Interop.Word.WdBuildingBlockTypes.wdTypeWatermarks;
for (int i = 1; i <= wordApplication.Templates.Count; i++)
{
try
{
if (wordApplication.Templates[i] != null)
{
Microsoft.Office.Interop.Word.Categories categories = wordApplication.Templates[i].BuildingBlockTypes.Item(type).Categories;
for (int c = 1; c <= categories.Count; c++)
{
try
{
//Category cat = categories.Application[0];
Microsoft.Office.Interop.Word.BuildingBlocks buildingBlocks = wordApplication.Templates[i].BuildingBlockTypes.Item(type).Categories.Item(categories.Item(c).Name).BuildingBlocks;
for (int b = 1; b <= buildingBlocks.Count; b++)
{
try
{
Microsoft.Office.Interop.Word.BuildingBlock buildingBlock = buildingBlocks.Item(b);
if (buildingBlock != null)
{
//saving to database occurs here
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
The WordPages parameter [wordPage] is used in the application to specify if it's a Watermark or Cover Page (it's a property in this user control).
You need to add it to the current list of add-ins, then you can open it as a template for working with building blocks. Apart from changing the attached template and loading it that way, I don't see any other way of doing this:
Dim app = Globals.ThisAddIn.Application
'load the file containing the building blocks
app.AddIns.Add("\\Path to File.dotx")
'get the object for the loaded template
Dim template = app.Templates(app.AddIns.Count)
'go through each building block in the file
For I = 1 to template.BuildingBlockEntries.Count
Dim bb = template.BuildingBlockEntries.Item(i)
Next
If you need to go down the xml route, the building blocks are stored inside the package in word\glossary\document.xml which is probably easier if you are doing this server side then you wont need to work with the word object model at all, just use the Open Xml SDK, it's pretty useful for things like this!
Sorry to put up yet another recursion question, but I've looked over a fair few on here and haven't found the solution for my problem.
I use the below function:
unsafe
{
// Allocate global memory space for the size of AccessibleContextInfo and store the address in acPtr
IntPtr acPtr = Marshal.AllocHGlobal(Marshal.SizeOf(new AccessibleContextInfo()));
try
{
Marshal.StructureToPtr(new AccessibleContextInfo(), acPtr, true);
if (WABAPI.getAccessibleContextInfo(vmID, ac, acPtr))
{
acInfo = (AccessibleContextInfo)Marshal.PtrToStructure(acPtr, typeof(AccessibleContextInfo));
if (!ReferenceEquals(acInfo, null))
{
AccessibleTextItemsInfo atInfo = new AccessibleTextItemsInfo();
if (acInfo.accessibleText)
{
IntPtr ati = Marshal.AllocHGlobal(Marshal.SizeOf(new AccessibleTextItemsInfo()));
WABAPI.getAccessibleTextItems(vmID, ac, ati, 0); //THIS IS WHERE WE DO IT
atInfo = (AccessibleTextItemsInfo)Marshal.PtrToStructure(ati, typeof(AccessibleTextItemsInfo));
if (ati != IntPtr.Zero)
{
Marshal.FreeHGlobal(ati);
}
}
AccessibleTreeItem newItem = BuildAccessibleTree(acInfo, atInfo, parentItem, acPtr);
newItem.setAccessibleText(atInfo);
if (!ReferenceEquals(newItem, null))
{
for (int i = 0; i < acInfo.childrenCount; i++)
{
//Used roles = text, page tab, push button
if (acInfo.role_en_US != "unknown" && acInfo.states_en_US.Contains("visible")) // Note the optomization here, I found this get me to an acceptable speed
{
AccessibleContextInfo childAc = new AccessibleContextInfo();
IntPtr childContext = WABAPI.getAccessibleChildFromContext(vmID, ac, i);
GetAccessibleContextInfo(vmID, childContext, out childAc, newItem);
if (childContext != IntPtr.Zero)
{
Settings.Save.debugLog("Releasing object " + childContext.ToString() + " from JVM: " + vmID);
WABAPI.releaseJavaObject(vmID, childContext);
childContext = IntPtr.Zero;
}
}
}
}
return newItem;
}
}
else
{
acInfo = new AccessibleContextInfo();
}
}
finally
{
if (acPtr != IntPtr.Zero)
Marshal.FreeHGlobal(acPtr);
}
}
return null;
}
To build an AccessibleTreeItem representing the entire GUI of a Java application. However, this function takes 5-6 seconds to run. I'm only looking for one particular subsection of the tree (Lets call it Porkchops).
What I'd like to do is prior to building the tree, get the values and as soon as acRole.name == "Porkchop", use that as the parent object and create an AccessibleTreeItem that represents the subtree.
How on earth do I manage this? If this is a simple question, apologies, but it's driving me crazy.
Edit 1 - The performance hit is encountered on releaseJavaObject(), as when I remove that line the function completes in less than a second, but it creates a horrible memory leak.
Therefore, I'm not really looking for alternative solutions, as I know that the above does work correctly. I just need some way to check the value of acInfo.name prior to creating the tree, and then using the correct acInfo node as the parent.
Edit 2 - See the attached image for a better explanation than my rambling. Currently, the function will pull this entire tree from the JVM. I've highlighted the appropriate section that I work with, and would like to know if there's a way that will allow me to get that information, without building the entire tree. Or even if I could just return the tree once all children of that node have been populated.