Setting System.Console.WindowHeight throws an System.NotSupportedException under Mono - exception

I get an Unhandled Exception: System.NotSupportedException: Operation is not supported. The Exception is raised under Mono using Ubuntu 11.10.
Reading the property works. The docs could suggest that the Method does not pose issues.
Any ideas on how to best handle or fix this situation?
My current solution is rather awkward, and does not solve the issue of setting the Window Size through the System.Console-API:
const int defaultConsoleWindowWidth = 80;
const int defaultConsoleWindowHeight = 25;
if (pid != PlatformID.Unix && pid != (PlatformID)128) {
System.Console.WindowHeight = lastConsoleWindowHeight;
System.Console.WindowWidth = defaultConsoleWindowWidth;
}else{
//assume *NIX system
try {
var p = new Process();
p.StartInfo = new ProcessStartInfo(#"stty cols " + defaultConsoleWindowWidth + " rows " + lastConsoleWindowHeight, "-n")
{
UseShellExecute = false
};
p.Start();
p.WaitForExit();
}
catch (Exception e) { /*...*/}
}
My Mono version:
lo#lo-VirtualBox:~/Desktop$ mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)

From the master branch on mono on Github Console.cs:
[MonoLimitation ("Only works on windows")]
public static int WindowHeight {
get { return ConsoleDriver.WindowHeight; }
set { ConsoleDriver.WindowHeight = value; }
}
Notice the MonoLimitation attribute

Related

Swagger not working (rather exception is thrown) after migrating project from .net core 2.2 to 3.0 preview-7

I have just migrated my project from .net core 2.2 to 3.0 preview 7. I am using Swashbuckle.AspNetCore (v4.0.1) in it. This is my startup class.
public class Startup
{
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration["ConnectionStrings:ConnectionStringAzureSQL"]));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddApplicationInsightsTelemetry();
services.AddLocalization(options => options.ResourcesPath = #"Resources");
services.AddMemoryCache();
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US")
};
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "GetAJobToday", Description = "GetAJobTodayAPIs" });
var xmlPath = AppDomain.CurrentDomain.BaseDirectory + #"PlatformAPI.xml";
c.IncludeXmlComments(xmlPath);
c.AddSecurityDefinition("Bearer",
new ApiKeyScheme
{
In = "header",
Description = "Please enter token into the field",
Name = "Authorization",
Type = "apiKey"
});
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
});
});
services.AddSingleton<ITelemetryInitializer, HttpContextItemsTelemetryInitializer>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseRouting();
app.UseMiddleware<ApiLoggingMiddleware>();
app.UseHttpsRedirection();
app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapControllerRoute("default", "{controller=Auth}/{action=RequestVerificationCode}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "GetAJobToday");
});
}
}
But it is throwing this exception when I run it:
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator': Failed to compare two elements in the array.) (Error while validating the service descriptor 'ServiceType: Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistryFactory': Failed to compare two elements in the array.)
Upgrading Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.Filters to v 5.0.0-rc2 solved the problem.
Upgrading Swashbuckle.AspNetCore to the latest version v 5.0.0-rc4 solved the problem.

Geotools 13 - error writing to MySQL in linux

