public Task <IEnumerable <FileItem> > GetItems(string path) { return(Task.Run(() => { if (string.IsNullOrEmpty(path)) { return GetRootItems().Items; } IEnumerable <FileItem> items; try { items = GetItemsInternal(path); } catch (UnauthorizedAccessException) { if (new Uri(path).IsUnc) { PinvokeWindowsNetworking.ConnectToRemote(path, "", "", true); items = GetItemsInternal(path); } else { throw; } } if (items.Any()) { return Workspace.Options.ShowHiddenItems ? items : items.Where(i => !i.IsSystemOrHidden); } return GetEmptyDirectoryItems(path); })); }
static void UpdateWallpaper(string remoteMachine, string windowsVersion = "") { const string domain = "npr"; const string user = "******"; const string password = "******"; PinvokeWindowsNetworking.ConnectToRemote(string.Format(@"\\{0}\C$\", remoteMachine), string.Format(@"{0}\{1}", domain, user), password); string dirDestination = string.Format(@"\\{0}\C$\_User", remoteMachine); if (!Directory.Exists(dirDestination)) { Directory.CreateDirectory(dirDestination); } if (!string.IsNullOrEmpty(windowsVersion)) { SaveWallpaparConfig(string.Format(@"{0}\SetInfoWallpaper.ini", dirDestination), windowsVersion); } const string dirSourse = @"D:\_Projects\ClientTool\SetInfoWallpaper\bin\Debug\"; CopyFile(dirSourse + "SetInfoWallpaper.exe", dirDestination); CopyFile(dirSourse + "SetInfoWallpaperStartUp.bat", dirDestination); CopyFile(@"D:\_Projects\ClientTool\Notification\bin\Debug\Notification.exe", dirDestination); Exec(remoteMachine, domain, user, password, @"C:\_User\SetInfoWallpaperStartUp.bat"); //Logoff nemote machine. //Process.Start(@"C:\PSTools\PsExec.exe", string.Format(@"\\{0} -u npr\karnaushenkosv -p qwert-+ZXCVB -d -i shutdown -l", remoteMachine)); //Process.Start(@"C:\PSTools\PsExec.exe", string.Format(@"\\{0} -u npr\karnaushenkosv -p qwert-+ZXCVB -d -i C:\_User\Notification.exe", remoteMachine)); }
public static async Task <IEnumerable <FileItem> > GetItems(string path) { //return new FileItem[] {new FileItem("C:\\temp") }; var tempItems = await Task.Run(() => { var folder = ShellObject.FromParsingName(path) as ShellFolder; if (folder == null) { return(Enumerable.Empty <FileItem>()); } ImmutableArray <FileItem> tempShares; try { tempShares = folder.Select(i => new FileItem(i.Properties.System.ParsingPath.Value, ItemType.Container)).ToImmutableArray(); } catch (UnauthorizedAccessException) { PinvokeWindowsNetworking.ConnectToRemote(path, "", "", true); tempShares = folder.Select(i => new FileItem(i.Properties.System.ParsingPath.Value, ItemType.Container)).ToImmutableArray(); } return(tempShares.ToList()); }); var shareThumb = GetShareImage(); shareThumb.Freeze(); var shares = tempItems.Select(i => new FileItem(i.Path, ItemType.Container) { IsFileShare = true, Thumbnail = shareThumb }).ToArray(); foreach (var i in shares) { i.Details = new FileDetailItem(i, CancellationToken.None) { Type = "Share", Thumbnail = shareThumb, LargeThumbnail = shareThumb } } ; return(shares); }
/// <summary> /// Standard Constructor /// </summary> /// <param name="db">The database where this component will save information /// for file descriptor. It is needed to perform queries.</param> /// <param name="collectionName">The name of the collection that will be used /// to store information of the file</param> /// <param name="baseDirectory">Base directory on filesystem where binary blob /// will be stored</param> /// <param name="counterService">Counter service to generate new <see cref="BlobId"/></param> public FileSystemBlobStore( IMongoDatabase db, String collectionName, String baseDirectory, ICounterService counterService, String userName, String password) { _directoryManager = new DirectoryManager(baseDirectory, FolderPrefixLength); _counterService = counterService; //_fileSystemBlobDescriptorStore = new FileSystemBlobDescriptorStore(_directoryManager); _mongodDbFileSystemBlobDescriptorStorage = new MongodDbFileSystemBlobDescriptorStorage(db, collectionName); _counterService = counterService; if (!String.IsNullOrEmpty(userName)) { PinvokeWindowsNetworking.ConnectToRemote(baseDirectory, userName, password); } }
private void SetFileSystemBaseDirectory(string name) { var storageValue = ConfigurationServiceClient.Instance.GetSetting($"storage.fileSystem.{TenantId}-{name}-baseDirectory"); if (!String.IsNullOrEmpty(_config.StorageUserName)) { var match = Regex.Match(storageValue, @"(?<root>\\\\.+?\\.+?)(\\|$)"); if (match.Success) { var shareRoot = match.Groups["root"].Value.TrimEnd('/', '\\'); var errors = PinvokeWindowsNetworking.ConnectToRemote(shareRoot, _config.StorageUserName, _config.StoragePassword); if (!String.IsNullOrEmpty(errors)) { //We cannot go on, we have no ability to save into file system. throw new ApplicationException($"Unable to map network share {storageValue} with username {_config.StorageUserName}. Error: {errors}"); } } } Set("storage.fs." + name, storageValue); }
public TenantConfiguration( String tenantId, ILogger logger) { TenantId = tenantId; //Eventstore connection string and username and password for file system. var eventStoreConnectionString = ConfigurationManager.AppSettings[$"eventStoreconnection-{tenantId}"]; var descriptorConnectionString = ConfigurationManager.AppSettings[$"fileSystemStoreDescriptors-{tenantId}"]; var fileSystemRootUserName = ConfigurationManager.AppSettings["fileSystemStoreUserName"]; var fileSystemRootPassword = ConfigurationManager.AppSettings["fileSystemStorePassword"]; EventStoreDb = GetDb(eventStoreConnectionString); //We need to have original blob store and destination blob store for original blob var originalConnectionString = ConfigurationManager.AppSettings[$"OriginalBlobConnection-{tenantId}"]; if (String.IsNullOrEmpty(originalConnectionString)) { throw new ConfigurationErrorsException($"App settings OriginalBlobConnection-{tenantId} with connection string of original blob store not found"); } OriginalGridFsBlobStore = new GridFsBlobStore(GetLegacyDb(originalConnectionString), null) { Logger = logger }; var originalFileSystemRoot = ConfigurationManager.AppSettings[$"fileSystemStoreOriginal-{tenantId}"]; if (!String.IsNullOrEmpty(fileSystemRootUserName)) { PinvokeWindowsNetworking.ConnectToRemote(originalFileSystemRoot, fileSystemRootUserName, fileSystemRootPassword); } if (String.IsNullOrEmpty(originalFileSystemRoot)) { throw new ConfigurationErrorsException($"File system settings for tenant {tenantId} (settings fileSystemStoreOriginal-{tenantId}) not found in configuration"); } OriginalFileSystemBlobStore = new FileSystemBlobStore( GetDb(descriptorConnectionString), FileSystemBlobStore.OriginalDescriptorStorageCollectionName, originalFileSystemRoot, null, //Counter service is not needed for the migrator fileSystemRootUserName, fileSystemRootPassword ) { Logger = logger }; //we need to have artifacts blob store for source and destination //We need to have original blob store and destination blob store for original blob var artifactConnectionString = ConfigurationManager.AppSettings[$"ArtifactBlobConnection-{tenantId}"]; if (String.IsNullOrEmpty(artifactConnectionString)) { throw new ConfigurationErrorsException($"App settings ArtifactBlobConnection-{tenantId} with connection string of original blob store not found"); } ArtifactsGridFsBlobStore = new GridFsBlobStore(GetLegacyDb(artifactConnectionString), null) { Logger = logger }; var artifactFileSystemRoot = ConfigurationManager.AppSettings[$"fileSystemStoreArtifacts-{tenantId}"]; if (String.IsNullOrEmpty(artifactFileSystemRoot)) { throw new ConfigurationErrorsException($"File system settings for tenant {tenantId} (settings fileSystemStoreArtifacts-{tenantId}) not found in configuration"); } ArtifactsFileSystemBlobStore = new FileSystemBlobStore( GetDb(descriptorConnectionString), FileSystemBlobStore.ArtifactsDescriptorStorageCollectionName, artifactFileSystemRoot, null, FileSystemUserName, FileSystemPassword) { Logger = logger }; //Null counter service is used to ensure that no new blob could be created. ArtifactsGridFsBlobStore = new GridFsBlobStore(GetLegacyDb(artifactConnectionString), null) { Logger = logger }; }