|
|
No idea what that means, but here[^] you can copy/paste and see for yourself
50k exceptions in a second. Your definition of "expensive" may vary from mine, ofc.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Exception is Expensive I agree.
But tested in console application on i7 processor, and time 500ms?
It seems to me this is some delay.
|
|
|
|
|
There's also a "timeout" on NetworkStream.
I don't know if it has any relation to the timeout on TcpClient.
|
|
|
|
|
ReadTimeout NetStream returned GetStream() is same as TCPClient.ReceiveTimeout
|
|
|
|
|
Did you time the GetStream() separate from the Read()?
|
|
|
|
|
I tried it's, but time not changed.
|
|
|
|
|
Well, which took longer? The GetStream() or the Read() ... or you don't understand what I'm talking about.
|
|
|
|
|
GetStream() 0ms
Read() 530ms
|
|
|
|
|
Message Closed
modified 9-Sep-16 16:38pm.
|
|
|
|
|
This is a test of the CP Forum posting system. If this were an actual posting, it would include useful content and might provide some context for a question.
Seriously though, I'm not going to click your link. Please explain what you need assistance with in as much detail as you can provide.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
I want to avoid referencing anything related to VB if at all possible.
Is there a C# equivalent to Microsoft.VisualBasic.FileIO.TextFieldParser floating around anywhere?
EDIT ======================
As a quick fix, I came up with the following. I don't know what all the VB version does, but this code appears to correctly parse quoted strings...
public partial class TextFieldParser
{
public TextFieldParser()
{
}
public string[] ParseFields(string text)
{
string[] parts = text.Split(',');
List<string> newParts = new List<string>();
bool inQuotes = false;
string currentPart = string.Empty;
for (int i = 0; i < parts.Length; i++)
{
string part = parts[i];
inQuotes = (inQuotes || part.StartsWith("\""));
if (inQuotes)
{
currentPart = (string.IsNullOrEmpty(currentPart))? part : string.Format("{0},{1}", currentPart, part);
}
else
{
currentPart = part;
}
inQuotes = (inQuotes && !part.EndsWith("\""));
if (!inQuotes)
{
currentPart = currentPart.Replace("\"", "");
newParts.Add(currentPart);
currentPart = string.Empty;
}
}
return newParts.ToArray();
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 9-Sep-16 12:27pm.
|
|
|
|
|
For CSV / TDF files, I tend to use this library[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Actually, I'm writing a (evidently much lighter) CSV parser, and was gonna write an article, but now I don't know.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
Hi, I want to know in simple words,What is Assembly in Dotnet framework???
|
|
|
|
|
Plenty of definitions here[^].
This space for rent
|
|
|
|
|
Hi Guys, hope my question is formed well enough and thanks for everyone who contributes to this site as I have had many successes in projects through Codeproject. However it is my first time asking a question. I have been struggling now for a good couple of days with the above. I am reading to AD and writing but for the life of me i just seem not to be able to write to the above. Following is my code: If any one can please assist me or point me into the right direction...please...and thank you really a lot.
Dim RootDSE As String
Dim DSESearcher As DirectorySearcher = New System.DirectoryServices.DirectorySearcher
Try
RootDSE = DSESearcher.SearchRoot.Path
RootDSE = RootDSE.Insert(7, Utility.ADUsersPath & ",")
Dim myDE As DirectoryEntry = New DirectoryEntry(RootDSE)
Dim myEntries As DirectoryEntries = myDE.Children
Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("CN=" + DisplayName, "user")
Utility.SetProperty(myDirectoryEntry, "givenName", FirstName)
Utility.SetProperty(myDirectoryEntry, "initials", MiddleInitial)
Utility.SetProperty(myDirectoryEntry, "sn", LastName)
Utility.SetProperty(myDirectoryEntry, "displayName", DisplayName)
If UserPrincipalName <> "" Then
Utility.SetProperty(myDirectoryEntry, "UserPrincipalName", UserPrincipalName)
Else
Utility.SetProperty(myDirectoryEntry, "UserPrincipalName", UserName)
End If
Utility.SetProperty(myDirectoryEntry, "PostalAddress", PostalAddress)
Utility.SetProperty(myDirectoryEntry, "StreetAddress", MailingAddress)
Utility.SetProperty(myDirectoryEntry, "HomePostalAddress", ResidentialAddress)
Utility.SetProperty(myDirectoryEntry, "Title", Title)
Utility.SetProperty(myDirectoryEntry, "HomePhone", HomePhone)
Utility.SetProperty(myDirectoryEntry, "TelephoneNumber", OfficePhone)
Utility.SetProperty(myDirectoryEntry, "Mobile", Mobile)
Utility.SetProperty(myDirectoryEntry, "FacsimileTelephoneNumber", Fax)
Utility.SetProperty(myDirectoryEntry, "mail", Email)
Utility.SetProperty(myDirectoryEntry, "Url", Url)
Utility.SetProperty(myDirectoryEntry, "sAMAccountName", UserName)
Utility.SetProperty(myDirectoryEntry, "UserPassword", Password)
Utility.SetProperty(myDirectoryEntry, "description", Description)
'Utility.SetProperty(myDirectoryEntry, "homeDrive", HomeDrive)
'Utility.SetProperty(myDirectoryEntry, "homeDirecrtory", HomeDirectory)
Utility.SetProperty(myDirectoryEntry, "scriptPath", ScriptPath)
myDirectoryEntry.Properties("userAccountControl").Value = Utility.UserStatus.Enable
''1ST COMMIT VALIDATES AGAINST USERNAME AND DISPLAY NAME RESPECTIVELY
myDirectoryEntry.CommitChanges()
SetMember(DisplayName, MemberOF)
''USE DISPLAY: USERNAME FAIL WHEN CREATING PASSWORD
myDirectoryEntry = GetUser(DisplayName)
Utility.SetUserPassword(myDirectoryEntry, Password)
myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_DONT_EXPIRE_PASSWD
myDirectoryEntry.CommitChanges()
myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_PASSWD_CANT_CHANGE
myDirectoryEntry.CommitChanges()
Return myDirectoryEntry
Catch ex As Exception
If Not ex.InnerException Is Nothing Then
MsgBox(ex.InnerException.Message)
End If
'Throw New Exception(ex.Message)
MsgBox(ex.Message)
Throw ex
End Try
End Function
Private Function SetMember(ByVal DisplayName As String, ByVal memberOF As String) As Integer
Dim RootDSE As String
Dim DSESearcher As DirectorySearcher = New System.DirectoryServices.DirectorySearcher
RootDSE = DSESearcher.SearchRoot.Path
RootDSE = RootDSE.Insert(7, Utility.ADUsersPath & ",")
Dim myDE As DirectoryEntry = New DirectoryEntry(RootDSE)
Dim myEntries As DirectoryEntries = myDE.Children
Try
'For Each thisGroup As [String] In memberOF
Dim myParent As DirectoryEntries = myDE.Parent.Children
Dim newGroup As DirectoryEntry = myParent.Find("CN=" + memberOF, "group")
If newGroup IsNot Nothing Then
Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("CN=" + DisplayName, "user")
newGroup.Invoke("Add", New Object() {myDirectoryEntry.Path.ToString()})
myDirectoryEntry.CommitChanges()
newGroup.Close()
End If
'Next
Catch ex As Exception
If Not ex.InnerException Is Nothing Then
MsgBox(ex.InnerException.Message)
End If
'Throw New Exception(ex.Message)
MsgBox(ex.Message)
End Try
End Function
Again, thank you for any input
|
|
|
|
|
You kind of forgot to describe the problem, where it happens in your code and any error messages.
|
|
|
|
|
Hi Dave,
Thank you for the reply.
After a lot of searching i sort of have resolved errors. However my problem is that I cannot find the correct way to update the (user account settings in AD i.e. password cannot change, do not expire etc.) as well as how to (update the homefolder drive and directory) and set (the member of group)...with the memberof group i get an error that says 'Object does not exist' so I am guessing the group Staff does not exist or spelling might be different...will confirm this still
'Utility.SetProperty(myDirectoryEntry, "homeDrive", HomeDrive)
'Utility.SetProperty(myDirectoryEntry, "homeDirecrtory", HomeDirectory)
myDirectoryEntry.CommitChanges()
SetMember(DisplayName, MemberOF)
''USE DISPLAY: USERNAME FAIL WHEN CREATING PASSWORD
myDirectoryEntry = GetUser(DisplayName)
Utility.SetUserPassword(myDirectoryEntry, Password)
myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_DONT_EXPIRE_PASSWD
myDirectoryEntry.CommitChanges()
myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_PASSWD_CANT_CHANGE
myDirectoryEntry.CommitChanges()
I was hoping that someone who were able to have done these updates could point me in the correct direction as to whether my syntax etc. is correct to update AD. This was a whole new experience and with a lot of searching and frustrations I got this far.
If at all possible a nudge or something more would be excellent.
Thanks again.
|
|
|
|
|
You might have better luck using the System.DirectoryServices.AccountManagement namespace[^]. It provides a much cleaner interface than the raw DirectoryServices version.
Using context As New PrincipalContext(ContextType.Domain)
Using user As New UserPrincipal(context, UserName, Password, True)
user.DisplayName = DisplayName
user.GivenName = FirstName
user.MiddleName = MiddleInitial
user.Surname = LastName
user.EmailAddress = Email
user.Description = Description
user.HomeDrive = HomeDrive
user.HomeDirectory = HomeDirectory
user.ScriptPath = ScriptPath
If UserPrincipalName <> "" Then
user.UserPrincipalName = UserPrincipalName
End If
user.PasswordNeverExpires = True
user.UserCannotChangePassword = True
Dim myDirectoryEntry As DirectoryEntry = TryCast(user.GetUnderlyingObject(), DirectoryEntry)
If myDirectoryEntry IsNot Nothing Then
Utility.SetProperty(myDirectoryEntry, "PostalAddress", PostalAddress)
Utility.SetProperty(myDirectoryEntry, "StreetAddress", MailingAddress)
Utility.SetProperty(myDirectoryEntry, "HomePostalAddress", ResidentialAddress)
Utility.SetProperty(myDirectoryEntry, "Title", Title)
Utility.SetProperty(myDirectoryEntry, "HomePhone", HomePhone)
Utility.SetProperty(myDirectoryEntry, "TelephoneNumber", OfficePhone)
Utility.SetProperty(myDirectoryEntry, "Mobile", Mobile)
Utility.SetProperty(myDirectoryEntry, "FacsimileTelephoneNumber", Fax)
Utility.SetProperty(myDirectoryEntry, "Url", Url)
End If
user.Save()
Using group As GroupPrincipal = GroupPrincipal.FindByIdentity(context, IdentityType.Name, MemberOf)
If group IsNot Nothing Then
group.Members.Add(user)
group.Save()
End If
End Using
End Using
End Using
Using System.DirectoryServices.AccountManagement[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 9-Sep-16 9:03am.
|
|
|
|
|
Thank you Richard, I am going to try userPricipal...will report on success.
|
|
|
|
|
Hi Richard,
I have worked this code into my app and resolved bugs to get it to run however, I keep getting 'User name or password is incorrect' at
Using user As New UserPrincipal(oPrincipalContext, UserName, Password, True)
Is this the current user being created? I am not sure...what I was able to find was indications that this is indeed user.username and user.password. If so why do i still fail.
Hope you can assist.
Thanks again
|
|
|
|
|
The UserName and Password should be the username and password for the user you're creating.
Does your AD domain have password complexity requirements that you're failing to meet?
Is your code running as a user that has permission to create users in your domain?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|