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)); }
private bool CopyFilesLocally(ATCommandDoneRequest indication) { bool result = false; string directory = GetOutputDirectory(indication.TestJobID, indication.TestCommandID); try { if (Directory.Exists(directory) == false) { Directory.CreateDirectory(directory); } else { Log("Deleting existing directory " + directory); try { Directory.Delete(directory, true); } catch (Exception ex) { Log("Exception when deleting directory: " + ex.Message); } } string shareDirectory = "\\\\" + mData.HostName; if (mData.HostName.ToLower().Contains("APPmac") == true) { shareDirectory = "\\\\" + mData.IPAddress + "\\testuser"; PinvokeWindowsNetworking.connectToRemote(@"\\" + mData.IPAddress + @"\testuser\Share", "testuser", "password"); } shareDirectory = shareDirectory + "\\Share"; result = CopyDirectory(shareDirectory, directory, true); if (mData.HostName.ToLower().Contains("testuser") == true) { PinvokeWindowsNetworking.disconnectRemote(@"\\" + mData.IPAddress + @"\testuser\Share"); } } catch (Exception ex) { Log("Exception in CopyFilesLocally [" + mData.VMName + "]: " + ex); throw ex; } return(result); }
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 }; }
public bool RunSync() { SerSettings.run = true; count = 0; bool retVal = (SerSettings.dirLocal != null && Directory.Exists(SerSettings.dirLocal)); if (retVal) { eggs.Start(); foreach (string s in Directory.GetDirectories(SerSettings.dirLocal)) { mapNetwork = false; stats = null; egg = eggs.GetEgg(s); isHatched = (egg != null); idx = 0; if (!isHatched) { idx = s.LastIndexOf(Settings.backSlash) + 1; // path length } if (idx > 0 || isHatched) { if (!isHatched) { rs = s.Substring(idx, s.Length - idx); } aux = rs; if (rs.Contains(Settings.chSlash) || isHatched) { if (!isHatched) { rs = Settings.GetDirRemoteName(rs); if (rs[0] != Settings.backSlash) { rs = rs.Insert(1, ":"); // director local } //Checks if the last character is \ as this causes error on mapping a drive. if (rs.Substring(rs.Length - 1, 1) == @"\") { rs = rs.Substring(0, rs.Length - 1); } } else { rs = egg.orc.set.dirRemote; } res = (Directory.Exists(rs) && Utils.DirectoryExists(rs)); //Lib.WrLog(string.Format(":--> {0} ", rs)); // && (Char.IsNumber(rs[2]) || Char.IsNumber(rs[3])) if (Utils.IsRemotePath(rs)) // ---> TRULLY REMOTE <--- { //if (Utils.IsDriveMapped(Settings.mapNetDrives[Settings.mapNetIdx] + Settings.backSlash)) //{ // //Utils.ExecuteCommand(string.Format("net use {0} /delete", Settings.mapNetDrive)); // l.DisconnectNetworkDrive(Settings.mapNetDrives[Settings.mapNetIdx], true); // // System.Threading.Thread.Sleep(100); //} //Utils.ExecuteCommand(string.Format("net use {0} {1} /user:{2} {3} /persistent:no", Settings.mapNetDrive, rs, usr, pas)); //Utils.ExecuteCommand("net use V: \"\\\\10.10.10.47\\video\\gi test\" /user:GI 1qaz@WSX"); //$$10.10.10.47$video$gi test //\\10.10.10.47\video\gi test //DriveSettings.MapNetworkDrive("W", "\\\\10.10.10.47\\video\\gi test", "GI", "1qaz@WSX"); // get user and password from the Passwords file pasFileLastWriteTime = DateTime.MinValue; bool pasFileUpdate = false; if (egg != null && File.Exists(SerSettings.passwFilePath)) { pasFileLastWriteTime = (new FileInfo(SerSettings.passwFilePath)).LastWriteTime; pasFileUpdate = eggs.pasFileLastWriteTimeVal != pasFileLastWriteTime.Second; } if (egg == null || pasFileUpdate) { Settings.SearchPasswordFile( SerSettings.passwFilePath, aux, ref usr, ref pas); if (pasFileUpdate) { eggs.pasFileLastWriteTimeVal = pasFileLastWriteTime.Second; egg.usr = usr; egg.pas = pas; } //usr = "******"; //pas = "******"; } if (egg != null) { usr = egg.usr; pas = egg.pas; } if (!string.IsNullOrEmpty(usr)) { //if (s[s.Length - 1] == 'w') //Utils.ExecuteCommand("net use C: \"\\\\10.10.10.47\\home\\www\" /user:GI 1qaz@WSX", @"c:\_sync\$$_temp"); //try //{ // Utils.ExecuteCommand(string.Format("net use {0} \"{1}\" /user:{2} {3}", "\\", rs, usr, pas), @"C:\_sync\$$_temp"); // mapNetwork = true; // res = true; //} //catch //{ // res = false; //} // DirectoryInfo di = new DirectoryInfo(rs); ///DirectorySecurity ds = di.GetAccessControl(); /// //foreach (AccessRule rule in ds.GetAccessRules(true, true, typeof(NTAccount))) //{ //Lib.WrLog(string.Format("Identity = {0}; Access = {1}", //rule.IdentityReference.Value, rule.AccessControlType)); //} connectStringResult = PinvokeWindowsNetworking.connectToRemote(rs, usr, pas); if (connectStringResult == null) { mapNetwork = true; res = true; } else { Lib.WrLog(rs + connectStringResult); res = false; } //if (l.MapNetworkDrive(rs, Settings.mapNetDrives[Settings.mapNetIdx], usr, pas) == 0) //{ // mapNetwork = true; // res = true; //} //else //{ // res = false; //} } } //VwSync.Imperson.DoWorkUnderImpersonation(rs); if (res) { ++count; try { if (isHatched) { o = egg.orc; o.DetectChanges(); stats = o.SyncOperationExecute(); } else { o = new Orchestrator(new Settings(SerSettings.dirLocal, rs)); stats = o.Sync(true, SerSettings.dirLocal, rs); } } catch (Exception ex) { if (o.set.ErrCount < Settings.ErrCountMax) { ++o.set.ErrCount; } if (egg != null) { egg.err = ex; } } //string // s1 = (o.GetIdLocal() == null) ? "null" : o.GetIdLocal().ToString(), // s2 = (o.GetIdRemote() == null) ? "null" : o.GetIdRemote().ToString(); //Lib.WrLog(string.Format("{0} {1} :: ===>{2} {3} {4}", // res, rs, VwSync.Imperson.mesaj, s1, s2)); execTime = 0; if (stats != null) { execTime = stats.SyncEndTime.Subtract(stats.SyncStartTime).Milliseconds; if (!isHatched) { egg = new Egg(); egg.lastExecTimeMs = execTime; egg.dir = s; egg.orc = o; egg.isMapped = mapNetwork; egg.usr = usr; egg.pas = pas; eggs.AddEgg(egg); } if (egg != null) { egg.wasChecked = true; } } ultimulTimpTotalDeExecutie += execTime; Lib.WrLog(string.Format(" done {0} in {1}ms", rs, execTime)); //Lib.WrLog("xxmapNetwork0" + mapNetwork.ToString()); //if (mapNetwork) //{ // Lib.WrLog("xxmapNetwork1"); // Utils.ExecuteCommand(string.Format("net use {0} /delete", Settings.mapNetDrives[Settings.mapNetIdx])); // //DriveSettings.DisconnectNetworkDrive(Settings.mapNetDrives[Settings.mapNetIdx], true); //} if (!SerSettings.run) { return(false); } } } if (mapNetwork) { PinvokeWindowsNetworking.disconnectRemote(rs); } } } retVal = count > 0; eggs.Stop(); Lib.WrLog(eggs.GetCount().ToString()); } SerSettings.run = false; return(retVal); }