public void TestCopyMoveFile() { var testFile = TestFiles.Docx; // Create temp folder var cRequest = new CreateFolderRequest("temp"); FolderApi.CreateFolder(cRequest); // Copy file var destPath = $"temp/{testFile.FileName}"; var request = new CopyFileRequest(testFile.FullName, destPath); FileApi.CopyFile(request); // Check copied file var eRequest = new ObjectExistsRequest(destPath); var eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); // Move file var newDestPath = $"temp/{testFile.FileName.Replace(".", "_1.")}"; var mRequest = new MoveFileRequest(destPath, newDestPath); FileApi.MoveFile(mRequest); // Check moved file eRequest = new ObjectExistsRequest(newDestPath); eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); // Delete temp folder var delRequest = new DeleteFolderRequest("temp", null, true); FolderApi.DeleteFolder(delRequest); }
public static async Task FolderAsync(UserPassword credentials) { // Get Folder { Helpers.WriteConsoleTitle("Get Folder"); var folder = await FolderApi.GetFolderAsync(credentials, new Guid("686e51c1-2df8-4596-88aa-113f9022474a")); Console.WriteLine($"ElectricityCounterValue: {folder.ElectricityCounterValue}, ElectricityPower: {folder.ElectricityPower}"); } // Get MeterFolderInformation { Helpers.WriteConsoleTitle("Get MeterFolderInformation"); var info = await FolderApi.GetMeterFolderInformationAsync(credentials, new Guid("d9cc91af-58a1-48ed-9342-4aaf974074f2")); Console.WriteLine($"Name: {info.Name}, IsFolder: {info.IsFolder}"); } // Set MeterFolderInformation { Helpers.WriteConsoleTitle("Set MeterFolderInformation"); await FolderApi.SetMeterFolderInformationAsync(credentials, new MeterFolderInformationToSet { Id = new Guid("d9cc91af-58a1-48ed-9342-4aaf974074f2"), Name = "Test" }); } }
public void BeforeAllTests() { var config = new Configuration(_appSid, _appKey) { ApiBaseUrl = _apiBaseUrl }; SignatureApi = new SignApi(config); InfoApi = new InfoApi(config); FileApi = new FileApi(config); FolderApi = new FolderApi(config); StorageApi = new StorageApi(config); //Prepare folder for signed files DownloadFolder = Path.Combine(GetTestDataPath(), "Downloaded"); if (Directory.Exists(DownloadFolder)) { ClearFolder(DownloadFolder); } else { Directory.CreateDirectory(DownloadFolder); } UploadTestFiles(); }
public async Task <IActionResult> OnGetAsync() { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext); return(await FolderApi.GetFolderAsync(tokenData.AccessToken, Id, new ResultHandler <SmartMeApiClient.Containers.Folder> { OnSuccess = (folder) => { Folder = folder; return Page(); }, OnError = (errorType, errorMessage) => { if (errorType == ErrorType.Unauthorized) { errorMessage = $"Folder with Id '{Id}' does not exist"; } return new RedirectResult("/Error?message=" + errorMessage); } })); }
public void FolderGetListFilesTest() { GetListFilesRequest request = new GetListFilesRequest(); request.path = Path.Combine(dataFolder, "folder2"); request.storage = storageName; var response = FolderApi.GetListFiles(request); Assert.AreEqual(200, response.Code); }
public void TestGetFilesList() { // Arrange var request = new GetFilesListRequest("words"); // Act & Assert var response = FolderApi.GetFilesList(request); Assert.Greater(response.Value.Count, 0); }
public void FolderDeleteFolderTest() { DeleteFolderRequest request = new DeleteFolderRequest(); request.path = Path.Combine(dataFolder, "folder1"); request.recursive = true; request.storage = storageName; var response = FolderApi.DeleteFolder(request); Assert.AreEqual(200, response.Code); }
public void FolderPutCreateFolderTest() { PutCreateFolderRequest request = new PutCreateFolderRequest(); request.path = Path.Combine(dataFolder, "folder1"); request.storage = storageName; request.destStorage = destStorageName; var response = FolderApi.PutCreateFolder(request); Assert.AreEqual(200, response.Code); }
public void FolderPostMoveFolderTest() { PostMoveFolderRequest request = new PostMoveFolderRequest(); request.src = Path.Combine(dataFolder, "folder1"); request.storage = storageName; request.dest = Path.Combine(dataFolder, "folder2"); request.destStorage = destStorageName; var response = FolderApi.PostMoveFolder(request); Assert.AreEqual(200, response.Code.Value); }
public void BeforeAllTests() { var config = new Configuration(_appSid, _appKey) { ApiBaseUrl = _apiBaseUrl }; WatermarkApi = new WatermarkApi(config); InfoApi = new InfoApi(config); FileApi = new FileApi(config); FolderApi = new FolderApi(config); StorageApi = new StorageApi(config); UploadTestFiles(); }
public static void Run() { var apiInstance = new FolderApi(Constants.GetConfig()); try { var request = new CopyFolderRequest("Annotationdocs", "Annotationdocs1", Constants.MyStorage, Constants.MyStorage); apiInstance.CopyFolder(request); Console.WriteLine("Expected response type is Void: 'Annotationdocs' folder copied as 'Annotationdocs1'."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public void BeforeAllTests() { var config = new Configuration(_appSid, _appKey) { ApiBaseUrl = _apiBaseUrl }; InfoApi = new InfoApi(config); AnnotateApi = new AnnotateApi(config); PreviewApi = new PreviewApi(config); FileApi = new FileApi(config); FolderApi = new FolderApi(config); StorageApi = new StorageApi(config); UploadTestFiles(); }
public static void Run() { var apiInstance = new FolderApi(Constants.GetConfig()); try { var request = new GetFilesListRequest("Annotationdocs", Constants.MyStorage); var response = apiInstance.GetFilesList(request); Console.WriteLine("Expected response type is FilesList: " + response.Value.Count); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var apiInstance = new FolderApi(Constants.GetConfig()); try { var request = new DeleteFolderRequest("Annotationdocs1", Constants.MyStorage, true); apiInstance.DeleteFolder(request); Console.WriteLine("Expected response type is Void: 'Annotationdocs1' folder deleted recusrsively."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new CreateFolderRequest("", Common.MyStorage); apiInstance.CreateFolder(request); Console.WriteLine("Expected response type is Void: 'WordProcessing' folder created."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new CopyFolderRequest("Comparisondocs", "Comparisondocs1", Common.MyStorage, Common.MyStorage); apiInstance.CopyFolder(request); Console.WriteLine("Expected response type is Void: 'Comparisondocs' folder copied as 'Comparisondocs1'."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new GetFilesListRequest("Comparisondocs", Common.MyStorage); var response = apiInstance.GetFilesList(request); Console.WriteLine("Expected response type is FilesList: " + response.Value.Count.ToString()); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new DeleteFolderRequest("conversions/conversions1", Common.MyStorage, true); apiInstance.DeleteFolder(request); Console.WriteLine("Expected response type is Void: 'conversions/conversions1' folder deleted recusrsively."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new MoveFolderRequest("viewerdocs1", "viewerdocs\viewerdocs1", Common.MyStorage, Common.MyStorage); apiInstance.MoveFolder(request); Console.WriteLine("Expected response type is Void: 'viewerdocs1' folder moved to 'viewerdocs/viewerdocs1'."); } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public static void UploadSampleTestFiles() { var storageConfig = new Configuration(MyAppSid, MyAppKey); StorageApi storageApi = new StorageApi(storageConfig); FolderApi folderApi = new FolderApi(storageConfig); FileApi fileApi = new FileApi(storageConfig); var path = "..\\..\\..\\Data"; Console.WriteLine("File Upload Processing..."); var dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories); foreach (var dir in dirs) { var relativeDirPath = dir.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeDirPath, MyStorage)); if (!response.Exists.Value) { folderApi.CreateFolder(new Sdk.Model.Requests.CreateFolderRequest(relativeDirPath, MyStorage)); } } var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (var file in files) { var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeFilePath, MyStorage)); if (!response.Exists.Value) { var fileName = Path.GetFileName(file); var relativeDirPath = relativeFilePath.Replace(fileName, string.Empty).Trim(Path.DirectorySeparatorChar); var fileStream = File.Open(file, FileMode.Open); Console.WriteLine("Uploading: " + relativeFilePath); fileApi.UploadFile(new Sdk.Model.Requests.UploadFileRequest(relativeFilePath, fileStream, MyStorage)); fileStream.Close(); } } Console.WriteLine("File Upload Process Completed."); }
public static void UploadSampleTestFiles() { var configuration = GetConfig(); var storageApi = new StorageApi(configuration); var folderApi = new FolderApi(configuration); var fileApi = new FileApi(configuration); var path = "..\\..\\..\\..\\Resources"; Console.WriteLine("File Upload Processing..."); var dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories); foreach (var dir in dirs) { var relativeDirPath = dir.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeDirPath, MyStorage)); if (response.Exists != null && !response.Exists.Value) { folderApi.CreateFolder(new Sdk.Model.Requests.CreateFolderRequest(relativeDirPath, MyStorage)); } } var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (var file in files) { var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.ObjectExists(new Sdk.Model.Requests.ObjectExistsRequest(relativeFilePath, MyStorage)); if (response.Exists != null && !response.Exists.Value) { var fileStream = File.Open(file, FileMode.Open); Console.WriteLine(file); var request = new Sdk.Model.Requests.UploadFileRequest(relativeFilePath, fileStream); fileApi.UploadFile(request); fileStream.Close(); } } Console.WriteLine("File Upload Process Completed."); }
public void Start() { var apiClient = new ApiClient(WebApi); var signer = new AuthSigner(BotKey); _userApi = new UserApi(apiClient, signer); _wordApi = new WordApi(apiClient); _serviceApi = new ServiceApi(apiClient); _folderApi = new FolderApi(apiClient); _userApi.LoginUser(new ApiUser { Id = AdminId }); _restWordRepository = new RestWordRepository(_wordApi, _userApi, _serviceApi, _folderApi); _testWords = GetTestWords(); _testWordFileBytes = GetTestWordFileBytes(); FillDb(); }
public static void Run(string path) { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new FolderApi(configuration); try { var request = new GetFilesListRequest(path, Common.MyStorage); var response = apiInstance.GetFilesList(request); foreach (StorageFile storageFile in response.Value) { Console.WriteLine("Expected response type is FilesList: " + storageFile.Path); } } catch (Exception e) { Console.WriteLine("Exception while calling FolderApi: " + e.Message); } }
public async Task <IActionResult> OnGetAsync() { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var accessToken = await HttpContext.GetTokenAsync("access_token"); return(await FolderApi.GetMeterFolderInformationAsync(accessToken, Id, new ResultHandler <MeterFolderInformation> { OnSuccess = (info) => { Info = info; return Page(); }, OnError = DefaultErrorHandler.Handle })); }
public async Task <IActionResult> OnGetAsync() { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext); return(await FolderApi.GetMeterFolderInformationAsync(tokenData.AccessToken, Id, new ResultHandler <MeterFolderInformation> { OnSuccess = (info) => { Info = info; return Page(); }, OnError = DefaultErrorHandler.Handle })); }
public OmrDemo() { DirectoryInfo current = new DirectoryInfo(Directory.GetCurrentDirectory()); string configFileRelativePath = Path.Combine(this.demoDataSubmoduleName, this.configFileName); // Locate submodule folder containing demo data and config while (current != null && !File.Exists(Path.Combine(current.FullName, configFileRelativePath))) { current = current.Parent; } // Check if config file exists if (current == null) { throw new Exception($"Unable to find {this.configFileName}"); } string configFilePath = Path.Combine(current.FullName, configFileRelativePath); // parse config this.Config = JObject.Parse(File.ReadAllText(configFilePath)); this.DataFolder = Path.Combine(Directory.GetParent(configFilePath).FullName, this.Config["data_folder"].ToString()); // create storage api and provide parameters string baseHost = new Uri(this.Basepath).GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped).ToString(); Configuration storageConfiguration = new Configuration(); storageConfiguration.AppKey = this.AppKey; storageConfiguration.AppSid = this.AppSid; storageConfiguration.ApiBaseUrl = baseHost; this.StorageApi = new StorageApi(storageConfiguration); this.FolderApi = new FolderApi(storageConfiguration); this.FileApi = new FileApi(storageConfiguration); this.OmrApi = new OmrApi(storageConfiguration); }
public void TestCopyMoveFolder() { // Create temp folder var cRequest = new CreateFolderRequest("temp"); FolderApi.CreateFolder(cRequest); // Copy folder var copyRequest = new CopyFolderRequest("temp", "temp1"); FolderApi.CopyFolder(copyRequest); // Check copied folder var eRequest = new ObjectExistsRequest("temp1"); var eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); Assert.IsTrue(eResponse.IsFolder); // Copy folder var moveRequest = new MoveFolderRequest("temp1", "temp2"); FolderApi.MoveFolder(moveRequest); // Check moved folder eRequest = new ObjectExistsRequest("temp1"); eResponse = StorageApi.ObjectExists(eRequest); Assert.IsFalse(eResponse.Exists); eRequest = new ObjectExistsRequest("temp2"); eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); // Delete temp and temp2 folders var delRequest = new DeleteFolderRequest("temp", null, true); FolderApi.DeleteFolder(delRequest); delRequest = new DeleteFolderRequest("temp2", null, true); FolderApi.DeleteFolder(delRequest); }
public void StorageCopyMoveFile() { var testFile = TestFiles.PdfStorage.FirstOrDefault(x => x.Name.Equals("01_pages.pdf")); // Create temp folder var cRequest = new CreateFolderRequest("temp"); FolderApi.CreateFolder(cRequest); // Copy file var destPath = $"temp/{testFile.Name}"; var request = new CopyFileRequest(testFile.Path, destPath); FileApi.CopyFile(request); // Check copied file var eRequest = new ObjectExistsRequest(destPath); var eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); // Move file var newDestPath = $"temp/{testFile.Path.Replace(".", "_1.")}"; var mRequest = new MoveFileRequest(destPath, newDestPath); FileApi.MoveFile(mRequest); // Check moved file eRequest = new ObjectExistsRequest(newDestPath); eResponse = StorageApi.ObjectExists(eRequest); Assert.IsTrue(eResponse.Exists); // Delete temp folder var delRequest = new DeleteFolderRequest("temp", null, true); FolderApi.DeleteFolder(delRequest); }
public async Task <IActionResult> OnPostAsync(MeterFolderInformationToSet infoToSet) { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext); return(await FolderApi.SetMeterFolderInformationAsync( tokenData.AccessToken, infoToSet, new ResultHandler <MeterFolderInformationToSet> { OnSuccess = (empty) => { // Trigger another GET to show the updated MeterFolderInformation return Redirect("/Folder/GetMeterFolderInformation"); }, OnError = DefaultErrorHandler.Handle } )); }
public void ConfigureServices(IServiceCollection services) { var botSettings = BotSettings; var tClient = new TelegramBotClient(botSettings.TelegramBotKey) { Timeout = botSettings.PollingTimeout }; var apiClient = new ApiClient(botSettings.ApiPublicUrl); var wordApi = new WordApi(apiClient); var signer = new AuthSigner(botSettings.TelegramBotKey); var userApi = new UserApi(apiClient, signer); var serviceApi = new ServiceApi(apiClient); var folderApi = new FolderApi(apiClient); var log4NetService = new Log4NetService(); var restWordRepository = new RestWordRepository(wordApi, userApi, serviceApi, folderApi); var antiDdosChecker = new AntiDdosChecker(GetDateTime); var commandManager = new CommandManager(GetCommands, GetHiddenCommands, new Dictionary <string, ECommands> { { botSettings.ServiceCommandPassword, ECommands.Admin } }); apiClient.OnAuthenticationRequest += (o, e) => { userApi.LoginUser(new ApiUser { Id = botSettings.UserId.ToString() }); }; services.AddSingleton(a => antiDdosChecker); services.AddSingleton(bS => botSettings); services.AddSingleton(cl => tClient); services.AddSingleton <ICommandManager>(commandManager); services.AddSingleton <ILogService>(log4NetService); services.AddSingleton <IWordRepository>(restWordRepository); var flashCardUrl = $"{botSettings.ApiPublicUrl}/word/file"; services.AddSingleton(qh => new QueryHandler(tClient, log4NetService, restWordRepository, antiDdosChecker, flashCardUrl, commandManager, MaxUploadFileSize)); services.AddSingleton <ISyllableColorProvider, ClassicSyllableColorProvider>(); services.AddSingleton <IChineseWordParseProvider, PinyinChineseWordParseProvider>(); services.AddSingleton <IStudyProvider, ClassicStudyProvider>(); services.AddSingleton <ISyllablesToStringConverter, ClassicSyllablesToStringConverter>(); services.AddSingleton <IChinesePinyinConverter, Pinyin4NetConverter>(); services.AddSingleton <IFlashCardGenerator, FontFlashCardGenerator>(); services.AddTransient(a => new AboutCommand(ReleaseNotesInfo, AboutInfo)); services.AddTransient(a => new HelpCommand(GetCommands)); services.AddTransient(a => new StartCommand(GetCommands, botSettings.WebhookPublicUrl)); services.AddTransient(a => new FolderCommand(ServiceProvider.GetService <IWordRepository>(), botSettings.FolderManagementText)); services.AddTransient(a => new DefaultCommand(ServiceProvider.GetService <IWordRepository>())); services.AddTransient(a => new ImportCommand(ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>(), MaxUploadFileSize)); services.AddTransient(a => new AddCommand(ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>())); services.AddTransient(a => new ViewCommand(ServiceProvider.GetService <IWordRepository>())); services.AddTransient(a => new DeleteCommand(ServiceProvider.GetService <IWordRepository>())); services.AddTransient(a => new EditCommand(ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <ImportCommand>(), ServiceProvider.GetService <IFlashCardGenerator>())); services.AddTransient(a => new LearnWritingCommand(ServiceProvider.GetService <IStudyProvider>(), ServiceProvider.GetService <EditCommand>())); services.AddTransient(a => new LearnViewCommand(ServiceProvider.GetService <IStudyProvider>(), ServiceProvider.GetService <EditCommand>())); services.AddTransient(a => new LearnSpeakCommand(ServiceProvider.GetService <IStudyProvider>(), ServiceProvider.GetService <EditCommand>())); services.AddTransient(a => new LearnTranslationCommand(ServiceProvider.GetService <IStudyProvider>(), ServiceProvider.GetService <EditCommand>())); services.AddTransient(a => new ModeCommand(ServiceProvider.GetService <IWordRepository>())); services.AddTransient(a => new PreInstallCommand(ServiceProvider.GetService <IWordRepository>())); services.AddTransient(a => new AdminCommand(ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>(), MaxUploadFileSize, PreInstalledFolder, botSettings.ServerUserId, botSettings.AdminUserId, tClient)); services.AddTransient(a => new WebCommand(signer, botSettings.ApiPublicUrl)); services.AddSingleton(a => new AntiDdosChecker(GetDateTime)); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }