private void Initialize() { var syncpoint = SyncPointsService.GetSyncpoint(_syncpointId); if (syncpoint == null) { throw new ArgumentException("Invalid Syncpoint Id"); } var storageEndpoints = StorageEndpointsService.GetStorageEndpoints(); var storageEndpoint = storageEndpoints.First(x => x.Id == syncpoint.StorageEndpointId); if (storageEndpoint.Urls == null || storageEndpoint.Urls.Length == 0) { throw new ArgumentException("Invalid StorageEndpoint Urls"); } _uploadUrl = string.Format(DownloadUlrFormat, storageEndpoint.Urls[0].Url); _sessionKey = string.Format(SessionKeyFormat, ConfigurationHelper.SyncplicityMachineTokenAuthenticationEnabled ? ApiContext.MachineToken : ApiContext.AccessToken); Debug.WriteLine($"Upload Url: {_uploadUrl}"); Debug.WriteLine($"Session Key: {_sessionKey}"); Console.WriteLine($"Upload Url: {_uploadUrl}"); Console.WriteLine($"Session Key: {_sessionKey}"); }
private void Initialize(Entities.File file) { _syncpointId = file.SyncpointId; _latestVersionId = file.LatestVersionId; var syncpoint = SyncPointsService.GetSyncpoint(_syncpointId); if (syncpoint == null) { throw new ArgumentException("Invalid Syncpoint Id"); } var storageEndpoint = StorageEndpointsService.GetStorageEndpoint(syncpoint.StorageEndpointId); if (storageEndpoint.Urls == null || storageEndpoint.Urls.Length == 0) { throw new ArgumentException("Invalid StorageEndpoint Urls"); } _downloadUrl = string.Format(DownloadUlrFormat, storageEndpoint.Urls[0].Url); if (ConfigurationHelper.UseSecureSessionToken) { _sessionKey = string.Format(SessionKeyFormat, ApiGateway.CreateSst(storageEndpoint.Id)); } else { _sessionKey = string.Format(SessionKeyFormat, ConfigurationHelper.SyncplicityMachineTokenAuthenticationEnabled ? ApiContext.MachineToken : ApiContext.AccessToken); } Debug.WriteLine($"Download Url: {_downloadUrl}"); Debug.WriteLine($"Session Key: {_sessionKey}"); Console.WriteLine($"Download Url: {_downloadUrl}"); Console.WriteLine($"Session Key: {_sessionKey}"); }
private static void CreateSyncpointInternal(User user, bool isObo = false) { Console.WriteLine(); Console.WriteLine("Start SyncPoint Creation..."); if (isObo) { ApiContext.OnBehalfOfUser = user.Id; } // Get default storage endpoint of current user var storageEndpoint = StorageEndpointsService.GetStorageEndpoint(); if (storageEndpoint == null) { Console.WriteLine(); Console.WriteLine("Unable to determine the user's storage endpoint. " + "Content APIs will not be able to proceed."); return; } ApiContext.HasStorageEndpoint = true; var newSyncPoint = new SyncPoint { Name = ConfigurationHelper.SyncpointName + _random.Next(), Type = SyncPointType.Custom, Path = @"C:\Syncplicity", StorageEndpointId = storageEndpoint.Id, Mapped = true, DownloadEnabled = true, UploadEnabled = true }; var createdSyncPoints = SyncPointsService.CreateSyncpoints(new[] { newSyncPoint }); Console.WriteLine(); if (createdSyncPoints == null || createdSyncPoints.Length == 0) { Console.WriteLine("Error occurred during creating SyncPoint."); return; } // Need to call getSyncPoint to hydrate all the meta data of the syncpoint, // in particular we need RootFolderId so that we can create a folder next. _currentSyncpoint = SyncPointsService.GetSyncpoint(createdSyncPoints[0].Id); // Map syncpoint to device if (ConfigurationHelper.SyncplicityMachineTokenAuthenticationEnabled) { Console.WriteLine($"Mapping the syncpoint {_currentSyncpoint.Id} to machine {ConfigurationHelper.MachineId}"); _currentSyncpoint.Mappings = new[] { new Mapping { SyncPointId = _currentSyncpoint.Id, Mapped = true, Machine = new Machine { Id = ConfigurationHelper.MachineId } } }; _currentSyncpoint = SyncPointsService.PutSyncpoint(_currentSyncpoint); } Console.WriteLine($"Finished SyncPoint Creation. Created new SyncPoint {_currentSyncpoint.Name} with Id: {_currentSyncpoint.Id}"); }