Skip to content

Commit 70800d4

Browse files
author
Ahmad Noman Musleh
committed
Change commands plugin sample to store SVG icons in code instead of using embedded resources due to incompatibility issue with embedded compiler.
1 parent 857aa9a commit 70800d4

File tree

6 files changed

+17
-41
lines changed

6 files changed

+17
-41
lines changed

Plugins/Commands Sample/Commands Sample/Commands Sample.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
// This code is intended to be used as a sample and does not guarantee any particular outcome or
66
// profit of any kind. Use it at your own risk.
77
//
8-
// This sample adds several commands to chart container toolbar, and uses .NET project assembly embedded resource
9-
// to store and load SVG icons.
8+
// This sample adds several commands to chart container toolbar, all SVG icons are stored inside SvgIcons
9+
// static class.
1010
//
1111
// -------------------------------------------------------------------------------------------------
1212

1313
using System;
14-
using System.IO;
15-
using System.Reflection;
16-
using System.Text;
1714
using cAlgo.API;
1815

1916
namespace cAlgo.Plugins
@@ -23,15 +20,15 @@ public class CommandsSample : Plugin
2320
{
2421
protected override void OnStart()
2522
{
26-
var commandWithoutResultIcon = new SvgIcon(GetSvgIconAsString("growth-icon.svg"));
23+
var commandWithoutResultIcon = new SvgIcon(SvgIcons.GrowthIcon);
2724
var commandWithoutResult = Commands.Add(CommandType.ChartContainerToolbar, CommandWithoutResultCallback, commandWithoutResultIcon);
2825
commandWithoutResult.ToolTip = "Without Result";
2926

30-
var commandWithResultIcon = new SvgIcon(GetSvgIconAsString("innovation-creativity-icon.svg"));
27+
var commandWithResultIcon = new SvgIcon(SvgIcons.InnovationCreativityIcon);
3128
var commandWithResult = Commands.Add(CommandType.ChartContainerToolbar, CommandWithResultCallback, commandWithResultIcon);
3229
commandWithResult.ToolTip = "With Result";
3330

34-
var disabledCommandIcon = new SvgIcon(GetSvgIconAsString("motor-pump-color-icon.svg"));
31+
var disabledCommandIcon = new SvgIcon(SvgIcons.MotorPumpColorIcon);
3532
var disabledCommand = Commands.Add(CommandType.ChartContainerToolbar, args => throw new InvalidOperationException("Shouldn't be executed!"), disabledCommandIcon);
3633

3734
disabledCommand.ToolTip = "Disabled Command";
@@ -74,23 +71,5 @@ private CommandResult CommandWithResultCallback(CommandArgs commandArgs)
7471
}
7572

7673
private void OnWebViewLoaded(WebViewLoadedEventArgs obj) => obj.WebView.NavigateAsync("https://ctrader.com/");
77-
78-
private string GetSvgIconAsString(string fileName)
79-
{
80-
var assembly = Assembly.GetAssembly(typeof(CommandsSample));
81-
82-
var assemblyName = assembly!.GetName().Name!.Replace(' ', '_');
83-
84-
var embeddedResourceName = $"{assemblyName}.{fileName}";
85-
86-
using var stream = assembly.GetManifestResourceStream(embeddedResourceName);
87-
88-
if (stream is null)
89-
throw new InvalidOperationException($"Resource {embeddedResourceName} not found.");
90-
91-
using var streamReader = new StreamReader(stream, Encoding.UTF8);
92-
93-
return streamReader.ReadToEnd();
94-
}
9574
}
9675
}

