|
I don't have much time at the moment so you're article will likely be out before I can even start on that. Exams, deadlines and stuff are keeping me away from programming fun :-/
But writing my article was fun enough for this week and a good break from learning
|
|
|
|
|
GravityPhazer wrote: I love all C#6 features and use them quite a lot.
I love writing code that I think others in the future will have a hope of figuring out without jumping through loops to do so.
And I appreciate those rare occasions when I must maintain someone else's code were they were more focused on implementing the needed business functionality in a straightforward manner and where they actually took the time to think about real error conditions and how to maintain the code when it runs in production.
Of course none of that has anything to do with the language that it is written in. Applies equally to C#, Java, C++, Flavors of SQL, perl and even OS script languages.
|
|
|
|
|
Sascha Lefèvre wrote:
Do you have a project where fast string formatting is critical?
Can't ever recall where that ever was an issue ever.
Worked on a project where reading and parsing text fast was a concern. But turn out via profiling and production metrics that language specific IO was sufficient with some minor tweaks.
Sascha Lefèvre wrote: Now that we have string interpolation
For me I can't see that as anything but syntactic sugar that provides no real benefit. To be fair the only thing I work on is back end servers so consequently the vast majority of strings I usually work with are logging strings.
|
|
|
|
|
jschell wrote: For me I can't see that as anything but syntactic sugar Sure that, but
jschell wrote: that provides no real benefit to me improved readability is a great benefit. Especially when you have a format string with a couple more than just 2-3 placeholders where some of them even repeat the index-notation becomes really cryptic.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: to me improved readability is a great benefit.
Only study I have ever seen that was even close to objectively measuring "readability" was one related to font choices in marketing material.
|
|
|
|
|
I can't find tutorials to understand
(Permissions ,Principal,AccessControl,Authentication)
|
|
|
|
|
Are looking for a tutorial for something specific (like cryptography or role based security)? System.Security contains plenty of classes which cater for different kinds of needs. Also, did you checked MSDN documentation if that helps you?
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
There is an article on Codeproject that might help...
Understanding .NET Code Access Security[^].
You might have more luck finding more articles and/or tutorials if you pick a more specific part of the namespace - use the MSDN documentation to drill down into what is available. For example if you pick on Cryptography then this pops up - Walkthrough: Creating a Cryptographic Application[^]
O'Reilly publish a book called "Programming .NET Security" by Allen Jones and Adam Freeman - a free trial at Safari could get you started Programming .NET Security [Book][^] (but the trial only lasts 10 days and it's a bit pricey after that) - Disclaimer - I am nothing to do with Safari and I am not recommending nor condemning it's use.
modified 20-Jan-16 8:25am.
|
|
|
|
|
Im using the following code to fix the orientation of image taking into account the EXIF Orientation Tag
static void FixImageOrientation(Image srce)
{
const int ExifOrientationId = 0x112;
if (!srce.PropertyIdList.Contains(ExifOrientationId)) return;
var prop = srce.GetPropertyItem(ExifOrientationId);
var orient = BitConverter.ToInt16(prop.Value, 0);
prop.Value = BitConverter.GetBytes((short)1);
srce.SetPropertyItem(prop);
switch (orient)
{
case 1:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
case 2:
srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
srce.RotateFlip( RotateFlipType.Rotate180FlipX);
break;
case 5:
srce.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
srce.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
srce.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
default:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
}
}
This code removes the EXIF Orientation Tag properly.
And saving the image works is i simply use **`img.save`**
But the app provides user the ability to select the format of the image.For that i use the following code
private void saveJpeg(string path, Bitmap img, long quality)
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo Codec = this.getEncoderInfo(imgformat);
if (Codec == null)
return;
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path + ext, Codec, encoderParams);
}
public string getimgext(string ccodec)
{
if (ccodec.Equals("image/png"))
{
return ".png";
}
else if (ccodec.Equals("image/jpeg"))
{
return ".jpg";
}
else if (ccodec.Equals("image/tiff"))
{
return ".tif";
}
else if (ccodec.Equals("image/bmp"))
{
return ".bmp";
}
else if (ccodec.Equals("image/gif"))
{
return ".gif";
}
else
{
return null;
}
}
private ImageCodecInfo getEncoderInfo(string mimeType)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
for (int i = 0; i < codecs.Length; i++)
if (codecs[i].MimeType == mimeType)
return codecs[i];
return null;
}
When i save the image with `SaveJpeg` the image gets saved with wrong orientation.What im i doing wrong? Please help.
|
|
|
|
|
1. context: Windows Forms. last year I posted a question here GZip, and the code shown here is based on content in that thread: [^].
2. currently: I am successfully using GZip to serialize and de-serialize a very complex object.
3. the issue is: if I do two reads/de-serializations of the code I get the "being used by another process" file access error. so far research on the web has not solved the problem.
4. comparison with using WCF to serialize to 'xml: using this very standard code:
using (FileStream fs = new FileStream(filepath, FileMode.Create))
{
dcs.WriteObject(DataObject, this);
} The serialized object can be de-serialized any number of times without the error seen using GZip.
5. the GZip code:
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization;
public static DataObject DeSerialize(string filepath)
{
DataContractSerializer dcs = new DataContractSerializer(typeof(DataObject));
DataObject dto;
using (MemoryStream xmlStream = new MemoryStream())
{
using(GZipStream deCompStream = new GZipStream(File.Open(filepath, FileMode.Open),CompressionMode.Decompress, true))
{
deCompStream.CopyTo(xmlStream);
deCompStream.Close();
xmlStream.Position = 0;
}
dto = (DataObject)dcs.ReadObject(xmlStream);
xmlStream.Close();
}
return dto;
} thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
modified 17-Jan-16 10:12am.
|
|
|
|
|
Bill, shouldn't you close the underlying stream as well?
using (MemoryStream xmlStream = new MemoryStream())
{
using (FileStream fs = File.Open(filepath, FileMode.Open))
{
using(GZipStream deCompStream = new GZipStream(fs, CompressionMode.Decompress, true))
{
deCompStream.CopyTo(xmlStream);
deCompStream.Close();
xmlStream.Position = 0;
}
dto = (DataObject)dcs.ReadObject(xmlStream);
xmlStream.Close();
}
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Alternatively just specifying false for the last ("leaveOpen") parameter of the GZipStream-c'tor.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks, Sacha, turns out I just didn't take a close look at that flag, setting it to 'false makes everything work.
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
To avoid those non-descriptive true's and false's (non-descriptive as arguments) I usually use the named argument syntax for them or, alternatively, if it's my own method declaration, enums.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thanks, Griff, looking at your code and mine I can't seem to see a difference, and I am, I believe, closing the XMLStream.
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
The difference is that your code opens the FileStream inside the GZipStream constructor call:
using(GZipStream deCompStream = new GZipStream(File.Open(filepath, FileMode.Open),CompressionMode.Decompress, true))
Where mine extracts that to a separate using block which closes and disposes it at the end.
using (FileStream fs = File.Open(filepath, FileMode.Open))
{
using(GZipStream deCompStream = new GZipStream(fs, CompressionMode.Decompress, true))
{
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi Griff,
Your code works.
I must be blind-as-a-bat tonight. fyi: I tried reversing the order of creating memorystream and gzipstream ... still using only two levels of 'using ... and got the same error.
Sascha also had a valid solution here: I was leaving the file open by my setting the Gzip calls 'leaveOpen flag to 'true.
But, your code adds an additional level of 'using that takes care of the "in-use" error independently of the value of the 'leaveOpen flag in the calls to GZip.
thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
modified 18-Jan-16 2:43am.
|
|
|
|
|
Hi,
Can you help me ? I am try diable that MainForum run again form volumepanel. I want this:
When i am goto to top of screen the mainform show only ove volumepanel.
Here is code:
X = Cursor.Position.X;
Y = Cursor.Position.Y;
if ( Y == 0 ) {
if (( Application.OpenForms["volumepanel"] as MainForm ) != null ) {
MessageBox.Show("fdf");
} else {
volumepanel vpanel = new volumepanel();
vpanel.Show();
}
|
|
|
|
|
I'm sorry, but I think you need to be more specific.
Personally, I have no idea what you're trying to achieve.
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
i am developing Dekstop Manager for disabled peoples, contolled with eyes.
If user goes to top of the screen:
X = Cursor.Position.X;
Y = Cursor.Position.Y;
if ( Y == 0 ) {
Exec this code:
volumepanel vpnelc = new volumepanel();
vpnelc.Show();
And show volumecontrol frame. The problem is that open in loop volumecontrol frame when user stay with mouse on top. I am need protect that show only one volumecontrol.
Here is captured the problem:
20160114 231834 - YouTube[^]
|
|
|
|
|
Then before you open the volume control you need to detect if it is already opened!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I know and try more examples and don´t workin
|
|
|
|
|
From your first message:
if (( Application.OpenForms["volumepanel"] as MainForm ) != null )
Is the VolumePanel-Form actually of the type MainForm? If not, the as-keyword will make the expression left of the equal-sign null, so that your if-check fails although the VolumePanel actually is open.
Also, since you're using the return value of Application.OpenForms["volumepanel"] only for checking for null you don't even need the as-keyword here.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Without seeing your code, I can only propose an answer that I think will work independent of your UI design; if I could see your code, I'd probably propose creating a "local" boolean variable.
1. set a global static variable 'IsVolumeControlShown
public static class ApplicationGlobals
{
public static bool IsVolumeControlShown = false;
} 2. when you get the event notification to show the VolumeControl:
public EyesAtTopEvent(????, ????)
{
if(! ApplicationGlobals.IsVolumeControlShown)
{
VolumeControl.Show();
ApplicationGlobals.IsVolumeControlShown = true;
}
} 3. When you get the Event to hide the VolumeControl:
public EyesNotAtTopEvent(????, ????)
{
if(ApplicationGlobals.IsVolumeControlShown)
{
VolumeControl.Hide();
ApplicationGlobals.IsVolumeControlShown = false;
}
} Note: this is not code I would actually use, but an example I hope will indicate to you a "path to follow:"
0. create the VolumeControl whatever (panel ? form ?) once and keep a reference to it where you can access it.
1. use a variable to control the visibility of the VolumeControl
2. use that variable in the right place to show/hide the VolumeControl as needed.
Note: "ideally" you would be so "in control" of the code that you would be certain when you were showing or hiding the VolumeControl, in which case you would not have to check the current visible state of the VolumeControl every time you needed to show or hide it. However, imho, the kind of "defensive programming" shown here ... the visible state check ... is often useful in UI work where events may happen at a high frequency.
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
modified 15-Jan-16 7:57am.
|
|
|
|
|