|
I am using winforms, my english is not good so the expression makes you confuse. This means that when I am in form design mode when dragging control into a form, adding, editing, and deleting controls on the form, for some reason the code control on the form is not removed in the Form.Designer file.cs. but Form.cs (UI) has deleted very well. Do you understand me ?
|
|
|
|
|
If you find this happening, raise a bug report with Microsoft. This would indicate the fault is in their tooling,
This space for rent
|
|
|
|
|
I do not think it is necessary because VS2005 is old.
|
|
|
|
|
How to store viewstate values in specified folder? I have designed a page and it contains textboxes to accept data fron user so i want to store the values in specified folder using viewstate?
Please help.
Thanks in advance
|
|
|
|
|
ViewState is used to persist the state of the view between requests. It is typically stored in one or more hidden fields on the page.
It has nothing to do with storing values in a folder.
ASP.NET View State Overview[^]
Understanding ASP.NET View State[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In C# VS2005 I embedded a picture (file in the form *.png) normal but when the rebuild was reported The "GenerateResource" task failed unexpectedly.
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI +. Have you know how to fix this ?
|
|
|
|
|
I can't do this because the MemoryStream is immutable: (code excerpt)
using(MemoryStream mstream = new MemoryStream(File.ReadAllBytes(filepath)))
{
if (useDecryption)
{
mstream = decryptor(mstream);
mstream.Position = 0;
}
if (useDecompression)
{
mstream = decompressor(mstream);
mstream.Position = 0;
}
result = (T) dcs.ReadObject(mstream)
} So, okay, I can do this: (code excerpt)
MemoryStream mstream = new MemoryStream(File.ReadAllBytes(filepath));
if (useDecryption)
{
mstream = decryptor(mstream);
mstream.Position = 0;
}
if (useDecompression)
{
mstream = decompressor(mstream);
mstream.Position = 0;
}
result = (T) dcs.ReadObject(mstream); But that violates my early .NET memory-potty-training.
Best/better practice ? Perhaps better to pass a byte array ?
thanks, Bill
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
modified 10-Aug-17 0:32am.
|
|
|
|
|
Disposing a MemoryStream doesn't release any unmanaged resources. It simply sets some flags to indicate that future attempts to read or write the stream should throw an exception.
protected override void Dispose(bool disposing)
{
try {
if (disposing) {
_isOpen = false;
_writable = false;
_expandable = false;
#if FEATURE_ASYNC_IO
_lastReadTask = null;
#endif
}
}
finally {
base.Dispose(disposing);
}
}
Reference Source[^]
Despite the comment about the base method cleaning up async IO resources, it doesn't:
protected virtual void Dispose(bool disposing)
{
}
Reference Source[^]
But I know what you mean - it doesn't feel right to omit the using statement.
Perhaps a helper method to create the stream might help to hide the unpleasantness?
private static MemoryStream CreateStream(byte[] rawBytes, IEnumerable<Func<MemoryStream, MemoryStream>> decorators)
{
var result = new MemoryStream(rawBytes);
foreach (Func<MemoryStream, MemoryStream> decorator in decorators)
{
result = decorator(result);
result.Position = 0;
}
return result;
}
...
var decorators = new List<Func<MemoryStream, MemoryStream>>();
if (useDecryption) decorators.Add(decryptor);
if (useDecompression) decorators.Add(decompressor);
using (MemoryStream mstream = CreateStream(File.ReadAllBytes(filepath), decorators))
{
result = (T)dcs.ReadObject(mstream);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for another interesting, and challenging, response !
My "gut" is now telling me to switch to using byte-arrays wherever possible. Whether you gain anything (performance, memory economy) when shipping the raw data off to be encrypted and/or compressed by using a byte-array rather than a stream ... that's terra incognita to me ... but, I suspect that as I research the various tools that will come into focus.
cheers, Bill
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
The benefits would probably be more obvious if you were passing around the base Stream class. That way, your methods could work with anything stream-like, and wouldn't be limited to byte arrays.
private static Stream DecorateStream(Stream input, IEnumerable<Func<Stream, Stream>> decorators)
{
Stream result = input;
foreach (Func<Stream, Stream> decorator in decorators)
{
result = decorator(result);
}
return result;
}
...
var decorators = new List<Func<Stream, Stream>>();
if (useDecryption) decorators.Add(decryptor);
if (useDecompression) decorators.Add(decompressor);
using (Stream input = DecorateStream(File.OpenRead(filePath), decorators)))
{
result = (T)dcs.ReadObject(input);
}
Now your code can work on the file in chunks, rather than having to read the whole thing into memory first.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I have solution that is using Entity Framework 4 database first approach. When I add something new to database mappings of edmx file are not properly changed to reflect changes in a database, so I get famous error "entity is not part of the current context".
I have tried to Run custom tool and also Transform T4 templates but none of these options gave me a solution to this problem. I'm using Visual Studio 2010 and 2012.
Does anyone know the exact steps that needs to be taken in order to DbContext be synced with database model. Since I have existing database I would like to stick with database first approach. I would like to be able to add and modify objects in database and after "Update Model from database" to have all mapped and in sync.
Thanks
|
|
|
|
|
Upgrade to the latest version of EF (which is, like, version 6 or 7).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks, but I have tried that already and for some reason reference to EF 4 always get pulled into project. Is there a way to stay with EF 4 and to normally work with db changes ?
|
|
|
|
|
How to retrieve gujarati data from sql server
|
|
|
|
|
You do not retrieve the content based their locale, instead you retrieve the content based on the column.
If your table structure is — annoying — designed as the following,
PK_Table | SomeColumn | GujratiContent | ...
Then you can do something like this,
SELECT GujratiContent FROM table_name
That would return only the content from the column which contains Gujrati data. Other columns would be skipped. But, since SQL Server (or any SQL database) has no idea about the language, locale or content meaning, other than the fact that is it ASCII, Unicode or anything else... It cannot understand how to get Gujrati.
Secondly, if you meant to say that your Gujrati content gets lost, while you store the data in the database and upon retrieval it returns boxes, and question marks only. Then the problem is that you are not storing it as Unicode. Gujrati is an International language, and not English (or Latin), thus you need to use Unicode encoding instead of ASCII. One way to do that is to ensure Unicode data gets inserted, thus when you retrieve, Unicode data will be returned,
INSERT INTO table_name (column1, column2, GujratiContent, column3)
VALUES (1, 'ABC', N'Gujrati data here', DATE());
See this article to understand how Microsoft platforms understand Unicode.
See this article of mine to cross-check, Reading and writing Unicode data in .NET, SQL Server and .NET framework both support Unicode, it is up to you to check how you are passing the data.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Are you asking how you retrieve data entered in the Gujarati script (encoded in a Unicode compliant Gujarati font [^] ) ... not Devanagiri ?
I voted for Afzaal's answer, and you should, too
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
Hello,
I am trying to write a database table to a csv file.
It works, but the problem i have is that it adds an "extra column" without a header but the rest of the cells containing:
System.Data.Linq.EntitySet`1[BookLendingLib.Models.RentedBook]
I am using LinqToSql for my database, and i have 3 tables: Books, Readers, and RentedBooks(RentedBooks being an associative table with BookId and ReaderId to define the books rented by a reader).
In my database designer file the RentedBook is "tagged" as an AssociationAttribute and i assume its related to the RentedBooks table.
What should i do to fix this?
These are the methods i use to export to csv:
<pre>private static IEnumerable<string> ToCsv<T>(IEnumerable<T> list)
{
var fields = typeof(T).GetFields();
var properties = typeof(T).GetProperties();
foreach (var @object in list)
{
yield return string.Join(",",
fields.Select(x => (x.GetValue(@object) ?? string.Empty).ToString())
.Concat(properties.Select(p => (p.GetValue(@object, null) ?? string.Empty).ToString()))
.ToArray());
}
}
private void ExportBookDb(string saveFilePath)
{
BookDBDataContext bDC = new BookDBDataContext();
if (ExclBookList != null)
{
ExclBookList.Clear();
}
ExclBookList = new ObservableCollection<Book>(bDC.Books);
Book bPropNames = new Book();
using (StreamWriter textWriter = File.CreateText(saveFilePath + ".csv"))
{
textWriter.WriteLine(nameof(bPropNames.Id) + "," + nameof(bPropNames.Title) + "," + nameof(bPropNames.Author) + "," + nameof(bPropNames.Isbn) + "," + nameof(bPropNames.Quantity) + "," + nameof(bPropNames.RezervedQty));
foreach (var line in ToCsv(ExclBookList))
{
textWriter.WriteLine(line);
}
}
Thank you in advance!
|
|
|
|
|
Your ToCsv method returns the string representation of the value of every public field and property of the entity you pass in.
The value System.Data.Linq.EntitySet`1[BookLendingLib.Models.RentedBook] suggests your entity contains a navigation property which returns a collection of RentedBook entities. This is a property, just like any other, and so will be included in the output.
Your code will also not work correctly if any property value contains a comma.
Try using a proper CSV library, like CsvHelper[^]:
private void ExportBookDb(string saveFilePath)
{
using (var bDC = new BookDBDataContext())
using (var textWriter = File.CreateText(saveFilePath + ".csv"))
using (var csv = new CsvWriter(textWriter))
{
csv.WriteRecords(bDC.Books);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I tried it(csv Helper), and it works.
Thank you!
|
|
|
|
|
Hi Team
I am novice developer in C# and was given a test to complete. There is an existing class, but i dont know how to implement these two functions and methods; Please team i sincerely need help and once i passed it would be employed as C# developer.
using System.Collections.Generic;
using System.Linq;
using TestCode.Models;
namespace TestCode
{
public class StatsCalculator
{
public IEnumerable<team> TeamReferenceData { get; set; }
public IStatsWeighting StatsWeighting { get; set; }
public StatsCalculator(IEnumerable<team> teamReferenceData, IStatsWeighting statsWeighting)
{
TeamReferenceData = teamReferenceData;
StatsWeighting = statsWeighting;
}
// TODO: Return the player for the specified player number, or null if not located.
// The playerNumber parameter must be > 0. If it is not then return a null result.
// Note
// Team.Players has the players for the team.
// Player.PlayerNumber is the field to be compared against
public Player PlayerByPlayerNumber(int playerNumber)
{
return null;
}
// TODO: For each team return their win % as well as their players win %, sorted by the team 'win %' highest to lowest.
// If a teamId is specified then return data for only that team i.e. result list will only contain a single entry
// otherwise if the teamId=0 return item data for each team in TeamReferenceData supplied in the constructor.
// If a team is specified and cannot be located then return a empty list (list must be empty and not null).
// NB! If any player on the team has played 100 or more matches then IStatsWeighting must be invoked with the required parameters
// ONLY make this call if one or more of the player matches is >= 100.
// The result must be stored in the PlayerWeighting field inside the TeamValue result class.
// If all the players within the team has played less than 100 matches each then PlayerWeighting must be set to 0.
// Note
// Team Win % is Team.Victories over Team.Matches
// Player Win % is Player.Wins over Player.Matches i.e. the sum of all players win / matches on the team.
public IEnumerable<teamvalue> TeamWinPercentage(int teamId = 0)
{
return new List<teamvalue>();
}
}
}
// instructions for this test
What must be completed:
Inside StatsCalculator.cs are 2 methods with ToDos that must be implemented. These are PlayerByPlayerNumber and TeamWinPercentage
Read the ToDo's in order to understand what each method must do.
You must implement these 2 methods. Please implemented any tests (in the test project) you feel are relevant.
|
|
|
|
|
This is effectively your homework: it's a test to see how well you can do a specific task (which may or may not have any bearing on the final employment). As such, if we do it for you - which is what you are asking - then that gives the company the wrong idea about your skill and ability level. They will believe that you are an experienced developer with significant experience in C# and perhaps give you the job on that basis.
That isn't fair: not on them (recruitment is a very expensive process), not on you (who wouldn't last long in the job once they find out you lied about doing it yourself), and especially not on your fellow applicants who can do the job they are being hired for.
If you can't follow instructions such as those you have been given, then you aren't ready for that job. I'd suggest that you try applying for jobs you can do until you have brought your skill level up to the required standard.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have to question you getting this job. The assignment you've given is not complicated at all. In fact, it's pretty trivial. If you can't do this assignment, you're not going to be in that job for very long.
Sorry, but that's the brutal reality of the industry.
modified 8-Aug-17 10:29am.
|
|
|
|
|
Hello everyone,
I want ask about very old libraries / snippers
- CommandLine Parser,
- NDesk Console ( ManyConsole )
- PowerArgs
- CommandLine
and more...
Why do they not work for me? I tried libraries but they are not successful. Just I have idea own parameters like mkbundle.cs from Github. I already read. mkbundle is great helper and you think mkbundle's example parameters better than hard understandable libraries: Is it correct?
I found https://github.com/mono/mono/blob/master/mcs/tools/mkbundle/mkbundle.cs mkbundle.cs from Github and shows how do I understand like I create arguments / parameters.
I write example:
class Program
{
private SDLWindow game;
static int Main(string[] args)
{
int argIndex = args.Length;
game = new SDLWindow();
for (int i = 0; i < argIndex; i++)
{
switch (args[i])
{
case "-width":
case "-w":
game.Width = int.Parse(args[++i]);
break;
case "-height":
case "-h":
game.Height = int.Parse(args[++i]);
break;
case "-game":
break;
default:
break;
}
}
game.Run(60);
return argIndex;
}
}
class SDLWindow : GameWindow
{
public SDLWindow()
{
WindowBorder = WindowBorder.Fixed;
}
}
Just example like game's parameters
game -w 1024 -h 600
output: http://i.imgur.com/lP8R3hF.jpg
Is it correct? If I understand parameters like hl.exe -game for example changes current game directory:
/basedir is default directory - If I use "-game" than /othergamedir -> "-game othergamedir"
Thanks for answer!
Example of game's parameters like hl.exe -w 1200 -h 600, etc any game with parameters
modified 4-Aug-17 21:47pm.
|
|
|
|
|
What results are you getting? Do you have an error message you can share with us?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Really? I don't see that....
Non errors! Just I want know if they have same. Thanks!
I thought you have code like mkbundle.cs from Github.
Thanks!
|
|
|
|
|