public void StateSynchronizationFinished(SynchronizationResult syncResult) { SafeCall <object>( () => { _interactionChannel.StateSynchronizationFinished(syncResult); return(null); }, _synchronizationCallProperties, null); }
public async Task UpdateLocalFromRemote() { try { await LoadStorage(); NotifySynchronizationStarted(); SynchronizationResult result = null; if (synchronizer != null) { result = await synchronizer.UpdateLocalFromRemote(plainStorage); if (result.Accounts != null) { accounts = result.Accounts.ToList(); await Persist(false); } } NotifySynchronizationCompleted(result); } catch (Exception e) { CompleteWithException(e); throw e; } }
public void Pull() { try { _logger.Info("Beginning periodic local directory refresh"); using (Session session = new Session()) { byte[] pw = new byte[Options.Password.Length]; Options.Password.CopyTo(pw, 0); ProtectedMemory.Unprotect(pw, MemoryProtectionScope.SameProcess); SessionOptions options = new SessionOptions { UserName = Options.Username, Password = Encoding.UTF8.GetString(pw), HostName = Options.Hostname, PortNumber = 443, Protocol = Protocol.Webdav, WebdavSecure = true }; session.FileTransferred += ResultHandler; session.Open(options); SynchronizationResult result = session.SynchronizeDirectories(SynchronizationMode.Local, Options.LocalDirectory, Options.RemoteDirectory, false); } } catch (SessionException e) { _logger.Debug(e.ToString()); throw; } }
public void SetUpTest() { _stepUnderTest = new ChangeDispatchingStep<LocalTestResource>(); _testActionResult = new SynchronizationResult(true); _testAction = new SynchronizationAction<LocalTestResource, string>("bogus", (resource, s) => _testActionResult, new LocalTestResource(1)); }
public string GetSynchronized(SyncParams syncParams) { string tcmURI = syncParams.Tcm; string status = string.Empty; try { if (!string.IsNullOrEmpty(tcmURI) && TcmUri.IsValid(tcmURI)) { SynchronizeOptions syncOptions = GetSyncOptions(syncParams.Flag); TcmUri uri = new TcmUri(tcmURI); switch (uri.ItemType) { case ItemType.Schema: status = SyncAllComponentsBasedOnSchema(tcmURI, uri.GetContextRepositoryUri(), syncOptions); break; case ItemType.Component: SynchronizationResult result = Client.SynchronizeWithSchemaAndUpdate(tcmURI, syncOptions); status = string.Format("Component Synchronization is successfull for Component: {0} ({1})", result.SynchronizedItem.Title, result.SynchronizedItem.Id); break; } return(status); } else { return("Component Synchronization Failed - Invalid TCM URI"); } } catch (Exception ex) { string errorMessage = "An error occured while synchronizing components. Error Message: " + ex.Message + ex.StackTrace; return(errorMessage); } }
public void SetUpTest() { _stepUnderTest = new ChangeDispatchingStep <LocalTestResource>(); _testActionResult = new SynchronizationResult(true); _testAction = new SynchronizationAction <LocalTestResource, string>("bogus", (resource, s) => _testActionResult, new LocalTestResource(1)); }
private static void ShowSynchronizationResultMessage(SynchronizationResult result) { var message = 0 == result.Errors ? "Data synchronized with success." : "Part of your work could not be synchronized to the server and is still pending."; Alert.Show("Data Synchronized", message); }
public void Abort(SynchronizationResult result) { lock (_lockObject) { if (_abortResult != SynchronizationResult.Completed) return; _abortResult = result; } }
private void NotifySynchronizationCompleted(SynchronizationResult synchronizationResult) { IsSynchronizing = false; if (SynchronizationCompleted != null) { SynchronizationCompleted(this, synchronizationResult); } }
public async Task <IActionResult> Synchronize() { await _hubContext.Clients.All.SendAsync("StartingSynchronization"); try { var allSwitches = await _nexusClient.ListDevicesAsync(); var added = 0; var existing = 0; var newSwitches = new List <SwitchViewModel>(); foreach (var entry in allSwitches) { var fqdn = $"{entry.Name}.{entry.DnsDomain}"; var match = await _dbContext.Switches.FindAsync(fqdn); if (match == null) { var newSwitch = new Switch { Fqdn = fqdn, Configured = true, DeployState = DeployState.Stationed }; var result = await _dbContext.AddAsync(newSwitch); added++; newSwitches.Add(ToViewModel(result.Entity)); } else { existing++; } } await _dbContext.SaveChangesAsync(); var synchronizationResult = new SynchronizationResult { Added = added, Existing = existing, NewSwitches = newSwitches }; await _hubContext.Clients.All.SendAsync("Synchronize", synchronizationResult); return(Ok(synchronizationResult)); } catch (Exception ex) { _logger.LogError(ex, "Failed to synchronize switches."); await _hubContext.Clients.All.SendAsync("Synchronize", null); throw; } }
public SynchronizationResult Execute() { if (_applicant == null) { throw new InvalidOperationException("Can't execute this synchronization action since there is no applicant."); } _synchronizationResult = _action(_applicant, _channelConfig); // Because the action contains state it can not be executed twice. Only other option is actually // returning a curried function from the AppliesTo. _applicant = null; return(_synchronizationResult); }
internal bool copy() { string sourcePath = txtSource.Text; string destPath = txtDest.Text; try { if (Directory.Exists(destPath) == false) { Directory.CreateDirectory(destPath); } } catch (Exception ex) { } try { // Setup session options SessionOptions sessionOptions = new SessionOptions(); //.Protocol = Protocol.Sftp sessionOptions.Protocol = Protocol.Ftp; sessionOptions.HostName = txtHost.Text; sessionOptions.UserName = txtUsername.Text; sessionOptions.Password = txtPassword.Text; //If using Protocol.Sftp: //.SshHostKeyFingerprint = "ssh-rsa 2048 93:a3:34:4c:43:dd:37:70:9e:e5:3a:dc:af:71:20:b5" using (Session session = new Session()) { // Will continuously report progress of synchronization session.FileTransferred += FileTransferred; // Connect session.Open(sessionOptions); // Synchronize files // The SynchronizationMode.Local option downloads modified files from the remote directory. SynchronizationResult synchronizationResult = default(SynchronizationResult); synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, destPath, sourcePath, false); // Throw on any error synchronizationResult.Check(); } return(true); } catch (Exception e) { txtResult.AppendText(string.Format("Error: {0}", e)); return(false); } }
public async Task Synchronize() { if (synchronizer != null) { SynchronizationResult result = await synchronizer.Synchronize(accounts); if (result.Accounts != null) { accounts = result.Accounts.ToList(); } await Persist(false); } }
public void StateSynchronizationFinished(SynchronizationResult syncResult) { Logger.LogVerbose(Message.SyncComplete, syncResult); lock (s_stateSync) { var synchronized = (syncResult == SynchronizationResult.Succeeded); foreach (var item in _stateDict) { item.Value.Synchronized = synchronized; } } lock (s_syncResultSync) { _lastSyncResult = syncResult; _synchronizationFinished.Set(); } }
private string SyncAllComponentsBasedOnSchema(string tcmURI, string pubID, SynchronizeOptions syncOptions) { string status = string.Empty; try { XElement allSchemaBasedComponent = GetAllComponentsBasedOnSchema(tcmURI, pubID); if (allSchemaBasedComponent != null) { StringBuilder success = new StringBuilder(); StringBuilder failure = new StringBuilder(); bool showFailureMessage = false; success.Append("Component Synchronization is Successful for Components: "); failure.Append("Component Synchronization is Failed for Components: "); for (IEnumerator <XElement> e = allSchemaBasedComponent.Descendants().GetEnumerator(); e.MoveNext();) { string comp_tcmURI = e.Current.Attribute(XName.Get("ID")).Value; try { SynchronizationResult result = Client.SynchronizeWithSchemaAndUpdate(comp_tcmURI, syncOptions); success.Append(string.Format("{0} ({1}){2}", result.SynchronizedItem.Title, result.SynchronizedItem.Id, " , ")); } catch (Exception ex) { showFailureMessage = true; failure.Append(string.Format("{0}{1}", comp_tcmURI, " , ")); } } status = showFailureMessage ? string.Concat(success.ToString().TrimEnd(','), failure.ToString().TrimEnd(',')) : success.ToString().TrimEnd(','); } else { status = "No component to synchronize"; } } catch (Exception ex) { status += "An error has occured while synchronizing components based on Schema - " + tcmURI + ex.Message + ex.StackTrace; } return(status); }
private async void SynchronizationCompleted(object sender, SynchronizationResult e) { if (e.HasChanges) { await LoadAccounts(); } else if (!e.Successful) { RevertAndReload(); } Edit.IsEnabled = true; ToggleCodesEnabled(true); ButtonUndo.IsEnabled = true; Synchronize.StopAnimationAndEnable(); firstLoad = false; }
private async Task UpdateRemoteFromLocal() { try { if (synchronizer != null) { NotifySynchronizationStarted(); SynchronizationResult result = await synchronizer.UpdateRemoteFromLocal(plainStorage, accounts); NotifySynchronizationCompleted(result); } } catch (Exception e) { CompleteWithException(e); throw e; } }
private static void WriteResult(SynchronizationResult result) { result.Check(); Console.WriteLine("Failures: " + result.Failures.Count); if (result.Failures.Count != 0) { foreach (SessionRemoteException item in result.Failures) { Console.WriteLine("\t" + item.Message); } } Console.WriteLine("Downloads: " + result.Downloads.Count); if (result.Downloads.Count != 0) { foreach (TransferEventArgs item in result.Downloads) { Console.WriteLine("\t" + item.FileName); } } Console.WriteLine("Uploads: " + result.Uploads.Count); if (result.Uploads.Count != 0) { foreach (TransferEventArgs item in result.Uploads) { Console.WriteLine("\t" + item.FileName); } } Console.WriteLine("Removals: " + result.Removals.Count); if (result.Removals.Count != 0) { foreach (RemovalEventArgs item in result.Removals) { Console.WriteLine("\t" + item.FileName); } } Console.WriteLine("IsSuccess: " + result.IsSuccess); }
public ContentResult Index(SynchronizationSettings settings) { var leftPair = ProviderPairFactory.CreateProviderPair(settings.LeftProviderPairName); var rightPair = ProviderPairFactory.CreateProviderPair(settings.RightProviderPairName); var leftValues = leftPair.ValueManager.GetAllValuesQualified().ToDictionary(qv => qv.Qualifier); var rightValues = rightPair.ValueManager.GetAllValuesQualified().ToDictionary(qv => qv.Qualifier); var leftNotRight = leftValues.Where(lv => !rightValues.ContainsKey(lv.Key)).Select(lv => lv.Value).ToArray(); var rightNotLeft = rightValues.Where(rv => !leftValues.ContainsKey(rv.Key)).Select(rv => rv.Value).ToArray(); var valueDifferences = leftValues.Values .Join(rightValues.Values, v => v.Qualifier, v => v.Qualifier, (lv, rv) => new SynchronizationData.DoubleQualifiedValue(lv, rv)) .Where(dv => !Equals(dv.Left.Value, dv.Right.Value)) .ToArray(); var leftAudits = leftPair.ValueManager.GetAudits().ToDictionary(a => a.Qualifier); var rightAudits = rightPair.ValueManager.GetAudits().ToDictionary(a => a.Qualifier); var synchronizationResult = new SynchronizationResult(); foreach (var missingRight in leftNotRight) { switch (settings.RightMissingStrategy) { case SynchronizationSettings.MissingResolutionStrategy.Audit: if (!rightAudits.ContainsKey(missingRight.Qualifier)) { Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; } var rightAudit = rightAudits[missingRight.Qualifier]; var leftAudit = leftAudits[missingRight.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if (leftAudit.LatestUpdate > rightAudit.LatestUpdate) { Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); } else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) { Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); } else { synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); } break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.CopyNew: Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.DeleteExisting: Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(leftPair.Name, missingRight.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); break; } } foreach (var missingLeft in rightNotLeft) { switch (settings.LeftMissingStrategy) { case SynchronizationSettings.MissingResolutionStrategy.Audit: if (!leftAudits.ContainsKey(missingLeft.Qualifier)) { Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; } var rightAudit = rightAudits[missingLeft.Qualifier]; var leftAudit = leftAudits[missingLeft.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if (leftAudit.LatestUpdate > rightAudit.LatestUpdate) { Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); } else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) { Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); } else { synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingLeft.Qualifier.ToString())); } break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingLeft.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.CopyNew: Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.DeleteExisting: Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(rightPair.Name, missingLeft.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name, missingLeft.Qualifier.ToString())); break; } } foreach (var difference in valueDifferences) { switch (settings.DifferingStrategy) { case SynchronizationSettings.DifferingResolutionStrategy.Audit: var rightAudit = rightAudits[difference.Right.Qualifier]; var leftAudit = leftAudits[difference.Left.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if (leftAudit.LatestUpdate > rightAudit.LatestUpdate) { UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); } else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) { UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); } else { synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); } break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; case SynchronizationSettings.DifferingResolutionStrategy.UseLeft: UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); break; case SynchronizationSettings.DifferingResolutionStrategy.UseRight: UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); break; case SynchronizationSettings.DifferingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; case SynchronizationSettings.DifferingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; } } if (settings.Execute) { foreach (var audit in leftAudits.Where(audit => !rightAudits.ContainsKey(audit.Key))) { rightAudits.Add(audit.Key, audit.Value); } foreach (var audit in rightAudits.Where(audit => !leftAudits.ContainsKey(audit.Key))) { leftAudits.Add(audit.Key, audit.Value); } leftPair.ValueManager.SetAudits(leftAudits.Values); rightPair.ValueManager.SetAudits(rightAudits.Values); } return(Content(JsonConvert.SerializeObject(synchronizationResult), "application/json", Encoding.UTF8)); }
/// <summary> /// Performs the syncronization (uploading and downloading) of directories (local and ftp) based on InputParameters set /// </summary> /// <param name="Parameters">Holds the properties needed for the synchronization</param> /// <returns>0 if successfull, 1 if error</returns> public int SynchronizeDirectories(InputParameters Parameters) { // Setup Event Log EventLogging.AppEventLog.Source = Parameters.AppLogSourceName; EventLogging.AppLoggingEventId = Parameters.AppLoggingEventId; EventLogging.AppLoggingCategory = Parameters.AppLoggingCategory; // Check if Downloading or Uploading bool IsDownloading = Parameters.UsedForDownloading.Equals("TRUE") ? true : false; // Check if to delete file afterwards bool DeleteFiles = Parameters.DeleteFiles.Equals("TRUE") ? true : false; string ActionVerb = IsDownloading ? "Downloading" : "Uploading"; SynchronizationMode SyncMode = IsDownloading ? SynchronizationMode.Local : SynchronizationMode.Remote; // Setup session options SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = Parameters.HostName, UserName = Parameters.UserName, SshHostKeyFingerprint = Parameters.SshHostKeyFingerprint, SshPrivateKeyPath = Parameters.SshPrivateKeyPath }; StringBuilder messages = new StringBuilder(); string message = ""; try { using (Session session = new Session()) { string FTPFolder = Parameters.FTPDownloadFolder; string LocalPath = Parameters.LocalDestinationPath; bool FoundFilesToSync = false; EventLogging.WriteEntry("Before Connecting for " + ActionVerb + " - " + sessionOptions.HostName + " : " + sessionOptions.UserName, EventLogEntryType.Information); // Connect session.Open(sessionOptions); message = "Connected for " + ActionVerb + " from " + (IsDownloading ? "FTP Folder " + FTPFolder + " to Local Folder " + LocalPath : "Local Folder " + LocalPath + " to FTP Folder " + FTPFolder); EventLogging.WriteEntry(message, EventLogEntryType.Information); // Will continuously report progress of synchronization session.FileTransferred += FileTransferred; // Synchronize Directories SynchronizationResult synchronizationResult = session.SynchronizeDirectories(SyncMode, LocalPath, FTPFolder, DeleteFiles); // Throw on any error synchronizationResult.Check(); // Check if downloaded anything and delete remote file foreach (TransferEventArgs Download in synchronizationResult.Downloads) { FoundFilesToSync = true; // log successfull message message = "Success in " + ActionVerb + " file '" + Download.FileName + "' to Local Folder " + Download.Destination; EventLogging.WriteEntry(message, EventLogEntryType.SuccessAudit); // remember messages for email sending messages.AppendLine(message); // delete remote file if (DeleteFiles) { session.RemoveFiles(Download.FileName); message = "Success in deleting remote file '" + Download.FileName + "'"; EventLogging.WriteEntry(message, EventLogEntryType.SuccessAudit); messages.AppendLine(message); } } // Check if uploaded anything and delete local file foreach (TransferEventArgs Upload in synchronizationResult.Uploads) { FoundFilesToSync = true; // log successfull message message = "Success in " + ActionVerb + " file '" + Upload.FileName + "' to FTP folder " + Upload.Destination; EventLogging.WriteEntry(message, EventLogEntryType.SuccessAudit); // remember messages for email sending messages.AppendLine(message); // delete local file if (DeleteFiles && File.Exists(Upload.FileName)) { File.Delete(Upload.FileName); message = "Success in deleting local file '" + Upload.FileName + "'"; EventLogging.WriteEntry(message, EventLogEntryType.SuccessAudit); messages.AppendLine(message); } } // Send Email if (FoundFilesToSync) { SendEmail.Send(true, Parameters, messages); } else { // nothing different found message = "No files found for " + ActionVerb; EventLogging.WriteEntry(message, EventLogEntryType.SuccessAudit); } } return(0); } catch (Exception e) { // log Error message message = "Error in " + ActionVerb + " : " + e.ToString(); EventLogging.WriteEntry(message, EventLogEntryType.Error); messages.AppendLine(message); SendEmail.Send(false, Parameters, messages); return(1); } }
public SynchronizationCompletingEventArgs(SynchronizationResult result, Exception exception = null) { Result = result; Exception = exception; }
private void Create(bool execute, ProviderPair targetPair, Dictionary <Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary <Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue sourceQualifiedValue, SynchronizationResult result) { if (execute) { if (sourceAudits.ContainsKey(sourceQualifiedValue.Qualifier)) { targetAudits[sourceQualifiedValue.Qualifier] = sourceAudits[sourceQualifiedValue.Qualifier]; } targetPair.ValueManager.CreateValue(sourceQualifiedValue.Qualifier, sourceQualifiedValue.Value); } result.Created.Add(new Creation(targetPair.Name, sourceQualifiedValue.Qualifier.ToString(), sourceQualifiedValue.Value)); }
private void Reset() { _abortResult = SynchronizationResult.Completed; Completed = false; }
private void sync_Click(object sender, EventArgs e) { try { bool uploaded = false; MySqlConnection conn = makeConnection(); string checkSyncQuery = "SELECT notificationType FROM webEditUsers WHERE teamName = '" + teamname + "'"; MySqlCommand checkSync = new MySqlCommand(checkSyncQuery, conn); string notiTypes = checkSync.ExecuteScalar().ToString(); string[] notiTypeSplit = notiTypes.Split(new string[] { ", " }, StringSplitOptions.None); foreach (string notiType in notiTypeSplit) { if (notiType == "newUpload") { uploaded = true; } } if (uploaded == false) { using (Session session = new Session()) { // Connect to FTP session.Open(SO()); //set transfer options i.e. whether imgaes/text files/both TransferOptions TO = new TransferOptions(); TO.TransferMode = TransferMode.Automatic; //remote directories string remotePath1 = teamname + "1"; string remotePath2 = teamname + "2"; string remotePath3 = teamname + "3"; string remotePath4 = teamname + "4"; string remotePath5 = teamname + "5"; //adding lables so user can see their website online Label l1 = new Label(); l1.Text = "You can see the website here: "; l1.Size = new Size(186, 13); l1.Location = new Point(60, 190); this.Controls.Add(l1); LinkLabel ll1 = new LinkLabel(); url = "http://webedit.heliohost.org/webEditTeams/" + teamname + "/" + remotePath1; ll1.Text = "Click Here"; ll1.Location = new Point(240, 190); ll1.LinkClicked += Ll1_LinkClicked; this.Controls.Add(ll1); bool synced = false; string[] uploadedFiles = new string[] { }; string[] downloadedFiles = new string[] { }; if (session.FileExists(teamname)) { Console.WriteLine("Folder found"); //for testing //checks for each directory on the server if it isn't there it creates it if (session.FileExists(teamname + @"/" + remotePath1 + @"/")) { if (session.FileExists(teamname + @"/" + remotePath2)) { if (session.FileExists(teamname + @"/" + remotePath3)) { if (session.FileExists(teamname + @"/" + remotePath4)) { session.MoveFile(teamname + @"/" + remotePath4, teamname + @"/" + remotePath5); session.MoveFile(teamname + @"/" + remotePath3, teamname + @"/" + remotePath4); session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath3); session.MoveFile(teamname + @"/" + remotePath1, teamname + @"/" + remotePath2); session.CreateDirectory(teamname + @"/" + remotePath1); } else { session.MoveFile(teamname + @"/" + remotePath3, teamname + @"/" + remotePath4); session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath3); session.MoveFile(teamname + @"/" + remotePath1, teamname + @"/" + remotePath2); session.CreateDirectory(teamname + @"/" + remotePath1); } } else { session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath3); session.MoveFile(teamname + @"/" + remotePath1, teamname + @"/" + remotePath2); session.CreateDirectory(teamname + @"/" + remotePath1); } } else { session.MoveFile(teamname + @"/" + remotePath1, teamname + @"/" + remotePath2); } Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\tempUpl"); session.GetFiles(teamname + @"/" + remotePath2, AppDomain.CurrentDomain.BaseDirectory + @"\tempUpl"); session.PutFiles(AppDomain.CurrentDomain.BaseDirectory + @"\tempUpl", teamname + @"/" + remotePath1); deleteDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\tempUpl"); SynchronizationResult SR = session.SynchronizeDirectories(SynchronizationMode.Both, projectPath, teamname + @"/" + remotePath1, false); TransferEventArgsCollection uploads = SR.Uploads; TransferEventArgsCollection downloads = SR.Downloads; synced = SR.IsSuccess; for (int i = 0; i < uploads.Count; i++) { uploadedFiles = new string[] { uploads[i].FileName }; } for (int j = 0; j < downloads.Count; j++) { downloadedFiles = new string[] { downloads[j].FileName }; } if (uploadedFiles.Length == 0) { if (session.FileExists(teamname + @"/" + remotePath2)) { if (session.FileExists(teamname + @"/" + remotePath3)) { if (session.FileExists(teamname + @"/" + remotePath4)) { session.RemoveFiles(teamname + @"/" + remotePath1); session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath1); session.MoveFile(teamname + @"/" + remotePath3, teamname + @"/" + remotePath2); session.MoveFile(teamname + @"/" + remotePath4, teamname + @"/" + remotePath3); } else { session.RemoveFiles(teamname + @"/" + remotePath1); session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath1); session.MoveFile(teamname + @"/" + remotePath3, teamname + @"/" + remotePath2); } } else { session.RemoveFiles(teamname + @"/" + remotePath1); session.MoveFile(teamname + @"/" + remotePath2, teamname + @"/" + remotePath1); } } else { Console.WriteLine("Something went wrong"); } } } else { session.CreateDirectory(teamname + @"/" + remotePath1); SynchronizationResult SR = session.SynchronizeDirectories(SynchronizationMode.Both, projectPath, teamname + @"/" + remotePath1, false); TransferEventArgsCollection uploads = SR.Uploads; TransferEventArgsCollection downloads = SR.Downloads; synced = SR.IsSuccess; for (int i = 0; i < uploads.Count; i++) { uploadedFiles = new string[] { uploads[i].FileName }; } for (int j = 0; j < downloads.Count; j++) { downloadedFiles = new string[] { downloads[j].FileName }; } } } else { //Console.WriteLine("Folder not found"); //for testing session.CreateDirectory(teamname); session.CreateDirectory(teamname + @"/" + remotePath1); } // if synced if (synced && (uploadedFiles.Length != 0 || downloadedFiles.Length != 0)) { MessageBox.Show("Synced files with the server"); //MessageBox.Show(uploadedFiles.ToString(), "Uploaded Files"); } else { MessageBox.Show("Something went wrong or no files to upload or download"); } string notiFiles = ""; foreach (string file in uploadedFiles) { notiFiles = file + "; "; Console.WriteLine(notiFiles); } try { string getTeamCodeQuery = @"SELECT teamCode FROM webEditUsers WHERE teamName = '" + teamname + "' AND NOT username = '******' LIMIT 1"; MySqlCommand getTeamCode = new MySqlCommand(getTeamCodeQuery, conn); string teamCode = getTeamCode.ExecuteScalar().ToString(); //checks if users in team to connect to have notifications that have not been seen string checkNotiTypeQuery = "SELECT COUNT(*) FROM `webEditUsers` WHERE teamCode='" + teamCode + "' AND `notificationType` IS NULL"; MySqlCommand checkNotiType = new MySqlCommand(checkNotiTypeQuery, conn); string checkNotiTypeResult = checkNotiType.ExecuteScalar().ToString(); if (checkNotiTypeResult != "0") { //if not just set as normal string updateNotiQuery = "UPDATE webEditUsers SET notificationType = 'newUpload', notification='" + user + " updated these files: " + Path.GetFileName(notiFiles) + "' WHERE teamCode='" + teamCode + "' AND NOT usernane ='" + user + ""; MySqlCommand updateNoti = new MySqlCommand(updateNotiQuery, conn); updateNoti.ExecuteNonQuery(); } else { //if so add new after previous with [,] as the definer to make easier later to get the notifications string updateNotiQuery = "UPDATE webEditUsers SET notificationType = concat(notificationType, ', newUpload'), notification = concat(notification, ', " + user + " updated these files: " + Path.GetFileName(notiFiles) + "') WHERE teamCode='" + teamCode + "'" + user + ""; MySqlCommand updateNoti = new MySqlCommand(updateNotiQuery, conn); updateNoti.ExecuteNonQuery(); } } catch (Exception) { MessageBox.Show("Make sure that there is more than one member in the team and if there is please contact the developer for issues", "Needs more than one team member"); } } } else { MessageBox.Show("A user has already made changes to the project. See the changes and accept or reject the changes to upload again", "A user already made changes"); } } catch (Exception ex) { MessageBox.Show(@"Make sure you have a working internet connection. If you do then please contact the developer for issues.", "Cannot sync with the team"); MessageBox.Show(ex.ToString()); } }
/// <summary> /// Run the upload /// </summary> /// <returns>Wheter or not the upload is successfull</returns> public static bool RunUpload(ConfigManager.BaseConfig baseConfig) { // Check file if (!baseConfig.IsValid()) { Console.WriteLine("Invalid config : " + baseConfig); return(false); } // Run each config try { SessionOptions sessionOptions = null; // Used to declare local variables that will die once if exitted if (true) { string hostKey = baseConfig.HostKeyPath; if (File.Exists(hostKey)) { hostKey = File.ReadAllText(hostKey); } sessionOptions = new SessionOptions() { Protocol = Protocol.Sftp, HostName = baseConfig.Hostname, UserName = baseConfig.Username, SshHostKeyFingerprint = hostKey, SshPrivateKeyPath = baseConfig.PrivateKeyPath, PrivateKeyPassphrase = baseConfig.Passphrase, PortNumber = baseConfig.Port, FtpMode = baseConfig.FtpMode, }; } // Open new session using (Session session = new Session()) { // Enable log string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "sftp_upload_log"); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } //session.SessionLogPath = (Path.Combine(logPath, "sessionLog.txt")); session.DebugLogPath = (Path.Combine(logPath, "debugLog.txt")); session.DebugLogLevel = -1; // Connect session.Open(sessionOptions); // Sort configs Array.Sort(baseConfig.Configs); foreach (ConfigManager.BaseConfig.Config config in baseConfig.Configs) { Console.WriteLine($"[{DateTime.Now.ToString("yyyy.MM.dd hh.mm.ss")}] Starting new upload"); if (config.SyncModeEnabled) { Console.WriteLine($"Synchronize local {config.LocalPath} to remote {config.RemotePath}"); } else { Console.WriteLine($"Upload local {config.LocalPath} to remote {config.RemotePath}"); } if (config.FileMask != string.Empty) { Console.WriteLine("With file mask : \"" + config.FileMask + "\""); } else { Console.WriteLine("Without file mask"); } if (!config.Enabled) { Console.WriteLine("Config disabled"); continue; } if (!config.IsValid()) { Console.WriteLine("Invalid config"); continue; } // Upload files TransferOptions transferOptions = new TransferOptions { TransferMode = config.TransferMode, FileMask = config.FileMask, }; if (config.SyncModeEnabled) { // Synchronise SynchronizationResult syncResult = session.SynchronizeDirectories(mode: config.SyncMode, localPath: config.LocalPath, remotePath: config.RemotePath, removeFiles: config.RemoveFiles, mirror: config.Mirror, criteria: config.SyncCriteria, options: transferOptions); WriteResult(syncResult); } else { // Upload TransferOperationResult transfResult = session.PutFiles(localPath: config.LocalPath, remotePath: config.RemotePath, remove: config.RemoveFiles, options: transferOptions); WriteResult(transfResult); } } // Session is automatically closed with the using keyword } Console.WriteLine($"[{DateTime.Now.ToString("yyyy.MM.dd hh.mm.ss")}] Upload success"); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(ex); return(false); } return(true); }
public ContentResult Index(SynchronizationSettings settings) { var leftPair = ProviderPairFactory.CreateProviderPair(settings.LeftProviderPairName); var rightPair = ProviderPairFactory.CreateProviderPair(settings.RightProviderPairName); var leftValues = leftPair.ValueManager.GetAllValuesQualified().ToDictionary(qv => qv.Qualifier); var rightValues = rightPair.ValueManager.GetAllValuesQualified().ToDictionary(qv => qv.Qualifier); var leftNotRight = leftValues.Where(lv => !rightValues.ContainsKey(lv.Key)).Select(lv => lv.Value).ToArray(); var rightNotLeft = rightValues.Where(rv => !leftValues.ContainsKey(rv.Key)).Select(rv => rv.Value).ToArray(); var valueDifferences = leftValues.Values .Join(rightValues.Values, v => v.Qualifier, v => v.Qualifier, (lv, rv) => new SynchronizationData.DoubleQualifiedValue(lv, rv)) .Where(dv => !Equals(dv.Left.Value, dv.Right.Value)) .ToArray(); var leftAudits = leftPair.ValueManager.GetAudits().ToDictionary(a => a.Qualifier); var rightAudits = rightPair.ValueManager.GetAudits().ToDictionary(a => a.Qualifier); var synchronizationResult = new SynchronizationResult(); foreach (var missingRight in leftNotRight) { switch (settings.RightMissingStrategy) { case SynchronizationSettings.MissingResolutionStrategy.Audit: if (!rightAudits.ContainsKey(missingRight.Qualifier)) { Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; } var rightAudit = rightAudits[missingRight.Qualifier]; var leftAudit = leftAudits[missingRight.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if(leftAudit.LatestUpdate > rightAudit.LatestUpdate) Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); else synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.CopyNew: Create(settings.Execute, rightPair, leftAudits, rightAudits, missingRight, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.DeleteExisting: Delete(settings.Execute, leftPair, rightAudits, leftAudits, missingRight, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(leftPair.Name, missingRight.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingRight.Qualifier.ToString())); break; } } foreach (var missingLeft in rightNotLeft) { switch (settings.LeftMissingStrategy) { case SynchronizationSettings.MissingResolutionStrategy.Audit: if (!leftAudits.ContainsKey(missingLeft.Qualifier)) { Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; } var rightAudit = rightAudits[missingLeft.Qualifier]; var leftAudit = leftAudits[missingLeft.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if (leftAudit.LatestUpdate > rightAudit.LatestUpdate) Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); else synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingLeft.Qualifier.ToString())); break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(leftPair.Name, missingLeft.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.CopyNew: Create(settings.Execute, leftPair, rightAudits, leftAudits, missingLeft, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.DeleteExisting: Delete(settings.Execute, rightPair, leftAudits, rightAudits, missingLeft, synchronizationResult); break; case SynchronizationSettings.MissingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(rightPair.Name, missingLeft.Qualifier.ToString())); break; case SynchronizationSettings.MissingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name, missingLeft.Qualifier.ToString())); break; } } foreach (var difference in valueDifferences) { switch (settings.DifferingStrategy) { case SynchronizationSettings.DifferingResolutionStrategy.Audit: var rightAudit = rightAudits[difference.Right.Qualifier]; var leftAudit = leftAudits[difference.Left.Qualifier]; if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash && leftAudit.PreviousValueHash == rightAudit.LatestValueHash) { if (leftAudit.LatestUpdate > rightAudit.LatestUpdate) UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); else if (leftAudit.LatestUpdate < rightAudit.LatestUpdate) UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); else synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; } if (leftAudit.LatestValueHash == rightAudit.PreviousValueHash) { UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); break; } if (rightAudit.LatestValueHash == leftAudit.PreviousValueHash) { UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); break; } synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; case SynchronizationSettings.DifferingResolutionStrategy.UseLeft: UpdateCreate(settings.Execute, rightPair, leftAudits, rightAudits, difference.Left, difference.Right.Value, synchronizationResult); break; case SynchronizationSettings.DifferingResolutionStrategy.UseRight: UpdateCreate(settings.Execute, leftPair, rightAudits, leftAudits, difference.Right, difference.Left.Value, synchronizationResult); break; case SynchronizationSettings.DifferingResolutionStrategy.Ignore: synchronizationResult.Ignored.Add(new Ignore(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; case SynchronizationSettings.DifferingResolutionStrategy.ShowConflict: synchronizationResult.Unresolved.Add(new Conflict(rightPair.Name + " <> " + leftPair.Name, difference.Left.Qualifier.ToString())); break; } } if (settings.Execute) { foreach (var audit in leftAudits.Where(audit => !rightAudits.ContainsKey(audit.Key))) rightAudits.Add(audit.Key, audit.Value); foreach (var audit in rightAudits.Where(audit => !leftAudits.ContainsKey(audit.Key))) leftAudits.Add(audit.Key, audit.Value); leftPair.ValueManager.SetAudits(leftAudits.Values); rightPair.ValueManager.SetAudits(rightAudits.Values); } return Content(JsonConvert.SerializeObject(synchronizationResult), "application/json", Encoding.UTF8); }
private void UpdateCreate(bool execute, ProviderPair targetPair, Dictionary<Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary<Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue sourceQualifiedValue, String targetOldValue, SynchronizationResult result) { if (execute) { if (sourceAudits.ContainsKey(sourceQualifiedValue.Qualifier)) targetAudits[sourceQualifiedValue.Qualifier] = sourceAudits[sourceQualifiedValue.Qualifier]; targetPair.ValueManager.UpdateCreateValue(new QualifiedValue(sourceQualifiedValue.Qualifier, sourceQualifiedValue.Value)); } result.Updated.Add(new Update(targetPair.Name, sourceQualifiedValue.Qualifier.ToString(), targetOldValue, sourceQualifiedValue.Value)); }
private void Delete(bool execute, ProviderPair targetPair, Dictionary<Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary<Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue targetQualifiedValue, SynchronizationResult result) { if (execute) { if (sourceAudits.ContainsKey(targetQualifiedValue.Qualifier)) targetAudits[targetQualifiedValue.Qualifier] = sourceAudits[targetQualifiedValue.Qualifier]; targetPair.ValueManager.DeleteValue(targetQualifiedValue.Qualifier); } result.Removed.Add(new Removal(targetPair.Name, targetQualifiedValue.Qualifier.ToString(), targetQualifiedValue.Value)); }
public void StateSynchronizationFinished(SynchronizationResult syncResult) { _localScannerChannel.StateSynchronizationFinished(syncResult); }
private void SynchronizeModToLocal() { try { using (Session session = new Session()) { // Will continuously report progress of synchronization session.FileTransferred += FileTransferred; // Will continuously report progress of transfer session.FileTransferProgress += SessionFileTransferProgress; //string fp = "ssh-rsa 2048 iGUY6ftkfgyHQ+Qcz1ntutaiSed8CETlcVb6elUO/Zk=."; //string fingerprint = session.ScanFingerprint(sessionOptions, "ssh-rsa"); //sessionOptions.SshHostKeyFingerprint = fp; // Connect session.Open(_sessionOptions); if (!session.FileExists(_remoteModPath)) { MessageBox.Show(string.Format("The mod [{0}] doesn't exist in the remote repository [{1}].", Mod.Name, Settings.Default.RepositoryStoragePath)); return; } if (!Directory.Exists(_localModPath)) { Directory.CreateDirectory(_localModPath); } RemoteDirectoryInfo remoteDirectoryInfo = session.ListDirectory(_remoteModPath); _countFilesToSynchronize = remoteDirectoryInfo.Files.Count; SynchronizationResult synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, _localModPath, _remoteModPath, true); // Throw on any error synchronizationResult.Check(); StringBuilder failedFiles = new StringBuilder(); foreach (TransferEventArgs failedFile in synchronizationResult.Failures) { failedFiles.AppendLine(string.Format("{0}", failedFile.FileName)); } if (failedFiles.Length > 0) { MessageBox.Show(failedFiles.ToString(), "Error downloading files."); } if (synchronizationResult.IsSuccess) { Dispatcher.Invoke(new Action(() => { overallPercentage.Content = string.Format("{0:P0}", 1); overallProgress.Value = 100; statusText.Text = "Operation succeeded."; string modName = Path.GetFileName(_localModPath); Mod synchedMod = ModUtility.LoadFile(Path.Combine(_localModPath, string.Format("{0}.json", modName))); foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(MainWindow)) { (window as MainWindow).Mod = synchedMod; (window as MainWindow).BindObject(); } } })); } } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } }
private void Delete(bool execute, ProviderPair targetPair, Dictionary <Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary <Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue targetQualifiedValue, SynchronizationResult result) { if (execute) { if (sourceAudits.ContainsKey(targetQualifiedValue.Qualifier)) { targetAudits[targetQualifiedValue.Qualifier] = sourceAudits[targetQualifiedValue.Qualifier]; } targetPair.ValueManager.DeleteValue(targetQualifiedValue.Qualifier); } result.Removed.Add(new Removal(targetPair.Name, targetQualifiedValue.Qualifier.ToString(), targetQualifiedValue.Value)); }
private async Task <DataSet> CheckAsync <TData>(DataSet arg, Func <DateTime, CancellationToken, Task <IEnumerable <TData> > > check, ILogger logger = null, [CallerMemberName] string caller = "") { if (arg == null || arg.Tables == null || arg.Tables.Count == 0 || arg.Tables[0].Rows.Count == 0) { throw new ArgumentException("arg"); } SynchronizationResult <TData> result = null; var ds = new DataSet(); try { var sessionKey = string.Empty; DateTime updateAt; var row = arg ?.Tables.Cast <DataTable>().FirstOrDefault() ?.AsEnumerable().FirstOrDefault(); sessionKey = row.Field <string>("SessionKey"); updateAt = row.Field <DateTime>("UpdateAt"); result = await authorizationProcessor.DoAuthorizeAsync(sessionKey, async token => { TData[] data = (await check(updateAt, token)).ToArray(); var list = (data == null) ? null : new List <TData>(data); return(new SynchronizationResult <TData> { Synchronizations = list, ProcessResult = new ProcessResult { Result = true }, }); }, logger, null, caller); } catch (Exception ex) { result = new SynchronizationResult <TData> { ProcessResult = new ProcessResult { ErrorCode = Rac.VOne.Common.ErrorCode.ExceptionOccured, ErrorMessage = ex.Message } }; //ログ出力 } ds.Tables.Add((new List <ProcessResult> { result.ProcessResult }).ToDataTable()); //ds.Tables.Add(result.Synchronizations).ToDataTable()); if (result.Synchronizations != null) { ds.Tables.Add(result.Synchronizations.ToDataTable("Synchronization")); } return(ds); }
public void StateSynchronizationFinished(SynchronizationResult syncResult) { Logger.LogVerbose(Message.SyncComplete, syncResult); lock (s_stateSync) { var synchronized = (syncResult == SynchronizationResult.Succeeded); foreach (var item in _stateDict) item.Value.Synchronized = synchronized; } lock (s_syncResultSync) { _lastSyncResult = syncResult; _synchronizationFinished.Set(); } }