Note: Running geotools 13.0.
I have an application that creates Point shapes. My application then writes these features in a shapefile and then into MySQL.
When I run the code under Windows, everything works perfect: the data is properly stored in MySQL and I can use it without any trouble.
When I run the code under Linux, shapefiles are created, but the data is not written in MySQL and the following exception is thrown:
WARNING: class org.geotools.filter.function.Collection_NearestFunction has name conflict betwee 'null' and 'Collection_Nearest'
Exception in thread "main" java.lang.NoSuchFieldError: LINEARIZATION_TOLERANCE
at org.geotools.jdbc.JDBCFeatureReader.init(JDBCFeatureReader.java:211)
at org.geotools.jdbc.JDBCFeatureReader.<init>(JDBCFeatureReader.java:137)
at org.geotools.jdbc.JDBCInsertFeatureWriter.<init>(JDBCInsertFeatureWriter.java:43)
at org.geotools.jdbc.JDBCFeatureStore.getWriterInternal(JDBCFeatureStore.java:280)
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:151)
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:122)
at org.geotools.data.store.ContentFeatureStore.getWriterAppend(ContentFeatureStore.java:263)
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:242)
at com.technip.projects.gis.GISGenerator.writeShapesMySQL(GISGenerator.java:763)
at com.technip.projects.gis.GISGenerator.generatePlatforms(GISGenerator.java:416)
at com.technip.projects.gis.GISGenerator.createShapefiles(GISGenerator.java:249)
at Machine.run(Machine.java:739)
at Machine.main(Machine.java:329)
My code:
private void writeShapesMySQL(List<SimpleFeature> features) throws IOException {
SimpleFeatureType TYPE = null;
if (!features.isEmpty()) {
TYPE = features.get(0).getType();
// Drop the table if exists
try (Connection con = conf.requestConnection("gis")) {
con.prepareCall("DROP TABLE IF EXISTS " + TYPE.getTypeName() + ";").execute();
} catch (Exception e) {}
if (factory == null) {
initMySQLStore();
}
SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
gisDS.createSchema(TYPE);
Transaction transaction = new DefaultTransaction("create");
String typeName = null;
for (String s : gisDS.getTypeNames()) {
if (s.equalsIgnoreCase(TYPE.getTypeName())) {
typeName = s;
break;
}
}
if (typeName == null) {
log.error("Cannot find the type " + TYPE.getTypeName() + " in the known types: " + String.valueOf(gisDS.getTypeNames()));
throw new IOException("Cannot find type " + TYPE.getTypeName() + " -- in other words, developer sucks.");
}
SimpleFeatureSource featureSource = gisDS.getFeatureSource(typeName);
// System.out.println("SHAPE:"+SHAPE_TYPE);
if (featureSource instanceof SimpleFeatureStore) {
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
featureStore.setTransaction(transaction);
try {
log.info("Adding " + collection.size() + " features into " + TYPE.getTypeName() + " table.");
featureStore.addFeatures(collection);
transaction.commit();
} catch (Exception problem) {
log.error("Cannot create shapes in MySQL for " + TYPE.getTypeName(), problem);
transaction.rollback();
} finally {
transaction.close();
}
}
} else {
log.warn("Passed empty list to create GIS database.");
}
}
private void initMySQLStore() throws IOException {
factory = new MySQLDataStoreFactory();
Map conMap = new HashMap();
conMap.put("dbtype", "mysql");
conMap.put("host", conf.getDbserver());
conMap.put("port", "3306");
conMap.put("database", "gis");
conMap.put("user", conf.getDbuser());
conMap.put("passwd", conf.getDbpass());
gisDS = factory.createDataStore(conMap);
Map<Class<?>, Integer> classMappings = gisDS.getClassToSqlTypeMappings();
classMappings.put(String.class, new Integer(Types.LONGVARCHAR));
}
My first hint is that MySQL is case sensitive in Linux, but not in Windows. So I checked the created tables both in Linux and Windows, and none of them has a field with such a name (LINEARIZATION_TOLERANCE).
Any hints?
Thanks,
Juan
--UPDATE: PROBLEM SOLVED--
It turned out I had an old .jar from a prior version of geotools in the Linux machine. Removing all old jars fixed the problem.
Problem solved:
It turned out I had an old .jar from a prior version of geotools in the Linux machine. Removing all old jars fixed the problem.
Dismiss this, it is a user error.

How to Call an Application with Parameters in NPAPI for Mac

