|
If you try them out, you'll find the answer. None of them.
This space for rent
|
|
|
|
|
var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary( "The first sentence", Windows.Security.Cryptography.BinaryStringEncoding.Utf8); await Windows.Storage.FileIO.WriteBufferAsync(sampleFile, buffer);
var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary( "The first sentence", Windows.Security.Cryptography.BinaryStringEncoding); await Windows.Storage.FileIO.WriteBufferAsync(sampleFile, buffer);
var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary( "The first sentence", Windows.Security.Cryptography.BinaryStringEncoding.Utf8); await Windows.Storage.FileIO.ReadBufferAsync(sampleFile, buffer);
Var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary( "The first sentence", Windows.Security.Cryptography.BinaryStringEncoding.Utf8); await Windows.Storage.FileIO(sampleFile);
|
|
|
|
|
byte[] bytes = System.Text.Encoding.UTF8.GetBytes("example string"); I'd like to point out that a text-encoding is not the same as encryption. A text encoded in UTF8 is still a readable text.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Or ...
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(myString);
File.WriteAllBytes(path, bytes);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Or ...
File.WriteAllText(sampleFile, stringContent, System.Text.Encoding.UTF8);
|
|
|
|
|
I was waiting for that. First class!
Regards,
Rob Philpott.
|
|
|
|
|
Thank you.
But why you have not posted it instead of waiting?
|
|
|
|
|
Ah well, the timing of my response is coincidental, I wasn't actually waiting until someone posted it, but just that that was the answer I was waiting for, being the best IMO. I read the thread about a minute after your answer.
Besides, I couldn't remember what the method was called and certainly couldn't be bothered to look it up. It's Friday and I'm just observing today, not participating.
Regards,
Rob Philpott.
|
|
|
|
|
Hi all,
In my first C# console application I want to avoid COM problems and therefore I'm registering the IOleMessageFilter to handle any threading errors.
Well this wouldn't be a question without the problem part so here we go:
public static void Register()
{
IOleMessageFilter newFilter = new MessageFilter();
IOleMessageFilter oldFilter = null;
int test = CoRegisterMessageFilter(newFilter, out oldFilter);
if (test != 0)
Debug.Fail("CoRegisterMessageFilter failed!");
else
_isRegistered = true;
}
This never goes past the Debug.Fail, but I can't understand why as the message is not very explanatory by itself:
---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
CoRegisterMessageFilter failed!
at SysConfig.MessageFilter.Register() in c:\...\MessageFilter.cs:line 42
at SysConfig.DTE.CreateDTE(Boolean ideVisible, Boolean suppressUI, Boolean userControl) in c:\...\DTE.cs:line 50
at SysConfig.Program.SysConfigM(Int32 i) in c:\...\Program.cs:line 163
at SysConfig.Program.SetNumberOfM() in c:\...\Program.cs:line 136
at SysConfig.Program.MenuHandler() in c:\...\Program.cs:line 48
at SysConfig.Program.Main(String[] args) in c:\...\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
---------------------------
What could happen?, searching about CoRegisterMessageFilter is very fun as it doesn't show a lot of information...
And... I've just copied the class from an example, and called Register()...
I'm trying to automate Visual Studio, in most cases the program flow works perfectly.
In some other cases it fails during calls to the Visual studio DTE...
In the manual from the manufacturer of the software I'm using they state that I should implement that COM Message Filter and they explain how to do it... Even they provide a sample that I've pasted directly into my code...
Anyone can see what's wrong given the message?
Should I add any dependency or similar thing into my project to get this working?
Being ultra-novice in C# I can't see where to search now...
And I truly would like not to add wait timers everywhere...
Thank you very much for your time and help.
|
|
|
|
|
|
I've just read this:
Please note that message filters can only be applied to STA-Threads and only one filter can be applied to each thread. Multithreaded apartments, for example console applications, cannot have message filters. These applications need to run in a STA-Thread to apply a message filter.
Now it seems the next step is to learn how to make a console application to run in a STA-Thread... well first I should know what is a STA-Thread...
Thank you for your answer Richard, I'll read about that GetLastError function. I guess it works like the one in C/C++ so it should be easy to get extra information.
But... reading the second link... it seems they are using a console application... let's see if I can get something there...
Thank you very much for the links!
|
|
|
|
|
Joan M wrote: Now it seems the next step is to learn how to make a console application to run in a STA-Thread.
It should be as simple as adding the [STAThread] attribute to your Main method:
using System;
static class Program
{
[STAThread]
static void Main()
{
...
}
}
STAThreadAttribute[^]
Understanding and Using COM Threading Models[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It was that...
Writing that [STAThread] on top of main made it work...
Still have to read about it to understand what happens under the hood but...
Thank you very much!
|
|
|
|
|
I have yet to take the time to learn EF, but I do have a few questions:
1). How does EF know if the data on an entity has been changed, and if so, in what way? For example, if I create a new instance of an entity, populate it, then send it to the repo, how does the repo know to do an insert instead of an up date?
2) When I query something and get back an entity, then change something on the entity, how does EF know what has changed? Does the entity contain old/new values somehow?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
There is a definite line of distinction between your operational entity and your persistent one; I think that's the piece missing in your puzzle.
Nothing is done automatically. If you want to do an upsert you generally need to code that, otherwise you're performing inserts or updates. If you want to modify a persistent entity with values on one that you've been working with, you need to pass it as an update.
Using an ORM like EF doesn't mitigate the need to have decision points about how you manipulate and update data, it just un-tethers the need to have SQL in the mix.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Not sure if that answered my questions. I'm just trying to understand the mechanics of what EF is doing.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Fair, enough, dialing it back:
1) It doesn't. You need to determine whether an insert or an update is appropriate.
2) It doesn't. You need to commit any updates.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
 Depending on the Version of EF you have different "Mechanisms" but they all basically boil down to
