public void AddEgg(Egg ou) { eggs.Add(ou); }
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); }