private Line GetRandomLine(float nowTime, int genCount) { SourceDir genDir = (SourceDir)(Random.Range(.0f, .999f) * 4); float timeRange = Configs.GEN_TIME_RANGE + Configs.GEN_TIME_EXTEND * (genCount / Configs.GEN_RETRY_TIMES); float genTime = nowTime + Random.value * timeRange; float genCoord = Random.value * Utils.GetDirCrossWidth(genDir); float genLength = Random.value * (Configs.GEN_MAX_LENGTH - Configs.GEN_MIN_LENGTH) + Configs.GEN_MIN_LENGTH; float genSpeed = Random.value * (Configs.GEN_MAX_SPEED - Configs.GEN_MIN_SPEED) + Configs.GEN_MIN_SPEED; Line_FormRoad lfr = new Line_FormRoad(); lfr.dir = genDir; lfr.genTime = genTime; lfr.genCoord = genCoord; lfr.genLength = genLength; lfr.genSpeed = genSpeed; Line res = new Line(lfr); return(res); }
private SourceDir DecideDir() { Dictionary <SourceDir, int> dic = new Dictionary <SourceDir, int>(); dic[SourceDir.North] = 0; dic[SourceDir.East] = 0; dic[SourceDir.South] = 0; dic[SourceDir.West] = 0; foreach (Line line in _allLines) { dic[line.Dir]++; } int minCount = int.MaxValue; SourceDir minDir = SourceDir.North; foreach (KeyValuePair <SourceDir, int> kv in dic) { if (kv.Value < minCount) { minCount = kv.Value; minDir = kv.Key; } } return(minDir); }
public static float GetDirCrossWidth(SourceDir dir) { if (IsNS(dir)) { return Configs.LENGTH_WE_CROSS; } return Configs.LENGTH_NS_CROSS; }
public static float GetDirFullLength(SourceDir dir) { if (IsNS(dir)) { return Configs.LENGTH_NS_FULL; } return Configs.LENGTH_WE_FULL; }
private void button3_Click(object sender, EventArgs e) { //F5 void CopyFolder(DirectoryInfo SourceDir, DirectoryInfo DestDir) { DirectoryInfo di = new DirectoryInfo(DestDir.FullName + "\\" + SourceDir.Name); if (di.Exists == false) { di.Create(); } foreach (FileSystemInfo fsi in SourceDir.GetFileSystemInfos()) { if (fsi is DirectoryInfo) { CopyFolder(((DirectoryInfo)fsi), di); } else if (fsi is FileInfo) { ((FileInfo)fsi).CopyTo(di.FullName + "\\" + fsi.Name); } } } MooveForm mf = new MooveForm(); mf.SourceFolder = totCommPanel1.CurrentDirectory.FullName; mf.DestFolder = totCommPanel2.CurrentDirectory.FullName; if (mf.ShowDialog() != DialogResult.OK) { return; } if (totCommPanel1.CurrentDirectory.FullName == mf.DestFolder) { MessageBox.Show("Не можна копіювати директорію саму у себе!"); return; } foreach (FileSystemInfo fs in totCommPanel1.foldersFilesPanel.selectedFoldersFiles) { if (fs is DirectoryInfo) { CopyFolder((DirectoryInfo)fs, new DirectoryInfo(mf.DestFolder)); } else if (fs is FileInfo) { ((FileInfo)fs).CopyTo(mf.DestFolder + "\\" + fs.Name); } } }
public Line GenerateLineOnce(List <Line> allLines, float nowTime, SourceDir dir) { bool isOK = true; Line myLine = null; int stepSearchCount = 0; for (int genCount = 0; genCount < 1000; genCount++) { if (stepSearchCount % 10 == 0) { myLine = GetRandomLine(nowTime, genCount, dir); } else { AdjustLine(ref myLine); } stepSearchCount++; isOK = true; foreach (Line otherLine in allLines) { if (!IsCompatible(myLine, otherLine)) { isOK = false; break; } } if (isOK == true) { break; } } if (isOK) { return(myLine); } else { return(null); } }
public static bool IsWE(SourceDir dir) { return (dir == SourceDir.West) || (dir == SourceDir.East); }
public static bool IsNS(SourceDir dir) { return (dir == SourceDir.North) || (dir == SourceDir.South); }
public static bool IsOppositeSide(SourceDir myDir, SourceDir anotherDir) { int absOffset = Mathf.Abs(myDir - anotherDir); return absOffset == 2; }
public static bool IsSameSide(SourceDir myDir, SourceDir anotherDir) { int offset = myDir - anotherDir; return offset == 0; }
public static bool IsRightSide(SourceDir myDir, SourceDir anotherDir) { int offset = myDir - anotherDir; return offset == 1 || offset == -3; }
public static bool IsParallel(SourceDir myDir, SourceDir anotherDir) { int absOffset = Mathf.Abs(myDir - anotherDir); return absOffset == 0 || absOffset == 2; }
/** * Copy the contents of the given source directory to the given destination directory * */ bool CopySourceToDestDir(string InSourceDirectory, string InDestinationDirectory, string InWildCard, bool bInIncludeSubDirectories, bool bInRemoveDestinationOrphans) { if (Directory.Exists(InSourceDirectory) == false) { Log.TraceInformation("Warning: CopySourceToDestDir - SourceDirectory does not exist: {0}", InSourceDirectory); return(false); } // Make sure the destination directory exists! Directory.CreateDirectory(InDestinationDirectory); SearchOption OptionToSearch = bInIncludeSubDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var SourceDirs = new List <string>(Directory.GetDirectories(InSourceDirectory, "*.*", OptionToSearch)); foreach (string SourceDir in SourceDirs) { string SubDir = SourceDir.Replace(InSourceDirectory, ""); string DestDir = InDestinationDirectory + SubDir; Directory.CreateDirectory(DestDir); } var SourceFiles = new List <string>(Directory.GetFiles(InSourceDirectory, InWildCard, OptionToSearch)); var DestFiles = new List <string>(Directory.GetFiles(InDestinationDirectory, InWildCard, OptionToSearch)); // Keep a list of the files in the source directory... without the source path List <string> FilesInSource = new List <string>(); // Copy all the source files that are newer... foreach (string SourceFile in SourceFiles) { string Filename = SourceFile.Replace(InSourceDirectory, ""); FilesInSource.Add(Filename.ToUpperInvariant()); string DestFile = InDestinationDirectory + Filename; System.DateTime SourceTime = File.GetLastWriteTime(SourceFile); System.DateTime DestTime = File.GetLastWriteTime(DestFile); if (SourceTime > DestTime) { try { DeployHelper_DeleteFile(DestFile); File.Copy(SourceFile, DestFile, true); } catch (Exception exceptionMessage) { Log.TraceInformation("Failed to copy {0} to deployment: {1}", SourceFile, exceptionMessage); } } } if (bInRemoveDestinationOrphans == true) { // If requested, delete any destination files that do not have a corresponding // file in the source directory foreach (string DestFile in DestFiles) { string DestFilename = DestFile.Replace(InDestinationDirectory, ""); if (FilesInSource.Contains(DestFilename.ToUpperInvariant()) == false) { Log.TraceInformation("Destination file does not exist in Source - DELETING: {0}", DestFile); try { DeployHelper_DeleteFile(DestFile); } catch (Exception exceptionMessage) { Log.TraceInformation("Failed to delete {0} from deployment: {1}", DestFile, exceptionMessage); } } } } return(true); }
public void Normalize() { TargetDir = TargetDir.Trim().Trim('/', '\\').Replace('/', '\\').Trim(); SourceDir = SourceDir.Trim().Trim('/', '\\').Replace('/', '\\').Trim(); }
public void AfterStarted() { DirectoryInfo targetInfo = new DirectoryInfo(TargetDir); targetInfo.Create(); Log.Info("Saving all generated images to '" + targetInfo.FullName + "'"); String[] sources = SourceDir.Split(';'); foreach (String source in sources) { Log.Info("Scanning for office files in '" + source + "'"); DirectoryInfo di = new DirectoryInfo(source); FileInfo[] directories = di.GetFiles("*", SearchOption.AllDirectories); IdentityHashMap <IFileParser, List <FileInfo> > queuedFilesMap = new IdentityHashMap <IFileParser, List <FileInfo> >(); foreach (FileInfo sourceFile in directories) { if (sourceFile.Name.Contains('~') || !sourceFile.Exists) { continue; } String lowercaseExtensionName = sourceFile.Extension.ToLowerInvariant(); if (lowercaseExtensionName.StartsWith(".")) { lowercaseExtensionName = lowercaseExtensionName.Substring(1); } IFileParser fileParser = fileParsers.GetExtension(lowercaseExtensionName); if (fileParser == null) { Log.Debug("Skipping '" + sourceFile.FullName + "': no parser configured for '" + lowercaseExtensionName + "'"); continue; } List <FileInfo> queuedFiles = queuedFilesMap.Get(fileParser); if (queuedFiles == null) { queuedFiles = new List <FileInfo>(); queuedFilesMap.Put(fileParser, queuedFiles); } queuedFiles.Add(sourceFile); } List <Thread> threads = new List <Thread>(); CountDownLatch latch = new CountDownLatch(queuedFilesMap.Count); foreach (Entry <IFileParser, List <FileInfo> > entry in queuedFilesMap) { IFileParser fileParser = entry.Key; IList <FileInfo> sourceFiles = entry.Value; Thread thread = new Thread(new ThreadStart(delegate() { ParseFiles(fileParser, sourceFiles, targetInfo, latch); })); thread.Name = fileParser.GetType().Name; thread.IsBackground = true; threads.Add(thread); } foreach (Thread thread in threads) { thread.Start(); } latch.Await(TimeSpan.FromMinutes(5)); // throw exception after some minutes } }