|
|
Good article
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
I'm having a mind blank right now, and I have googled for the answer, I can seem to come up with it.
as an example;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;
The source "database" will stay the same, the location may change. I think I did it on a project where it was "*\new folder\mydatabase.mdb" for the source, but I can't think of it off hand (nor find).
Anyone come across this? Is this the correct forum?
Thanks.
/////////////////
Groucho Marx
Those are my principles, if you don't like them… I have others.
|
|
|
|
|
Try this .\new folder\mydatabase.mdb
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
That's the one thanks for putting me out my misery.
/////////////////
Groucho Marx
Those are my principles, if you don't like them… I have others.
|
|
|
|
|
You are welcome.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
Hello!, well that is the question i remember fixing this in MFC returning a false in the initdialog method, but how to do this in C#?
|
|
|
|
|
Override ShowWithoutActivation in the non-modal form:
protected override bool ShowWithoutActivation
{
get { return true; }
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
This made the job, just some info for anyone else, using this with topmost property to true will not work, i think this is a bug on windows forms
|
|
|
|
|
Hello everyone,
I've made a multithread data base application, which is collecting data from multiple data bases from different threads and then process it and notifies the result on GUI. I've made a console which is just a big text box. Now, my question is that what is the best way to update a single GUI component from multiple threads. So far, I've made class called class IOConsole which constains a variable called static Queue(String message) and a method public static println(string str) and then I've added a background worker in GUI thread which keep looping and checks if queque is empty or not and if not empty then it pop the string and print it on the GUI. To me its does't look very nice approach, not sure if it might be. But could I get some suggestion about how can I achieve this most efficiently.
Thanks,
Shivam Kalra
|
|
|
|
|
why not just use begininvoke or invoke? this is executed in the main thread always, or even using windows messages, or there is even invoke required way since .NET 2
the invoke way can be something like this, using anonymous method
string nextText = "qwe";
this.Invoke( (MethodInvoker)delegate {
oneLabel.Text = nextText;
}
);
|
|
|
|
|
The right idea, but it's generally better to have the updater fire events and not be tightly linked in to the UI class. E.g.
class DatabaseUpdater {
event EventHandler<UpdateEventArgs> Update;
void ThreadMethod() {
while(true){
if(thereWasAnUpdate && Update != null){
Update(this, new UpdateEventArgs(updatedTable, key, Value);
}
}
}
}
class MainForm {
List<DatabaseUpdater> updaters;
MainForm(){
foreach(DatabaseUpdater updater in updaters)
updater.Update += DatabaseUpdated;
}
void DatabaseUpdated(object sender, UpdateEventArgs e){
this.Invoke((MethodInvoker) delegate { myTextBox.Text += e.UpdatedTable + "\n"; });
}
}
|
|
|
|
|
Hi, thanks for the reply. Will this code make sure that even if I invoke it through multiple threads..may be 5 threads then will be able to print all 5 of them on the console text box? And if "yes" then could you put more light on how it does that? I thought code should have been more complicated but it looks just one sentence thing?
|
|
|
|
|
|
As an update, I am able to run get-alias, but not run test-servicehealth. Would anyone know why the difference?
|
|
|
|
|
You ran the example from that link as is, without modification, and it did not work?
|
|
|
|
|
|
|
Then the real problem is that you want to do something more complicated and that the code given doesn't provide an exact solution.
I would suppose that there is a way to do it.
I would also suppose that it will require reading the documentation, experimenting and guessing to get to a solution. Similar to other programming tasks that one might encounter.
|
|
|
|
|
Hi,
Here is what I have, and so far this is working. It is far from finished and sorry for all of the comments, but I just got it working. It works for get-mailbox -identity first.last, it works for get-alias and it works for test-servicehealth. It itterates through everything, but it is a start
I'm sorry for the post length, I thought that codeblock would limit the screen usage and put a scrollable window within the post. If anyone knows how to do that, please let me know.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using exchangePowerShell;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
namespace TempTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
ExchangeManagementShellWrapper ems = ExchangeManagementShellWrapper.Instance;
ICollection<PSObject> results;
results = ems.RunspaceInvoke(textBox2.Text);
try
{
foreach (PSObject item in results)
{
List<string> propertyListTotal = new List<string>();
foreach (PSPropertyInfo itemSubProperty in item.Properties)
{
propertyListTotal.Add(itemSubProperty.ToString());
}
foreach (string propertyListItem in propertyListTotal)
{
string propertyListItemTrimBack = propertyListItem.Remove(propertyListItem.LastIndexOf(" "));
string propertyListItemTrimFront = propertyListItemTrimBack.Substring(propertyListItemTrimBack.LastIndexOf(" "));
propertyListItemTrimFront = propertyListItemTrimFront.TrimStart();
propertyListItemTrimFront = propertyListItemTrimFront.TrimEnd();
PSPropertyInfo propertyInfo = (PSPropertyInfo)item.Properties[propertyListItemTrimFront];
if (propertyInfo != null)
{
if (!(propertyInfo.TypeNameOfValue == "System.String[]") && !(propertyInfo.TypeNameOfValue.Contains("System.Nullable")))
{
if ((propertyInfo.Name != null) && (propertyInfo.Value != null))
{
textBox1.Text += ("Property name: " + propertyInfo.Name.ToString() + ", Property value: " + propertyInfo.Value.ToString());
textBox1.Text += System.Environment.NewLine;
}
else
{
textBox1.Text += ("Property has a null value");
textBox1.Text += System.Environment.NewLine;
}
}
if (propertyInfo.TypeNameOfValue == "System.String[]" && !(propertyInfo.TypeNameOfValue.Contains("System.Nullable")))
{
IList propertyArrayList = (IList)propertyInfo.Value;
if (propertyArrayList.Count == 0)
{
if ((propertyInfo.Name != null) && (propertyInfo.Value != null))
{
textBox1.Text += ("Property name: " + propertyInfo.Name.ToString() + ", Property value: " + propertyArrayList.Count);
textBox1.Text += System.Environment.NewLine;
}
else
{
textBox1.Text += ("Property has a null value");
textBox1.Text += System.Environment.NewLine;
}
}
if (propertyArrayList.Count > 0)
{
if ((propertyInfo.Name != null) && (propertyInfo.Value != null))
{
textBox1.Text += ("Property name: " + propertyInfo.Name.ToString() + ", Property value: " + propertyArrayList.Count);
textBox1.Text += System.Environment.NewLine;
foreach (string listItem in propertyArrayList)
{
textBox1.Text += ("Property name: " + propertyInfo.Name.ToString() + ", Property value: " + listItem);
textBox1.Text += System.Environment.NewLine;
}
}
else
{
textBox1.Text += ("Property has a null value");
textBox1.Text += System.Environment.NewLine;
}
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
namespace exchangePowerShell
{
public sealed class ExchangeManagementShellWrapper
{
#region Variable Declaration
private RunspaceConfiguration rc;
private Runspace r;
private RunspaceInvoke ri;
private static readonly ExchangeManagementShellWrapper instance = new ExchangeManagementShellWrapper();
#endregion
private ExchangeManagementShellWrapper(){}
public static ExchangeManagementShellWrapper Instance
{
get
{
return instance;
}
}
private void InitializeRunspace()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver);
rc = RunspaceConfiguration.Create();
PSSnapInException warning;
PSSnapInInfo info = rc.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning);
if (warning != null)
{
System.Console.Write(warning.Message);
return;
}
r = RunspaceFactory.CreateRunspace(rc);
r.Open();
}
private void InitializeRunspaceInvoke()
{
if (r == null) { InitializeRunspace(); }
ri = new RunspaceInvoke(r);
}
public ICollection<PSObject> RunspaceInvoke(string EMSCommand)
{
if (ri == null) { InitializeRunspaceInvoke(); }
return ri.Invoke(EMSCommand);
}
public ICollection<PSObject> RunspaceInvoke(string EMSCommand, IEnumerable input)
{
if (ri == null) { InitializeRunspaceInvoke(); }
return ri.Invoke(EMSCommand, input);
}
public ICollection<PSObject> RunspaceInvoke(string EMSCommand, out IList errors)
{
return RunspaceInvoke(EMSCommand, null, out errors);
}
public ICollection<PSObject> RunspaceInvoke(string EMSCommand, IEnumerable input, out IList errors)
{
if (ri == null) { InitializeRunspaceInvoke(); }
return ri.Invoke(EMSCommand, input, out errors);
}
public ICollection<PSObject> PipelineInvoke(Collection<Command> EMSCommands, out PipelineReader<object> Errors)
{
if (r == null) { InitializeRunspace(); }
Pipeline pipeline = r.CreatePipeline();
foreach (Command item in EMSCommands)
{
pipeline.Commands.Add(item);
}
ICollection<PSObject> results = pipeline.Invoke();
Errors = pipeline.Error;
pipeline = null;
return results;
}
public ICollection<PSObject> PipelineInvoke(Collection<Command> EMSCommands)
{
if (r == null) { InitializeRunspace(); }
Pipeline pipeline = r.CreatePipeline();
foreach (Command item in EMSCommands)
{
pipeline.Commands.Add(item);
}
return pipeline.Invoke();
}
public ICollection<PSObject> PipelineInvoke(Command EMSCommand, out PipelineReader<object> Errors)
{
if (r == null) { InitializeRunspace(); }
Pipeline pipeline = r.CreatePipeline();
pipeline.Commands.Add(EMSCommand);
ICollection<PSObject> results = pipeline.Invoke();
Errors = pipeline.Error;
pipeline = null;
return results;
}
public ICollection<PSObject> PipelineInvoke(Command EMSCommand)
{
if (r == null) { InitializeRunspace(); }
Pipeline pipeline = r.CreatePipeline();
pipeline.Commands.Add(EMSCommand);
return pipeline.Invoke();
}
public void Dispose()
{
r.Close();
ri = null;
r = null;
}
private static System.Reflection.Assembly AssemblyResolver(object p, ResolveEventArgs args)
{
if (args.Name.Contains("Microsoft.Exchange"))
{
return Assembly.LoadFrom(Path.Combine("C:\\Program Files\\Microsoft\\Exchange Server\\bin\\", args.Name.Split(',')[0] + ".dll"));
}
else
{
return null;
}
}
}
}
|
|
|
|
|
|
If the examples use a COM component you need to register it first (either by running its installer or on the command line with regsvr32).
|
|
|
|
|
I have this FTP code. I'm trying to get a list of files from the server. All it returns is an entry for the root folder.. Using FileZilla and/or CuteFTP I can see the subfolders and files in them. Why isnt't my returning anything other than the root folder?
public struct FTPCredentials
{
public string FTPServer { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
public List<string> GetFileList(FTPCredentials Credentials)
{
List<string> retVal = new List<string>();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Credentials.FTPServer);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.KeepAlive = true;
request.UsePassive = false;
try
{
request.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string line = reader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
retVal.Add(line);
line = reader.ReadLine();
}
reader.Close();
response.Close();
}
catch (Exception e)
{
throw e;
}
return retVal;
}
Everything makes sense in someone's mind
|
|
|
|
|
FTP works similar to filesystem operations, so requesting anything from the server will work only in the current working directory. Since you're using FtpWebRequest, you'll also need to think of your FTP 'session' more in terms of HTTP style communications (browsing an FTP site using a web browser instead of an FTP client). You make one request, and you get one response. When you create the request:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
The variable 'uri' is actually both the server and the full path of your working directory. So if you want to connect to ftp.server.com and get the directory contents of path 'some/path', you would create your FtpWebRequest like so:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.server.com/some/path");
If you want to monitor how FTP actually communicates with ftp servers, enable the messages view in FileZilla (View > Message log). These are all happening implicitly when using the FtpWebRequest object.
I'd recommend finding an FTP library (or writing your own if you have the cohones, several RFCs make up the spec now) if you're going to be doing anything more than simple FTP operations.
modified on Thursday, June 16, 2011 4:29 PM
|
|
|
|
|
Thanks for the response. I think I understand. Some comments...
I set up a test FTP folder:
FTPServer = "ftp://ftp.maroisconsulting.com/test",
UserName = "FTPTest",
Password = "testftp"
When I run the code, I get the exception:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
I'm sorta lost here. I don't understand why this doesn't work. The folder exitst with 2 test files in it. My FTP Client (FileZilla )works, but not this code.
Everything makes sense in someone's mind
|
|
|
|