I am getting all websites from localhost IIS manager 6 using DirectoryEntry class, I would like to get local path of each web application, but not sure how to get it, Is there anyway I can enumerate all properties of directory entry ?
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IIsWebServer")
{
Console.WriteLine(e.Properties["ServerComment"].Value.ToString());
// how can I enumerate all properties and there values here ?
// maybe write to a xml document to find the local path property
I think you can use following code to find what you need. In case other questions just use the same approach. This code works for IIS6.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices;
namespace IIS_6
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
string VirDirSchemaName = "IIsWebVirtualDir";
foreach (DirectoryEntry e in root.Children)
{
foreach (DirectoryEntry folderRoot in e.Children)
{
foreach (DirectoryEntry virtualDirectory in folderRoot.Children)
{
if (VirDirSchemaName == virtualDirectory.SchemaClassName)
{
Console.WriteLine(String.Format("\t\t{0} \t\t{1}", virtualDirectory.Name, virtualDirectory.Properties["Path"].Value));
}
}
}
}
}
}
}
With regards to IIS 7 I wrote this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// to add it from %windir%\System32\InetSrv\Microsoft.Web.Administration.dll
using Microsoft.Web.Administration;
namespace IIS_7
{
class Program
{
static void Main(string[] args)
{
using (ServerManager serverManager = new ServerManager())
{
foreach (var site in serverManager.Sites)
{
Console.WriteLine(String.Format("Site: {0}", site.Name));
foreach (var app in site.Applications)
{
var virtualRoot = app.VirtualDirectories.Where(v => v.Path == "/").Single();
Console.WriteLine(String.Format("\t\t{0} \t\t{1}", app.Path, virtualRoot.PhysicalPath));
}
}
}
}
}
}
Related
I have many files in folder. and whenever there is any update in any file I Receive an event for that in my windows service application.
And I am looking for something by which I can validate the file with specific pattern. If it matches then only that file should be processed or else it should be ignored.
Something like this
if(File.Matches("genprice*.xml"))
{
DoSomething();
}
genprice20212604.xml
genprice20212704.xml
price20212604.xml
genprice20212704.txt
From above only #1 and #2 should be processed others should be ignored.
Your can try with regular expressions:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ConsoleAppRegex
{
class Program
{
static void Main(string[] args)
{
string[] fileNames = new string[] { "genprice20212604.xml",
"genprice20212704.xml",
"price20212604.xml",
"genprice20212704.txt"};
Regex re = new Regex(#"genprice[^\.]*.xml");
foreach (string fileName in fileNames)
{
if (re.Match(fileName).Success)
{
Console.WriteLine(fileName);
}
}
Console.ReadLine();
}
}
}
I suggest to use Regex:
using System.Text.RegularExpressions;
using System.IO;
var reg = new Regex(#"genprice\d{8}$");
var fileNamesFromFolder = Direcotory.GetFiles(" #FolderĀ“s path ", "*.xml")
.Where(path => reg.IsMatch(Path.GetFileNameWithoutExtension(path)))
.Select(Folder=>
Path.GetFileNameWithoutExtension(Folder));
foreach (var file in fileNamesFromFolder )
{
//Do something...
}
I want to monitor retrieve messages so that the bot can respond to them.
I can send pm using tweetinvi but for some reason, I can't get it to retrieve any of the messages in that account. GetLastMessage always returns a null.
I have tried the following:
in this test, I have a timer that runs every 1s and pols the messages.
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
IEnumerable<IMessage> MSG = controller.GetLatestMessagesReceived(); ; // Message.GetLatestMessagesReceived(100);
if (MSG != null)
{
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
if ((MSG.ElementAt(0).SenderId == ####MYID#####) & (MSG.ElementAt(0).Text == "?"))
{
Message.PublishMessage(tweet, ####MYID#####);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
Console.ResetColor();
Message.DestroyMessage(MSG.ElementAt(0));
}
}
} catch
{
}
}
I have also tried
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
var latestMessagesSent = Message.GetLatestMessagesSent();
var latestMessagesSentParameter = new MessagesSentParameters();
latestMessagesSentParameter.PageNumber = 239823;
var latestMessagesSentFromParameter = Message.GetLatestMessagesSent(latestMessagesSentParameter);
if (latestMessagesSentFromParameter != null)
{
Console.WriteLine("Messages Send : ");
foreach (var mms in latestMessagesSentFromParameter)
{
Console.WriteLine("- '{0}'", mms.Text);
}
}
} catch
{
}
}
I also tried using
IAuthenticatedUser authenticatedUser = User.GetAuthenticatedUser();
authenticatedUser.GetLatestMessagesReceived();
I am using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Collections;
using System.Globalization;
//using System.Threading;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Reflection;
// REST API
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;
// STREAM API
using Tweetinvi.Streaming;
using Stream = Tweetinvi.Stream;
// Others
using Tweetinvi.Exceptions; // Handle Exceptions
using Tweetinvi.Core.Extensions; // Extension methods provided by Tweetinvi
using Tweetinvi.Models.DTO; // Data Transfer Objects for Serialization
using Tweetinvi.Json; // JSON static classes to get json from Twitter.
Your app must have permission to read and write on twitter API.
Trying to use Linq and the Entity Framework to make a super-simple lists database. The query runs, but it does not return the data I enter into it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using static System.Console;
namespace CheckList
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Building the list.");
using (var db = new ListContext())
{
ListItem socks = new ListItem() { Title = "Get Socks" };
db.ListItems.Add(socks);
Here is the actual query:
var queryresults = from item in db.ListItems
orderby item.Title
select item;
But the foreach loop doesn't print out anything:
WriteLine("Printing out the list:");
foreach (var item in queryresults)
{
WriteLine("Item's name:");
WriteLine(item.Title);
}
The rest:
}
WriteLine("All done.");
Console.Read();
}
}
}
I've tried to simplify as much as possible, but I cannot seem to get the results to show up. What is my mistake here?
Before the query try to save changes.
db.SaveChanges();
I am in the middle implementation small program of WSDL parser. But I am getting ptobject is coming NULL. This is happening with the wsdl mentioned in the program. I don't think WSDL is wrong because if give the same WSDL to SOAP UI it is parsing successfully.
Could you please help in understanding the root cause of the problem ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Net;
using System.Reflection;
using System.Web.Services.Description;
namespace ConsoleApplication14
{
class XmlSchemaReadWriteExample
{
static void Main()
{
XmlTextReader myReader = new XmlTextReader("https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl");
if (ServiceDescription.CanRead(myReader))
{
ServiceDescription myDescription = ServiceDescription.Read(myReader);
Dictionary<string, Service> Services;
foreach (Service srv in myDescription.Services)
{
Services = new Dictionary<string, Service>();
Services.Add(srv.Name, srv);
foreach (Port p in srv.Ports)
{
Binding b = myDescription.Bindings[p.Binding.Name];
foreach (Object e in b.Extensions)
{
if (e is Soap12Binding || e is SoapBinding)
{
PortType ptobject = myDescription.PortTypes[b.Type.Name];
}
}
}
}
}
}
}
}
Thanks in advance.
Bheem.
Try this
static void Main()
{
XmlTextReader myReader = new XmlTextReader("https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl");
if (ServiceDescription.CanRead(myReader))
{
ServiceDescription myDescription = ServiceDescription.Read(myReader);
Dictionary<string, Service> Services;
foreach (Service srv in myDescription.Services)
{
Services = new Dictionary<string, Service>();
Services.Add(srv.Name, srv);
foreach (Port p in srv.Ports)
{
Binding b = myDescription.Bindings[p.Binding.Name];
foreach (Object e in b.Extensions)
{
if (e is Soap12Binding || e is SoapBinding)
{
//only change right here:
Port ptobject = srv.Ports[b.Type.Name];
}
}
}
}
}
}
I think you are looking at portType when maybe you were wanting the Port?
There seem to be no portTypes defined for the service you are pointing at.
EDIT..................
Ok fiddled around with this some more. loaded up soap UI and yep its there... i think i may have found what your looking for...
try hiting https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl=wsdl0
static void Main()
{
XmlTextReader myReader = new XmlTextReader("https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl=wsdl0");
if (ServiceDescription.CanRead(myReader))
{
ServiceDescription myDescription = ServiceDescription.Read(myReader);
foreach (PortType pt in myDescription.PortTypes)
{
Console.WriteLine(pt.Name);
}
}
}
I noticed this in the tab name pat of soap ui ... it is pulling an extra wsdl "wsdl0" file. it is an import
From the original Wsdl:
<wsdl:import namespace="http://domainws.ficora.fi.operations" location="https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl=wsdl0"/>
and you can get to the URL programmatic ...
myDescription.Imports[0]
I am working on collecting urls from the web site in C# using WatiN framework. In my program it is fetching only one url. I don't know what is the problem. Any help will be appreciated.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WatiN.Core;
using WatiN.Core.Native.InternetExplorer;
namespace magicbricks
{
class scroll
{
[STAThread]
static void Main(string[] args)
{
Browser browserInstance;
browserInstance = new IE(#"http://www.99acres.com/property-in-chennai- ffid?search_type=QS&search_location=CP32&lstAcn=CP_R&lstAcnId=32&src=CLUSTER&isvoicesearch=N&keyword_suggest=chennai%20%28all%29%3B&fullSelectedSuggestions=chennai%20%28all%29&strEntityMap=W3sidHlwZSI6ImNpdHkifSx7IjEiOlsiY2hlbm5haSAoYWxsKSIsIkNJVFlfMzIsIFBSRUZFUkVOQ0VfUywgUkVTQ09NX1IiXX1d&texttypedtillsuggestion=chennai&refine_results=Y&Refine_Localities=Refine%20Localities&action=%2Fdo%2Fquicksearch%2Fsearch&suggestion=CITY_32%2C%20PREFERENCE_S%2C%20RESCOM_R");
foreach (var links in browserInstance.Links.Filter(Find.ByClass("b")))
{
Console.WriteLine(links.Url);
String filePath = "C:/Users/User/Desktop/New folder";
String fileName = "newop4.csv";
using (StreamWriter sr = new StreamWriter(Path.Combine(filePath, fileName), true))
{
sr.WriteLine(links.Url);
}
Console.ReadLine();
}
}
}
}
the above code prints only one url in the console.
Remove the Console.ReadLine(); As you are in a ForEach loop. If you still want the Console.ReadLine(); move it out the foreach
The Console.ReadLine(); waits for a user input, after you enter any value you should see the next URL.