c# Trying to call a file, filenotfound exception. Is it the VMWare? - streamreader

This is a really beginner question, I'm trying to read a file and write a JSON, but I keep getting "filenotfound" exception in visual studio. I'm using VMWARE windows 10, and I'm confused about how to establish the directory using VMWare. Maybe it's more of a lack of understanding the code itself than how it's effected by the VMWare.
Also would like to know cases in which VMware effects a similar situation.
I'm trying to call the folder this way:
const string _data1 = "Data1.txt"; // initilize
string Filename = #"\\vmware-host\Shared Folders\Desktop\JSONproject";
then futher down the program:
using (StreamReader r = new StreamReader(_data1))
{
string line;
while ((line = r.ReadLine()) != null)
{
Data1.Add(line); // add to list
}
}
Console.WriteLine(outputMessage);
break;

I've come upon this problem. You need to move the file into the C: rather than it be on the desktop. The VMware desktop is shared with the mac, which makes it ambiguous for visual studio to call.

Related

How to get a working x64 THREADSAFE Ghostscript DLL

Main context
We're actually trying to get a multi-threading version of Ghostscript x64 DLL, to make use of it through Ghostscript .NET. This component is supposed to "allow runing multiple Ghostscript instances simultaneously within a single process", but, as we have checked in our project, works fine until concurrent requests are made to the application. Same behavior can be replicated lauching same method using Tasks. The error description that raises in both cases, just when a call to the process is made until the last is being executed, is:
An error occured when call to 'gsapi_new_instance' is made: -100
Even it does no seem to be related with .NET directly, I will post a sample of our C# method code, just for contextualize.
// Define switches...
string[] switchesArray = switches.ToArray();
using (GhostscriptProcessor procesador = new GhostscriptProcessor())
{
try
{
procesador.StartProcessing(switchesArray, null);
byte[] destinationFile = System.IO.File.ReadAllBytes(destinationPath);
return destinationFile;
}
catch (Exception ex)
{
throw ex;
}
finally
{
System.IO.File.Delete(sourceFile);
}
}
THREADSAFE solution
Starting our investigation, we found this KenS's answer on this post, indicating that Ghostscript DLL must be generated with GS_THREADSAFE compiler definition.
To clarify, as we make use of Ghostscript 9.52 x64 to generate our PDFs, we need this x64 DLL compiled for Release configuration. After trying to compile Ghostscript sources on Windows 10 x64 machine, using Visual Studio Community 2017 and Visual Studio Community 2019, we finally managed to build and generate all items (only with VS Community 2019) without GS_THREADSAFE parameter, just to confirm that compilation is fine, and we check that the DLLs and executables are working. For this process we took in mind all we found in Ghostscript official documentation.
As we have no other guide to include this GS_THREADSAFE parameter, we followed the instructions given in this solution, including XCFLAGS="-DGS_THREADSAFE=1" on nmake build commands, usign this sentence for Rebuild all option:
cd .. && nmake -f psi\msvc32.mak WIN64= SBR=1 DEVSTUDIO= XCFLAGS=-DGS_THREADSAFE=1 && nmake -f psi\msvc32.mak WIN64= DEVSTUDIO= XCFLAGS=-DGS_THREADSAFE=1 bsc
This approach, rises an error during build:
Error LNK2019 unresolved external symbol errprintf_nomem referenced in
function gs_log_error File \mkromfs.obj 1
As it seems, the file mkromfs.c has a method called errprintf_nomem, which can't be found when GS_THREADSAFE is set.
Questions
1 - Is there any public release of Ghostscript that include x64 DLLs compiled to be THREADSAFE?
And, if not (that's what I'm guessing...)
2 - Is it possible to get this DLL to be THREADSAFE without changing the source code?
3- Could anyone provide, please, a step by step guide or walkthrough to build a x64 Ghostscript DLL using GS_THREADSAFE using Visual Studio (or even any other possible alternative) over Windows 10 x64?
4 - A few posts talk about people achive to manage multithreading using Ghostscript .NET. I assume this examples are all using a GS_THREADSAFE DLL... Is any other workaround we have passed?
Thank a lot in advance.
To summarize all this questions, and as a guide for future developers having this same trouble, these are the answers we've found until now:
AS #KenS mentions in his reply: "No, the Ghostscript developers don't actually build thread-safe versions of the binaries."
At this very moment, clearly not, as it has been reported on this opened bug.
As it seems to be a matter of commercial licensing support, we avoid comment on this point anymore.
Thanks again to #HABJAN. I absolutely take back what I've stated on my question, as it is possible to have Ghostscript .NET working on multi-threading scenarios. Below comes the solution we applied, in case it could be useful for someone.
Based on HABJAN example, what we have done to achieve this was to create a custom class to capture Ghostscript logging:
protected class ConsoleStdIO : Ghostscript.NET.GhostscriptStdIO
{
public ConsoleStdIO(bool handleStdIn, bool handleStdOut, bool handleStdErr) : base(handleStdIn, handleStdOut, handleStdErr)
{
}
public override void StdIn(out string input, int count)
{
char[] userInput = new char[count];
Console.In.ReadBlock(userInput, 0, count);
input = new string(userInput);
}
public override void StdOut(string output)
{
//log
}
public override void StdError(string error)
{
//log
}
}
For our previous method, we simple include a call to this class and this avoids errors when multiple tasks are executed at the same time:
// Define switches...
string[] switchesArray = switches.ToArray();
using (GhostscriptProcessor procesador = new GhostscriptProcessor())
{
try
{
procesador.StartProcessing(switchesArray, new ConsoleStdIO(true, true, true));
byte[] destinationFile = System.IO.File.ReadAllBytes(destinationPath);
return destinationFile;
}
catch (Exception ex)
{
throw ex;
}
finally
{
System.IO.File.Delete(sourceFile);
}
}
Well, it seems to me that you are asking here for technical support.
You clearly want to use Ghostscript in a commercial undertaking, indeed one might reasonably say you want an enterprise version of Ghostscript. Presumably you don't want to alter the source in order to permit you to use an open source license, because you don't want to pay for a commercial license.
With that in mind the answers to your questions are:
No, the Ghostscript developers don't actually build thread-safe versions of the binaries.
Currently, no. That's probably an oversight.
That would be a technical support question, there's no guarantee of technical support to free users, it's the one of the few areas of leverage for dual license vendors to persuade people to take up a commercial license. So I hope you will understand that I'm not going to provide that.
as far as I can see, no.