I try to create a simple NPAPI which passes an URL to Safari.
plugin_invoke method is below:
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
// Make sure the method called is "open".
NPUTF8 *name = npnfuncs->utf8fromidentifier(methodName);
if(strcmp(name, plugin_method_name_open) == 0) {
npnfuncs->memfree(name);
BOOLEAN_TO_NPVARIANT(false, *result);
// Meke sure the arugment has at least one String parameter.
if(argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
// Build CFURL object from the arugment.
NPString str = NPVARIANT_TO_STRING(args[0]);
CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)str.UTF8Characters, str.UTF8Length, kCFStringEncodingUTF8, NULL);
if(url) {
// Open URL with the default application by Launch Service.
//OSStatus res = LSOpenCFURLRef(url, NULL);
//CFRelease(url);
OSStatus resultt = eventNotHandledErr;
//FSRef appRef;
FSRef appRef = {0};
Boolean isDir =true;
resultt = FSPathMakeRef((UInt8 *) "/Applications/Safari.app", &appRef,
&isDir);
LSApplicationParameters appParams = {0, kLSLaunchDefaults};
appParams.application = &appRef;
appParams.version = 0;
appParams.flags = kLSLaunchDefaults;
resultt = LSOpenApplication(&appParams, NULL);
BOOLEAN_TO_NPVARIANT(resultt == noErr, *result);
}
}
return true;
}
npnfuncs->memfree(name);
return false;
}
Currently it just invokes Safari but URL can not be passed.
How can I pass an example URL to the Safari in NPAPI? I read LSOpenFromURLSpec might work but I could not create the code.
Read the documentation for Launch Services, especially LSOpenURLsWithRole.
FYI, nothing about your question is NPAPI-specific, it's just about launching a Mac application from another process. In general you'll get more answers if you don't post general questions as NPAPI questions, since way more people know the answers to general Mac questions than to NPAPI-specific questions.

net.rim.device.api.io.file.FileIOException: File system out of resources in blackberry

Below code throws net.rim.device.api.io.file.FileIOException: File system out of resources this exception.
Can anyone tell me how it happens?
public Bitmap loadIconFromSDcard(int index) {
FileConnection fcon = null;
Bitmap icon = null;
InputStream is=null;
try {
fcon = (FileConnection) Connector.open(Shikshapatri.filepath + "i"
+ index + ".jpg", Connector.READ);
if (fcon.exists()) {
byte[] content = new byte[(int) fcon.fileSize()];
int readOffset = 0;
int readBytes = 0;
int bytesToRead = content.length - readOffset;
is = fcon.openInputStream();
while (bytesToRead > 0) {
readBytes = is.read(content, readOffset, bytesToRead);
if (readBytes < 0) {
break;
}
readOffset += readBytes;
bytesToRead -= readBytes;
}
EncodedImage image = EncodedImage.createEncodedImage(content,
0, content.length);
image = resizeImage(image, 360, 450);
icon = image.getBitmap();
}
} catch (Exception e) {
System.out.println("Error:" + e.toString());
} finally {
// Close the connections
try {
if (fcon != null)
fcon.close();
} catch (Exception e) {
}
try {
if (is != null)
is.close();
is = null;
} catch (Exception e) {
}
}
return icon;
}
Thanks in advance...
Check this BB dev forum post - http://supportforums.blackberry.com/t5/Java-Development/File-System-Out-of-Resources/m-p/105597#M11927
Basically you should guaranteedly close all connections/streams as soon as you don't need them, because there is a limited number of connection (be it a file connection or http connection) handles in OS. If you execute several loadIconFromSDcard() calls at the same time (from different threads) consider redesign the code to call them sequentially.
UPDATE:
To avoid errors while reading the content just use the following:
byte[] content = IOUtilities.streamToBytes(is);
And since you don't need file connection and input stream any longer just close them right after reading the content (before creating EncodedImage):
is.close();
is = null; // let the finally block know there is no need to try closing it
fcon.close();
fcon = null; // let the finally block know there is no need to try closing it
Minor points:
Also in the finally block it is worth set fcon = null; explicitly after you close it, I believe this can help old JVMs (BB uses Java 1.3 - rather old one) to decide quicker that the object is ready to be garbage collected.
I also believe that the order you close streams in the finally block may be important - I'd change to close is first and then fcon.

GWT Javascript Exception in Hosted Mode: Result of expression 'doc.getBoxObjectFor' [undefined] is not a function

