private static bool ConnectNetworkPrinters(HikariModel model) { if (model.Printers.Count == 0) { return(true); } Console.WriteLine(); log.Info("Connecting network printers..."); Console.WriteLine(); bool success = true; Forker printerForker = new Forker(); foreach (Tuple <string, string> printer in model.Printers) { printerForker.Fork(delegate { if (!AddPrinterConnection(printer.Item2)) { log.Error($"Error connecting network printer \"{printer.Item2}\""); success = false; } else { log.Info($"[{printer.Item1}] -> \"{printer.Item2}\""); } }); } printerForker.Join(); return(success); }
public void Parse(string s) { Model = new HikariModel(); queue = new Queue <Tuple <string, string> >(); byte[] inputBuffer = System.Text.Encoding.Default.GetBytes(s); MemoryStream stream = new MemoryStream(inputBuffer); Scanner = new HikariScriptScanner(stream); Parse(); queue.Clear(); }
private static bool ConnectNetworkDrives(HikariModel model) { log.Info("Connecting network drives..."); Console.WriteLine(); bool success = true; Forker driveForker = new Forker(); foreach (var drive in model.Drives) { Tuple <string, string> exp_unc = (drive.Value).FirstOrDefault(); string driveLetter = drive.Key; string expression = exp_unc.Item1; string unc = exp_unc.Item2; driveForker.Fork(delegate { if (!Directory.Exists(unc)) { log.Error($"Network path \"{unc}\" doesn't exist! Drive {driveLetter} for [{expression}] is NOT connected!"); success = false; } else { string result = InvokeWindowsNetworking.connectToRemote(driveLetter, unc); if (!string.IsNullOrEmpty(result)) { log.Error($"Network drive {driveLetter} -> \"{unc}\" ERROR: {result}"); success = false; } else { log.Info($"{driveLetter} -> \"{unc}\" [{expression}]"); } } }); } driveForker.Join(); return(success); }
public static void ResolveMappings(HikariModel model) { uint totalConflicts = model.TotalConflicts(); if (totalConflicts == 0) { log.Info("No conflicting drive mappings found"); return; } Console.WriteLine(); log.Warn($"There {(totalConflicts == 1 ? "is" : "are")} {totalConflicts} conflict{(totalConflicts == 1 ? string.Empty : "s")} detected."); Console.WriteLine(); // A, B and C are taken for sure! =) List <string> alpha = "DEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().Select(c => c + ":").ToList(); List <string> used = model.UsedDriveLetters(); // Only in real-run exclude local drives other than A-C if (doMapping) { // All local fixed drives & CD/DVD drives List <string> localDrives = DriveInfo.GetDrives() .ToList() .Where(d => d.DriveType == DriveType.Fixed || d.DriveType == DriveType.CDRom) .Select(d => d.Name.Substring(0, 2).ToUpper()) .ToList(); // Add local fixed drives to used drives used.AddRange(localDrives); log.Info($"Excluding locally found drives: [{string.Join(", ", localDrives.ToArray())}]"); Console.WriteLine(); } // Generate unused drive letters queue out of all possible excluding used and local fixed drives unused = new Queue <string>(alpha.Where(l => used.All(c => c != l))); // Try moving until resolved or no more available drives while (model.TotalConflicts() > 0 && unused.Count > 0) { string drive = model.GetNextConflictDriveIndex(); if (!string.IsNullOrWhiteSpace(drive)) { if (!getFirstAvailableLetter) { // compute next drive letter string nextDrive = NextDriveLetter(drive); log.Info($"Next drive: \"{nextDrive}\""); model.MoveFirstUNCConflict(drive, nextDrive); } else { // Pop 1st available string unusedDrive = unused.Dequeue(); model.MoveFirstUNCConflict(drive, unusedDrive); } } if (unused.Count == 0) { Console.WriteLine(); log.Warn("No more drive letters available!"); log.Warn("All unresolved drives will be reduced to the 1st UNC!"); model.EmergencyReduceUNCs(); } } Console.WriteLine(); log.Info("Final mappings result:"); log.Info(model); }