Why Ctrl+F5 is not working with my vtk code in Visual C++ debugging

I am a vtk beginner.There's a strange problem confused for long.I have written a VTK console application by vs2017.If I run it in vs2017 with ctrl+f5,it will show the following picture as error.But, if I directly run it in application work directory,it will operate normally.Why this problem occured?Anyone could help me, thanks a lot.
error picture
my c++ code is as follows:
int main()
{
vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
reader->SetFileName("fruit.png");
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
vtkSmartPointer<vtkJPEGWriter> writer = vtkSmartPointer<vtkJPEGWriter>::New();
writer->SetFileName("fruit.jpg");
writer->SetInputConnection(reader->GetOutputPort());
writer->Write();
renderWindowInteractor->Start();
return 0;
}
The problem is that Visual Studio isn't looking in your application work directory for fruit.png, instead it's looking in your project directory.
Go to Project/Properties/Debugging/Working Directory and change the value there to whatever your application work directory is.

Swift 2 and Linux/OS X differences

I'm trying to port some basic app from OS X to Linux but it seems that even basic stuff is missing on Linux platform. Is there some documentation what is missing ??
Here is example:
exmcast.swift:7:20: error: value of type 'String' has no member 'stringByReplacingOccurrencesOfString'
let name: String = address.stringByReplacingOccurrencesOfString(".", withString: "_")
This simple code works on OS X. On Linux - you see results.
It's very hard to port anything when there is no basic info what is missing.
And it looks like even basic stuff is missing..
Swift 3 will be released in fall 2016.
The recently open-sourced Swift and the Linux port are work in progress:
The port is still a work in progress but we’re happy to say that it is usable today for experimentation.
You can go to Swift.org and github.com/apple and enjoy the fantastic work.
When you find something not yet implemented, you can file a bug and/or help implement the feature.
New versions of the open source Swift will be posted regularly on Swift.org.
The method you are trying to call is actually part of NSString. String is bridged behind the scenes to NSString and that is why you are able to use that method on OS X. NSString is part of the Foundation framework, and Foundation is not totally implemented for Linux. You can check the status of the various parts of Foundation here: Foundation Status. NSString is currently only partially implemented.
On OSX you still need to import Foundation
You are free to use pure Swift solution, in your case
let str = "alfa.beta"
// (1)
let str1 = str.characters.map {
$0 == "." ? "_": $0
}.reduce("") { (str, c) -> String in
str + String(c)
}
// (2)
let str2 = String(str.characters.split(".").joinWithSeparator(["_"]))
print(str,str1,str2) // alfa.beta alfa_beta alfa_beta
for something more advanced, you have powerful functions
mutating func replaceRange<C : CollectionType where C.Generator.Element == Character>(subRange: Range<Index>, with newElements: C)
or
mutating func replaceRange(subRange: Range<Index>, with newElements: String)

