|
|
|
I have a requirement to serialize out an object to XML where certain elements are encrypted for privacy / security reasons.
I've seen some samples on the internet for doing this, but they are all hardcoded. I.e. after the object is serialized you "patch" the elements you want to encrypt with the encrypted version. Not liking the hardcoded aspect of this solution. Also having to hardcode the decryption parts.
I've seen another solution where you use the XmlIgnore attribute on the plain text property and then add an "encrypted" version of the property and use the XML attributes to rename it. Not liking that you need 2 versions of every "secure" property.
Are there any other options? Ideally I would like something "in the spirit of .NET" along the lines of:
public class SomeObject
{
[XMLEncrypt]
public string SomeProp { get; set; }
public int SomeIntProp { get; set; }
}
where its something ".NETy" like a custom attribute or something like that. Unfortunately, I don't really see any way to hook into the XML serializer without completely re-writing it.
I thought about deriving a class from XMLSerializer and providing my own Serialize function that calls the base class and then afterwards goes through the object graph via reflection and patches the elements marked with the XMLEncrypt attribute, but I'm not really liking that idea that much either.
Any other suggestions?
|
|
|
|
|
SharpSerializer[^]?
It's open source, so you can mod it to make it do what you want. It's a NewBSD License, so I think you can do pretty much anything you need with it.
Bob Dole The internet is a great way to get on the net.
 2.0.82.7292 SP6a
|
|
|
|
|
Hmm... don't really care for its dictionary style XML output (makes the files a lot bigger then they need to be) and couldn't find a quick way to turn that off, but I looked around for another open source serializer based on your suggestion and found YaxLib... gonna see if I can hook my encryption into that one.
|
|
|
|
|
You're going to have to use reflection to find the encrypted properties in some way. That last suggestion of yours doesn't sound that bad to me. Deserialisation might be a pain in that case though.
|
|
|
|
|
I was thinking about this on the way into work this morning. You are right. The encrypted version is always going to be a string. Even if the underlying value is an int or something, so I'd have to find a way to store the temp string value before decrypting it to the real type. Currently looking into modding an open source serializer to support encryption "the right way".
|
|
|
|
|
Binary formatter solves this by providing custom serialization option. It calls OnSerializing, OnSerialized, OnDeserializing and OnDeserialized methods. There may be a similar solution for XML Serializer, you may also try this.
|
|
|
|
|
Could someone explain the best method for deleting all rows from a datatable where the value in column 0 is zero? I'm not sure how to handle the indexing after a row has been deleted...
Many thanks 
|
|
|
|
|
One way is that you loop through the rows and test if the row satisfies with your condition. So something like:
foreach(System.Data.DataRow datarow in mydatatable.Rows) {
if ((int)datarow["columnname"] == 0) {
datarow.Delete();
}
}
mydatatable.AcceptChanges();
For more information, see: DataRow.Delete Method[^]
|
|
|
|
|
Thanks for the response. I forgot to mention that my column's type is double. I tried your code and got an error, so I changed it to :-
foreach (System.Data.DataRow datarow in tblStanding.Rows)
{
if ((double)datarow["Charge"] == 0)
{
datarow.Delete();
}
}
tblStanding.AcceptChanges();
...and I get this error:-
"Collection was modified; enumeration operation might not execute."
Any ideas why?
|
|
|
|
|
Sorry, my mistake. The safest way to loop through the rows when modifying them is to use the index. So try something like:
for (int counter = tblStanding.Rows.Count - 1; counter >= 0; counter--) {
if ((double)tblStanding.Rows[counter]["Charge"] == 0)
{
tblStanding.Rows[counter].Delete();
}
}
tblStanding.AcceptChanges();
modified 6-Jan-13 16:31pm.
|
|
|
|
|
I tried the code and got this message :-
The name 'datarow' does not exist in the current context"
So, I tried changing the code to:-
tblStanding.Rows[counter].Delete();
That ran, but the rows with zeros weren't deleted??
Edit - Strangely some of the rows with zeros were deleted, but some remain??
|
|
|
|
|
That was still left from the previous version. I corrected the original answer.
The rows aren't deleted until you call AcceptChanges. They are only marked to be deleted. So depending if you have a database where you want to reflect the changes, you can first mark the rows to be deleted, actually delete from a database and the accept any pending changes.
Have a look at DataTable.AcceptChanges Method[^]
|
|
|
|
|
Accept changes was called. As per the edit in my previous post, only some of the rows with zeros have been removed?
Is the indexing here working correctly? I've seen other methods were the loop starts at the bottom of the table.
|
|
|
|
|
You're correct, looping from the end is working since when an item is removed, it would be 'skipped' if looping forward.
|
|
|
|
|
Sorry - I didn't notice your loop was starting at the bottom
I will try and figure out why only some zeros are being removed. Thanks for your help.
|
|
|
|
|
You're welcome, hopefully you find the reason. If needed, post a new question to the forums
|
|
|
|
|
Hi
i have problem in this senario :
I have Sql server database 2008 R2 ,
Entity FrameWork 4 with ModelFirst approach
project : PM software with GIS
beacuse security we decided that security of system implemented with RLS(Row level Security ) on server side (DBMS) , i mean with Schema and View on Sql only Record's of views showed up for valid user ,
and for Views in SQL don't have relation to other views
" for example tables that we connect their relation wity PK and FK "
when i generate EF model from database only i add views in the Model
so , i corrected Name Of Views with polorilize , change Updatableview Confige for any view that supported as well as Table ,
and by hand i connect all relation between entities that made up of views
by Navigation panel and association Tool
what's the problem :
beacuse i created all relation in EDM between entitys and thease not exsit in between of views
,
any time i change fileds,views , name of views , schema of view and important of them New Views with New Schema and ,...
when I update model by EF EDm (ModelFirst)
all of older entities crashed ,
all of realation between entities damaged
, and all change not returned
note :
for speed , security and distributed business of system
we tryed all proccess and all calculation on server sidee
plaese Help me....
Regard
DOT NET Developer
Ali Sarshogh . Iran country.Isfahan City
Chief programmer.

