/// <summary> /// Uploads selected images on cloud storage /// </summary> private async void OnUploadImages() { try { BusyIndicatorManager.Enable(); ControlHelper.HideAllChildViews(); Dictionary <string, byte[]> imagesData = new Dictionary <string, byte[]>(); string folderPath = string.IsNullOrEmpty(this.ExtraStoragePath) ? string.Empty : this.ExtraStoragePath + @"\"; foreach (FileToUpload item in this.ImagesToUpload) { imagesData.Add(string.Concat(folderPath, item.Name), File.ReadAllBytes(item.FullPath)); } await Task.Run(() => CoreApi.StorageUploadImages(imagesData)); if (this.ViewClosed != null) { this.ViewClosed(this.ExtraStoragePath); } this.view.Close(); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } finally { BusyIndicatorManager.Disable(); ControlHelper.RestoreHidderChildViews(); } }
public async Task <KeyValuePair <IEnumerable <ChinaStock>, IEnumerable <SecurityProviderInfo> > > GetChinaStocksAsync(Exchange?exchange = null, StockStatus stockStatus = StockStatus.Listing) { CoreApi client = new CoreApi { Token = token }; var response = client.stock_basic(null, stockStatus, exchange); if (response.Code == 0) { var stocks = response.ChinaStocks; ObservableCollection <SecurityProviderInfo> securityProviderInfos = new ObservableCollection <SecurityProviderInfo>(); foreach (var stock in stocks) { securityProviderInfos.Add(new SecurityProviderInfo() { Deleted = false, Id = Guid.Empty, Provider = DataProvider.TuShare, ProviderKey = stock.ProviderKey, Security = stock }); } return(new KeyValuePair <IEnumerable <ChinaStock>, IEnumerable <SecurityProviderInfo> >(stocks, securityProviderInfos)); } else { throw new Exception(response.Message.ToString()); } }
public WebApi(Connection connection, WebContext context) { this.context = context; this.sender = connection; this.Api = new CoreApi(this.sender); this.d = new BusinessLogic(); }
/// <summary> /// Calls template generation /// </summary> private async Task GenerateTemplate() { this.view.Hide(); BusyIndicatorManager.Enable(); string expectedFileNameExtension = ".txt"; byte[] templateDescriptionBytes = Encoding.UTF8.GetBytes(this.TemplateDescription); if (!Path.HasExtension(this.TemplateName) || (Path.HasExtension(this.TemplateName) && Path.GetExtension(this.TemplateName) != expectedFileNameExtension)) { this.TemplateName += expectedFileNameExtension; } try { this.GenerationContent = await Task.Run(() => CoreApi.GenerateTemplate( this.TemplateName, templateDescriptionBytes, this.ExtraStoragePath, string.Empty)); this.GenerationContent.Name = this.TemplateName; } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } finally { BusyIndicatorManager.Disable(); } }
public void SetUp() { ActualEvent = new List <TestEvent>(); ExpectedEvent = new List <TestEvent>(); Remotes = new List <IPEndPoint>(); Routers = new List <IAudioRouter>(); NetworkMoq = new Mock <ITcpСontroller>(); NetworkMoq .Setup(s => s.Send(It.IsAny <IPEndPoint>(), It.IsAny <ArraySegment <byte> >())) .Callback <IPEndPoint, ArraySegment <byte> >((remote, data) => { ActualEvent.Add(new TestEvent(remote, data.ToArray())); }); NetworkMoq .Setup(s => s.Disconnect(It.IsAny <IPEndPoint>())) .Callback <IPEndPoint>((remote) => { ActualEvent.Add(new TestEvent(remote)); NetworkMoq.Raise(s => s.ConnectionClosing += null, remote); }); MessageFactory = new MessageFactory(true); Container = new KeyContainer(); Core = new CoreApi(NetworkMoq.Object, MessageFactory); Calls = new CallController(Container, () => { Routers.Add(new BridgeRouter(new AudioProvider(NetworkMoq.Object))); return(Routers[^ 1]); });
/// <summary> /// Saves keys /// </summary> private void OnSaveCommand() { // check app sid length if (this.AppSidText.Length != 36) { DialogManager.ShowErrorDialog("Incorrect APP SID length! APP SID should be 36 symbols length."); return; } // check app key length if (this.AppKeyText.Length != 32) { DialogManager.ShowErrorDialog("Incorrect APP KEY length! APP KEY should be 32 symbols length."); return; } // update keys to provide new values CoreApi.UpdateKeys(this.AppKeyText, this.AppSidText); // encrypt keys and save in settings byte[] encryptedAppKey = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppKeyText)); byte[] encryptedAppSid = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppSidText)); UserSettingsUtility.SaveCredentials(encryptedAppKey, encryptedAppSid); this.view.Close(); }
public SentralApi(string baseUrl, string apiKey, string tenantCode) { Enrolments = new EnrolmentApi(baseUrl, apiKey, tenantCode); Core = new CoreApi(baseUrl, apiKey, tenantCode); Timetables = new TimetableApi(baseUrl, apiKey, tenantCode); WebCal = new WebCalApi(baseUrl, apiKey, tenantCode); }
/// <summary> /// Runs template finalization /// </summary> private void OnFinilizeTemplate() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { string templateData = TemplateSerializer.TemplateToJson(this, false); string additionalPars = string.Empty; try { string templateName = Path.GetFileNameWithoutExtension(this.TemplateImageName) + "_template.omr"; FinalizationData finalizationResult = CoreApi.FinalizeTemplate(templateName, Encoding.UTF8.GetBytes(templateData), this.TemplateId, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ProcessFinalizationResponse(finalizationResult); }); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } }; worker.RunWorkerCompleted += (sender, args) => { BusyIndicatorManager.Disable(); }; BusyIndicatorManager.Enable(); worker.RunWorkerAsync(); }
public static void BasicSetup(TestContext context) { var myStorageEngine = new CassandraIndexEngine(); //CassandraIndexEngine();//CassandraEngine(); myStorageEngine.Init("host =127.0.0.1 & database = jdbc_unittest"); //127.0.0.1 myCoreApi = CoreApi.GetInstance(); myCoreApi.CoreService.Init("mongodb://127.0.0.1:27017", "JDBC-test", "Experiment", (IStorageEngine)myStorageEngine); }
/// <summary> /// Runs template correction /// </summary> private void OnCorrectTemplate() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { string templateData = TemplateSerializer.TemplateToJson(this, false); byte[] imageData = TemplateSerializer.CompressImage(this.TemplateImage, this.ImageSizeInBytes); //string imageData = TemplateConverter.CheckAndCompressImage(this.TemplateImage, this.ImageFileFormat, this.ImageSizeInBytes); string additionalPars = string.Empty; try { TemplateViewModel correctedTemplate = CoreApi.CorrectTemplate(this.TemplateImageName, imageData, templateData, this.WasUploaded, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ClearSelection(); this.PageQuestions.Clear(); this.AddQuestions(correctedTemplate.PageQuestions); this.TemplateId = correctedTemplate.TemplateId; this.FinalizationComplete = false; double koeff = this.TemplateImage.PixelWidth / correctedTemplate.PageWidth; ZoomKoefficient *= koeff; this.OnPropertyChanged(nameof(this.PageScale)); this.PageWidth = correctedTemplate.PageWidth; this.PageHeight = correctedTemplate.PageHeight; this.WasUploaded = true; this.Warnings.Add("Template correction complete!"); }); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } }; worker.RunWorkerCompleted += (sender, args) => { BusyIndicatorManager.Disable(); }; BusyIndicatorManager.Enable(); worker.RunWorkerAsync(); }
/// <summary> /// Performs recognition for provided image /// </summary> /// <param name="itemToProcess">Image to process</param> private void RecognizeImageRoutine(ImagePreviewViewModel itemToProcess) { // check if image was already processed if (itemToProcess.IsProcessed) { // ask user confirmation if (!DialogManager.ShowConfirmDialog( string.Format("Image {0} was already recognized. Are you sure you want to run recognition again?", itemToProcess.Title))) { // if no confirmation, clean up and return itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; return; } } itemToProcess.CanCancel = false; itemToProcess.StatusText = "Preparing for dispatch..."; var image = new BitmapImage(new Uri("file://" + itemToProcess.PathToImage)); byte[] imageData = TemplateSerializer.CompressImage(image, itemToProcess.ImageSizeInBytes); //string imageData = TemplateConverter.CheckAndCompressImage(image, itemToProcess.ImageFileFormat, itemToProcess.ImageSizeInBytes); string additionalPars = string.Empty; itemToProcess.StatusText = "Core processing..."; try { string result = CoreApi.RecognizeImage(itemToProcess.Title, imageData, this.templateId, itemToProcess.WasUploaded, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ProcessResult(result, itemToProcess); // update item states itemToProcess.WasUploaded = true; itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; itemToProcess.CanCancel = true; }); } catch (Exception e) { // clean up in case of exception itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; itemToProcess.CanCancel = true; DialogManager.ShowErrorDialog(e.Message); } }
public static void BasicSetup(TestContext context) { var myStorageEngine = new CassandraIndexEngine(); //CassandraIndexEngine();//CassandraEngine(); myStorageEngine.Init("host =localhost & database = jdbc_unittest"); //127.0.0.1 myCoreApi = CoreApi.GetInstance(); //JDBC-test jdbc_liuweb myCoreApi.CoreService.Init("mongodb://127.0.0.1:27017", "jdbc_liuweb", "Experiment", (IStorageEngine)myStorageEngine); myCoreApi.CoreService.RegisterClassMap <FixedIntervalWaveSignal>(); }
public async void ClickImportExecute() { //获取类型 MusicSource source; if (ChooseKugou) { source = MusicSource.Kugou; } else if (ChooseNetease) { source = MusicSource.Netease; } else { source = MusicSource.Tencent; } ISongList songList = null; bool isError = false; await Task.Run(() => { Thread.Sleep(300); ImportButtonVisibility = Visibility.Hidden; LoadingButtonVisibility = Visibility.Visible; try { songList = CoreApi.GetPlatformSongList(source, ImportUrl); } catch { isError = true; } ImportButtonVisibility = Visibility.Visible; LoadingButtonVisibility = Visibility.Hidden; }); if (isError) { Toast.Show("导入失败!", Toast.InfoType.Error); } else { new PlatformInfoManager().Insert(new PlatformInfoModel(songList)); foreach (var item in songList.Musics) { new PlatformListManager().Insert(new PlatformListModel { MusicId = item.Id, PlatformId = songList.Id }); new MusicInfoManager().Insert(new MusicInfoModel(item)); } ViewModelManager.BasePageViewModel.RefreshPlatformList(); Toast.Show("导入成功!", Toast.InfoType.Success); } }
public async Task <IEnumerable <TradeCalendar> > GetTradeCalendars(Exchange exchange = Exchange.SSE, DateTime?startDate = null, DateTime?endDate = null) { CoreApi client = new CoreApi { Token = token }; var response = client.trade_cal(exchange, startDate, endDate); return(response.TradeCalendars); }
public static void BasicSetup(TestContext context) { //todo wankuanhong inject service here myCoreService = CoreService.GetInstance(); myCoreService.Init("JDBC-test"); storageEngine.Init("host =127.0.0.1 & database = jdbc_unittest"); myCoreService.MyStorageEngine = storageEngine; myCoreApi = CoreApi.GetInstance(); myCoreApi.MyCoreService.Init("JDBC-test", (IStorageEngine)storageEngine); }
public void initial() { var myStorageEngine = new CassandraIndexEngine(); //CassandraIndexEngine();//CassandraEngine(); myStorageEngine.Init("host =192.168.137.153 & database = jdbc_unittest"); //127.0.0.1 myCoreApi = CoreApi.GetInstance(); myCoreApi.CoreService.Init("mongodb://127.0.0.1:27017", "JDBC-test", "Experiment", (IStorageEngine)myStorageEngine); myCoreApi.CoreService.RegisterClassMap <FixedIntervalWaveSignal>(); var fixedWaveDataTypePlugin = new FixedWaveDataTypePlugin(myCoreApi.CoreService); myCoreApi.AddDataTypePlugin(fixedWaveDataTypePlugin); }
public static void BasicSetup(TestContext context) { //实例化StorageEngine,初始化 var myStorageEngine = new CassandraIndexEngine();//CassandraIndexEngine();//CassandraEngine(); myStorageEngine.Init("host =127.0.0.1 & database = jdbc_unittest"); //实例化CoreService和CoreApi myCoreApi = CoreApi.GetInstance(); myCoreApi.CoreService.Init("mongodb://127.0.0.1:27017", "JDBC-test", "Experiment", (IStorageEngine)myStorageEngine); //实例化DataTypePlugin,注入StorageEngine、CoreService,将其添加到CoreApi var fixedWaveDataTypePlugin = new FixedWaveDataTypePlugin(myCoreApi.CoreService); myCoreApi.AddDataTypePlugin(fixedWaveDataTypePlugin); }
static void Main(string[] args) { LogManager.Configuration ??= new NLog.Config.LoggingConfiguration(); var tcpProvider = new TcpProvider(NetworkSocket.Create); var udpProvider = new UdpProvider(NetworkSocket.Create); var watcher = new ActivityWatcher(tcpProvider) { Interval = 15000, }; // TODO Impl udp transport layer. var provider = new AudioProvider(udpProvider); var calls = new CallController(new KeyContainer(), () => new BridgeRouter(provider)); var authorization = new AuthorizationController(); var core = new CoreApi(tcpProvider, new MessageFactory(true)); new AuthApi(core, authorization); new TextApi(core, authorization); new CallApi(core, authorization, calls); // TODO Impl ping message. //watcher.Start(); // TODO Add network interfaces. _ = tcpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010)); _ = udpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010)); Console.WriteLine("Press key:\r\n S - stop\r\n Q - exit"); while (true) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.Q: return; case ConsoleKey.S: tcpProvider.Stop(); udpProvider.Stop(); break; default: break; } } }
public async void SearchTask() { //UI SearchProgressVisibility = Visibility.Visible; DataVisibility = Visibility.Hidden; NoResultVisibility = Visibility.Hidden; //清空当前绑定数据 MusicInfos.Clear(); IMusic[] infos; try { //网易云 if (SearchOption.Netease) { infos = await Task.Run(() => CoreApi.SearchMusic(MusicSource.Netease, SearchContent)); InsertMusicInfo(infos, 1); } //酷狗 if (SearchOption.Kugou) { infos = await Task.Run(() => CoreApi.SearchMusic(MusicSource.Kugou, SearchContent)); InsertMusicInfo(infos, 2); } //QQ音乐 if (SearchOption.Tencent) { infos = await Task.Run(() => CoreApi.SearchMusic(MusicSource.Tencent, SearchContent)); InsertMusicInfo(infos, 3); } } catch (Exception e) { MessageBox.Show($"搜索失败!\n{e.Message}"); } PlayerList.SetPreList(MusicInfos, "搜索"); //UI SearchProgressVisibility = Visibility.Hidden; DataVisibility = MusicInfos.Count == 0 ? Visibility.Hidden : Visibility.Visible; NoResultVisibility = MusicInfos.Count == 0 ? Visibility.Visible : Visibility.Hidden; }
/// <summary> /// config the business logic /// </summary> public static void ConfigBusiness() { //从config文件加载数据库连接字符串 mongoHost = ConfigurationManager.AppSettings["MongoHost"]; mongoDatabase = ConfigurationManager.AppSettings["MongoDatabase"]; mongoCollection = ConfigurationManager.AppSettings["MongoCollection"]; cassandraInit = ConfigurationManager.ConnectionStrings["CassandraDB"].ConnectionString; //初始化StorageEngine var cassandraStorageEngine = new CassandraIndexEngine();//CassandraEngine cassandraStorageEngine.Init(cassandraInit); //初始化CoreApi MyCoreApi = CoreApi.GetInstance(); MyCoreApi.CoreService.Init(mongoHost, mongoDatabase, mongoCollection, (IStorageEngine)cassandraStorageEngine); //添加QueryPlugIn var pathQueryPlugIn = new PathQueryPlugIn(MyCoreApi.CoreService); MyCoreApi.AddQueryPlugin(pathQueryPlugIn); var idQueryPlugin = new IDQueryPlugIn(MyCoreApi.CoreService); MyCoreApi.AddQueryPlugin(idQueryPlugin); //添加DataTypePlugin var fixedWaveDataTypePlugin = new FixedWaveDataTypePlugin(MyCoreApi.CoreService); MyCoreApi.AddDataTypePlugin(fixedWaveDataTypePlugin); //添加ExpressionPlugin var expressionPlugin = new ExpressionPlugin(MyCoreApi.CoreService); MyCoreApi.AddDataTypePlugin(expressionPlugin); //将继承类在MongoDB中进行注册 MyCoreApi.CoreService.RegisterClassMap <FixedIntervalWaveSignal>(); //MyCoreApi.MyCoreService.RegisterClassMap<IntFixedIntervalWaveSignal>(); //MyCoreApi.MyCoreService.RegisterClassMap<DoubleFixedIntervalWaveSignal>(); //创建DTO映射 ConfigDtoMapping(); SetExpressionRoot(); }
/// <summary> /// Remove from storage all files that were uploaded during session /// </summary> public static void CleanUpStorage() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { CoreApi.StorageCleanUp(uploadedFilesList); }; worker.RunWorkerCompleted += (sender, args) => { // clean up list uploadedFilesList.Clear(); BusyIndicatorManager.Disable(); // close app System.Windows.Application.Current.Shutdown(); }; BusyIndicatorManager.Enable(); worker.RunWorkerAsync(); }
public async Task Fetchdata() { try { //Authentication //CoreApi.Authentication(8080, "admin", "adminadmin").Wait(); var credentials = CoreApi.GetTorrentCredential(); ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; string port = (string)localSettings.Values["localport"]; //TODO : Factory Pattern. Returns "a method was called at an unexpected time" at any way. bool authentication = await CoreApi.Authentication(port, credentials.UserName, credentials.Password).ConfigureAwait(false); if (authentication) { //fetch data list = await Comm.GetTorrentList(); } } catch (Exception e) { IsErrorVisualVisible = Visibility.Visible; ErrorValue = e.ToString(); } }
public BotApi(Connection connection, BotContext context) { this.context = context; this.sender = connection; this.Api = new CoreApi(this.sender); }
/// <summary> /// Performs recognition for provided image /// </summary> /// <param name="itemToProcess">Image to process</param> private void RecognizeImageRoutine(ImagePreviewViewModel itemToProcess) { // check if image was already processed if (itemToProcess.IsProcessed) { // ask user confirmation if (!DialogManager.ShowConfirmDialog( string.Format("Image \"{0}\" was already recognized. Are you sure you want to run recognition again?", itemToProcess.Title))) { // if no confirmation, clean up and return itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; return; } } itemToProcess.CanCancel = false; itemToProcess.StatusText = "Preparing for dispatch..."; if (!File.Exists(itemToProcess.PathToImage)) { DialogManager.ShowErrorDialog("Could not find image " + "\"" + itemToProcess.PathToImage + "\"."); return; } byte[] imageData = this.PreprocessImage(itemToProcess.PathToImage, this.SelectedPreprocessingConfiguration); string additionalPars = string.Empty; itemToProcess.StatusText = "Recognizing..."; try { ImageRecognitionResult result = CoreApi.RecognizeImage(itemToProcess.Title, imageData, this.templateId, itemToProcess.WasUploaded, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ProcessResult(result, itemToProcess); // update item states itemToProcess.WasUploaded = true; itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; itemToProcess.CanCancel = true; itemToProcess.RecognitionError = false; }); } catch (Exception e) { // clean up in case of exception itemToProcess.IsProcessing = false; itemToProcess.StatusText = string.Empty; itemToProcess.CanCancel = true; itemToProcess.RecognitionError = true; Application.Current.Dispatcher.Invoke(() => { DialogManager.ShowErrorDialog(e.Message); }); } }
public DashboardController(CoreApi coreApi) { this.coreApi = coreApi; }
/// <summary> /// Returns help for a given Type. /// </summary> /// <param name="type"></param> /// <returns></returns> public Help Help(CoreApi api, Type type) { return(api.Help(typeof(Type))); }
public void Init() { instance = new CoreApi(); }