Skip to content

CNT-672: OpenFile, OpenFolder, SaveFileDialog samples #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Indicators/.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@
{
"name": "Notifications Sample"
},
{
"name": "OpenFileDialog Sample"
},
{
"name": "OpenFolderDialog Sample"
},
{
"name": "Orientation Sample"
},
Expand Down Expand Up @@ -344,6 +350,9 @@
{
"name": "Rectangle Shape Sample"
},
{
"name": "SaveFileDialog Sample"
},
{
"name": "ScrollBarVisibility Sample"
},
Expand Down
22 changes: 22 additions & 0 deletions Indicators/OpenFileDialog Sample/OpenFileDialog Sample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFileDialog Sample", "OpenFileDialog Sample\OpenFileDialog Sample.csproj", "{3040baa2-c3e6-46b2-a167-5594d4036ef0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3040baa2-c3e6-46b2-a167-5594d4036ef0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3040baa2-c3e6-46b2-a167-5594d4036ef0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3040baa2-c3e6-46b2-a167-5594d4036ef0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3040baa2-c3e6-46b2-a167-5594d4036ef0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using cAlgo.API;
using System.Text;

namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class OpenFileDialogSample : Indicator
{
private OpenFileDialog _openFileDialog;

protected override void Initialize()
{
_openFileDialog = new OpenFileDialog()
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Multiselect = true,
Title = "My Open File Dialog Title"
};

var showOpenFileDialog = new Button { Text = "Show Open File Dialog" };
showOpenFileDialog.Click += showOpenFileDialog_Click;

var panel = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

panel.AddChild(showOpenFileDialog);
Chart.AddControl(panel);
}

private void showOpenFileDialog_Click(ButtonClickEventArgs obj)
{
var result = _openFileDialog.ShowDialog();
Print($"Result: {result} | FileName: {_openFileDialog.FileName} | FileNames: {string.Join(',', _openFileDialog.FileNames)}");
}

public override void Calculate(int index)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Indicators/OpenFolderDialog Sample/OpenFolderDialog Sample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFolderDialog Sample", "OpenFolderDialog Sample\OpenFolderDialog Sample.csproj", "{96cc103a-7c47-4eb7-bfbd-0749bd22e097}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{96cc103a-7c47-4eb7-bfbd-0749bd22e097}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96cc103a-7c47-4eb7-bfbd-0749bd22e097}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96cc103a-7c47-4eb7-bfbd-0749bd22e097}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96cc103a-7c47-4eb7-bfbd-0749bd22e097}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using cAlgo.API;

namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class OpenFolderDialogSample : Indicator
{
private OpenFolderDialog _openFolderDialog;

protected override void Initialize()
{
_openFolderDialog = new OpenFolderDialog()
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Title = "My Open Folder Dialog Title"
};

var showOpenFolderDialog = new Button { Text = "Show Open Folder Dialog" };
showOpenFolderDialog.Click += showOpenFolderDialog_Click;

var panel = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

panel.AddChild(showOpenFolderDialog);
Chart.AddControl(panel);
}

private void showOpenFolderDialog_Click(ButtonClickEventArgs obj)
{
var result = _openFolderDialog.ShowDialog();
Print($"Result: {result} | FolderName: {_openFolderDialog.FolderName}");
}

public override void Calculate(int index)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Indicators/SaveFileDialog Sample/SaveFileDialog Sample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaveFileDialog Sample", "SaveFileDialog Sample\SaveFileDialog Sample.csproj", "{5ec3ab32-b5ab-493c-8747-46eb9ec16b0e}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5ec3ab32-b5ab-493c-8747-46eb9ec16b0e}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ec3ab32-b5ab-493c-8747-46eb9ec16b0e}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ec3ab32-b5ab-493c-8747-46eb9ec16b0e}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ec3ab32-b5ab-493c-8747-46eb9ec16b0e}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using cAlgo.API;
using System.Text;

namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class SaveFileDialogSample : Indicator
{
private SaveFileDialog _saveFileDialog;

protected override void Initialize()
{
_saveFileDialog = new SaveFileDialog()
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Title = "My Save File Dialog Title"
};

var showSaveFileDialogText = new Button { Text = "Show Save File Dialog (Set Content as text)" };
var showSaveFileDialogBytes = new Button { Text = "Show Save File Dialog (Set Content as bytes)" };

showSaveFileDialogText.Click += showSaveFileDialogText_Click;
showSaveFileDialogBytes.Click += showSaveFileDialogBytes_Click;

var panel = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
panel.AddChild(showSaveFileDialogText);
panel.AddChild(showSaveFileDialogBytes);
Chart.AddControl(panel);
}

private void showSaveFileDialogText_Click(ButtonClickEventArgs obj)
{
var result = _saveFileDialog.ShowDialog();
Print($"Result: {result}");
if (result != FileDialogResult.Cancel)
{
_saveFileDialog.WriteToFile("Test in text");
}
}

private void showSaveFileDialogBytes_Click(ButtonClickEventArgs obj)
{
var result = _saveFileDialog.ShowDialog();
Print($"Result: {result}");
if (result != FileDialogResult.Cancel)
{
_saveFileDialog.WriteToFile(Encoding.UTF8.GetBytes("Test in bytes"));
}
}

public override void Calculate(int index)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>