Truth be told I wanted to put this in design and infrastructure but for some reason the page was blank. Anyways this is a good spot because it has some .net specific issues. I am starting to write a rather large program. Easily my biggest ever by a long shot. Now I am having an issue with how the interface should deal with requirements of the dll. I will give an example. The dll will make a submission to a website and the submission should have at least 1 image. So as I see it I have 2 options and could actually do both. Should the interface know this requirement and check if the user has added at least one image (therefore alerting the user and not making the submission) or should the dll throw an exception to which the interface will catch and then let the user know. Or should I do both? Or is there another way that I am not thinking of?
bfis108137
Posts
-
Relationship of dll and interface -
2 way eventsJust what I was looking for. thx
-
2 way eventsWell in this case it's a captcha. So I don't know if it will even be required for 1 and 2 I need the user to solve it.
-
2 way eventsIs there such a thing as 2 way events? OR maybe I am doing this wrong. My form is making a call to a dll to submit a form and logon to a web site if required. The dll all of a sudden needs more information that wasn't thought it would need prior so it wants to ask the user for more information and then continue when it has it. I have searched around for 2 way events with no luck. I started to make an event that calls back to the form and then the form calls back with the new information to a continuation event but then I started to realize that there are issues with this such as another function called the logon function and the form doesn't know about that. Obviously I could track that as well. In any event I would like to know if I am doing it the wrong way.
-
c#To get the position you just use the MouseEventArgs X and Y values. Using the standard visual studio format your code would look like this for a label called label1 that moved with the mouse.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
label1.Location = new Point(e.X, e.Y);
}From here
-
How to deal with environment variables and non admin usersWell it was a machine environment variable since the path was going to be the same across all users. And you are right Application.StartupPath does work correctly but here is where the problems started. I was using a dll. I wasn't using Application.StartupPath. I was just trying to get information out of a file so I wasn't even using a path. I was just doing something like string someString = File.ReadAllText("FileName.txt"); When it would run normally (not at startup) then it would read and write to the folder where the app was. If it was run at startup however, it would read or write to the user's folder. I misspoke myself about the Application.StartupPath. I have been doing a lot of debugging and apparently that wasn't what happened but I assure you the issue I just presented did happen. The file with a dll is in c:\test. Here is the code. Now the first time it's run as expected there is a file called error.txt which says "Could not find file 'C:\test\test.txt'." The path.txt file and the test.txt files are as expected. However when it runs at startup, the time in the test.txt file doesn't change and when I look in the user folder, I see a new error.txt file along with a test.txt file. The error.txt file says "Could not find file 'C:\Documents and Settings\User\test.txt'." and the time in the test.txt file is more up to date. So again I misspoke before and I assure you it was accidental but and I have found a way to solve my problem but this was my situation. I hope you accept my apology. A button and form load with the following code.
private void Form1_Load(object sender, EventArgs e)
{
TestClass tc = new TestClass();
tc.ReadFile();
tc.WriteFile();
}private void button1\_Click(object sender, EventArgs e) { string path = Application.StartupPath + @"\\CurrentFolderTest.exe"; RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run", true); File.WriteAllText("path.txt", Application.StartupPath); key.SetValue("foldertest", path); }
Here is the code from the dll
public void WriteFile()
{
File.WriteAllText("test.txt", DateTime.Now.ToLongTimeString() + DateTime.Now.Millisecond.ToString());
}
public void ReadFile()
{
try
{
string test = File.ReadAllText("test.txt"); -
How to deal with environment variables and non admin usersThe path I tried was in 2 places. First I made a folder in the c root. Then I thought it had to do with permissions so I used the public folder. This is c:\users\public on win7/vista and it's c:\documents and settings\All Users in xp. Like I said I used Application.StartupPath and it works but only when I start it myself. When it runs automatically at startup, "Application.StartupPath" points to c:\users\current user. With all that being said I found a solution. I add an environment variable which does require elevation but it's a one time thing when the app is first installed which i use a separate app to do(which i call from the main app) so as to not require the higher privilege all the time. That much I had working before. Where I got stuck was trying to retrieve the variable. It would require elevation as well which was unacceptable. However I found a solution. I found this on another site but since I know how some sites are with links I am not going to post the link. Here is the code I used to retrieve an environment variable without elevation.
string keyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment\";
string path = (string)Registry.LocalMachine.OpenSubKey(keyName).GetValue("variablename", "", RegistryValueOptions.DoNotExpandEnvironmentNames); -
How to deal with environment variables and non admin usersI have a program that needs to run at startup for each user on the pc and it reads a file that was made using binary serialization. The file just sits in the program folder but the path that comes up (I used Application.StartupPath) points me to the user folder of the active user if I am not mistaken. So I thought I would access the registry entry that I put in order for it to start up at startup but I get access denied. I tried setting an environment variable, but it requires admin privileges to access the variables. I must be going about this the wrong way. Could someone please point me in the right direction.
-
c++ exporting class variablesI am very very new to c++. I have been allowed lol to be a part of this c++ project. I am supposed to write a c++ dll that will export to c#. Anyways I am having trouble with class variables in functions that are exported. Could someone help me pleaser with this. Fyi we are using qt framework so that's why you see a few qt things. Basically it is crashing if I access a class variable which in this case is called testInt. this is not the actual code we are working with but it does duplicate the problem exactly as it occurs in the real code. The problem is my c# code crashes when the variable testInt is accessed but not if testInt2 is accessed. header
#ifndef QTDDLLTESTCLASSVARIABLE_H
#define QTDDLLTESTCLASSVARIABLE_H#include "qtddlltestclassvariable_global.h"
class QTDDLLTESTCLASSVARIABLE_EXPORT qtdDllTestClassVariable
{
public:
qtdDllTestClassVariable();
~qtdDllTestClassVariable();
void Test();
int testInt;
private:};
#endif // QTDDLLTESTCLASSVARIABLE_H
#include "qtddlltestclassvariable.h"
#includecpp file
qtdDllTestClassVariable::qtdDllTestClassVariable()
{}
qtdDllTestClassVariable::~qtdDllTestClassVariable()
{}
void qtdDllTestClassVariable::Test()
{
qDebug() << "started";
testInt = 5;
int testInt2 = 5;
qDebug() << testInt << " after int";
qDebug() << testInt2 << " after int2";
}c# code
[DllImport(@"..\..\..\Win32\Debug\qtdDllTestClassVariable.dll", CharSet = CharSet.Unicode, EntryPoint = "?Test@qtdDllTestClassVariable@@QAEXXZ")]
public static extern void Test(); -
advanced settingsIs this only for certain kinds of serialization because I just in the past few minutes successfully manually persisted the objects using the following code. It works perfectly except that it uses a file that the user can screw with which I wanted to avoid. I.E. They could move the program without the file. for loading
if (File.Exists(settingsFileName))
{
Stream TestFileStream = File.OpenRead(settingsFileName);
BinaryFormatter deserializer = new BinaryFormatter();
accounts = (Accounts)deserializer.Deserialize(TestFileStream);
TestFileStream.Close();
foreach (Account a in accounts.List)
{
ListViewItem item = new ListViewItem(new string[] { a.Broker, a.Name, a.AccountNumber, a.Balance.ToString(), a.Equity.ToString() });
listView1.Items.Add(item);
}
}for saving
Stream TestFileStream = File.Create(settingsFileName); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(TestFileStream, accounts); TestFileStream.Close();
-
advanced settingsok so after getting frustrated I decided to run a test. My thinking was that maybe it can't save it. It would seem this is correct but I don't know why. I tried to save a string using the same method and it worked without editing the app.config file. So then I would try just to save one instance of the nested class Account and it did not work either so who knows.
-
advanced settingsI didn't have a company but I added it and it didn't help. I will just put the code for the class and the nested class. Also as I noted before I never touched the app.config file so if I do need to make changes to that then I would need to know how to do that. Here is the Accounts class
[Serializable]
public class Accounts
{
public Accounts()
{
List = new List();
}public List List { get; set; } public decimal TotalBalance() { decimal balance = 0; foreach (Account a in List) { balance += a.Balance; } return balance; } public decimal TotalEquity() { decimal equity = 0; foreach (Account a in List) { equity += a.Equity; } return equity; } }
And here is the Account class
[Serializable]
public class Account
{
public Account(string path)
{
Path = path;
Initialize();
}private bool Initialize() { using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(fs)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); Broker = values\[0\]; Name = values\[1\]; AccountNumber = values\[2\]; Balance = decimal.Parse(values\[3\]); Equity = decimal.Parse(values\[4\]); break; } } } return true; } public bool Update() { using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(fs)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); Balance = decimal.Parse(values\[3\]); Equity = decimal.Parse(values\[4\]);
-
advanced settingsI would have done that from the beginning but my type is not supported there.
-
advanced settingsI did not edit the app.config file at all. What do I need to put in the app.config file?
-
advanced settingsAt the moment I don't have versions so upgrade isn't the issue. As you can see by the code, it is being saved and as I noted before, the class is there because I can see it right there in the debugger. I assume that because I can see it in the debugger that there is no serialization issue but maybe I am wrong. The class itself is not too complex. It is 4 strings and 2 decimal variables so I think it can be serialized. I checked where you said and there is no xml file so that is definitely the issue. I just don't know why there is no xml file.
-
advanced settingsWhere does it put the xml file and if it's not writing to the xml file where should I look to find out why?
-
advanced settingsI want to save a collection of custom objects. It seems that I succeed but when I try to retrieve the setting after the program restarts, the data is gone. I have searched extensively for the solution but to no avail. Here is what I have. Any help would be deeply appreciated. In my settings.cs file I have added the following code.
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public List<Account> Accounts
{
get
{
return ((List<Account>)(this["Accounts"]));
}
set
{
this["Accounts"] = value;
}
}Then I have the class marked as serializable. I have the following code at window close and as you can see it does compile so it picks up on the code and the data is there after I save it using the debugger to verify.
Properties.Settings.Default.Accounts = accounts.List;
Properties.Settings.Default.Save();All should be ok when I run the following code except the data just isn't there as it has a value of null.
if (Properties.Settings.Default.Accounts != null)
{
accounts.List = Properties.Settings.Default.Accounts;
} -
difficult ajax problem in mvc3For anyone who reads this, the problem was AVG Antivirus. I have been killing myself for almost a week now over this searching google and posting to forums etc. And now finally it's the Antivirus. I want to cry. At least it works. hope this post saves someone else the grief that I went through.
-
difficult ajax problem in mvc3I am very new to ajax (as in this is my first time trying something in ajax) but here is what I am dealing with. I am working on a db4o web server control client. Once finished, I will hopefully be using this in many other projects. What I have at this point is a connect and disconnect button to open and close the db. My code works flawlessly in Firefox but in IE and Chrome it doesn't. I have traced it to a problem where sometimes my Json value (which is just a bool) comes back as null. I stress sometimes in that for no particular reason it just happens. Sometimes it works. Sometimes it doesn't. But it always works in Firefox. However, I have debugged my server side code and the value is never coming back null. In chrome I see that the request comes back as cancelled. The http response and request regardless of successful or fail are identical other than I noticed that the request content-length varies slightly but it doesn't seem to change . This code is supposed to help me with attacks where someone could mimic my ajax request so it sends a validation token as it's body. If there's a better way then please do tell me. Here is my code. My Jquery functions
$(document).ready(function () { $.ajaxSetup({ cache: false, timeout: 5000 }); $("#connectButton").click(function (connect) { connect.preventDefault(); $.ajax({ type: 'post', contentType: "application/json; charset=utf-8", dataType: 'Json', cache: false, url: 'DBAdmin/ConnectDbAjax', data: $('<form>@Html.AntiForgeryToken()</form>').serialize(), success: function (response) { if (response) { $("#disconnectButton").attr("disabled", false); $("#connectButton").attr("disabled", true); } } }); }); $("#disconnectButton").click(function (disconnect) { disconnect.preventDefault(); $.ajax({ type: 'post', contentType: "application/json; charset=utf-8", dataType: 'Json', cache: false, url: 'DBAdmin/DisconnectD</x-turndown>
-
Relation TheoryI am not new but somehow I have really avoided getting too involved in database design. My question is fairly basic. If I have a relationship where one object technically possesses many of another, should I just make a standard many to one relation or should I create a bridge table? I will give an example. Let's say that I am trying to keep track of credit card numbers and their owners which I am not just so I don't get screamed at by the security people. The real example would be too hard to explain but this is comparable. So anyways, should I have a credit card numbers table that will have ID (pri key), CCnumber, and Owner columns? Then I would point the Owner column at the pri key column in the People table right? Does it matter that technically that people own credit cards and then maybe I should be making a bridge table? My hunch is that I don't need a bridge table but since this is going to be a big project, I would rather not find out the hard way after I have over 100 tables.