Anyone ever seen this exception? I'm running in hosted mode on GWT 1.6.4 on a mac. I'm using the AutoSuggest and it's throwing this exception trying to show the popup. It works fine in compiled mode, but obviously hosted mode is rather important.
[ERROR] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError): Result of expression 'doc.getBoxObjectFor' [undefined] is not a function.
line: 71
sourceId: 1152617088
sourceURL: jar:file:/Users/holmes/.m2/repository/com/google/gwt/gwt-user/1.6.4/gwt-user-1.6.4.jar!/com/google/gwt/dom/client/DOMImplMozillaOld.java
expressionBeginOffset: 288
expressionCaretOffset: 307
expressionEndOffset: 313
at com.google.gwt.dom.client.DOMImplMozillaOld.getAbsoluteLeftImpl(Native Method)
at com.google.gwt.dom.client.DOMImplMozillaOld.getAbsoluteLeft(DOMImplMozillaOld.java:29)
at com.google.gwt.dom.client.Element$.getAbsoluteLeft$(Element.java:86)
at com.google.gwt.user.client.DOM.getAbsoluteLeft(DOM.java:646)
at com.google.gwt.user.client.ui.UIObject.getAbsoluteLeft(UIObject.java:487)
at com.google.gwt.user.client.ui.PopupPanel.position(PopupPanel.java:1015)
at com.google.gwt.user.client.ui.PopupPanel.access$5(PopupPanel.java:958)
at com.google.gwt.user.client.ui.PopupPanel$1.setPosition(PopupPanel.java:811)
at com.google.gwt.user.client.ui.PopupPanel.setPopupPositionAndShow(PopupPanel.java:700)
at com.google.gwt.user.client.ui.PopupPanel.showRelativeTo(PopupPanel.java:809)
at com.google.gwt.user.client.ui.SuggestBox.showSuggestions(SuggestBox.java:768)
at com.google.gwt.user.client.ui.SuggestBox.access$3(SuggestBox.java:738)
at com.google.gwt.user.client.ui.SuggestBox$1.onSuggestionsReady(SuggestBox.java:281)
at com.google.gwt.user.client.ui.MultiWordSuggestOracle.requestSuggestions(MultiWordSuggestOracle.java:225)
at com.google.gwt.user.client.ui.SuggestBox.showSuggestions(SuggestBox.java:640)
at com.google.gwt.user.client.ui.SuggestBox.refreshSuggestions(SuggestBox.java:713)
at com.google.gwt.user.client.ui.SuggestBox.access$6(SuggestBox.java:705)
at com.google.gwt.user.client.ui.SuggestBox$1TextBoxEvents.onKeyUp(SuggestBox.java:678)
at com.google.gwt.event.dom.client.KeyUpEvent.dispatch(KeyUpEvent.java:54)
at com.google.gwt.event.dom.client.KeyUpEvent.dispatch(KeyUpEvent.java:1)
at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:65)
at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:52)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:90)
at com.google.gwt.user.client.ui.TextBoxBase.onBrowserEvent(TextBoxBase.java:193)
at com.google.gwt.user.client.ui.Composite.onBrowserEvent(Composite.java:54)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1320)
at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1299)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1262)
I had a similar problem when using Firefox 3.7a1pre ("Minefield") in compiled mode. Function getBoxObjectFor was replaced by getBoundingClientRect. Here my workaround to get GWT working again. Just call the following method somewhere at the beginning, at least for me it does work.
private static native void firefox3compatibility() /*-{
if (!$doc.getBoxObjectFor) {
$doc.getBoxObjectFor = function (element) {
var box = element.getBoundingClientRect();
return { "x" : box.left, "y" : box.top,
"screenX": box.left, "screenY" : box.top,
"width" : box.width, "height" : box.height };
}
}
}-*/;
I fixed this successfully with the following inserted after nitobi.browser.detect(); in the nitobi.toolkit.js file. It's around line 575. (ish)
if(nitobi.browser.MOZ) {
if(typeof document.getBoxObjectFor == "undefined") {
document.getBoxObjectFor = function(elem) {
var obj = new Object;
var rect = elem.getBoundingClientRect();
obj.y = rect.top;
obj.x = rect.left;
obj.width =Math.abs(rect.right-rect.left);
obj.height = Math.abs(rect.bottom-rect.top);
return obj;
}
}
}
It works well if the Gecko browser you're targeting is implementing the function getBoundingClientRect like Mozilla.
They deprecated getBoxObjectFor, and instead added this function.
Hope that helps.
getBoxObjectFor was deprecated for FF3.6. Here is the issue which addresses this problem in GWT: Issue 4605
This is a great fix, but I also needed to add the screenX, and screenY to the returned object:
private static native void firefox3compatibility() /-{ if (!$doc.getBoxObjectFor) { $doc.getBoxObjectFor = function (element) { var box = element.getBoundingClientRect(); return { "x" : box.left, "y" : box.top, "width" : box.width, "height" : box.height, "screenX": box.left, "screenY":box.top }; } } }-/;