using Prism.Commands; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading; using System.Windows; using System.Windows.Input; using WolfOfWallStreet.Models; using WolfOfWallStreet.Models.MofidOnline; using WolfOfWallStreet.Models.OnlinePlus; using WolfOfWallStreet.Services; using WolfOfWallStreet.Services.Contracts; using MessageBox = HandyControl.Controls.MessageBox; namespace WolfOfWallStreet.ViewModels { public class MofidOnlineControllerViewModel : ViewModelBase { private readonly SettingsServices _settingsServices; private readonly IMofidOnlineService _mofidOnlineService; public MofidOnlineOrder MoOrder { get; set; } = new MofidOnlineOrder(); public bool Ordered = true; public ICommand SendOrderCommand { get; set; } public ICommand SelectSymbolCommand { get; set; } public ICommand StopOrderCommand { get; set; } public ICommand ClearOrdersCommand { get; set; } public int Stock { get; set; } private MofidOnlineSymbol _mofidOnlineSymbol; public MofidOnlineSymbol MofidOnlineSymbol { get { return _mofidOnlineSymbol; } set { SetProperty(ref _mofidOnlineSymbol, value); } } public ObservableCollection Symbols { get; set; } = new ObservableCollection(); public ObservableCollection OrderResults { get; set; } = new ObservableCollection(); public MofidOnlineControllerViewModel(SettingsServices settingsServices , IMofidOnlineService mofidOnlineService) { _settingsServices = settingsServices; _mofidOnlineService = mofidOnlineService; _settingsServices.GetSymbols().ForEach(s=>Symbols.Add(s)); MoOrder.Cookies = "_ga=GA1.2.425920926.1593494313; _gid=GA1.2.467195288.1596362017; ASP.NET_SessionId=umwh11qs2uqamsejqzylsow5; crisp-client%2Fsession%2Fe95056ad-2681-452d-976d-0c2a304165c9=session_1cd28bbf-3aa4-4c96-b069-313739c186a0; Token=5d18d4ca-6e0a-4821-8e43-03347dfd2aa2; .ASPXAUTH=D35126B56A8F94324B69FC0A9389F5B4CC6DDF28F8CDAFC4903D8962BFC57CA15A98712B461428FEBD51D7729EA10C77A3B9406EA2EAE241DCDE583BF5C09A3AD8F1FF4AC8963E3BA764B1FED54C8D1FB8B70803F5D9B1507B2313D521AF6A72E657F74A3E707E563CAF60C20BB47017B5A5BD7A012F96C2B4BE5ADC8D51705A7888E255F90EE7BDDCACC953CD8C7DA09A1C2CDD; LS6_https_1603_https%3A%2F%2Fpush2v7.etadbir.com%2F=|485_TadbirConnection|; LS6_https_1603_TadbirConnection=|485|; LS6_https_1603_485_TadbirConnection=1596619228044|C|LS6__mofidonline_com_485_TadbirConnection|mofidonline.com"; } public override void InitialCommand() { base.InitialCommand(); SelectSymbolCommand = new DelegateCommand(async (symbol) => { MofidOnlineSymbol = await _mofidOnlineService.GetSymbolOrderBase(symbol, Stock); }); SendOrderCommand = new DelegateCommand(async () => { Ordered = true; for (int i = 0; i < 7; i++) { Thread thr = new Thread(SendOrder); thr.Start(); } }); StopOrderCommand = new DelegateCommand(() => Ordered=false); ClearOrdersCommand = new DelegateCommand(()=>OrderResults.Clear()); } async void SendOrder() { while (Ordered) { try { if (string.IsNullOrEmpty(MoOrder.Cookies)) throw new Exception("کوکی های درخواست را وارد کنید"); MoOrder.OrderPrice = MofidOnlineSymbol.ht.ToString(); MoOrder.OrderTotalQuantity = MofidOnlineSymbol.Quantity.ToString(); MoOrder.SymbolNsc = MofidOnlineSymbol.nc; MoOrder.SymbolId = ""; MofidOnlineOrderResult res; res = await _mofidOnlineService.SendOrder(MoOrder); if (res != null) { if(res.Value.Contains("محدودیت ارسال سفارش در ثانیه") == false) Application.Current.Dispatcher.Invoke(() => OrderResults.Add(res)); } } catch (Exception e) { MessageBox.Show(e.Message); } } } } }