Simple Poco Classes for each data type returned(table or stored procedure), and references to any linked tables.
Then there is the map file which defines the parameters and settings for each object (which columns are required, field sizes, single or many...
To be perfectly honest its my experience that EF is a cool toy for pulling reports or nested data (Pull a Customer and have all his orders in a single call)
HOWEVER if performance is in any way a consideration for the application Avoid EF like the plague.
I personally prefer to use parameterized stored procedure ADO DB calls, then inside my POCO classes I will add two methods called FromADO one takes a DataRow and the Other Takes a DataTable
public static List<Deposit> FromADO(DataTable objectsToConvert)
{
return (from DataRow objectToConvert in objectsToConvert.Rows select FromADO(objectToConvert)).ToList();
}
public static Deposit FromADO(DataRow objectToConvert)
{
var returned = new Deposit();
if (objectToConvert.Table.Columns["ID"] != null && !string.IsNullOrEmpty(objectToConvert["ID"].ToString()))
returned.ID = int.Parse(objectToConvert["ID"].ToString());
if (objectToConvert.Table.Columns["DateTime"] != null && !string.IsNullOrEmpty(objectToConvert["DateTime"].ToString()))
returned.DateTime = System.DateTime.Parse(objectToConvert["DateTime"].ToString());
if (objectToConvert.Table.Columns["Description"] != null && !string.IsNullOrEmpty(objectToConvert["Description"].ToString()))
returned.Description = objectToConvert["Description"].ToString();
if (objectToConvert.Table.Columns["Total"] != null && !string.IsNullOrEmpty(objectToConvert["Total"].ToString()))
returned.Total = double.Parse(objectToConvert["Total"].ToString());
return returned;
}
What this accomplishes is any call that needs a Deposit you pass the DataTable or DataRow and you get a list or a single Deposit back.
Similarly your ORM class call becomes simple and easy to maintain
public Deposit GetDepositById(int id)
{
var parms = new List<SqlParameter>
{
new SqlParameter {DbType = DbType.Int16, Value = id, Direction = ParameterDirection.Input, ParameterName = "@ID", SqlDbType = SqlDbType.Int}
};
var returned = ADOHelper.ReturnDataTable(conn, "sp_DepositGetById", parms, CommandType.StoredProcedure);
return Deposit.FromADO(returned).FirstOrDefault();
}
And for a call the returns more than one deposit
public List<Deposit> GetDepositsByDateRange(DateTime begindate, DateTime enddate)
{
var parms = new List<SqlParameter>
{
new SqlParameter {DbType = DbType.DateTime, Value = begindate, Direction = ParameterDirection.Input, ParameterName = "@BeginDate", SqlDbType = SqlDbType.DateTime},
new SqlParameter {DbType = DbType.DateTime, Value = enddate, Direction = ParameterDirection.Input, ParameterName = "@EndDate", SqlDbType = SqlDbType.DateTime}
};
var returned = ADOHelper.ReturnDataTable(conn, "sp_DepositsGetByDateRange", parms, CommandType.StoredProcedure);
return Deposit.FromADO(returned);
}
While not Sexy, flashy or new its fast stable and simple to maintain.. my two cents
|
|
|
|
|
C. David Johnson wrote: To be perfectly honest its my experience that EF is a cool toy for pulling reports or nested data (Pull a Customer and have all his orders in a single call)
HOWEVER if performance is in any way a consideration for the application Avoid EF like the plague.
I can definitely understand where you're coming from; the biggest issue that most people have with EF is some of the completely insane and inefficient queries that it can generate when handling complex relationships.
The main problem presented by Kevin, though, is the concurrency issue. EF builds a local in-memory model of the data that it tracks so that updates can be batched back to the database, and this can cause some pretty contentious concurrency issues if not understood and handled correctly. This, in my opinion, is the biggest issue with the framework.
I prefer abstracting my DAL, which has led me to take a closer look at object stores and in-memory databases for high-performance applications, and a lot of custom interface work that allows me to inject a SQL provider if appropriate. This has definitely led me on a path away from ADO, though.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
As has been pointed out, all the magic happens when you "SaveChanges".
Prior to that, EF is capturing your "intentions" via add, updates and deletes to the "in-memory" data model; which involves entity keys, hash codes and "attached / detached" entities.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
I generate programmatically an excel file and I want to save it in a shared directory in the network but there is an error on the line like this xls.saveas("\\\\myserver\\shareddirectory\\myfile.xlsx");
Do you have any idea ?
Thanks !
|
|
|
|
|
Member 13421843 wrote: Do you have any idea ? No, because you have not told us what the error is.
|
|
|
|
|
Yes. Save it to a local location and copy it after it is saved. That way you'll know if there's a problem with saving or with network-access, and you'll have the added benefit that someone can sneakernet the file to where it is needed regardless of the network.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is it "like this" or "exactly" like this?
(There is no "universal" "share").
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
i need to add option in proprieties of performance counter because the category name don't appear in properties
|
|
|
|
|