|
I decided to port one of my vb apps over to c#, so far so good. I decided to give MongoDB a try and load the MongoDB.Bson, MongoDB.Driver, MongoDB.Driver.Core and MongoDB.Respository.Crud packages from Nuget. I went the repository route like I did in my Angular6 wrapped in .Net Core 2.2 App, but didn't think it through all the way, or it's sort of a test run with it.
It just occurred to me that on my repository DBContext configuration, that it uses the appSettings.json file and Microsoft.Extensions.Options to read the MongoDB values. I did some research and found that extension is tied to .Net Core 2. Well I guess I just answered my own question of how to find a workaround for it. This should work, just need to figure out where to initialize it, like in main form loading.
I was going to try that C# Mongo Driver but it hasn't been updated since 2010.
Is anybody else using MongoDB 4.0 in VS2017 c# Win Form, And have any experience with it?
I would to take .Net Core 3 for a test run on this project. It just makes sense to me since I have written lots of .Net Core 2 code already that I can reuse.
In my Angular .Net Core 2 App
public class CRMRepository : ICRMRepository
{
private readonly MongoDBContext _context = null;
public CRMRepository(IOptions<Settings> settings)
{
_context = new MongoDBContext(settings);
}
Proposed Thought
public class MongoDB {
public string Connection { get;set; }
public string Database { get; set; }
}
public class CRMRepository : ICRMRepository
{
private readonly MongoDBContext _context = null;
public CRMRepository(MongoDB _mongoDB)
{
_context = new MongoDBContext(_mongoDB);
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I need to have 15 digits of precision (after the decimal point) on a double precision value when it's written to a file for comparison to some legacy code. I can't seen to get it work consistently.
For instance if I perform the following;
double d = 0.123456789012345
Debug.WriteLine(d.ToString("G15"));
I get the expected output of -> 0.123456789012345 15 trailing digits of precision as expected
Then if I have the following;
double d = 10.123456789012345;
Debug.WriteLine(d.ToString("G15"));
The output is -> 10.1234567890123 13 digits of trailing precision
Finally;
double d = 12345.123456789012345;
Debug.WriteLine(d.ToString("G15"));
The output is -> 12345.123456789 9 digits of precision after decimal point
Using good old C++ you can just specify "%.15lf" as a format specifier and always get 15 digits of precision. This just seems to give a specific number of digits based shifting the decimal point.
|
|
|
|
|
It seem to me that "G15" produces 15 digits, not 15 decimal places!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Try:
d.ToString("F15") But...Double values only have a precision of "15 ~ 17" digits (depending on the value, it's down to how they are stored as binary): double keyword (C# Reference) | Microsoft Docs[^] so specifying 15 digits after the decimal poitn is probably not going to work in many cases.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Using "F15" produces the same result, this is maddening.
|
|
|
|
|
OriginalGriff wrote: But...Double values only have a precision of "15 ~ 17" digits (depending on the value, it's down to how they are stored as binary)... so specifying 15 digits after the decimal point is probably not going to work in many cases.
I suggest you read that part again.
If the total precision of the number is 15-17 digits, and you have four digits before the decimal point, you're not going to be able to get 15 digits after the decimal point.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I get exactly what I expect:
double d = 0.123456789012345;
Debug.WriteLine(d.ToString("G15"));
d = 12345.123456789012345;
Debug.WriteLine(d.ToString("F15"));
0.123456789012345
12345.123456789000000
Remember what I said?
Quote: But...Double values only have a precision of "15 ~ 17" digits (depending on the value, it's down to how they are stored as binary): double keyword (C# Reference) | Microsoft Docs[^] so specifying 15 digits after the decimal poitn is probably not going to work in many cases.
If the double variable can only hold a total of 15~17 significant decimal digits, then you can't get 20 output of it!
Remember how double values are stored: as binary with a mantissa and an exponent. So the code (rightly) prints the same number of significant digits and pads the rest to the size you asked for.
To be honest, if you think any number you can come up with is going to be accurate to fifteen digits, you are very probably wrong!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Oh i totally agree with you on the accuracy thing.
Oddly enough in C when you do the same thing;
double d = 0.123456789012345;
char buf[20];
sprintf(buf, "%.15lf\n", d);
OutputDebugStringA(buf);
output is 0.123456789012345
d = 12345.123456789012345;
sprintf(buf, "%.15lf\n", d);
OutputDebugStringA(buf);
output is 12345.12345678901
I still get 2 more digits of precision and that's exactly what I'm fighting against.
|
|
|
|
|
Not really - The C version depends on the compiler. If I try with an online C compiler[^] I get:
0.123456789012345
12345.123456789011470 If I try with Virtual-C[^] I get this:
0.123456789012345
12345.123456789011135
IT's not "extra accurate digits" it's "different interpretation of the output". Because floating point numbers don't translate well into binary (for example, 0.2 in decimal is a fixed value, in binary is a repeating sequence so it isn't accurate) you can "generate" more digits if you take the first one, then multiple by 10.0 and repeat. That doesn't mean that the values to get are "more accurate" - in fact they are prone to reduced accuracy but a higher digit count. Try it again with some different numbers and you should see what I mean.
Generally speaking, all systems use the same floating point storage design: IEEE 754, (because if they don't they can't use floating point coprocessors to do the hard stuff!)
IEEE 754 - Wikipedia[^]
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've punted on this issue it will be interesting to see the results of the data analysis when I load this data back into the system and process against the original data. I'm dealing with nanometer measurement data.
Thanks for the help.
|
|
|
|
|
Hi Guys,
Below code don't allow to create entry at database with null areas and pop-up comes to warn user.
I fill all fields/create entry and all fields are cleared up for new entry but once I try to add new entry, program allows me to create with empty fields.
Do I need to add some code in order form to reload or something like that?
What would be the way of getting rid of this issue?
Thanks.
note: something other than Application.Restart(). that would be great if no close&open app.
private void btnStokEkle_Click_1(object sender, EventArgs e)
{
if (txtAdi.Text == "" || txtModel.Text == "" || txtSeriNo.Text == "" || gon.Text == "" || tah.Text == "")
{
MessageBox.Show("Lütfen Tüm Alanları Doldurunuz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
vt.sqlCalistir("insert into kolon (siparis,malzeme,takip,gonder,tahmini,gercek) values ('" + txtAdi.Text + "','" + txtModel.Text + "','" + txtSeriNo.Text + "','" + gon.Text + "','" + tah.Text + "', '" + tt.Text + "')");
MessageBox.Show("İşlem Kaydı Yapıldı.", "İşlem Tamam", MessageBoxButtons.OK, MessageBoxIcon.Information);
getir();
txtId.Clear();
txtAdi.Clear();
txtModel.Clear();
txtSeriNo.Clear();
gon.EditValue = " ";
tah.EditValue = " ";
tt.EditValue = " ";
txtSeriNo.Text = Environment.UserName;
}
modified 13-Feb-19 21:02pm.
|
|
|
|
|
Not like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well noted OriginalGriff. As a C# beginner, I was trying to practice basic CRUD in Access db and yes backup is on.
I am just stuck at solving this. so is it all about SQL commands? if I use correct commands then that click event won't save any entry with a null field?
modified 13-Feb-19 21:02pm.
|
|
|
|
|
What null field? A TextBox never contains null, if it is empty, then its .Text property returns the empty string, not null.
|
|
|
|
|
Hi Al Soyo,
This was interesting, Please ping me on skype (tranthanhtu83) if you still not solve this issue.
Best regards,
TU Tran
Technical Leader
Blog: http://tranthanhtu.vn
Mail: contact@tranthanhtu.vn
Mobile: +84 90 883 884 6
Skype: tranthanhtu83
CodeProject: @techcoaching
LinkedIn: tutrancoaching
Github: techcoaching
|
|
|
|
|
You've been here long enough to know that this is NOT how CodeProject works.
If you want to help someone, then help them here on the site, so that others who are having the same problem can see the discussion and benefit from it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard Deeming,
I intend to check the code and will write another comment for the root cause.
Just look at the code, seems not create such problem.
And I will appreciate if you can talk in more friendly way (such as: this will violate the rule, .....).
We are here to learn and share friend and you are not my boss.
Thanks
Best regards,
TU Tran
Technical Leader
Blog: http://tranthanhtu.vn
Mail: contact@tranthanhtu.vn
Mobile: +84 90 883 884 6
Skype: tranthanhtu83
CodeProject: @techcoaching
LinkedIn: tutrancoaching
Github: techcoaching
|
|
|
|
|
Trying to take the discussion off-line violates the rules of this site.
If you want to help people on CodeProject, then help them HERE, not in a Skype discussion.
You've been here over 11 years. That's more than long enough to know the rules!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank Richard Deeming,
Best regards,
TU Tran
Technical Leader
Blog: http://tranthanhtu.vn
Mail: contact@tranthanhtu.vn
Mobile: +84 90 883 884 6
Skype: tranthanhtu83
CodeProject: @techcoaching
LinkedIn: tutrancoaching
Github: techcoaching
|
|
|
|
|
Since I'm not your boss, I need not stay friendly. There is nothing "interesting" about his "issue", and it seems like spamming. Going for a coffee before I decide whether or not to report this as spam, since your post does not contribute anything.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thank Eddy Vluggen for letting me know your idea.
Yeah, it was up to you.
Let consider the situation, @Eddy Vluggen has a problem with his code and the code seems works fine.
The problem was still there, I intend to ask him and may run the code to see any potential cause raises this problem, and may help him to fix. of course, I can write another comment about the root cause if I can found.
And I was not allowed and may be reported as spammer just because someone did not see what I see: The code looks ok but not work.
@Eddy Vluggen: Do you think this is the interesting point.
Again, thank for let me know your idea and you can do what ever you think is right.
Best regards,
TU Tran
Technical Leader
Blog: http://tranthanhtu.vn
Mail: contact@tranthanhtu.vn
Mobile: +84 90 883 884 6
Skype: tranthanhtu83
CodeProject: @techcoaching
LinkedIn: tutrancoaching
Github: techcoaching
|
|
|
|
|
tranthanhtu.vn wrote: And I was not allowed and may be reported as spammer just because someone did not see what I see: The code looks ok but not work. The code does not look "ok".
It is also not a particular complicated subject, there's literally examples on MSDN that you can copy and paste.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thank Eddy Vluggen,
Oh, I may lack of knowledge about "Win Application".
Ok, will come back and see the root cause and learn.
Best regards,
TU Tran
Technical Leader
Blog: http://tranthanhtu.vn
Mail: contact@tranthanhtu.vn
Mobile: +84 90 883 884 6
Skype: tranthanhtu83
CodeProject: @techcoaching
LinkedIn: tutrancoaching
Github: techcoaching
|
|
|
|
|
Hi,
How can i perform correlation on several charts(Draw lines to connect specific digits (e.g. depth or height) of a specific track on several multi-track charts) and print it in my report. on the another word, i want to connect related or same parts of all tracks together. for example imagine a hill that you dig(drill) a hole on that and dig(drill) another one beside it on a plane surface. the depth for both of holes is 1000m, the height of the hill is 5m. the lithology (Rock or Ore type) for both holes will be the same for 95m and there will be 5m difference between their lithology changes. i want to connect related parts together. i am also using from DevExpress components. if there are methods to achieve this, with DevExpress components or the visual studio itself, i will be thankful to help me or guide me through some useful assays. another question is how can i attach an image to my question.
thank you in advance.
|
|
|
|
|
For my serializer I have a table of all types from all loaded assembly that have an GuidAttribute.
Today, for debugging / diagnostic purpose, I decided to Log whenever a duplicate was found
Imagine my surprise when I found out zillion of duplicates! Mostly what looks like C++/RT COM interface.. behold!
(000214F2-0000-0000-C000-000000000046, ): Standard.IEnumIDList, Standard.IEnumIDList
(2c1c7e2e-2d0e-4059-831e-1e6f82335c2e, ): Standard.IEnumObjects, Standard.IEnumObjects
(92CA9DCD-5622-4bba-A805-5E9F541BD8C9, ): Standard.IObjectArray, Standard.IObjectArray
(92CA9DCD-5622-4bba-A805-5E9F541BD8C9, ): Standard.IObjectArray, Standard.IObjectCollection
(886d8eeb-8cf2-4446-8d02-cdba1dbdcf99, ): Standard.IPropertyStore, Standard.IPropertyStore
(000214E6-0000-0000-C000-000000000046, ): Standard.IShellFolder, Standard.IShellFolder
(43826d1e-e718-42ee-bc55-a1e261c37bfe, ): Standard.IShellItem, Standard.IShellItem
(B63EA76D-1F85-456F-A19C-48159EFA858B, ): Standard.IShellItemArray, Standard.IShellItemArray
(7e9fb0d3-919f-4307-ab2e-9b1860310c93, ): Standard.IShellItem2, Standard.IShellItem2
(000214F9-0000-0000-C000-000000000046, ): Standard.IShellLinkW, Standard.IShellLinkW
(56FDF342-FD6D-11d0-958A-006097C9A090, ): Standard.ITaskbarList, Standard.ITaskbarList
(602D4995-B13A-429b-A66E-1935E44F4317, ): Standard.ITaskbarList2, Standard.ITaskbarList2
(12337d35-94c6-48a0-bce7-6a9c69d4d600, ): Standard.IApplicationDestinations, Standard.IApplicationDestinations
(3c594f9f-9f30-47a1-979a-c9e83d3d0a06, ): Standard.IApplicationDocumentLists, Standard.IApplicationDocumentLists
(6332debf-87b5-4670-90c0-5e57b408a49e, ): Standard.ICustomDestinationList, Standard.ICustomDestinationList
(36db0196-9665-46d1-9ba7-d3709eecf9ed, ): Standard.IObjectWithAppUserModelId, Standard.IObjectWithAppUserModelId
(71e806fb-8dee-46fc-bf8c-7748a8a1ae13, ): Standard.IObjectWithProgId, Standard.IObjectWithProgId
(ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf, ): Standard.ITaskbarList3, Standard.ITaskbarList3
(ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf, ): Standard.ITaskbarList3, Standard.ITaskbarList4
What kind of criteria could I apply to skip such a type?
I don't foresee any would be used by the application, but if I could find some criteria that automatically dismiss such type and warn when they are used it would be nice... but I am not sure what to use...
mmm.. me think I could use (new) MyGuidAttribute instead of GuidAttribute. but it's kind of a hassle...
[EDIT]
I skipped all type where type.IsCOMObject || type.IsImport and I am down to 8 duplicates!
(496B0ABE-CDEE-11d3-88E8-00902754C43A, ): System.Collections.IEnumerable, System.Runtime.InteropServices.UCOMIEnumerable
(496B0ABF-CDEE-11d3-88E8-00902754C43A, ): System.Collections.IEnumerator, System.Runtime.InteropServices.UCOMIEnumerator
(AFBF15E5-C37C-11d2-B88E-00A0C9B471B8, ): System.Reflection.IReflect, System.Runtime.InteropServices.UCOMIReflect
(AFBF15E6-C37C-11d2-B88E-00A0C9B471B8, ): System.Runtime.InteropServices.UCOMIExpando, System.Runtime.InteropServices.Expando.IExpando
(496B0ABE-CDEE-11d3-88E8-00902754C43A, ): System.Collections.IEnumerable, System.Runtime.InteropServices.ComTypes.IEnumerable
(496B0ABF-CDEE-11d3-88E8-00902754C43A, ): System.Collections.IEnumerator, System.Runtime.InteropServices.ComTypes.IEnumerator
(AFBF15E6-C37C-11d2-B88E-00A0C9B471B8, ): System.Runtime.InteropServices.UCOMIExpando, System.Runtime.InteropServices.ComTypes.IExpando
(AFBF15E5-C37C-11d2-B88E-00A0C9B471B8, ): System.Reflection.IReflect, System.Runtime.InteropServices.ComTypes.IReflect
Mm.. that might be acceptable... although there is the risk of skipping IEnumerable instead of UCOMIEnumerable...
[EDIT2, solved]
I skipped all types where type.IsCOMObject || type.IsImport || type.Namespace.StartsWith("System.Runtime.InteropServices")
And I have no more duplicates
modified 5-Nov-18 8:49am.
|
|
|
|
|