public void Combine(CommitWork work) { // New objects can't possibly be in more than one UOW, // so just add all of them. foreach (KeyValuePair<Guid, byte[]> newby in work.Newbies) Newbies.Add(newby.Key, newby.Value); foreach (KeyValuePair<Guid, byte[]> dirtball in work.Dirtballs) { if (Newbies.ContainsKey(dirtball.Key)) // use the updated XML string from the dirtball if it is new Newbies[dirtball.Key] = dirtball.Value; else // otherwise the newer modifications trump the older modifications Dirtballs[dirtball.Key] = dirtball.Value; } foreach (Guid gonerId in work.Goners) { // Deleting trumps modified. Dirtballs.Remove(gonerId); // Only add it to deleted list, if it is *not* in the new list. // An object that is both new and deleted has not been saved in the store, // so no further action is needed. if (!Newbies.Remove(gonerId)) Goners.Add(gonerId); } // just use the latest list of custom fields CustomFields = work.CustomFields; }
internal static void HandleAndCommitAndPost( SubscriberMessage message, PublishersBySubscription publishersBySubscription, NotificationsByCorrelationsFunction <TUowProvider> notificationsByCorrelationsFunction, PublisherVersionByCorrelationsFunction <TUowProvider> publisherVersionByCorrelationsFunction, SaveNotificationsByPublisherAndVersionAction <TUowProvider> saveNotificationsByPublisherAndVersionAction, CommitWork <TUowProvider> commitWork, Action <IEnumerable <IDomainEvent> > publish) { var list = new List <IDomainEvent>(); commitWork(provider => { Handle( message, publishersBySubscription, notificationsByCorrelationsFunction(provider), publisherVersionByCorrelationsFunction(provider), () => DateTimeOffset.Now, saveNotificationsByPublisherAndVersionAction(provider), messages => list.AddRange(messages)); }); publish(list); }
public static void Handle <TStreamProvider, TStateProvider>( CommitWork <TStateProvider> commitState, CommitWork <TStreamProvider> commitStream, Func <TStateProvider, LastSeen> lastSeenFunction, Func <TStreamProvider, RecentNotifications> recentNotificationsFunction, IEnumerable <TypeContract> contracts, Action <IEnumerable <IDomainEvent> > publish, Func <TStateProvider, RecordLastSeen> recordLastSeenFunction) where TStreamProvider : IUowProvider where TStateProvider : IUowProvider { commitState ( stateProvider => commitStream ( streamProvider => ConsumeAndRecordLastSeen ( lastSeenFunction(stateProvider), recentNotificationsFunction(streamProvider), contracts, publish, recordLastSeenFunction(stateProvider) ) ) ); }
protected override void WriteCommitWork(CommitWork workItem) { using (m_commitLogMutex.Lock()) { base.WriteCommitWork(workItem); using (MemoryMappedViewStream stream = m_commitLogMetadata.CreateViewStream()) { CommitLogMetadata metadata = GetMetadata(stream); metadata.FileGeneration = metadata.Peers[m_peerID].Generation; SaveMetadata(stream, metadata); } } }
public void Star() { if (string.IsNullOrEmpty(PathDir)) { return; } //continuamos MakeLists(); Debug.WriteLine($"Creadas las dos listas ..."); AnalisisPaths(); //encontramos los ficheros que faltan Debug.WriteLine($"Analisis de directorios"); WorkingDatos(); //trabajos los datos. Debug.WriteLine($"Make a gif ..."); ThrowProcessMakeGif(); Debug.WriteLine($"End process ..."); OnEndThreadEvent(CommitWork.ToArray(), true); }
private void OutputBGWorker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null || e.Cancelled) { return; } MyArgument result = (MyArgument)e.Result; OutputToTextBox(result.StrArg); if (result.TypeArg == MyArgument.WorkType.COPY_CHECK && CBCopyPush.Checked == true) { if (!CommitWork.IsBusy) { OutputToTextBox("开始提交"); CommitWork.RunWorkerAsync(new MyArgument(TbPlatform.Text.Trim(), MyArgument.WorkType.COMMIT_WORK, result.StrArg2)); } else { OutputToTextBox("提交后台任务繁忙中,请等待"); } } }
internal static void HandleAndCommit( SubscriberMessage message, ProjectorsBySubscription <TProjectorUowProvider> projectorsBySubscription, Handler <TProjectorUowProvider> handler, NotificationsByCorrelationsFunction <TEventStoreUowProvider> notificationsByCorrelationsFunction, CommitWork <TProjectorUowProvider> commitProjectionProvider, CommitWork <TEventStoreUowProvider> commitEventStoreProvider, Func <DateTimeOffset> clock) { commitProjectionProvider ( projectionProvider => commitEventStoreProvider ( eventStoreProvider => handler ( message, projectorsBySubscription, notificationsByCorrelationsFunction(eventStoreProvider), clock, projectionProvider ) ) ); }
protected virtual void WriteCommitWork(CommitWork workItem) { // Check m_lastWriteTime against current mod time, // to see if anyone else modified it, while we weren't watching. // Can't lock the file, so it is possible someone could be ill-behaved and have modified it. var currentWriteTime = File.GetLastWriteTimeUtc(ProjectId.Path); if (m_lastWriteTime != currentWriteTime) { var msg = String.Format(Strings.ksFileModifiedByOther, m_lastWriteTime, currentWriteTime); ReportProblem(msg, null); return; } // use a temp file in case the write doesn't work. Want to write temp file to a local drive // if the final destination is not a fixed drive writing record by record to a remote drive // can be slow. bool fUseLocalTempFile = !IsLocalDrive(ProjectId.Path); var tempPathname = fUseLocalTempFile ? Path.GetTempFileName() : Path.ChangeExtension(ProjectId.Path, "tmp"); try { using (var writer = FdoXmlServices.CreateWriter(tempPathname)) { // Create a reader on the old version // so we can move its data to the new file. using (var reader = FdoXmlServices.CreateReader(ProjectId.Path)) { reader.MoveToContent(); var str = reader.LocalName; if (str != "languageproject") throw new ArgumentException("XML not recognized."); FdoXmlServices.WriteStartElement(writer, m_modelVersionOverride); if (workItem.CustomFields.Count > 0) { // Write out optional custom fields var customPropertyDeclarations = new XElement("AdditionalFields"); foreach (var customFieldInfo in workItem.CustomFields) { customPropertyDeclarations.Add(new XElement("CustomField", new XAttribute("name", customFieldInfo.m_fieldname), new XAttribute("class", customFieldInfo.m_classname), new XAttribute("type", GetFlidTypeAsString(customFieldInfo.m_fieldType)), (customFieldInfo.m_destinationClass != 0) ? new XAttribute("destclass", customFieldInfo.m_destinationClass.ToString()) : null, (customFieldInfo.m_fieldWs != 0) ? new XAttribute("wsSelector", customFieldInfo.m_fieldWs.ToString()) : null, (!String.IsNullOrEmpty(customFieldInfo.m_fieldHelp)) ? new XAttribute("helpString", customFieldInfo.m_fieldHelp) : null, (customFieldInfo.m_fieldListRoot != Guid.Empty) ? new XAttribute("listRoot", customFieldInfo.m_fieldListRoot.ToString()) : null, (customFieldInfo.Label != customFieldInfo.m_fieldname) ? new XAttribute("label", customFieldInfo.Label) : null)); } DataSortingService.SortCustomPropertiesRecord(customPropertyDeclarations); DataSortingService.WriteElement(writer, customPropertyDeclarations); } var sortableProperties = m_mdcInternal.GetSortableProperties(); if (reader.IsEmptyElement) { // Make sure there are no dirtballs or goners. if (workItem.Dirtballs.Count > 0) throw new InvalidOperationException("There are modified objects in a new DB system."); if (workItem.Goners.Count > 0) throw new InvalidOperationException("There are deleted objects in a new DB system."); // Add all new objects. foreach (var newbyXml in workItem.Newbies.Values) { DataSortingService.WriteElement(writer, DataSortingService.SortMainElement(sortableProperties, DataSortingService.Utf8.GetString(newbyXml))); } } else { // Copy unchanged objects to new file. // Replace modified objects with new content. // Delete goners. var keepReading = reader.Read(); while (keepReading) { // Eat optional AdditionalFields element. if (reader.LocalName == "AdditionalFields") { while (reader.LocalName != "rt" && !reader.EOF) reader.Read(); } if (reader.EOF) break; // 'rt' node is current node in reader. // Fetch Guid from 'rt' node and see if it is in either // of the modified/deleted dictionaries. var transferUntouched = true; var currentGuid = new Guid(reader.GetAttribute("guid")); // Add new items before 'currentGuid', if their guids come before 'currentGuid'. // NB: workItem.Newbies will no longer contain items returned by GetLessorNewbies. foreach (var newbieXml in DataSortingService.GetLessorNewbies(currentGuid, workItem.Newbies)) { DataSortingService.WriteElement(writer, DataSortingService.SortMainElement(sortableProperties, DataSortingService.Utf8.GetString(newbieXml))); } if (workItem.Goners.Contains(currentGuid)) { // Skip this record, since it has been deleted. keepReading = reader.ReadToNextSibling("rt"); workItem.Goners.Remove(currentGuid); transferUntouched = false; } byte[] dirtballXml; if (workItem.Dirtballs.TryGetValue(currentGuid, out dirtballXml)) { // Skip this record, since it has been modified. reader.ReadOuterXml(); //reader.Skip(); keepReading = reader.IsStartElement(); // But, add updated data for the modified record. DataSortingService.WriteElement(writer, DataSortingService.SortMainElement(sortableProperties, DataSortingService.Utf8.GetString(dirtballXml))); workItem.Dirtballs.Remove(currentGuid); transferUntouched = false; } if (!transferUntouched) continue; // Copy old data into new file, since it has not changed. writer.WriteNode(reader, true); keepReading = reader.IsStartElement(); } // Add all remaining new records to end of file, since they couldn't be added earlier. foreach (var newbieXml in workItem.Newbies.Values) { DataSortingService.WriteElement(writer, DataSortingService.SortMainElement(sortableProperties, DataSortingService.Utf8.GetString(newbieXml))); } } writer.WriteEndElement(); // 'languageproject' writer.Close(); } } } catch (Exception e) { ReportProblem(String.Format(Strings.ksCannotSave, ProjectId.Path, e.Message), tempPathname); } CopyTempFileToOriginal(fUseLocalTempFile, ProjectId.Path, tempPathname); }
protected override void WriteCommitWork(CommitWork workItem) { m_commitLogMutex.WaitOne(); try { base.WriteCommitWork(workItem); using (MemoryMappedViewStream stream = m_commitLogMetadata.CreateViewStream()) { CommitLogMetadata metadata = GetMetadata(stream); metadata.FileGeneration = metadata.Peers[m_peerID].Generation; SaveMetadata(stream, metadata); } } finally { m_commitLogMutex.ReleaseMutex(); } }