How to run the plugin in cefsharp? - plugins

I have WinForms application with CEF. I create my oun plugin and I want to run it in CEF. But in no running.
My goal is to run my plugin. In work with Chrome good.
My InitializeChromium() is:
public void InitializeChromium()
{
string pluginPath = #"C:\Users\....AppData\Local\Google\Chrome\User Data\Default\Extensions\iifchhfnnmpdbibifmljnfjhpififfog /Run=yes";
CefSettings settings = new CefSettings();
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
settings.CefCommandLineArgs.Add("single-process", "1");
settings.CefCommandLineArgs.Add("plugin-launcher", pluginPath);
Cef.Initialize(settings);
_browser = new ChromiumWebBrowser("https://www.google.com");
this.Controls.Add(_browser);
_browser.Dock = DockStyle.Fill;
}
I expect the plugin's work. How to run my plugin?

Related

Need help for Checkmarx.Api cake plugin

I am trying to incorporate "Checkmarx" Static code scans as a stage into my devops pipeline. Currently our code uses "cake" files to excute the stages (invoked by PowerShell).
I was checking the cake support for Checkmarx.Api but could not find any neither in the Checkmarx site or in the Cake website. The NuGet gallery has a tab for the cake addin - https://www.nuget.org/packages/Checkmarx.API/
but does not share any information on the contracts exposed.
So reaching out to the community to see if anyone has done any work on this or has any references. Any other way you have incorporated "Checkmarx" into your build pipeline (without directly using the plugin rather using the CxCLi) would also be helpful as well.
As answered in the GitHub discussion where you asked the same question:
Cake scripts based on "normal" C#, so whatever the usage of Checkmarx.API, you can simply incorporate that in your cake scripts. Probably something like:
Task("Scan")
.Does(() =>
{
// place your code here..
});
As for using Checkmarx.API, I would suggest asking in the Checkmarx.API repo.
Alternatively, it seems that there is a CLI available. You can use that using the one of the process aliases.
Probably something like:
Task("Scan")
.Does(() =>
{
StartProcess("runCxConsole.cmd", new ProcessSettings
{
Arguments = #"Scan -v -ProjectName ""CxServer/bookname j2"" -CxServer http://localhost -CxUser username -CxPassword admin -LocationType folder -LocationPath ""C:\Data\Projects\Java\bs java"" -preset ""Checkmarx Default"""
});
});
(Note: I took the Arguments to runCxConsole.cmd from the documentation - I did not test that.)
I will mark this as closed as I have been able to get around this using .net HttpClient but unfortunately could not implement using Checkmarx cake addin.
I will paste the sample code, i was getting some ssl eerror until i added the "ServerCertificateCustomValidationCallback" to return true
string accessToken = string.Empty;
try
{
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
using (var client = new HttpClient(httpClientHandler))
{
client.BaseAddress = new Uri(CXUrl+"/auth/identity/connect/token");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Accept", "*/*");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("scope", "access_control_api sast_api"),
new KeyValuePair<string, string>("username", username),
new KeyValuePair<string, string>("password", pwd),
new KeyValuePair<string, string>("client_id", "resource_owner_sast_client"),
new KeyValuePair<string, string>("client_secret", "****************************"),
});
var response = client.PostAsync("", content);
var result = JsonConvert.DeserializeObject<CXAccessToken>(response.Result.Content.ReadAsStringAsync().Result);
accessToken = result.access_token;
}
}
}

Detecting installed plugin in Eclipse

I'd like to detect the presence of a plugin from within the Eclipse plugin I'm maintaining. From a few other questions asked on this subject it looks like this is difficult.
The plugin I'm looking to detect provides a view. As such the following works, but I'm hoping that a prettier option exists:
public static boolean internalPluginInstalled() {
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint point = reg.getExtensionPoint("org.eclipse.ui.views");
IExtension[] extensions = point.getExtensions();
for(IExtension extension : extensions) {
IConfigurationElement[] configs = extension.getConfigurationElements();
for (IConfigurationElement config : configs) {
if (config.getName().equals("view") && config.getAttribute("id").equals("view.id.goes.here")) {
return true;
}
}
}
return false;
}
Use Platform.getBundle (org.eclipse.core.runtime.Platform):
Bundle bundle = Platform.getBundle("plugin id");
bundle will be non-null if the plug-in is installed.
bundle.getState() returns you the exact state of the plug-in - Bundle.ACTIVE if the plug-in has been started.

How to implement the Plugin Architecture in Flutter Dart

I want to implement a plugin architecture in Flutter Dart. The process will be as follows:
1. User downloads the app.
2. The user loads plugins from our site.
3. The apps look if the plugin implements an interface.
4. If the interface is implemented then load information and widgets from the plugin to the app.
I've implemented the same process in C# using compiled DLL loading in runtime but unable to find it for Flutter.
I've looked into some of the previous questions and resource available on the internet and the closest one I found was this, https://pub.dev/packages/plugins but the plugin is not supported in Dart 2 and deprecated
This was the code I implemented in C#.
int i = 0;
if (Directory.Exists("Plugins"))
{
dllFileNames = Directory.GetFiles("Plugins", "*.dll");
ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
foreach (string dllFile in dllFileNames)
{
AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
Assembly assembly = Assembly.Load(an);
assemblies.Add(assembly);
}
Type pluginType = typeof(IPlugin);
List<Type> pluginTypes = new List<Type>();
foreach (Assembly assembly in assemblies)
{
if (assembly != null)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsInterface || type.IsAbstract)
{
continue;
}
else if (pluginType.IsAssignableFrom(type))
{
pluginTypes.Add(type);
}
}
}
i++;
}
ICollection<IPlugin> plugins = new List<IPlugin>(pluginTypes.Count);
foreach (Type type in pluginTypes)
{
IPlugin plugin = (IPlugin)Activator.CreateInstance(type);
plugin.Initiate();
plugins.Add(plugin);
}
return plugins;
}
return null;
It's probably not possible.
Part of the AOT compilation preparing your app for upload to the stores is a tree-shaking, removing everything that isn't needed by the current build. So, anything your plugin would need to call is gone.

How to create a builtin file and folder in custom eclipse plugin

I am developing an Eclipse plugin which need to be shipped with builtin ant build file. Its working when I am running the project. However, when I am exporting the plugin and deploying the exported plugin in another eclipse, the ant build file is not getting generated. My suspect is that in the runtime, the source of the ant build file is not accessed. Any pointer how to solve the issue? Here is the code :
private void createAntFile(IProject project, Properties properties) throws CoreException, IOException {
InputStream antFileInputStream =null;
try {
String antFileName = properties.getProperty("name.ant.file");
String antFilePath = properties.getProperty("path.ant.file");
IFile file = project.getFile(antFileName);
antFileInputStream = Activator.getDefault().getBundle().getEntry(antFilePath).openStream();
file.create(antFileInputStream, false, null);
antFileInputStream.close();
}finally{
if(antFileInputStream!=null){
try {
antFileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
name.ant.file=build.xml
path.ant.file=src/weblogic/ant/build.xml
The source build file I am hard coding in the path src/weblogic/ant/build.xml
Edit:
Here is the code to create builtin folders:
private void createWeblogicTemplate(IProject project, Properties properties) throws IOException, CoreException {
String weblogicTemplateSourcePath = properties.getProperty("path.weblogic.template.source");
Path path = new Path(weblogicTemplateSourcePath);
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL = FileLocator.find(bundle, path, null);
String filePath = FileLocator.resolve(fileURL).getPath();
System.out.println(filePath);
File sourceFile = new File(filePath);
String weblogicTemplateTargetPath = properties.getProperty("path.weblogic.template.target");
IFolder folder = project.getFolder(weblogicTemplateTargetPath);
copyFolder(sourceFile,folder,project,properties);
}
The line System.out.println(filePath) is printing path as
/C:/Users//Desktop/eclipse-rcp-luna-SR2-win32-x86_64/eclipse/../../../workspace-plugin/weblogic/resources/weblogictemplate/
So, locally its working. However, its not working when I deploy the pluin in some other eclipse. Any pointer how to create builtin folders?
You appear to be expecting the src/weblogic/ant/ directory to be included in the exported plugin jar - the src directory is not normally included in the plugin jar.
Put resources you want to include in the plugin in a separate directory (such as resources) and include that directory in the plugin build.properties so that it is included in the exported plugin jar.

Need to scan WEB-INF/lib/xxx-ejb.jar for Type and Method annotations

I want to do the following using Google Reflections:
Scan only WEB-INF/lib/Patrac-ejb.jar
Scan only the package com.patrac and all of its sub-packages.
Scan for only type- and method annotations.
The following configuration seems to work fine but I don't have any experience with Google Reflections.
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder().include("Patrac-ejb.jar").include(FilterBuilder.prefix("com.patrac")))
.setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner())
.setUrls(ClasspathHelper.forWebInfLib(servletContext))
);
It appears to be working. I want to make sure it's not scanning all the other JARs in WEB-INF/lib. Is there an easy way to discover what JARs are being matched by the filter inputs in the configuration? Any advice about my approach would be much appreciated.
The following worked:
// Get the URL for Patrac-ejb.jar:
Set<URL> urls = ClasspathHelper.forWebInfLib(webUtil.getServletContext());
URL patracJarUrl = null;
for(URL url : urls)
{
if(url.getFile().endsWith("Patrac-ejb.jar"))
{
patracJarUrl = url;
break;
}
}
if(null == patracJarUrl)
{
throw new IllegalStateException("Patrac-ejb.jar not found.");
}
// Add the Patrac-ejb.jar URL to the configuration.
Configuration configuration = new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder()
.include(FilterBuilder.prefix("com.patrac")))
.setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner())
.setUrls(patracJarUrl);