Haxe/OpenFL app targeting flash/html5/air(desktop). How to handle filesystem data writing/reading?

I'm making an app that needs to target flash/air and ideally html5. This app has a feature of writing data in filesystem.
I've started using Haxe/OpenFL (this is my first experience).
I understand that flash and html5 won't be able to access local user's filesystem to write and read data. So those version would have this feature swapped by storing data in the cloud.
But AIR always had a possibility to operate the filesystem.
So I have two quetions now:
Is it possible to package Haxe/OpenFL project into AIR app, and
make a proper .air installer? Or should I be using some sorts of
cpp/c++ alternatives? What's the best practice in such a case?
Which API of OpenFL/Haxe gives me the possibility to
write data on filesystem?
Different platforms have different implementations to save/load user data. You should #if all the possible options for all the target platforms.
E.g.:
#if cpp
import haxe.io.Eof;
import sys.FileSystem;
import sys.io.File;
import sys.io.FileOutput;
import sys.io.FileInput;
#else if flash
import flash.net.SharedObject;
import flash.net.SharedObjectFlushStatus;
import flash.events.NetStatusEvent;
#end
class FileIO {
public function SaveData() : Void {
#if cpp
var Fout : FileOutput = null;
try {
myFout = sys.io.File.write("c:\mypath\myfile.name", false);
myFout.writeInt32(100);
[.....]
#else if flash
var shObj : SharedObject = null;
try {
shObj = SharedObject.getLocal("mySHODATA");
var ret : String = shObj.flush(MinFileSize);
[......]
#end
}
}
and so on. flash AIR, long story short is just -pretty much- a flash wrapper for desktop execution. Imagine it as a swf container for desktop (instead of instantiating an swf container in a web browser). So AIR-wrapped app == flash/swf app. If you want to use AIR implementations for file access, you can do that by following these steps.If you use haxe, it has it's own implementation for different targets, i.e. "#if" will find "flash" branch true, even if you plan to AIR-wrap you flash-app; so you'll have to use sharedobject.
I think it's wiser to compile cpp against desktop target, instead of "flash + wrap around with AIR" later.
It's supposedly doable, haven't tried it though.
Check out sys.FileSystem and sys.io.
this guide should walk you through the process of publishing for iOS and Android with AIR http://www.openfl.org/archive/community/installing-openfl/building-air/

Nashorn : how to evaluate scripts in scripting mode

Im starting to explore jdk 8 new javascript engine nashorn and wanted to build some automating task scripts. I ve an issue, ive no idea how to evaluate a js file in scripting mode from javascript, using engine.eval() eg .
p.s: im not talking about jjs -scripting which is good but only works one way. I want the other way; make the engine evaluate in scripting mode from java
The easiest way is to add -Dnashorn.args=-scripting to you java command line.
After a lot of head scratching, i came up with a trick where i can actually launch my script's execution through a command line from a hand crafted System Process :
//tricking the nashorn engine with jjs command
public void evalScriptInScriptingMode(String fileName)
{
String[] args = new String[]{"jjs", "-scripting", fileName};
//This class is used to create operating system processes
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(null);
File log = new File("jjs_log.txt");
int i = 0;
while(log.exists())
{
i++;
log = new File("jjs" + i + "_log.txt");
}
pb.redirectErrorStream(true);
pb.redirectOutput(ProcessBuilder.Redirect.appendTo(log));
Process p = null;
try
{
p = pb.start(); //start the process which remains open
}
catch(IOException e)
{
e.printStackTrace();
}
}
You can pass arguments to the script engine via the NashornScriptEngineFactory.
import jdk.nashorn.api.scripting.NashornScriptEngineFactory
new NashornScriptEngineFactory()
.getScriptEngine( "-scripting" )
.eval( "" );
You can also use new NashornScriptEngineFactory().getScriptEngine("-scripting"); which will retrieve a new Nashorn ScriptEngine in scripting mode. This method is slightly better than using a System Process mainly because this automatically adds you classes to the nashorn classpath.
Basically, you can program classes in java and then use'em in javascript. If you do not need to be able to reference your classes in javascript then the System Process should do just fine and there won't be problems, ( if the machine on which this is running has jjs in their classpath )

Resources