protobufUtility 1.0.4
dotnet add package protobufUtility --version 1.0.4
NuGet\Install-Package protobufUtility -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="protobufUtility" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add protobufUtility --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: protobufUtility, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install protobufUtility as a Cake Addin #addin nuget:?package=protobufUtility&version=1.0.4 // Install protobufUtility as a Cake Tool #tool nuget:?package=protobufUtility&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
using ProtoBuf;
using protobufUtility;
/** Inherit ProtoBufBaseData */
/** Require [ProtoContract] */
[ProtoContract]
class MyApplicationSettings : ProtoBufBaseData
{
/** Require [ProtoMember(x)] to save value. x is need to be unique (and >=1 ?)
* Type must be serializable!
* For example, Rectangle isn't serializable. */
[ProtoMember(1)]
string _startPosition;
public Rectangle StartPosition
{
get
{
var ar = _startPosition.Split(';');
return new Rectangle(int.Parse(ar[0]), int.Parse(ar[1]), int.Parse(ar[2]), int.Parse(ar[3]));
}
set
{
_startPosition = string.Join(";", value.Left.ToString(), value.Top.ToString(), value.Width.ToString(), value.Height.ToString());
}
}
/** Require [ProtoMember(x)] to save value. x is need to be unique (and >=1 ?) */
[ProtoMember(2)]
public DateTime LastTime;
/** Require [ProtoMember(x)] to save value. x is need to be unique (and >=1 ?) */
[ProtoMember(3)]
public string InitialFolder;
/** Require [ProtoMember(x)] to save value. x is need to be unique (and >=1 ?) */
[ProtoMember(4)]
public string DataFileFullPath;
/** Require default constructor */
public MyApplicationSettings()
{
StartPosition = default(Rectangle);
InitialFolder = Application.StartupPath;
DataFileFullPath = "mydata.dat";
}
}
/** Inherit ProtoBufBaseData */
/** Require [ProtoContract] */
[ProtoContract]
class MyApplicationData : ProtoBufBaseData
{
/** Require [ProtoMember(x)] to save value. x is need to be unique (and >=1 ?) */
[ProtoMember(1)]
public List<string> TargetFolders;
/** Require default constructor */
public MyApplicationData()
{
TargetFolders = new List<string>();
}
public void AddFolder(string folder)
{
TargetFolders.Add(folder);
}
}
public partial class protobufUtilityTester : Form
{
public protobufUtilityTester()
{
InitializeComponent();
/** Load settings */
var settings = ProtoBufBaseData.Load<MyApplicationSettings>("settings.dat");
settings.LastTime = DateTime.Now;
/** Data */
MyApplicationData myApplicationData = null;
ListBox listBoxTargetFolders = new ListBox() { Parent = this, Dock = DockStyle.Top, };
Button buttonAddFolder = new Button() { Parent = this, Dock = DockStyle.Top, Text = "Add folder", };
MenuStrip menu = new MenuStrip() { Parent = this, };
ToolStripMenuItem toolStripMenuItemFile = new ToolStripMenuItem() { Text = "File", };
ToolStripMenuItem toolStripMenuItemCreate = new ToolStripMenuItem() { Text = "Create new data file", };
ToolStripMenuItem toolStripMenuItemSave = new ToolStripMenuItem() { Text = "Save", };
toolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemCreate);
toolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemSave);
menu.Items.Add(toolStripMenuItemFile);
Action<string> CreateOrOpen = (fn) =>
{
/** Load data */
myApplicationData = ProtoBufBaseData.Load<MyApplicationData>(fn);
listBoxTargetFolders.Items.Clear();
listBoxTargetFolders.Items.AddRange(myApplicationData.TargetFolders.ToArray());
Text = string.Format("protobufUtilityTester, datafilename={0}", fn);
};
toolStripMenuItemCreate.Click += (sender, e) =>
{
SaveFileDialog sfd = new SaveFileDialog() { InitialDirectory = Application.StartupPath, };
if (sfd.ShowDialog() == DialogResult.OK)
{
CreateOrOpen(sfd.FileName);
settings.DataFileFullPath = sfd.FileName;
}
};
toolStripMenuItemSave.Click += (sender, e) =>
{
myApplicationData.Save();
};
buttonAddFolder.Click += (sender, e) =>
{
FolderBrowserDialog fbd = new FolderBrowserDialog() { SelectedPath = settings.InitialFolder, };
if (fbd.ShowDialog() == DialogResult.OK)
{
settings.InitialFolder = fbd.SelectedPath;
myApplicationData.TargetFolders.Add(fbd.SelectedPath);
listBoxTargetFolders.Items.Add(fbd.SelectedPath);
}
};
FormClosing += (sender, e) =>
{
/** Update settings */
settings.StartPosition = new Rectangle(Left, Top, Width, Height);
/** Update data. */
myApplicationData.TargetFolders = listBoxTargetFolders.Items.Cast<string>().ToList();
if (settings.SaveRequired)
{
while (true)
{
/** Save settings if changed. */
if (settings.Save()) break;
var ret = MessageBox.Show("settings.dat save failed. Retry?", "Error", MessageBoxButtons.YesNo);
if (ret == DialogResult.Cancel)
{
e.Cancel = true;
return;
}
else if (ret == DialogResult.No)
{
break;
}
}
}
if (myApplicationData.SaveRequired)
{
while (true)
{
/** Save data if changed. */
if (myApplicationData.Save()) break;
var ret = MessageBox.Show(string.Format("{0} save failed. Retry?", myApplicationData.FileName), "Error", MessageBoxButtons.YesNo);
if (ret == DialogResult.Cancel)
{
e.Cancel = true;
return;
}
else if (ret == DialogResult.No)
{
break;
}
}
}
};
SizeChanged += (sender, e) =>
{
listBoxTargetFolders.Height = ClientSize.Height - buttonAddFolder.Height;
};
if (settings.StartPosition == default(Rectangle))
{
StartPosition = FormStartPosition.CenterScreen;
}
else
{
StartPosition = FormStartPosition.Manual;
Location = new Point(settings.StartPosition.Left, settings.StartPosition.Top);
Width = settings.StartPosition.Width;
Height = settings.StartPosition.Height;
}
CreateOrOpen(settings.DataFileFullPath);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- protobuf-net (>= 2.4.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.4 | 273 | 3/27/2022 |