I am trying to register multiple database in an Enterprise Library 5 container. I am able to register one but unable to register a second. Can anybody tell me what I am doing wrong in the code snippet below? If I uncomment the commented out section then an error is returned saying 'An item with the same key has already been added.'
I have checked various threads but have been unable to find an answer.
https://entlib.codeplex.com/discussions/401337
http://entlib.codeplex.com/discussions/539775
What is the correct\preferred method for adding multiple registries to the container? Any answers in VB or C# would be appreciated.
Private Sub RegisterDatabase()
Dim _connectionString as string = "ConnectionString"
Dim _connectionString2 as string = "ConnectionString2"
Dim builder = New ConfigurationSourceBuilder
builder.ConfigureData().ForDatabaseNamed(_databaseName). _
ThatIs.AnOracleDatabase().WithConnectionString(_connectionString)
'####################################################################
'Code works fine with this section commented out.
'If it's added back in, then it errors with 'An item with the same key has already been added.'
'builder.ConfigureData().ForDatabaseNamed("APPLICATION"). _
' ThatIs.AnOracleDatabase().WithConnectionString(_connectionString2).AsDefault()
'####################################################################
Dim configSource = New DictionaryConfigurationSource
builder.UpdateConfigurationWithReplace(configSource)
Dim container As IUnityContainer
container = New UnityContainer()
container.AddNewExtension(Of EnterpriseLibraryCoreExtension)()
Dim configurator As New UnityContainerConfigurator(container)
EnterpriseLibraryContainer.ConfigureContainer(configurator, configSource)
EnterpriseLibraryContainer.Current = New UnityServiceLocator(container)
End Sub
OK, I got the answer form Sujoy Roy Chowdhury's response on
Changing connection string at runtime in Enterprise Library where he demonstrates the following syntax:
builder.ConfigureData() _
.ForDatabaseNamed(_databaseName) _
.ThatIs.AnOracleDatabase() _
.WithConnectionString(_connectionString) _
.ForDatabaseNamed("APPLICATION") _
.ThatIs.AnOracleDatabase() _
.WithConnectionString(_connectionString2).AsDefault()
Related
On a WebApp, I am trying to simulate a Hammer.js "press" (a long-press vs a simple 'Click') using Selenium WebDriver with ChromeDriver. Coming up empty on searches.
Something like a driver.FindElement(By.Id("elem_id")).ClickLong()?
Edit: Figures... just saw THIS - will investigate and get back..
OK - here we go. Sorry for the VB.
First for the documentation: Selenium Actions for ClickAndHold.
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports OpenQA.Selenium.Interactions
Dim opts = New ChromeOptions With {.BinaryLocation = "pathTo_Chrome.exe"}
Dim d As ChromeDriver = New ChromeDriver("pathTo_ChromeDriver", opts)
'... (you would probably have all the above already setup)
Sub LongPress(d As ChromeDriver, elemId As String)
Dim actions As Actions = New Actions(d)
Dim wElem As IWebElement = d.FindElement(By.Id(elemId))
actions.ClickAndHold(wElem).Perform()
actions.Release() 'releases at virtual "click" at last mouse position
End Sub
Function will be used like:
LongPress(d, "elemId")
I'm sure there are better ways to do this, but I'm off to the races again. Hope this helps.
its possible to get list recent item in windows like in this picture? how can i access that from vb.net?
list recent item(right click on icon bar)
http://i.stack.imgur.com/hnPtQ.png
Thanks
What you are referring to is a Jump List. You can access from within .NET starting with .NET 4. Since you want this in VB.Net check out this article
and the official documentation on msdn
Imports System.Windows.Shell
Class Application
Public Sub New()
Dim jl As New JumpList
JumpList.SetJumpList(Application.Current, jl)
Dim SaveAs As New JumpTask
SaveAs.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly.Location()
SaveAs.Title = "Save as..."
SaveAs.Arguments = "-saveas"
jl.JumpItems.Add(SaveAs)
Dim Configuration As New JumpTask
Configuration.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly.Location()
Configuration.Title = "Configuration"
Configuration.CustomCategory = "Settings"
Configuration.Arguments = "-config"
jl.JumpItems.Add(Configuration)
jl.Apply()
End Sub
Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup
' Handle "Save As" JumpList example
If e.Args.Contains("-saveas") Then
' Fancy Code Funtime
' -- Remember, this launches as a new instance - if you don't want that, this end kills it when your done --
End
End If
' Handle "Configuration" JumpList example
If e.Args.Contains("-config") Then
' I launch a configuration window here, really up to you
' -- Remember, this launches as a new instance - if you don't want that, this end kills it when your done --
End
End If
End Sub
End Class
I am using redemption in my windows application. There I have written this code
try
{
rFolder = rSession.GetSharedDefaultFolder(memberName, rdoDefaultFolders.olFolderCalendar);
rItems = rFolder.Items;
}
But when it executing the line which includes Session.GetSharedDefaultFolder(), it throws following exception.
"Error in IAddrBook.ResolveName: MAPI_E_NOT_FOUND"
I searched online for this issue, but I was not able to get something straight forward. Please advice me.
What do you pass to GetSharedDefaultFolder? Can that name be resolved in Outlook in the To edit box in Outlook?
Keep in mind that GetSharedDefaultFolder takes either a string or an RDOAddressEntry object. In the latter case there is nothing to resolve, so if you already have an instance of the RDOAddressEntry object, it might be more reliable to pass it instead of a string.
Why do you need to use Redemption?
Instead, I'd suggest using the GetSharedDefaultFolder method of the Namespace class instead. It returns a Folder object that represents the specified default folder for the specified user.
Sub ResolveName()
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
Dim CalendarFolder As Outlook.Folder
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowCalendar(myNamespace, myRecipient)
End If
End Sub
Sub ShowCalendar(myNamespace, myRecipient)
Dim CalendarFolder As Outlook.Folder
Set CalendarFolder = _
myNamespace.GetSharedDefaultFolder _
(myRecipient, olFolderCalendar)
CalendarFolder.Display
End Sub
Be aware, you need to pass an instance of the Recipient class (resolved) to the method, not just a member name.
Do you get any error when running the code listed above (of course, with a valid name)?
I have added global error handling into my application to catch-all unhandled exceptions. I now just added the functionality to add the bug automatically to my fogbugz account. Now here is my issue.
I added a reference to the dll and also had to add the import declaration for the library. After doing this the code shows no errors. Although as soon as I go to debug the code or build it I get this error:
'BugReport' is not declared. It may be inaccessible due to its protection level.
I am geussing it has to do with some kind of protection? This catch all is in my applicationevents.vb class.
I have tried the same code in another project and it works without error so I know it is not the code. I just don't know what it is? Do I have to change something in my application settings? Here is the code anyways. I replaced the strings with my information for privacy.
Imports FogBugz
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_UnhandledException(ByVal _
sender As Object, ByVal e As _
Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) _
Handles Me.UnhandledException
'TO DO: SET THESE VALUES BEFORE CALLING THIS METHOD!
Dim url As String = "StackOverFlowDemoString"
'example: http://localhost/fogbugz/scoutSubmit.asp
Dim user As String = "StackOverFlowDemoString"
'existing FogBugz User
Dim project As String = "StackOverFlowDemoString"
'existing FogBugz project
Dim area As String = "StackOverFlowDemoString"
'existing FogBugz area
Dim email As String = "StackOverFlowDemoString"
'email address of the customer who reports the bug
Dim defaultMessage As String = "Bug has been submitted. Every bug submitted helps us make this software that much better. We really do appreciate it."
'the message to return to the user if no Scout Message is found for an existing duplicate bug
Dim forceNewBug As Boolean = False
'If set to true, this forces FogBugz to create a new case for this bug, even if a bug with the same description already exists.
'************************************************************************************
'send the bug we created:
BugReport.Submit(url, user, project, area, email, forceNewBug, _
defaultMessage, e.Exception, True, "{0}.{1}.{2}.{3}", True)
' If the user clicks No, then exit.
e.ExitApplication = _
MessageBox.Show(e.Exception.Message & _
vbCrLf & "Oops! It looks like we have encountered a bug. A bug report has been sent to the developers, so they can have it fixed in a jiffy. Continue?", "An Error has occured.", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) _
= DialogResult.No
End Sub
End Class
End Namespace
The "protection level" refers to the access modifier on your BugReport class.
If you declare a class as Friend (Internal in C#), it is accessible to other classes in the same assembly (.dll).
When you attempt to reference that class from another project, it is not accessible.
You need to change Friend to Public.
I'm looking at some old ASP code that contains the following:
Set objDSE = GetObject("LDAP://RootDSE")
Set objSysInfo = CreateObject("adsysteminfo")
Set objUser= Getobject("LDAP://" & Replace(objSysInfo.UserName,"/","\/"))
dtmValue = objUser.PasswordLastChanged
objMaxPwdAge = GetObject("LDAP://" & objDSE.get("DefaultNamingContext")).maxPwdAge
dblMaxPwdDays = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart) _
* ONE_HUNDRED_NANOSECOND / SECONDS_IN_DAY
pwdExpDate = dtmValue + dblMaxPwdDays
This is for an intranet app that uses integrated authentication.
Is there a replacement for the ASP adsysteinfo object? I can probably port most of the LDAP calls using System.DirectoryServices.DirectoryEntry, but is there a better/easier way to do this in ASP.NET (VB.Net or C#)?
Is there any documentation for how to convert the ASP object properties to DirectoryEntry properies?
In your example code, adsysteminfo is just use to retrieve the current user name. In an ASP.Net application, you can get this one of two ways, depending on your configuration:
1) If you are impersonating each user, then you should be able to use:
Return System.Security.Principal.WindowsIdentity.GetCurrent().Name
2) If you are not impersonating the user, but you do have integrated authentication as the only security mechanism for the web site, then you can get the user's domain name as follows:
Return Request.ServerVariables("logon_user")
As for the other LDAP call, System.DirectoryServices is definitely what you want to use. Here is a sample of how we get hooked into AD to start searching for users:
Private m_Searcher As DirectorySearcher
Private m_sNamingContext As String
Dim theRootEntry As DirectoryEntry
Dim theEntry As DirectoryEntry
Dim theNamingContext As Object
' First, fetch any information that we need from the database
If Not GetConfigurationInfoFromDB() Then
Return False
End If
' Obtain the domain root entry
theRootEntry = New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
' Verify that we retrieved it correctly and raise an error if we did not
If theRootEntry Is Nothing Then
Throw New Exception("A directory services entry for the LDAP RootDSE could not be created.")
End If
' Get the root naming context
theNamingContext = theRootEntry.Properties("rootDomainNamingContext").Value
' Verify that we retrieved it correctly and raise an error if we did not
If (theNamingContext Is Nothing) OrElse (theNamingContext.ToString().Length = 0) Then
Throw New Exception("The root domain naming context property could not be retrieved from the LDAP directory services")
Else
m_sNamingContext = theNamingContext.ToString()
End If
' And create a new directory entry for the root naming context
theEntry = New DirectoryEntry("LDAP://" & m_sNamingContext)
' Verify that we retrieved it correctly and raise an error if we did not
If theEntry Is Nothing Then
Throw New Exception("A directory entry object could not be created for LDAP://" & m_sNamingContext)
End If
' Now we configure what we are looking for from Active Directory
' Start with a new searcher for the root domain
m_Searcher = New DirectorySearcher(theEntry)
Then we can use m_Searcher to start extracting what we need from AD (this is just one example for using directory services).