|
|
|
|
|
Hi,
So I am to design an application with some basic functionality and hardware interface (COMs etc), have decided to use C#.
The System which the app run on will be WinXp, without Internet and it will be a dedicated system to run that app ONLY, nothing else has to be run on it, there will be keyboard/mouse to sue the app but the user is not expected to go elsewhere, not be able to close the app and app should start-up as XP starts, no explorer,task manager etc.
It is for a dedicated POS terminal... can someone here please guide me a bit in the right direction, I am sort of lost as from where to start.
I know I will need to put the app in startup to get it running when system starts and somehow keep explorer from starting, I can capture key sequences and/or disable Windows shortcuts altogether (don't know how), provide a control to shutdown PC from within the app.
Note: the user is not the opponent, he is not deliberately trying to get out of the app, I hope.
Does anyonehave experience with this type of requirement.
|
|
|
|
|
Zaid Pirwani wrote: Does anyonehave experience with this type of requirement.
Kiosk mode[^]
|
|
|
|
|
KIOSK, so this was the magic word I was missing.... simply didn't came to mind.
THANKS for the tutorial link. 
|
|
|
|
|
You're welcome 
|
|
|
|
|
As noted in the other thread kiosk is the key word but do further research on it besides just the one tutorial.
There are many clever ways to break a kiosk and you should insure that at least the common ones are not allowed.
|
|
|
|
|
when I try to open a office word file with c# in website, everything is working fine on my local machine. However when I upload the files to hosting server I receive an error like:
"Could not load file or assembly 'office, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c' or one of its dependencies.
The system cannot find the file specified".
I have learned that hosting server machine hasn't installed office version because of licence an security reasons.
How can I solve this problem ?maybe can I reference a dll file on client machine to open the word document with c# code or .. please help me about it.
|
|
|
|