|
I should know better than to question anything you say ! If that option is enabled, I'd say you were "living dangerously"
I think it's reasonable to assume here the OP is using double-click to launch apps; however, what if someone else using their code is not: that's an issue the OP would have to deal with if they pursue this (imho) strange goal.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
BillWoodruff wrote: I should know better than to question anything you say ! On the contrary, you should never assume I know anything, let alone everything.
And I agree with your second statement. Trouble is I've been using single click for so long (since early XP days) I forget it's not the default.
|
|
|
|
|
First, I have never seen any application that exhibits this type of behavior; I think you must have a very strong reason for doing something so unusual.
There are three strategies you could pursue:
1. create a Windows Explorer-scope context-click menu extension that showed an option to create a folder for every Application context-clicked on. I would find such a menu extension very annoying.
To research this, start here: [^],
2. create a Windows Global Application Hook that would detect selection of a .exe file, and raise an Event you could process. I have never seen anyone try to create an Application Hook from a Console app, but, that doesn't mean it could not be done.
I suggest reading/studying this MSDN article first: [^].
There are several articles here on CodeProject on Windows Global App Hooks; I suggest you start with this one by George Mamaldze: [^]; then, search for and read other articles here on the same topic.
3. try to enumerate every Explorer window open and get the selected files/folders: [^].
In all these cases I think you are going to have a headache trying to implement them in a Console app, and I think the result will be not too useful.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 19-Jun-16 7:29am.
|
|
|
|
|
|
I'm not sure of what your trying to achieve - to me, it sounds like
a) load data into 'R.Net'
b) process data in 'R.Net'
c) draw a chart in 'R.Net'
d) export the chart as an image to Excel
if 'd' is correct, then I think you're wasting your time .. can you not do
d) export the chart data to a '.csv' file that excel can read and produce a chart from
? - it seems 'simpler' and less complex - its just iterating the data frame, writing it as comma separated values to a file on disk
|
|
|
|
|
that is exactly what I wish to do. I know it may be simpler to do it directly in excel, but I would like to learn how to do it in C# using RDotNet.
If you could please tell me how, I would really appreciate it.
Thanks in advance.
|
|
|
|
|
well, I guess the crux is 'what you get back from the function'. That line
var x = engine.Evaluate("x <- rnorm(100, mean=50, sd=10)").AsNumeric();
returns 100 data points in x, yes ? what I dont know, is if x is a 2-d array or a dataframe - once you can determine that - I'd single step in debug mode until that step has been executed, then use the mouse and hover over 'x' and see what the debugger says its type is .... (I dont have 'R' installed) it surely is a simply matter to
a) open a file for writing - use a 'using' block
b) iterate 'x' by rows
c) for each column in the row, build a comma separated string
d) write the comma separated string to the file
e) {end-for}
really b & c are the bits that will differ depending on what it is (array, dataframe)
|
|
|
|
|
Thanks for the reply. I just have one more question.
How would I use an int array in RDotNet?
Currently I have this:
public void variance(REngine e, string[] x,int[] y)
{
var var1 = e.GetSymbol("var").AsFunction();
var1.Invoke(x).AsNumeric();
}
How would I use an int array in this function I am trying to call?
I am trying to use this as a method.
I think what I have to do is convert the array into a dataFrame, but I just don't know how.
modified 24-Jun-16 12:31pm.
|
|
|
|
|
I wrote this new version of a function to replace an older version, which reads a HTML file, replaces some values, and sends it back out for emailing.
I wrote an earlier post in which I said the HTML didn't persist, but that was an easy fix. I currently just don't understand why the replace is not working. It worked before when html_Template was a string builder.
I really don't want to use regex to replace the values, I'm not good at writing regex.
And I'm sure not if what I wrote is kosher and efficient. Maybe I can move the replace outside the using filestream.
private static string read_HTML_Template(
model_crm_contact_request cm)
{
string html_Template = string.Empty;
using (var htmlStream = new FileStream(cm.smtp_templatePath_customer, FileMode.Open, FileAccess.Read))
{
long htmlLen = htmlStream.Length;
byte[] bytes = new byte[htmlLen];
htmlStream.Read(bytes, 0, (int)htmlLen);
if (!(htmlStream == null))
htmlStream.Close();
var enc = new UTF8Encoding(true);
var preamble = enc.GetPreamble();
if (preamble.Where((p, i) => p != bytes[i]).Any())
html_Template = enc.GetString(bytes.ToArray());
else
html_Template = enc.GetString(bytes.Skip(preamble.Length).ToArray());
html_Template.Replace("<% smtp.WebsiteUrl %>", cm.smtp_websiteUrl);
html_Template.Replace("<% smtp.HeaderImage %>", cm.smtp_headerImage);
html_Template.Replace("<% smtp.CustomerName %>", cm.Name);
html_Template.Replace("<% smtp.WebsiteName %>", cm.smtp_websiteName);
html_Template.Replace("<% smtp.CustomerComment %>", cm.Query);
html_Template.Replace("<% smtp.TimeStamp_GMT %>", DateTime.UtcNow + " GMT");
html_Template.Replace("<% smtp.TimeStamp_UTC %>", DateTime.UtcNow + " UTC");
}
return html_Template;
}
|
|
|
|
|
I don't enough sleep on Thursday nights. Say I have a question, do you think this new version is the equiv to the old version below? Functionally the same except for the linefeed detector?
private static string read_HTML_Template(
model_crm_contact_request cm)
{
string html_Template = string.Empty;
using (var htmlStream = new FileStream(cm.smtp_templatePath_customer, FileMode.Open, FileAccess.Read))
{
long htmlLen = htmlStream.Length;
byte[] bytes = new byte[htmlLen];
htmlStream.Read(bytes, 0, (int)htmlLen);
if (!(htmlStream == null))
htmlStream.Close();
var enc = new UTF8Encoding(true);
var preamble = enc.GetPreamble();
if (preamble.Where((p, i) => p != bytes[i]).Any())
html_Template = enc.GetString(bytes.ToArray());
else
html_Template = enc.GetString(bytes.Skip(preamble.Length).ToArray());
}
html_Template = html_Template.Replace("<% smtp.WebsiteUrl %>", cm.smtp_websiteUrl);
html_Template = html_Template.Replace("<% smtp.HeaderImage %>", cm.smtp_headerImage);
html_Template = html_Template.Replace("<% smtp.CustomerName %>", cm.Name);
html_Template = html_Template.Replace("<% smtp.WebsiteName %>", cm.smtp_websiteName);
html_Template = html_Template.Replace("<% smtp.CustomerComment %>", cm.Query);
html_Template = html_Template.Replace("<% smtp.TimeStamp_GMT %>", DateTime.UtcNow + " GMT");
html_Template = html_Template.Replace("<% smtp.TimeStamp_UTC %>", DateTime.UtcNow + " UTC");
return html_Template;
}
This is the old version
private static string read_HTML_Template(
model_crm_contact_request cm)
{
FileStream htmlStream = null;
htmlStream = new FileStream(cm.smtp_templatePath_website, FileMode.Open, FileAccess.Read);
long htmlLen = htmlStream.Length;
byte[] fileData = new byte[htmlLen];
htmlStream.Read(fileData, 0, (int)htmlLen);
if (!(htmlStream == null))
htmlStream.Close();
byte[] byteLine = new byte[0];
string[] strArray = new string[0];
for (int bdx = 0; (bdx
<= (fileData.Length - 1)); bdx++)
{
byte byteVal = fileData[bdx];
if (!(byteVal == 13))
{
Array.Resize(ref byteLine, byteLine.Length + 1);
byteLine[byteLine.Length - 1] = byteVal;
}
else
{
Array.Resize(ref byteLine, byteLine.Length + 1);
byteLine[byteLine.Length - 1] = byteVal;
char[] charLine = new char[0];
Array.Resize(ref charLine, byteLine.Length + 1);
for (int cdx = 0; (cdx <= (byteLine.Length - 1)); cdx++)
{
charLine[cdx] = AsciiByteToChar(byteLine[cdx]);
}
string value = new string(charLine);
Array.Resize(ref strArray, strArray.Length + 1);
strArray[strArray.Length - 1] = value;
Array.Resize(ref byteLine, 0);
bdx++;
}
}
StringBuilder html_Template = new StringBuilder();
for (int idx = 0; (idx <= (strArray.Length - 1)); idx++)
{
int integerRead = 0;
char characterRead;
StringBuilder htmlBuilder = new StringBuilder();
StringReader charReader = new StringReader(strArray[idx]);
while (true)
{
integerRead = charReader.Read();
if ((integerRead == -1))
{
break;
}
characterRead = Convert.ToChar(integerRead);
if ((characterRead == '\t'))
{
}
else if (((characterRead == '\r') || (characterRead == '\n')))
{
}
else
{
htmlBuilder.Append(characterRead);
}
}
string htmlString = htmlBuilder.ToString();
htmlString = htmlString.Substring(0, (htmlString.Length - 1));
html_Template.Append(htmlString);
}
html_Template.Replace("<% smtp.WebsiteUrl %>", cm.smtp_websiteUrl);
html_Template.Replace("<% smtp.HeaderImage %>", cm.smtp_headerImage);
html_Template.Replace("<% smtp.CustomerName %>", cm.Name);
html_Template.Replace("<% smtp.WebsiteName %>", cm.smtp_websiteName);
html_Template.Replace("<% smtp.CustomerComment %>", cm.Query);
html_Template.Replace("<% smtp.TimeStamp_GMT %>", DateTime.UtcNow + " GMT");
html_Template.Replace("<% smtp.TimeStamp_UTC %>", DateTime.UtcNow + " UTC");
return html_Template.ToString();
}
|
|
|
|
|
I followed the tutorial here:
Importing and displaying a Data frame with C# and R.NET | Psychwire[^]
and I got errors on the code, here:
REngine.SetDllDirectory(dlldir);
REngine.CreateInstance("RDotNet");
REngine engine = REngine.GetInstanceFromID("RDotNet");
engine.EagerEvaluate("dataset<-read.table(file.choose(), header=TRUE, sep = ',')");
DataFrame dataset = engine.EagerEvaluate("dataset").AsDataFrame();
saying that it couldn't find the methods inRDotNet.Engine.
This is the code I am using:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using RDotNet;
using RDotNet.NativeLibrary;
using Microsoft.Win32;
namespace RScript
{
public partial class Form1 : Form
{
public Form1()
{
string dlldir = @"C:\Program Files\R\R-3.3.0\bin\x64";
bool r_located = false;
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dlldir);
InitializeComponent();
while (r_located == false)
{
try
{
REngine.SetDllDirectory(dlldir);
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch
{
MessageBox.Show(@"Unable to find R installation's \bin\i386 folder.
Press OK to attempt to locate it.");
/if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
dlldir = @folderBrowserDialog1.SelectedPath;
}/
}
}
}
private void button1_Click(object sender, EventArgs e)
{
REngine engine = REngine.GetInstanceFromID("RDotNet");
try
{
engine.EagerEvaluate("dataset<-read.table(file.choose(), header=TRUE, sep = ',')");
DataFrame dataset = engine.EagerEvaluate("dataset").AsDataFrame();
for (int i = 0; i < dataset.ColumnCount; ++i)
{
dataGridView1.ColumnCount++;
dataGridView1.Columns[i].Name = dataset.ColumnNames[i];
}
for (int i = 0; i < dataset.RowCount; ++i)
{
dataGridView1.RowCount++;
dataGridView1.Rows[i].HeaderCell.Value = dataset.RowNames[i];
for (int k = 0; k < dataset.ColumnCount; ++k)
{
dataGridView1[k, i].Value = dataset[i,k];
}
}
}
catch
{
MessageBox.Show(@"Equation error.");
}
}
}
}
can someone please help me out, since I really need your help?
I am new to R.Net.
I am using the newest version of RDotNet (1.6.5).
Thanks in advance!
|
|
|
|
|
If you are following a tutorial on another site, then I'd start by asking the person who wrote the tutorial, not a different site that has nothing to do with it.
If you look at the bottom of the page you link to, there is a "Thoughts on..." area, which is there for people - like you - to comment and ask questions.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I'm creating code to select monitor in a multi-monitor configuration. I was wondering if someone with many monitors could help me understand what is happening once you have 5-6 monitors connected to your PC by running this script and just reporting results it prints out.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Scr.Tests
{
class Program
{
static void Main(string[] args)
{
Rectangle desktop = SystemInformation.VirtualScreen;
Console.WriteLine(desktop.ToString());
Screen[] screens = Screen.AllScreens;
for (int i = 0; i < screens.Length; i++)
{
Console.WriteLine(screens[i].Bounds.ToString());
Console.WriteLine(screens[i].DeviceName);
Console.WriteLine(screens[i].WorkingArea.ToString());
}
}
}
}
Sincerely,
Tomaz
|
|
|
|
|
Your question is not clear here. What is about what is "printed out" by your code that you don't understand. Given the information produced by enumerating the Screens, what is you want to do ?
Given that more than one Screen can have (one or more) TaskBar objects, what does that mean in this context.
You are aware that 'ScreenPrimaryScreen() will return the current active device Window, and if you are enumerating multiple Screens, the Screen.Primary method will return a boolean value for a given Screen indicating whether it's Primary.
In any case, I think there's code on this post, and on this thread, on StackOverFlow you may find useful: [^]
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Short answer is: I would like to draw monitor configuration on screen and I need test data sample to be able to resolve my dilemmas:
- which monitor is monitor 1 (is it always left, top?),
- can coordinates be negative,
- what if one monitor is "missiong" and hence rectangular virtual desktop has "holes" in it, how does mouse behave then,
...
Configurations such as this one: https://s-media-cache-ak0.pinimg.com/736x/c4/2f/90/c42f908f046399f8d097a7ecc6cf8bf4.jpg[^] are not that uncommon in the financial industry anymore. And my apps must follow the trend. So I really need a printout of this program. Then I can use the coordinates in my test program to simulate multi- monitor environment and draw it correctly.
|
|
|
|
|
To get the type of information you mention, I think you'll have to use the MonitorInfo API call 'GetMonitorInfo, and examine the state of the 'MONITORINFO or MONITORINFOEX structures it returns: [^].
This may be useful: [^].
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
I want do show my gps cursor in Mapwingis by C#. I want to show red cursor when gps stop and show green cursor when gps is running? I want to do it in C# please help me.
|
|
|
|
|
What exactly have you tried? What code do you have in place already? Do you have GPS capability in your application already? What platform are you going to run this on?
This space for rent
|
|
|
|
|
actually i have got lat and long from Gps by serial port but i want to show gps cursor on my mapwingis. MY program is based on dot net framework.
programming language is C#.
|
|
|
|
|
I was actually asking whether it was WinForms or WPF?
This space for rent
|
|
|
|
|
|
And are you talking about the commercial MapWin GIS from ThinkGeo which has it's own support center[^] which is full of helpful information?
This space for rent
|
|
|
|
|
Hello,
I just want to find out if the tollbaricon or the notifyicon ist clicked. I know how to do that in a own class. My problem is, that I have a while-loop and in this one, I must check if one of the button is klicked. (Because only then the while have to break.)
May you help me? May you have other ideas how i can realize it?
|
|
|
|
|
You can't, without playing some very nasty games with DoEvents.
The problem is that unless you are explicitly threading your app, the while loop is executing on the same thread as the rest of the UI elements - so the click action won't get honoured until after the loop has finished and the event handler that started it has returned control to the system.
It's like a man who is so busy concentrating on what's in front of him while he is driving, that he doesn't notice the fire engine trying to get past!
You can do it, but you have to change the way your application works, and move the loop into a separate thread. You can then set up an "terminate" variable which you check in the loop, and set in the Click event handler. Have a look at the BackgroundWorker Class (System.ComponentModel)[^] - it provides a safe and easy way to do this, but be aware that you cannot access any UI elements except on the same thread they were created on - if you try to do that inside your loop using a BackgroundWorker you will get a "Cross thread exception" and that means you need to use Invoke to move the access back onto the original thread. This isn't a simple subject and it's probably an idea if you do some background reading on Threading first before you get too complicated.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|