|
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...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I need to access my gmail contacts to upgrade an Access database. A program in C # manages this basis. I checked on the Internet and appeared several ways, but none worked. I found a video that the speaker creates the code step by step and in the end he managed to access the gmail contacts.
I typed the code and is giving an error in word in of code:
foreach (Contact contato in f.Entries)
The following code:
using System;
using System.Data;
using Google.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
namespace ContatosGmail
{
public partial class Default : System.Web.UI.Page
{
protected void btnObter_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add("GmailContacts");
ds.Tables[0].Columns.Add("EmailId");
RequestSettings rs = new RequestSettings("Taveira", txtUsername.Text, txtPassword.Text);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact contato in f.Entries)
{
foreach (EMail email in contato.Emails)
{
DataRow row = ds.Tables[0].NewRow();
row["EmailId"] = email.Address.ToString();
ds.Tables[0].Rows.Add(row);
}
}
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
lblStatus.Text = "Toal de contatos para " + txtUsername.Text + ": " + ds.Tables[0].Rows.Count.ToString();
}
}
}
I am in urgent need of this solution.
Using Visual Studio Professional 15 and Windows 10.
Thank you.
|
|
|
|
|
Most likely no one here is going to debug this code for you, or provide you with a "fixed" version.
It is your task to analyze the code, single-step through it and observe the specific error(s). Then, ask specific questions here, giving a clear description of the error message(s). And, unless you understand the code, how will you maintain it in the future when Google changes their API's, or some change in whatever occurs ?
«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
|
|
|
|
|
check for "Contact" . It should be in blue color. Try to navigate.
|
|
|
|
|
When you get an error in your code and post a question about it, it would be helpful if you actually said what the error was. I'm going to go out on a limb and suggest that the exception you see on your first foreach line is that you have an "Object reference not set to an instance of an object" exception. You will see this if the call that is responsible for creating the object (i.e., your call to GetContacts) returns a null value. To be honest, this sounds to me like your RequestSettings are inaccurate or you have something like a Firewall preventing you accessing Google from your app.
I will add that we consider it rude to put "urgent" in a question. It's only urgent for you; you aren't paying us anything for our time and we're all volunteers so it's at our discretion when we answer your question.
This space for rent
|
|
|
|
|
Thanks a lot for the help.
|
|
|
|
|
Been hearing a lot of people having trouble with icons, I decided to updated my article I wrote back in 2004 Access multiple icons in a single icon file[^] with a long needed update.
New version of the library lets you import pictures and create 32bit icons with multiple sizes of the image. Hopefully, this can help people who are having troubles with icons with this replacement for the icon class.
Grab the library and sample app:
GitHub - hazlema/MultiIcon: Display or Convert 32bit icons.[^]
Written in C#, Community 2015
Matthew Hazlett
Fighting the good fight for web usability.
modified 14-Jun-16 19:29pm.
|
|
|
|
|
This forum is for asking questions about, or having technical discussions about, C#.
It's not the place to promote your article. That's the job of the various newsletters, RSS feeds, Twitter feeds, Google+ feeds, and "updated article" lists.
I suggest you remove your message, before trigger-happy members start reporting it as spam.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|