|
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.
|
|
|
|
|
|
Hello
I need to create a sw that send SMS from a c# form using a Sony Xperia E4.
1) I cannot find the AT command to drive the smartphone
2) I cannot find the way to assign the correct portname to the usb port I connect the smartphone to.
I am using System.IO.Ports .
Then I make this nameport.WriteLine("AT+CMGS=" + Celnumber + "r") but here code return with exception.
Regards
Roberto
|
|
|
|
|
The AT commands are documented all over the web. The command set is standardized, with vendor specific extensions. A little Google goes a long way[^]. Sending an SMS normally doesn't use any vendor extensions.
As for "assigning a port", your code doesn't do that. You have to get that information from either from the user or your code can take an educated guess at the port name. Example[^].
|
|
|
|
|
Hi All,
I want to create my own report builder for our windows or web c# application, for each project we are build we must create a reports my need is we want to build the report builder and we can add it to any project and create the reports using this builder dynamically.
Please let me know if there is a tool can do that or how we can build this tool.
Thank you all
|
|
|
|
|
There are many component vendors out there who provide exactly this. I like the Syncfusion options, but you can choose any of the major vendors (DevExpress is a popular choice).
This space for rent
|
|
|
|
|
ok, look for my need.
1. create windows/web application that can connect to a database.
2. choose type of report from procedures, or from views
3. then we choose the report type is pivot or not
4. we have 3 list first for row header, second for column header, and the last for the sql operation such as sum, count, max
5. if the report is not pivot the it will be a normal select, and we drag and drop the view fields name to the column header list and if there is an sql operation we drag a field over one of them (sum, count,....), and create the select
6. if the report is pivot we drag fields for the column header, and fields for the rows header, and fields for the operation if found and we create the pivot select.
7. after that we save this select to a report database contains report name , select query, report classification.
8. in each application we build the reports from these database in the application menu and we can view the data and print it using the shown screen which is built in the dll or api that we can create for the web and for the windows
please let me know if this is possible or not, or if there is a tool can we buy it to use and don't create our own one.
|
|
|
|
|
Please stop spamming the thread with your requirements. This isn't a code-on-demand service where you list your vague requirements and someone spends days coding a solution for you. If you can't do this work yourself then look to hire a freelancer.
|
|
|
|
|
zead jalil wrote: Please let me know if there is a tool can do that or how we can build this tool. The amount of code is incredibly complex and very time consuming to do this yourself. As such, there is no way we can tell you how to do it here. It all depends on how much control you want to give your users.
I suggest using a tool like Microsoft SSRS and it's Ad hoc report builder or some other tool that already exists.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
ok, look for my needed.
1. create windows/web application that can connect to a database.
2. choose type of report from procedures, or from views
3. then we choose the report type is pivot or not
4. we have 3 list first for row header, second for column header, and the last for the sql operation such as sum, count, max
5. if the report is not pivot the it will be a normal select, and we drag and drop the view fields name to the column header list and if there is an sql operation we drag a field over one of them (sum, count,....), and create the select
6. if the report is pivot we drag fields for the column header, and fields for the rows header, and fields for the operation if found and we create the pivot select.
7. after that we save this select to a report database contains report name , select query, report classification.
8. in each application we build the reports from these database in the application menu and we can view the data and print it using the shown screen which is built in the dll or api that we can create for the web and for the windows
please let me know if this is possible or not, or if there is a tool can we buy it to use and don't create our own one.
|
|
|
|
|
public string SimpleReport(string title, string head, bool disp_head, int size, string csvHeader, string sizes, ref ArrayList myReport)
{
if (myReport.Count == 0)
return "";
ArrayList lstHeader = new ArrayList(),
lstContent = new ArrayList(),
lstTableSizes = new ArrayList(),
lstMessages = new ArrayList(),
lstFilters = new ArrayList(),
lst_sub_tbl_head = new ArrayList();
lstContent.Add(myReport);
lstMessages.Add(title);
lstTableSizes.Add(size);
string[] par = csvHeader.Split(',');
if (sizes == "")
{
for (int t = 0; t < par.Length; ++t)
{
sizes += (size / par.Length).ToString() + ",";
}
sizes = sizes.TrimEnd(',');
}
for (int t = 0; t < par.Length; ++t)
lst_sub_tbl_head.Add(par[t]);
lstHeader.Add(lst_sub_tbl_head);
return CodeReport ( title, head, disp_head, ref lstHeader, ref lstContent, sizes );
}
public string SimpleReport(string title, int size, string csvHeader, string sizes, ref ArrayList myReport)
{
return SimpleReport(title, "Resultados", size, csvHeader, sizes, ref myReport);
}
public string SimpleReportAlt(string title, int size, string csvHeader, string sizes, ref ArrayList myReport)
{
return SimpleReport("", title, size, csvHeader, sizes, ref myReport);
}
public bool changeColor = false;
public string CodeReport ( string info, string head, bool disp_head, ref ArrayList lstHeader, ref ArrayList lstContents, string sizes )
{
string[] s_pw = sizes.Split(',');
int t_size = 0;
for (int t = 0; t < s_pw.Length; ++t)
t_size += Convert.ToInt32(s_pw[t]);
StringBuilder sb = new StringBuilder();
sb.Append(info + "<span style='font-size:12px'><section class='widget2'><table class='table table-hover'>");
ArrayList tmp_head_cur_categ = lstHeader[0] as ArrayList;
ArrayList tmp_content_cur_categ = lstContents[0] as ArrayList;
if (disp_head)
{
sb.Append("<thead><tr>");
for (int t = 0; t < tmp_head_cur_categ.Count; ++t)
{
string cont = tmp_head_cur_categ[t].ToString();
sb.Append("<th valign='top' align='left'><b>" + cont + "</b></th>");
}
sb.Append("</tr></thead>");
}
sb.Append("<tbody>");
for (int t = 0; t < tmp_content_cur_categ.Count; ++t)
{
ArrayList tmp_line = tmp_content_cur_categ[t] as ArrayList;
sb.Append("<tr>");
for (int g = 0; g < tmp_line.Count; ++g)
sb.Append("<td valign='top' width=\"" + s_pw[g] + "px\">" + tmp_line[g].ToString() + "</td>");
sb.Append("</tr>");
}
sb.Append("</tbody></table></section></span>");
return sb.ToString();
}
List<UserData> lst_report = new List<UserData>();
ArrayList myReport = new ArrayList();
for (int t = 0; t < lst_report.Count; ++t)
{
UserData p = lst_report[t];
ArrayList columns = new ArrayList();
columns.Add("<a href='SamplePage.aspx?cod=" + p["id"] + "'>" + p["login"] + "</a>");
columns.Add(p["name"]);
columns.Add(p["email"]);
myReport.Add(columns);
}
LitRes.Text = var_util.SimpleReport( "", 0, "Login,Full Name,Email", "100,180,120", ref myReport);
|
|
|
|
|