|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
string x = string.Format("T{0}", number.ToString("00000"));
".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
|
|
|
|
|
Even simpler:
string x = string.Format("T{0:D5}", number); Or:
string x = $"T{number:D5}";
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
isn't the "$" notation for PHP or some other stupid language? Or is it a new pointless operator in C#?
".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
|
|
|
|
|
|
Let's obfuscate C# even more than it already is...
".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
|
|
|
|
|
String interpolation was a pretty good addition, IMO. Especially when you compare it to the abomination that became of default interface methods[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I agree - I use string interpolation precisely because it de-obfuscates code:
Console.WriteLine("({2},{1}):({0},{3})={4}", destX, y, x, destY, dist); Isn't as obvious as
Console.WriteLine($"({x},{y}):({destX},{destY})={dist}");
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: precisely because it de-obfuscates code: Except when you use random ordering of your variables.
|
|
|
|
|
I've seen code like that before: when the variable list order is wrong, and it was easier to renumber than juggle the names ... Not that I'd write code like that, oh no.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
For me, the numbers have to be in order, so I juggle the names.
".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
|
|
|
|
|
A legitimate use case for unordered variables might be when writing output in different languages. In one language you might want to write "Page 1 of 10", but in another it might be "10 pages, No. 1" or some such. You would read the template from the resource file, filling in the values as necessary.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Hi,
I would like to get the device operations log so that we can do checks on the device and see if administrators changed settings on the device.
Can you help us ?
|
|
|
|
|
You should talk to the people who created it - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I want to do a telegram bot that answers messages and get updates. I created web application on Visual Studio 2015 Express. I write my codes to global.asax. I have installed Telegram.Bot package. I can run the program but program doesn't anything. What may be the problem? Thanks for asistance.
My codes are below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;
using System.IO;
namespace EC
{
public class Global : System.Web.HttpApplication
{
Telegram.Bot.TelegramBotClient Bot = new TelegramBotClient("xxxxxx");
protected void Application_Start()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Bot.OnMessage += Bot_OnMessage;
Bot.OnUpdate += Bot_OnUpdate;
Bot.StartReceiving();
}
private void Bot_OnMessage(object sender, MessageEventArgs messageEventArgs)
{
var message = messageEventArgs.Message;
if (message == null || message.Type != MessageType.Text) return;
if (message.Text.Contains("/start"))
{
string Str = "Start Received";
Bot.SendTextMessageAsync(message.Chat.Id, Str);
}
else if (message.Text.Contains("/Stop"))
{
string Str = "Stop Received";
Bot.SendTextMessageAsync(message.Chat.Id, Str);
}
}
}
|
|
|
|
|
I would suggest starting here, Introduction - Telegram Bots[^]
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Message Closed
modified 16-Jul-20 1:06am.
|
|
|
|
|
Congratulations on this achievement. You might want to post this in the Lounge instead. This page is for asking questions about C# problems.
|
|
|
|
|
Pete's right - this is the wrong place, The Lounge[^] is where this belongs.
And it's a pity you decided to learn Python ... C# would have been a lot better (I hate Python because of the indentation which can cause massive problems as spaces and tabs aren't equivelant, and all languages where the type of a variable depends on what you last stuffed into it). C#is stricter, but that's actually a bonus because it spots more problems at compile time rather than leave them to crash your app at run time.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm tryinig to recurse through the objects under a specific Organization Unit.
string domain = "LDAP://DC=MyCompany,DC=com";
string serverName = "192.168.30.10";
string ou = "OU=OrgUnit-Test-1,DC=MyCompany,DC=com";
I already know that under the OU above there are other OU's, Groups, and users. Each child OU can have groups and users, and each group can have users. It's a hierarchy of info that I want to interate over.
All the examples I'm finding are about finding users in groups and the like. What I'ds really like is some way of looping over some objects to examine them.
Here's an example I have that finds users in a specific group:
<pre>public List<ActiveDirectoryUser> GetAllUsersInGroup(string domainName, string groupName)
{
List<ActiveDirectoryUser> results = new List<ActiveDirectoryUser>();
using (var context = new PrincipalContext(ContextType.Domain, domainName))
{
using (var group = GroupPrincipal.FindByIdentity(context, groupName))
{
if (group != null)
{
var users = group.GetMembers(true).ToList();
foreach (UserPrincipal user in users)
{
var adu = new ActiveDirectoryUser(user.DisplayName, user.UserPrincipalName, user.GivenName, user.Surname, user.EmailAddress, user.Enabled.Value);
results.Add(adu);
}
}
}
}
return results;
}
This works fine - if you know the group name.
Is there any way, given a starting OU, to examine all child objects under it? Again, I need to examine the entire hierarchy.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 13-Jul-20 16:37pm.
|
|
|
|
|
Does this SO answer help?
c# - Get Groups From OU using DirectoryServices.AccountManagement - Stack Overflow[^]
using (var yourOU = new PrincipalContext(ContextType.Domain, "mycompany.local", "OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local"))
using (var findAllGroups = new GroupPrincipal(yourOU, "*"))
using (var ps = new PrincipalSearcher(findAllGroups))
{
foreach(var group in ps.FindAll())
{
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Does this SO answer help?
Only partly. I already have something like this that gives back groups for an OU. What's missing is child OU's. An OU can havee other OU's under it.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
active directory - How to get list of OU using AccountManagement (C#) - Stack Overflow[^]
You can extend the GroupPrincipal to search for OUs:
[DirectoryRdnPrefix("OU")]
[DirectoryObjectClass("organizationalUnit")]
public class OuPrincipal : GroupPrincipal
{
public OuPrincipal(PrincipalContext context) : base(context)
{
}
} You should then be able to use this in a similar way to the other code to find the child OUs.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
which website learn and solution C# window Application >
|
|
|
|