Use Custom DLLs into Progress - openedge

I'm having some issues while loading my custom DLL to OpenEdge Enviroment.
I've already copied my DLL to an PROPATH value and imported the DLL inside ProAsmRef.exe (The DLL is in the same folder as ProAsmRef and assemblies.xml)
The problem is, when I try to load my custom file inside a procedure, it sends me this current error:
**Unknown table name PCControl. (200)
I've already imported the DLL on my definition block with:
USING PCControl.*.
My DLL depends on another DLL (System.DirectoryServices.dll) but is already on assemblies.xml.
I can't figure it out why PCControl isn't importing, because I already have another two DLL's and they are working just fine...
Thanks for the help!
My DLL Code:
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Outlook;
namespace PCControl{
public class PCC{
public static string AzureLogin(string user, string password) {
string status;
try {
DirectoryEntry entry = new DirectoryEntry("LDAP://AUTOEXPR.COM", user, password) {
AuthenticationType = AuthenticationTypes.Secure,
Username = user,
Password = password
};
DirectorySearcher _searcher = new DirectorySearcher(entry);
_searcher.Filter = "(objectclass=user)";
SearchResult _sr = _searcher.FindOne();
string? _name = _sr.Properties["displayname"][0].ToString();
status = "SUCCESS - User " + user + " has logged in.";
} catch (System.Exception e) {
status = "ERROR - While logging in: " + e.ToString();
}
return status;
}
}
}
My XML:
<?xml version="1.0" encoding="utf-8"?>
<references xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly name="ClassADT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<assembly name="ClassOPC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<assembly name="PCControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<assembly name="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</references>
My login.p (resumed):
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE Login C-Win
PROCEDURE Login :
/*------------------------------------------------------------------------------
Purpose:
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
DEF VAR lSuccess AS CHAR NO-UNDO.
lSuccess = PCControl.PCC:AzureLogin("arorap1", "12345").
MESSAGE lSuccess
VIEW-AS ALERT-BOX INFO
TITLE "ok".
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
This issue is not related to my code into DLL... I've added the function in my co-worker's DLL and it works perfectly:
USING ClassADT.*.
DEFINE VARIABLE LSuccess AS CHAR NO-UNDO.
IF AVAIL usr_param AND usr_param.usr_ativo EQ TRUE THEN
lSuccess = ClassADT.MyAdt:MyLogin(txtUser:SCREEN-VALUE, txtPassword:SCREEN-VALUE).

It is not required and not advised to have your custom .NET Assembly and the assemblies.xml file in the c:\dlc117\bin folder at all.
Also your first assumption that those need to be in the PROPATH is not correct.
Progress provides the -assemblies startup parameter which can be used to point to the folder that contains you assemblies.xml file along with the custom .NET Assemblies (.dll files).

Related

ASP.NET Web API - App.config does not work?

I have simple self-host Web API application. I installed EnityFramework6 package and added following lines in App.config under <enityframework> section:
<contexts>
<context type="simple_api.MyContext, simple_api">
<databaseInitializer type="simple_api.MyInitializer, simple_api" />
</context>
</contexts>
Initializer class is like following:
public class MyInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<Context>
{
protected override void Seed(Context context)
{
Console.log("My seed method");
var persons = new List<Person> { };
var john = new Person() { Firstname = "John", Lastname = "Doe" };
context.Persons.Add(john);
context.SaveChanges();
}
}
I enabled and created migration, but the problem is that running it does not trigger my Seed method:
PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201805210804206_initial].
Applying explicit migration: 201805210804206_initial.
Running Seed method.
I also tried changing App.config, but It seems to be totally ignored, because <context type="foobar, nomatterwhatishere"> does not trigger any warning nor error.
What can be the problem?
--
By the way, when I configured log4net, file was ignored also and I have to call log4net.Config.XmlConfigurator.Configure(). Maybe there is similar thing for EntityFramework?
I was wrong: config file works, but Seed method for DropCreateDatabaseIfModelChanges is not triggered. I replaced it with DropCreateDatabaseAlways and after querying model it throwed exception:
Failed to set database initializer of type 'simple_api.MyInitializer, simple_api' for DbContext type 'simple_api.MyContext, simple_api' specified in the application configuration. See inner exception for details.
After some debugging I figured out that namespace is simple_api, but assembly name is simple-api, so configuration should be as follows:
...
<entityframework>
<contexts>
<context type="simple_api.MyContext, simple-api">
<databaseInitializer type="simple_api.MyInitializer, simple-api" />
</context>
</contexts>
...
</entityframework>
...
Now everything is working, but I am not sure why Seed was
not called for DropCreateDatabaseIfModelChanges.

Custom tags in App.config - type of my ConfigurationSection class is not recognised

I have followed (almost) to the letter the example from MSDN to create custom tags in my App.config (find documentation here:
https://msdn.microsoft.com/en-us/library/2tw134k3.aspx) but I am getting this error:
An unhandled exception of type
'System.Configuration.ConfigurationErrorsException' occurred in
System.configuration.dll
Additional information: An error occurred creating the configuration
section handler for MyServiceGroup/ServiceUpdater: Could not load type
'MyNamespace.ServiceUpdaterSection' from assembly
'System.configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f33d50a4a'.
and the error is triggered on this line (inside Main from my Console App when I try to make use of the custom information from App.config):
MyNamespace.ServiceUpdaterSection serviceUpdaterSection =
(ServiceUpdaterSection)ConfigurationManager.GetSection("MyServiceGroup/ServiceUpdater");
and from the error message I can already see this is because it's trying to locate MyNamespace.ServiceUpdaterSection inside System.Configuration, on the contrary, it should find this class (ServiceUpdaterSection) inside MyNamespace as I have given it the fully qualified name.
Here is how my App.config looks:
<configSections>
<sectionGroup name="MyServiceGroup">
<section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection"/>
</sectionGroup>
</configSections>
and further below inside App.config I have:
<MyServiceGroup>
<ServiceUpdater>
<licenseKey id="blablabla"/>
</ServiceUpdater>
As for the ServiceUpdaterSection class, it looks as follows:
namespace MyNamespace
{
public class LicenseKeyElement : ConfigurationElement
{
[ConfigurationProperty("id")]
public string Id
{
get
{
return (string)this["id"];
}
set
{
this["id"] = value;
}
}
}
public class ServiceUpdaterSection : ConfigurationSection
{
[ConfigurationProperty("licenseKey")]
public LicenseKeyElement LicenseKey
{
get
{
return (LicenseKeyElement)this["licenseKey"];
}
set
{
this["licenseKey"] = value;
}
}
}
}
What are your thoughts on this please?
Thank you.
The error was here:
<section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection"/>
which should have been:
<section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection, MyNamespace"/>
Will leave it in case someone else encounters the same issue.

Http Handler is working in iis express and not working in iis server

I am going to implement HttpHandler in order to allow file downloading from my site based on session values. If the session exist allow the user to download the file otherwise redirect to index page which is the login page for the site. My code is working perfect in iis express when I run my website in iis server the handler is not working.
For IIS express the web.config file has the following sections which I have added. The below configuration is working in iis express.
<system.web>
<httpHandlers>
<add verb="*" path="*.pdf" type="QDMS.FileHandler" />
Same add tag for all the files to restrict downloading without session.
</httpHandlers>
</system.web>
The configurations for IIS servers which is not working is below.
<system.webServer>
<handlers>
<add name="Files" path="*.pdf,*.doc,*.docx,*.rar,*.zip,*.ppt,*.pptx,*.jpg,*.png,*.bmp,*.gif,*.html,*.htm,*.pps" verb="*" type="QDMS.FileHandler" resourceType="Unspecified" requireAccess="script" />
</handlers>
</system.webServer>
My File handler is below
using System;
using System.Web;
using System.Web.SessionState;
using QDMS.Old_App_Code;
namespace QDMS
{
public class FileHandler : IHttpHandler, IReadOnlySessionState
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
if (!CheckWetherTheRequestForFileExistOrNot(context)) return;
if (CheckUsersForFileDownloading(context))
context.Response.Redirect("~/index.aspx");
else
{
var rawURL = context.Request.RawUrl;
var dotIndex = rawURL.LastIndexOf(".", System.StringComparison.Ordinal);
var ext = rawURL.Substring(dotIndex);
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = MIMEEType.Get(ext);
context.Response.AddHeader("Content-Disposition", "attachment");
context.Response.WriteFile(rawURL);
context.Response.Flush();
}
}
public bool CheckWetherTheRequestForFileExistOrNot(HttpContext context)
{
string url = context.Request.RawUrl.ToLower().Trim();
if (url.Contains(".pdf") || url.Contains(".xls") || url.Contains(".xlsx") || url.Contains(".jpg") ||
url.Contains(".bmp") || url.Contains(".rar") || url.Contains(".doc") || url.Contains(".docx") ||
url.Contains(".png") || url.Contains(".gif") || url.Contains(".pptx") || url.Contains(".zip") ||
url.Contains(".ppt") || url.Contains(".pps") || url.Contains(".htm") || url.Contains(".html"))
return true;
else
return false;
}
public bool CheckUsersForFileDownloading(HttpContext context)
{
return (context.Session["FrontHiddenID"] == null) && (context.Session["HiddenID"] == null);
}
}
}
I am sure that in the section in the web.config file is not correct that is why it is not working. So I need suggestions to rectify my handlers section in web.config file.
Any advice and help regarding this issue will be higly appreciated
Your IIS handler should be like this :
<add name="Files" path="*.pdf" verb="*" type="QDMS.FileHandler" resourceType="Unspecified" requireAccess="Script" />
Two differences with your version :
only one file mask, you should register a handler for each file type
requireAccess="Script" with 'Script' having an upper-case 'S'
Hope this will help
To map a file-name extension in IIS 7.0 running in Classic mode
Open IIS Manager.
Expand the node for the Web server computer, expand Sites, and then expand Default Web Site.
Select the node for your application.
The Features View pane is displayed.
In Features View, double-click Handler Mappings.
On the Actions pane, click Add Script Map.
The Add Script Map dialog box is displayed.
In the Add Script Map dialog box, specify the following:
o Request Path. The name or file-name extension to map.
o Executable. The path of the .exe or .dll file that will handle the request. For Classic mode, specify the ASP.NET ISAPI extension (Aspnet_isapi.dll).
o Name. A descriptive name.
Click OK to close the Add Script Map dialog box.
Open the Web.config file for the application.
Locate the httpHandlers element of the system.web section and add an entry for the file-name extension.
To map a file-name extension in IIS 7.0 running in Integrated mode
Follow steps 1 through 3 of the previous procedure.
On the Actions pane, click Add Managed Handler.
The Add Managed Handler dialog box is displayed.
In the Add Managed Handler dialog box, specify the following:
o Request Path. The file name or file-name extension to map.
o Type. The type (class) name of the managed handler. If the handler is defined in the App_Code folder of the ASP.NET application, its type name will appear in the drop-down list.
o Name. A descriptive name.
Click OK to close the Add Managed Handler dialog box.

Mysql syntax error while creating Database for Entity Framework

I'm playing around with asp.net for the first time. I want to use it with a MySQL database because this is what is offered by my hosting service and I don't want to upgrade/change services. I'm using visual web developer 2010 express. I created an MVC 4 project from the default template. The template created the ASP.NET Simple Membership objects which is what I'm trying to get working. The project builds and runs correctly when using the default database connection string. When I change the web.config file to point to MySQL I get the following error when I attempt to navigate to any of the pages in the account folder.
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'IDENTITY,
RoleName nvarc' at line 2
When I open the MySQL work bench and connect to the local server I notice that the database has been created. If I drop the DB and run the app again it gets recreated. I'm note sure if it was created correctly or if the entire database was created but there is something there.
Obviously there is an issue with the SQL syntax that is created by the Entity Framework. Do I need to add something to the web.config file to tell it what syntax it should use when creating the queries?
I've been searching for an answer to this for the past two days. any help pointing in the right direction would be appreciated.
I'm using mysql server version 5.5.27. and connector 6.5.4.0
here is the mysql part of my web.config file:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MyWebPage-20120817115958;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="myDatabaseConnection" connectionString="server=localhost;Port=3306;uid=root;pwd=****;database=myDatabase;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Edit adding code
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Ensure ASP.NET Simple Membership is initialized only once per app start
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("LocalMySqlServer", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
catch (Exception ex)
{
throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
}
}
}
}
public class UsersContext : DbContext
{
public UsersContext()
: base("LocalMySqlServer")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
Try to modify the source of the SMP and remove the syntax specific to ms sql server.
The role provider is still defaulting to the standard ASP one which is expecting a SQLServer DB on the end of the connection, "Identity" is SQLServerese for "autoinc".
You can set the default providers in the web.config like this:-
<configuration>
<system.web>
<profile defaultProvider="MySQLProfileProvider"></profile>
<roleManager defaultProvider="MySQLRoleProvider"></roleManager>
</system.web>
</configuration>

microsoft.contracts dll error when creating facebookclient object in facebook c#sdk

using Facebook;
using Facebook.Web;
public pageLoad()
public void fetchFacebookData()
{
var fbApp = new FacebookClient();// error occured at this line
var result = (IDictionary<string, object>)fbApp.Get("me");
var name = (string)result["name"];
}
the above code generated error......
Could not load file or assembly 'Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16' or one of its dependencies. The system cannot find the file specified.
my web.config section is as follows
<configSections>
<section name="facebookSettings" type="Facebook.FacebookConfigurationSection,Facebook" allowLocation="true" allowDefinition="Everywhere"/>
</configsection>
<facebookSettings
appId="1xxxxxxxx" appSecret="eeeeeeeeeeeeeeeeeee"/>
</facebookSettings?
You are using an old version of the Facebook C# SDK. Download the current release which does not depend on Code Contracts.

Resources