private async Task RunLock() { base.CheckForFileId(this._fileId.Value, this._app); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var lockRequest = new BoxFileLockRequest(); var boxLock = new BoxFileLock(); if (this._preventDownload.HasValue()) { boxLock.IsDownloadPrevented = true; } if (this._expires.HasValue()) { boxLock.ExpiresAt = GeneralUtilities.GetDateTimeFromString(this._expires.Value()); } lockRequest.Lock = boxLock; var boxLocked = await boxClient.FilesManager.LockAsync(lockRequest, this._fileId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(boxLocked); return; } base.PrintFileLock(boxLocked); }
private async Task RunCreate() { base.CheckForValue(this._fileId.Value, this._app, "A file ID is required for this command"); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskRequest = new BoxTaskCreateRequest(); taskRequest.Item = new BoxRequestEntity() { Id = this._fileId.Value, Type = BoxType.file }; if (this._message.HasValue()) { taskRequest.Message = this._message.Value(); } if (this._due.HasValue()) { taskRequest.DueAt = GeneralUtilities.GetDateTimeFromString(this._due.Value()); } var createdTask = await boxClient.TasksManager.CreateTaskAsync(taskRequest); if (this._idOnly.HasValue()) { Reporter.WriteInformation(createdTask.Id); return; } if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(createdTask); return; } base.PrintTask(createdTask); }
private void RunStartSession() { string id; if (this._userId.HasValue()) { id = this._userId.Value(); base._environments.SetTempAsUserIdSetting(id); base._environments.ToggleUseTempUserSetting(turnOn: true); base._environments.ToggleUseDefaultUserSetting(turnOff: true); base._environments.ToggleUserSessionEnabledSetting(turnOn: true); } else { id = base._environments.GetDefaultAsUserIdSetting(); base._environments.ToggleUseDefaultUserSetting(turnOn: true); base._environments.ToggleUseTempUserSetting(turnOff: true); base._environments.ToggleUserSessionEnabledSetting(turnOn: true); } if (string.IsNullOrEmpty(id)) { Reporter.WriteError("No user set and cannot start a user session."); base._environments.ExpireUserSession(); } else { DateTime expiresAt; if (this._expires.HasValue()) { expiresAt = GeneralUtilities.GetDateTimeFromString(this._expires.Value()); } else { expiresAt = GeneralUtilities.GetDateTimeFromString("08h"); } base._environments.SetUserSessionExpirationSetting(expiresAt); Reporter.WriteInformation($"Session started for User {id}. Session expires at {expiresAt}"); } }
private async Task RunUpdate() { base.CheckForValue(this._taskId.Value, this._app, "A task ID is required for this command"); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskRequest = new BoxTaskUpdateRequest(); if (this._message.HasValue()) { taskRequest.Message = this._message.Value(); } if (this._due.HasValue()) { taskRequest.DueAt = GeneralUtilities.GetDateTimeFromString(this._due.Value()); } var task = await boxClient.TasksManager.UpdateTaskAsync(taskRequest); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(task); return; } base.PrintTask(task); }
private async Task RunUpdate() { if (this._bulkFilePath.HasValue()) { var json = false; if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { json = true; } await this.UpdateFoldersFromFile(this._bulkFilePath.Value(), this._save.HasValue(), this._filePath.Value(), this._fileFormat.Value(), json : json); return; } base.CheckForId(this._folderId.Value, this._app); var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderUpdateRequest = new BoxFolderRequest(); folderUpdateRequest.Id = this._folderId.Value; if (this._parentFolderId.HasValue()) { folderUpdateRequest.Parent = new BoxRequestEntity() { Id = this._parentFolderId.Value() }; } if (this._access.HasValue()) { folderUpdateRequest.FolderUploadEmail = new BoxEmailRequest() { Access = this._access.Value() }; } if (this._sharedLinkAccess.HasValue() || this._sharedLinkPassword.HasValue() || this._sharedLinkUnsharedAt.HasValue() || this._sharedLinkCanDownload.HasValue()) { folderUpdateRequest.SharedLink = new BoxSharedLinkRequest(); if (this._sharedLinkAccess.HasValue()) { folderUpdateRequest.SharedLink.Access = base.ResolveSharedLinkAccessType(this._sharedLinkAccess.Value()); } if (this._sharedLinkPassword.HasValue()) { folderUpdateRequest.SharedLink.Password = this._sharedLinkPassword.Value(); } if (this._sharedLinkUnsharedAt.HasValue()) { folderUpdateRequest.SharedLink.UnsharedAt = GeneralUtilities.GetDateTimeFromString(this._sharedLinkUnsharedAt.Value()); } if (this._sharedLinkCanDownload.HasValue()) { folderUpdateRequest.SharedLink.Permissions = new BoxPermissionsRequest(); folderUpdateRequest.SharedLink.Permissions.Download = true; } } if (this._notSynced.HasValue()) { folderUpdateRequest.SyncState = BoxSyncStateType.not_synced; } else if (this._partiallySynced.HasValue()) { folderUpdateRequest.SyncState = BoxSyncStateType.partially_synced; } else if (this._synced.HasValue()) { folderUpdateRequest.SyncState = BoxSyncStateType.synced; } if (this._tags.HasValue()) { folderUpdateRequest.Tags = this._tags.Value().Split(','); } if (this._name.HasValue()) { folderUpdateRequest.Name = this._name.Value(); } if (this._description.HasValue()) { folderUpdateRequest.Description = this._description.Value(); } if (this._onlyOwnersCanInvite.HasValue()) { folderUpdateRequest.CanNonOwnersInvite = false; } BoxFolder updated; if (this._etag.HasValue()) { updated = await boxClient.FoldersManager.UpdateInformationAsync(folderUpdateRequest, etag : this._etag.Value()); } else { updated = await boxClient.FoldersManager.UpdateInformationAsync(folderUpdateRequest); } if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(updated); return; } Reporter.WriteSuccess($"Updated folder {this._folderId.Value}"); base.PrintFolder(updated); }
private async Task RunCreate() { if (!string.IsNullOrEmpty(_path.Value())) { var json = false; if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { json = true; } await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, json : json); return; } base.CheckForId(this._id.Value, this._app); if (base._t == BoxType.enterprise) { if (this._type.Value == String.Empty || (this._type.Value != SharedLinkSubCommandBase.BOX_FILE && this._type.Value != SharedLinkSubCommandBase.BOX_FOLDER)) { _app.ShowHelp(); throw new Exception("You must provide an item type for this command: choose file or folder"); } } var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var sharedLinkRequest = new BoxSharedLinkRequest(); if (this._access.HasValue()) { sharedLinkRequest.Access = base.ResolveSharedLinkAccessType(this._access.Value()); } if (this._password.HasValue()) { sharedLinkRequest.Password = this._password.Value(); } if (this._unsharedAt.HasValue()) { sharedLinkRequest.UnsharedAt = GeneralUtilities.GetDateTimeFromString(this._unsharedAt.Value()); } if (this._canDownload.HasValue()) { sharedLinkRequest.Permissions = new BoxPermissionsRequest(); sharedLinkRequest.Permissions.Download = true; } if (base._t == BoxType.file || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FILE)) { var result = await boxClient.FilesManager.CreateSharedLinkAsync(this._id.Value, sharedLinkRequest); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(result); return; } Reporter.WriteSuccess("Created shared link:"); base.PrintSharedLink(result.SharedLink); } else if (base._t == BoxType.folder || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FOLDER)) { var result = await boxClient.FoldersManager.CreateSharedLinkAsync(this._id.Value, sharedLinkRequest); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(result); return; } Reporter.WriteSuccess("Created shared link:"); base.PrintSharedLink(result.SharedLink); } else { throw new Exception("Box type not supported for this command."); } }
private async Task RunGet() { var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (this._enterprise.HasValue()) { var createdBefore = DateTime.Now; var createdAfter = DateTime.Now.AddDays(-5); if (this._createdBefore.HasValue()) { try { createdBefore = GeneralUtilities.GetDateTimeFromString(this._createdBefore.Value(), true); } catch { createdBefore = DateTime.Parse(this._createdBefore.Value()); } Reporter.WriteInformation(createdBefore.ToString()); } if (this._createdAfter.HasValue()) { try { createdAfter = GeneralUtilities.GetDateTimeFromString(this._createdAfter.Value(), true); } catch { createdAfter = DateTime.Parse(this._createdAfter.Value()); } } if (this._save.HasValue()) { var fileName = $"{base._names.CommandNames.Events}-enterprise-{base._names.SubCommandNames.Get}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; Reporter.WriteInformation("Saving file..."); var events = await BoxCollectionsIterators.ReturnAllEvents((position) => { return boxClient.EventsManager.EnterpriseEventsAsync(limit: 1000, createdAfter: createdAfter, createdBefore: createdBefore, streamPosition: position); }); base.WriteEventListResultsToReport(events.Entries, fileName, _path.Value(), _fileFormat.Value()); return; } if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { var events = await BoxCollectionsIterators.ReturnAllEvents((position) => { return boxClient.EventsManager.EnterpriseEventsAsync(limit: 1000, createdAfter: createdAfter, createdBefore: createdBefore, streamPosition: position); }); base.OutputJson(events); return; } await BoxCollectionsIterators.ListEventCollectionToConsole((position) => { return boxClient.EventsManager.EnterpriseEventsAsync(createdAfter: createdAfter, createdBefore: createdBefore, streamPosition: position); }, base.PrintEvent); } else { if (this._save.HasValue()) { var fileName = $"{base._names.CommandNames.Events}-user-{base._names.SubCommandNames.Get}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; Reporter.WriteInformation("Saving file..."); var events = await BoxCollectionsIterators.ReturnAllEvents((position) => { return boxClient.EventsManager.UserEventsAsync(limit: 1000, streamPosition: position); }); base.WriteEventListResultsToReport(events.Entries, fileName, _path.Value(), _fileFormat.Value()); return; } if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { var events = await BoxCollectionsIterators.ReturnAllEvents((position) => { return boxClient.EventsManager.UserEventsAsync(limit: 1000, streamPosition: position); }); base.OutputJson(events); return; } await BoxCollectionsIterators.ListEventCollectionToConsole((position) => { return boxClient.EventsManager.UserEventsAsync(streamPosition: position); }, base.PrintEvent); } }
protected async override Task <int> Execute() { if (string.IsNullOrEmpty(this._query.Value) && (string.IsNullOrEmpty(this._mdFilterScope.Value()) && string.IsNullOrEmpty(this._mdFilterTemplateKey.Value()))) { _app.ShowHelp(); return(await base.Execute()); } var fileExtensions = new List <string>(); var ancestorFolderIds = new List <string>(); var ownerUserIds = new List <string>(); var contentTypes = new List <string>(); var mdFilters = new List <BoxMetadataFilterRequest>(); DateTime createdAtFrom = DateTime.Now.AddMonths(-6); DateTime createdAtTo = DateTime.Now; DateTime updatedAtFrom = DateTime.Now.AddMonths(-6); DateTime updatedAtTo = DateTime.Now; if (this._ownerUserIds.HasValue()) { ownerUserIds = this._ownerUserIds.Value().Split(',').ToList(); } if (this._fileExtenstions.HasValue()) { fileExtensions = this._fileExtenstions.Value().Split(',').ToList(); } if (this._contentTypes.HasValue()) { contentTypes = this._contentTypes.Value().Split(',').ToList(); } if (this._ancestorFolderIds.HasValue()) { ancestorFolderIds = this._ancestorFolderIds.Value().Split(',').ToList(); } if (this._createdAtFrom.HasValue() && this._createdAtTo.HasValue()) { try { createdAtFrom = GeneralUtilities.GetDateTimeFromString(this._createdAtFrom.Value(), true); } catch { createdAtFrom = DateTime.Parse(this._createdAtFrom.Value()); } try { createdAtTo = GeneralUtilities.GetDateTimeFromString(this._createdAtTo.Value(), true); } catch { createdAtTo = DateTime.Parse(this._createdAtTo.Value()); } } if (this._updatedAtTo.HasValue() && this._updatedAtFrom.HasValue()) { try { updatedAtFrom = GeneralUtilities.GetDateTimeFromString(this._updatedAtFrom.Value(), true); } catch { updatedAtFrom = DateTime.Parse(this._updatedAtFrom.Value()); } try { updatedAtTo = GeneralUtilities.GetDateTimeFromString(this._updatedAtTo.Value(), true); } catch { updatedAtTo = DateTime.Parse(this._updatedAtTo.Value()); } } if (this._mdFilterTemplateKey.HasValue() && this._mdFilterScope.HasValue() && this._mdFilterJson.HasValue()) { var mdTempKeyCount = this._mdFilterTemplateKey.Values.Count(); var mdScopeCount = this._mdFilterScope.Values.Count(); var mdJsonCount = this._mdFilterJson.Values.Count(); if (mdTempKeyCount != mdScopeCount && mdTempKeyCount != mdJsonCount) { throw new Exception("Mismatch on metadata filtering. Can't perform search."); } for (var i = 0; i < mdTempKeyCount; i++) { var mdRequest = new BoxMetadataFilterRequest(); mdRequest.TemplateKey = this._mdFilterTemplateKey.Values[i]; mdRequest.Scope = this._mdFilterScope.Values[i]; mdRequest.Filters = this._mdFilterJson.Values[i]; mdFilters.Add(mdRequest); } } var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); BoxCollection <BoxItem> result; if (mdFilters.Count() > 0) { result = await boxClient.SearchManager.SearchAsync(this._query.Value, scope : this._scope.Value(), fileExtensions : fileExtensions, ancestorFolderIds : ancestorFolderIds, ownerUserIds : ownerUserIds, type : this._type.Value(), contentTypes : contentTypes, createdAtRangeFromDate : createdAtFrom, createdAtRangeToDate : createdAtTo, updatedAtRangeFromDate : updatedAtFrom, updatedAtRangeToDate : updatedAtTo, mdFilters : mdFilters); } else { result = await boxClient.SearchManager.SearchAsync(this._query.Value, scope : this._scope.Value(), fileExtensions : fileExtensions, ancestorFolderIds : ancestorFolderIds, ownerUserIds : ownerUserIds, type : this._type.Value(), contentTypes : contentTypes, createdAtRangeFromDate : createdAtFrom, createdAtRangeToDate : createdAtTo, updatedAtRangeFromDate : updatedAtFrom, updatedAtRangeToDate : updatedAtTo); } foreach (var item in result.Entries) { base.PrintItem(item); } return(await base.Execute()); }