list.Skip(1).Take(1).First()
- это такой бред. Там же понятно, что перечисление из двух элементов. Зачем делать какое-то Skip(), Take(), если можно просто сделать Last()namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var firstObject = new FirstClass();
var secondObject = new SecondClass();
var thirdObject = new ThirdClass();
var list = new List<IParent>();
list.Add(firstObject);
list.Add(secondObject);
thirdObject.Collection = list;
}
}
/// <summary>
/// Родительский интерфейс
/// </summary>
public interface IParent
{
}
/// <summary>
/// Класс наследуемый от родительского интерфейса
/// </summary>
public class FirstClass : IParent
{
}
/// <summary>
/// Класс наследуемый от родительского интерфейса
/// </summary>
public class SecondClass : IParent
{
}
public class ThirdClass
{
public List<IParent> Collection { get; set; } = new List<IParent>();
}
}
<DataGrid ItemsSource="{Binding CollectionTechWallets}"/>
BigInteger result = 0;
var inputBlock = new BufferBlock<(string,string)>(); // Блок для входных данных
var options = new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = 200 // указываем сколько потоков будут обрабатывать наши данные
};
var callBalanceBlock = new TransformBlock<(string,string), BigInteger>(async x =>
{
BigInteger wallet = await function.CallAsync<BigInteger>(x.Item1);
BigInteger eth = await Current.Eth.GetBalance.SendRequestAsync(x.Item1);
TechWallets.TechEURGWallets.Add(new TechWallet
{
Address = x.Item1,
TokenValue = Web3.Convert.FromWei(wallet,2),
EthValue = Web3.Convert.FromWei(eth, UnitConversion.EthUnit.Ether),
PrivateKey = x.Item2
});
return wallet;
}, options); // Это главный испольнительный блок. Получает информация в виде (string,string) и отдает в формате BigInteger.
var calc = new ActionBlock<BigInteger>(x => result += x, options); // Получает данные после работы TransformBlock, чтобы подсчитать число
inputBlock.LinkTo(callBalanceBlock); // Прокидываем линк(соединение), что после BufferBlock, должен отрабатывать TransformBlock
inputBlock.Completion.ContinueWith(task => callBalanceBlock.Complete());
callBalanceBlock.LinkTo(calc); // Тоже самое, но для ActionBlock
callBalanceBlock.Completion.ContinueWith(task => calc.Complete());
foreach (var i in TechWallets.ListEURGTechWallets)
inputBlock.Post(i); // Заполняем наш BufferBlock входными значениями
inputBlock.Complete(); // Запускаем работу наших блоков
try
{
calc.Completion.Wait(); // Ждем завершения работы последнего блока
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
public partial class SetColdBalance : Window
{
public SetColdBalance()
{
InitializeComponent();
}
}
public class RelayCommand<T> : ICommand
{
#region Fields
readonly Action<T> _execute = null;
readonly Predicate<T> _canExecute = null;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of <see cref="DelegateCommand{T}"/>.
/// </summary>
/// <param name="execute">Delegate to execute when Execute is called on the command. This can be null to just hook up a CanExecute delegate.</param>
/// <remarks><seealso cref="CanExecute"/> will always return true.</remarks>
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
/// <summary>
/// Creates a new command.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion
#region ICommand Members
///<summary>
///Defines the method that determines whether the command can execute in its current state.
///</summary>
///<param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param>
///<returns>
///true if this command can be executed; otherwise, false.
///</returns>
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute((T)parameter);
}
///<summary>
///Occurs when changes occur that affect whether or not the command should execute.
///</summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
///<summary>
///Defines the method to be called when the command is invoked.
///</summary>
///<param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to <see langword="null" />.</param>
public void Execute(object parameter)
{
_execute((T)parameter);
}
#endregion
}
<Window x:Class="AdminTool.SetColdBalance"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:AdminTool"
mc:Ignorable="d"
Title="Задать баланс"
Height="150"
Width="250"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"">
<Window.DataContext>
<local:ColdWalletViewModel/>
</Window.DataContext>
<Grid>
<Button Grid.Row="2" Width="100" Height="30" Content="Save" Command="{Binding SaveColdWallets}"/>
</Grid>
</Window>
public class ColdWalletViewModel : BindableBase
{
ICommand _saveColdWallet;
public ICommand SaveColdWallets
{
get
{
return _saveColdWallet ?? (_saveColdWallet = new RelayCommand<object[]>((obj) =>
{
///Тут пишешь что должна выполнять твоя кнопка
}), /*Тут можно написать условие при котором можно будет выполнить данную команду*/);
}
}
}
/// <summary>
/// Implementation of <see cref="INotifyPropertyChanged" /> to simplify models.
/// </summary>
public abstract class BindableBase : INotifyPropertyChanged
{
/// <summary>
/// Multicast event for property change notifications.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
/// </summary>
/// <typeparam name="T">Type of the property.</typeparam>
/// <param name="storage">Reference to a property with both getter and setter.</param>
/// <param name="value">Desired value for the property.</param>
/// <param name="propertyName">
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers that
/// support CallerMemberName.
/// </param>
/// <returns>
/// True if the value was changed, false if the existing value matched the
/// desired value.
/// </returns>
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Equals(storage, value))
{
return false;
}
storage = value;
this.OnPropertyChanged(propertyName);
return true;
}
/// <summary>
/// Notifies listeners that a property value has changed.
/// </summary>
/// <param name="propertyName">
/// Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support <see cref="CallerMemberNameAttribute" />.
/// </param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public static string keyStr = "ТУТ ЛЮБАЯ ТВОЯ СТРОЧКА(Любой рандомный текст)";
public static string Encrypt(string PlainText)
{
RijndaelManaged aes = new RijndaelManaged();
aes.BlockSize = 128;
aes.KeySize = 256;
aes.Mode = CipherMode.ECB;
byte[] keyArr = Convert.FromBase64String(keyStr);
byte[] KeyArrBytes32Value = new byte[32];
Array.Copy(keyArr, KeyArrBytes32Value, 32);
aes.Key = KeyArrBytes32Value;
ICryptoTransform encrypto = aes.CreateEncryptor();
byte[] plainTextByte = ASCIIEncoding.UTF8.GetBytes(PlainText);
byte[] CipherText = encrypto.TransformFinalBlock(plainTextByte, 0, plainTextByte.Length);
return Convert.ToBase64String(CipherText);
}
public static string Decrypt(string CipherText)
{
RijndaelManaged aes = new RijndaelManaged();
aes.BlockSize = 128;
aes.KeySize = 256;
aes.Mode = CipherMode.ECB;
byte[] keyArr = Convert.FromBase64String(keyStr);
byte[] KeyArrBytes32Value = new byte[32];
Array.Copy(keyArr, KeyArrBytes32Value, 32);
aes.Key = KeyArrBytes32Value;
ICryptoTransform decrypto = aes.CreateDecryptor();
byte[] encryptedBytes = Convert.FromBase64CharArray(CipherText.ToCharArray(), 0, CipherText.Length);
byte[] decryptedData = decrypto.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length);
return ASCIIEncoding.UTF8.GetString(decryptedData);
}