Plugins/Commands Sample/Commands Sample/Commands Sample.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@
66
<ItemGroup>
77
<PackageReference Include="cTrader.Automate" Version="*-*" />
88
</ItemGroup>
9-
10-
<ItemGroup>
11-
<EmbeddedResource Include="growth-icon.svg" />
12-
<EmbeddedResource Include="innovation-creativity-icon.svg" />
13-
<EmbeddedResource Include="motor-pump-color-icon.svg" />
14-
</ItemGroup>
159
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace cAlgo.Plugins;
2+
3+
public static class SvgIcons
4+
{
5+
public const string GrowthIcon =
6+
"<?xml version=\"1.0\" encoding=\"utf-8\"?><svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" viewBox=\"0 0 122.88 118.3\" style=\"enable-background:new 0 0 122.88 118.3\" xml:space=\"preserve\"><style type=\"text/css\"><![CDATA[\n\t.st0{fill:#6BBE66;}\n\t.st1{fill:#393939;}\n]]></style><g><path class=\"st0\" d=\"M115.5,85.67v11.24h-14.21V85.67H115.5L115.5,85.67L115.5,85.67z M39.32,53.3v43.61H25.11V53.3H39.32 L39.32,53.3L39.32,53.3z M64.71,65.7v31.21h-14.2V65.7H64.71L64.71,65.7L64.71,65.7z M90.1,73.84v23.07H75.9V73.84H90.1L90.1,73.84 L90.1,73.84z\"/><path class=\"st1\" d=\"M12.53,19.38v86.39h108.46v12.53H6.27c-3.46,0-6.27-2.81-6.27-6.27V19.38H12.53L12.53,19.38L12.53,19.38z M40.66,17.78l-1.04,8.14c-0.32,2.51-2.61,4.28-5.12,3.97c-2.51-0.32-4.28-2.61-3.97-5.12l2.65-20.62 c0.14-1.45,0.97-2.81,2.33-3.57c1.24-0.69,2.65-0.74,3.88-0.27l19.86,7.65c2.36,0.91,3.53,3.56,2.62,5.92 c-0.91,2.36-3.56,3.53-5.92,2.62l-6.78-2.61c7.43,10.08,16.33,18.5,25.94,25.06c13.84,9.45,29.1,15,43.51,16.04 c2.53,0.18,4.43,2.37,4.25,4.9c-0.18,2.53-2.37,4.43-4.9,4.25c-15.99-1.13-32.85-7.23-48.03-17.6 C59.02,39.09,48.95,29.41,40.66,17.78L40.66,17.78L40.66,17.78z\"/></g></svg>";
7+
8+
public const string InnovationCreativityIcon =
9+
"<?xml version=\"1.0\" encoding=\"utf-8\"?><svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" viewBox=\"0 0 114.98 122.88\" style=\"enable-background:new 0 0 114.98 122.88\" xml:space=\"preserve\"><style type=\"text/css\"><![CDATA[\n\t.st0{fill:#F4BB2C;}\n\t.st1{fill:#5C546A;}\n]]></style><g><path class=\"st1\" d=\"M68.72,116.34c-1.22,2.09-2.9,3.72-4.82,4.83c-1.71,1-3.62,1.57-5.53,1.69c-1.94,0.12-3.9-0.25-5.69-1.11 c-1.22-0.6-2.36-1.43-3.37-2.51L68.72,116.34L68.72,116.34L68.72,116.34L68.72,116.34z M71.41,95.83l-0.63,2.95l-0.16,2.1 l-25.33,3.77c-0.09-1.51-0.33-3.14-0.71-4.83L71.41,95.83L71.41,95.83L71.41,95.83L71.41,95.83z M70.57,105.48l0.02,1.27l0.03,0.44 c0.07,0.83,0.08,1.67,0.03,2.5l-0.38,1.83l-23.52,3.5l-0.41-0.94l-0.92-3.76l-0.02-1.09L70.57,105.48L70.57,105.48L70.57,105.48 L70.57,105.48z\"/><path d=\"M56.76,3.84c0.03-1.09,0.49-2.06,1.22-2.75c0.71-0.68,1.69-1.09,2.75-1.08V0c0.09,0,0.18,0.01,0.27,0.02 c0.99,0.08,1.88,0.53,2.52,1.2c0.68,0.71,1.09,1.68,1.08,2.75h0.01c0,0.07,0,0.14-0.01,0.2l-0.21,8.37h0.01 c0,0.09-0.01,0.18-0.02,0.27c-0.08,1-0.53,1.88-1.2,2.52c-0.72,0.68-1.69,1.09-2.75,1.08v0.01c-0.09,0-0.18-0.01-0.27-0.02 c-1-0.08-1.88-0.53-2.52-1.2c-0.68-0.72-1.09-1.69-1.08-2.75h-0.01c0-0.07,0-0.14,0.01-0.2L56.76,3.84L56.76,3.84L56.76,3.84 L56.76,3.84z M14.26,18.5c-0.79-0.74-1.21-1.73-1.25-2.73s0.31-2.02,1.04-2.81c0.74-0.79,1.73-1.21,2.73-1.25s2.02,0.31,2.81,1.04 l6.28,5.85c0.79,0.74,1.21,1.73,1.25,2.73c0.04,1.01-0.31,2.02-1.04,2.81c-0.74,0.79-1.73,1.21-2.73,1.25 c-1.01,0.04-2.02-0.31-2.81-1.04L14.26,18.5L14.26,18.5L14.26,18.5L14.26,18.5z M3.99,61.66c-1.06,0.02-2.03-0.39-2.75-1.06 c-0.73-0.69-1.2-1.65-1.24-2.74c-0.04-1.08,0.37-2.08,1.06-2.81c0.69-0.73,1.65-1.2,2.74-1.23l8.57-0.29 c1.08-0.04,2.08,0.37,2.81,1.06c0.73,0.69,1.2,1.65,1.23,2.74v0.06h0.01l-0.01,0.14c-0.02,1.01-0.42,1.92-1.06,2.61 c-0.69,0.73-1.65,1.19-2.74,1.23h-0.06v0.01h-0.09L3.99,61.66L3.99,61.66L3.99,61.66L3.99,61.66z M110.69,49.51l0.13-0.01 c1.02-0.06,1.97,0.27,2.71,0.87c0.78,0.63,1.31,1.57,1.43,2.64v0.04c0.01,0,0.01,0.11,0.01,0.13c0.06,1.02-0.27,1.97-0.87,2.71 c-0.63,0.78-1.57,1.31-2.64,1.43l-8.53,0.9c-1.08,0.11-2.1-0.23-2.87-0.86c-0.78-0.63-1.32-1.57-1.43-2.64 c-0.11-1.07,0.23-2.1,0.86-2.87c0.63-0.78,1.57-1.32,2.64-1.43C104.98,50.11,107.84,49.78,110.69,49.51L110.69,49.51L110.69,49.51 L110.69,49.51L110.69,49.51z M93.8,15.38c0.61-0.9,1.51-1.46,2.49-1.66c0.98-0.19,2.03-0.01,2.94,0.59l0.01,0.01 c0.9,0.6,1.47,1.51,1.66,2.49c0.19,0.98,0.01,2.03-0.59,2.94l-4.77,7.13c-0.6,0.9-1.51,1.47-2.5,1.67 c-0.98,0.19-2.03,0.01-2.94-0.59c-0.9-0.6-1.47-1.52-1.67-2.5c-0.19-0.98-0.01-2.03,0.59-2.94L93.8,15.38L93.8,15.38L93.8,15.38 L93.8,15.38z\"/><path class=\"st0\" d=\"M36.37,82.46c-2.88-3.29-5.86-6.71-8.22-11.74c-2.31-4.96-3.59-10.08-3.55-15.4c0.05-5.32,1.4-10.8,4.34-16.46 c0.02-0.04,0.04-0.07,0.06-0.11l0,0c3.85-6.52,9.24-10.88,15.24-13.32c5.03-2.06,10.5-2.76,15.86-2.27 c5.34,0.49,10.57,2.17,15.14,4.87c5.81,3.44,10.59,8.54,13.22,14.98c1.42,3.49,2.38,7.38,2.5,11.64c0.12,4.25-0.61,8.83-2.57,13.67 c-3,7.43-10.01,15.39-14.6,22.7c-0.25-0.05-0.51-0.06-0.77-0.02c-9.89,1.47-19.78,2.94-29.67,4.41 C41.72,90.56,39.22,85.72,36.37,82.46L36.37,82.46L36.37,82.46L36.37,82.46z M68.47,36.97c-0.46-0.32-0.99-0.47-1.53-0.36 c-0.54,0.11-0.99,0.39-1.31,0.85l-1.81,2.56c-0.65-0.29-1.31-0.5-2.03-0.68s-1.38-0.32-2.1-0.43l-0.57-3.34 c-0.11-0.57-0.39-0.99-0.81-1.31c-0.47-0.32-0.96-0.43-1.53-0.32l-4.19,0.75c-0.54,0.11-0.96,0.36-1.31,0.82 c-0.32,0.47-0.46,0.96-0.36,1.53l0.54,3.06c-0.68,0.29-1.31,0.61-1.92,0.99c-0.61,0.36-1.21,0.79-1.74,1.21l-2.84-1.96 c-0.47-0.32-0.96-0.47-1.49-0.36c-0.54,0.11-0.99,0.39-1.31,0.86l-2.42,3.45c-0.32,0.46-0.46,0.99-0.36,1.53 c0.11,0.57,0.39,0.99,0.86,1.31l2.55,1.81c-0.29,0.64-0.5,1.31-0.68,2.03c-0.18,0.72-0.32,1.38-0.43,2.1l-3.34,0.57 c-0.57,0.11-0.99,0.39-1.31,0.81c-0.32,0.47-0.43,0.96-0.32,1.53l0.75,4.19c0.11,0.54,0.36,0.96,0.81,1.31 c0.47,0.32,0.96,0.47,1.53,0.36l3.06-0.54c0.29,0.68,0.61,1.31,0.99,1.92c0.36,0.61,0.79,1.21,1.21,1.78l-1.96,2.8 c-0.32,0.46-0.46,0.96-0.36,1.49c0.11,0.54,0.39,0.99,0.85,1.31l3.49,2.45c0.47,0.32,0.99,0.43,1.53,0.32 c0.54-0.11,0.99-0.36,1.35-0.81l1.82-2.59c0.65,0.29,1.31,0.5,2.03,0.68c0.72,0.18,1.38,0.32,2.1,0.43l0.57,3.34 c0.11,0.57,0.39,0.99,0.81,1.31c0.47,0.32,0.96,0.43,1.53,0.32l4.19-0.75c0.54-0.11,0.96-0.36,1.31-0.81 c0.32-0.46,0.47-0.96,0.36-1.53l-0.54-3.06c0.68-0.29,1.31-0.61,1.92-0.99c0.61-0.36,1.21-0.78,1.78-1.21l2.81,1.96 c0.46,0.32,0.96,0.46,1.53,0.36c0.57-0.11,0.99-0.39,1.31-0.85l2.45-3.49c0.32-0.46,0.43-0.99,0.32-1.53 c-0.11-0.54-0.36-0.99-0.82-1.35l-2.59-1.78c0.29-0.64,0.5-1.31,0.68-2.03c0.18-0.72,0.32-1.39,0.43-2.1l3.34-0.57 c0.57-0.11,0.99-0.39,1.31-0.82C78.9,55.06,79,54.57,78.9,54l-0.75-4.19c-0.11-0.54-0.36-0.96-0.81-1.31 c-0.47-0.32-0.96-0.47-1.53-0.36l-3.06,0.54c-0.29-0.65-0.61-1.28-0.99-1.92c-0.36-0.65-0.79-1.21-1.21-1.74l1.96-2.84 c0.32-0.46,0.46-0.96,0.36-1.49c-0.11-0.54-0.39-0.99-0.85-1.31l-3.45-2.42L68.47,36.97L68.47,36.97L68.47,36.97z M56.27,46.86 c1.1-0.18,2.21-0.18,3.31,0.07c1.06,0.25,2.03,0.68,2.91,1.28c0.85,0.61,1.6,1.38,2.21,2.32c0.61,0.92,0.99,1.96,1.17,3.06 c0.18,1.1,0.18,2.21-0.07,3.31c-0.25,1.06-0.68,2.03-1.28,2.91c-0.61,0.85-1.38,1.6-2.32,2.21c-0.92,0.61-1.96,0.99-3.06,1.17 c-1.1,0.18-2.21,0.18-3.31-0.07c-1.06-0.25-2.03-0.68-2.91-1.28c-0.85-0.61-1.6-1.38-2.21-2.31c-0.61-0.92-0.99-1.96-1.17-3.06 c-0.18-1.1-0.18-2.21,0.07-3.31c0.25-1.06,0.68-2.03,1.28-2.91c0.61-0.85,1.39-1.6,2.32-2.21C54.15,47.43,55.17,47.03,56.27,46.86 L56.27,46.86L56.27,46.86z\"/></g></svg>";
10+
11+
public const string MotorPumpColorIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" shape-rendering=\"geometricPrecision\" text-rendering=\"geometricPrecision\" image-rendering=\"optimizeQuality\" fill-rule=\"evenodd\" clip-rule=\"evenodd\" viewBox=\"0 0 512 475.957\"><path fill-rule=\"nonzero\" d=\"M57.705 238.569V281H21.216C9.5 281 0 271.5 0 259.786c0-11.717 9.5-21.217 21.216-21.217h36.489zM244.873 0h103.279c12.371 0 23.607 5.058 31.744 13.195 8.143 8.143 13.198 19.388 13.198 31.748s-5.062 23.602-13.203 31.743c-8.14 8.14-19.383 13.203-31.739 13.203H244.873c-12.359 0-23.605-5.056-31.747-13.199-8.137-8.137-13.195-19.373-13.195-31.744 0-12.315 5.051-23.538 13.192-31.703l.081-.08C221.366 5.038 232.578 0 244.873 0zM390.17 418.092l16.693 38.83a13.188 13.188 0 011.322 5.776c0 7.321-5.937 13.259-13.259 13.259H198.667v-.053c-1.479 0-2.982-.249-4.454-.776-6.864-2.459-10.436-10.021-7.977-16.884l14.386-40.152H163.42c-12.047 0-23.006-4.936-30.956-12.882l-.051-.051c-7.946-7.949-12.882-18.909-12.882-30.956v-13.741H79.938c-6.111 0-11.679-2.5-15.703-6.525-4.017-4.016-6.522-9.573-6.522-15.7V181.332c0-6.123 2.496-11.684 6.518-15.706 4.023-4.023 9.583-6.519 15.707-6.519h39.593v-13.741c0-12.047 4.936-23.006 12.882-30.956l.051-.051c7.95-7.946 18.909-12.882 30.956-12.882h240.492c29.737 0 56.762 12.156 76.346 31.741C499.843 152.802 512 179.828 512 209.565v107.642c0 27.758-11.346 52.982-29.625 71.26-18.279 18.279-43.504 29.625-71.26 29.625H390.17z\"/><path fill=\"#2A6F80\" d=\"M375.75 418.093l-161.334.652-15.75 43.952h196.261z\"/><path fill=\"#6BAEC0\" d=\"M79.938 172.366h39.592v174.838H79.938c-4.908 0-8.967-4.034-8.967-8.966V181.332c0-4.933 4.034-8.966 8.967-8.966z\"/><path fill=\"#B2EEFD\" d=\"M163.42 114.736h233.097v290.041l.001.056H163.42c-16.846 0-30.63-13.782-30.63-30.63V145.366c0-16.847 13.784-30.63 30.63-30.63zm35.713 228.48a9.508 9.508 0 010-19.016h143.743c5.25 0 9.508 4.258 9.508 9.508 0 5.251-4.258 9.508-9.508 9.508H199.133zm0-144.96a9.508 9.508 0 010-19.015h143.743c5.25 0 9.508 4.257 9.508 9.507 0 5.251-4.258 9.508-9.508 9.508H199.133zm0 72.481a9.508 9.508 0 010-19.016h143.743c5.25 0 9.508 4.257 9.508 9.508 0 5.25-4.258 9.508-9.508 9.508H199.133zm212.174-155.712c48.735 3.805 87.434 44.871 87.434 94.54v107.642c0 48.132-39.328 87.519-87.436 87.623l.002-.053V115.025z\"/><path fill=\"#F5DAA8\" d=\"M244.873 13.267h103.279c17.423 0 31.676 14.285 31.676 31.676v.003c0 17.391-14.284 31.675-31.676 31.675H244.873c-17.391 0-31.675-14.253-31.675-31.675v-.003c0-17.423 14.253-31.676 31.675-31.676z\"/></svg>";
12+
}

Plugins/Commands Sample/Commands Sample/growth-icon.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

Plugins/Commands Sample/Commands Sample/innovation-creativity-icon.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)