public Stream GetLastest(SourceKey sourceKey) { if (!_persistent) return null; var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); var task = Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { return context.CreateQuery<Snapshot>() .Where(p => p.AggregateRootId == sourceKey.SourceId && p.AggregateRootTypeCode == aggregateRootTypeCode) .FirstOrDefault(); } }); task.Wait(); var snapshot = task.Result; if (snapshot == null) return null; return new Stream { Key = sourceKey, Payload = snapshot.Data, Version = snapshot.Version }; }
/// <summary> /// Allocate and load an image from the specified file. /// </summary> /// <param name="fileName">Name of image file</param> /// <param name="transparent">True if the image should have /// transparency</param> public DirectXBitmap(string fileName, Device dev, bool transparent) { Bitmap bmp = new Bitmap(fileName); widthValue = bmp.Width; heightValue = bmp.Height; if (transparent) { sourceKey = bmp.GetPixel(0, 0); } transparentValue = transparent; bmp.Dispose(); bmp = null; #if DESKTOP Format format = Format.A8R8G8B8; Pool pool = Pool.Default; #else Format format = Format.A1R5G5B5; Pool pool = Pool.VideoMemory; #endif tex = TextureLoader.FromFile(dev, fileName, Width, Height, 1, Usage.None, format, pool, Filter.Linear, Filter.None, SourceKey.ToArgb()); }
public void Save(SourceKey sourceKey, string correlationId, IEnumerable<Stream> events) { Ensure.NotNullOrWhiteSpace(correlationId, "correlationId"); var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); var datas = events.Select(item => new Event { AggregateRootId = sourceKey.SourceId, AggregateRootTypeCode = aggregateRootTypeCode, AggregateRootTypeName = string.Concat(aggregateRootTypeName, ", ", sourceKey.AssemblyName), Version = item.Version, CorrelationId = correlationId, Payload = item.Payload, AssemblyName = item.Key.AssemblyName, Namespace = item.Key.Namespace, TypeName = item.Key.TypeName, EventId = item.Key.SourceId, Timestamp = DateTime.UtcNow }).AsEnumerable(); Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { datas.ForEach(context.Save); context.Commit(); } }).Wait(); }
public bool Release() { if (State != RendererDataState.Compiled) { return(false); } Debug.Assert(_shader is not null); Debug.Assert(_vertexType is not null); var key = new SourceKey(_shader, _vertexType); var screen = Engine.GetValidCurrentContext(); CompiledProgramCacheStore.Delete(screen, key, ref _program); try { _shader.InvokeOnProgramDisposed(); } catch { if (EngineSetting.UserCodeExceptionCatchMode == UserCodeExceptionCatchMode.Throw) { throw; } // ignore exceptions in user code. } Debug.Assert(State != RendererDataState.Compiled); return(true); }
IEnumerable<Stream> IEventStore.FindAll(SourceKey sourceKey, int version) { var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); var task = Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { var events = context.CreateQuery<Event>() .Where(p => p.AggregateRootId == sourceKey.SourceId && p.AggregateRootTypeCode == aggregateRootTypeCode && p.Version > version) .OrderBy(p => p.Version) .ToList(); return events.Select(item => new Stream { Key = new SourceKey(item.EventId, item.Namespace, item.TypeName, item.AssemblyName), Version = item.Version, Payload = item.Payload }).AsEnumerable(); } }); task.Wait(); return task.Result; }
///// <summary> ///// 删除该聚合根下的溯源事件 ///// </summary> //public void Delete(IEventSourced aggregateRoot) //{ // this.Delete(aggregateRoot.GetType(), aggregateRoot.Id); //} /// <summary> /// 删除该聚合根下的溯源事件 /// </summary> public void Delete(Type aggregateRootType, object aggregateRootId) { _cache.Remove(aggregateRootType, aggregateRootId); var key = new SourceKey(aggregateRootId, aggregateRootType); _snapshotStore.Remove(key); _eventStore.RemoveAll(key); }
public IEnumerable<Stream> FindAll(SourceKey sourceKey, int version) { IDictionary<Stream, string> streams; if (!collection.TryGetValue(sourceKey, out streams)) return Enumerable.Empty<Stream>(); return streams.Keys.Where(item => item.Version > version).AsEnumerable(); }
public IEnumerable<Stream> FindAll(SourceKey sourceKey, string correlationId) { IDictionary<Stream, string> streams; if (!collection.TryGetValue(sourceKey, out streams) ) return Enumerable.Empty<Stream>(); return streams.Where(item => item.Value == correlationId).Select(item => item.Key).AsEnumerable(); }
int IEventPublishedVersionStore.GetPublishedVersion(SourceKey sourceKey) { var version = this.GetPublishedVersionFromMemory(sourceKey); if (version < 0) { version = this.GetPublishedVersion(sourceKey); this.AddOrUpdatePublishedVersionToMemory(sourceKey, 0, version); } return version; }
private int GetPublishedVersionFromMemory(SourceKey sourceKey) { ConcurrentDictionary<string, int> dict; var sourceTypeCode = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName).GetHashCode(); if (_versionCache.TryGetValue(sourceTypeCode, out dict)) { int version; if (dict.TryGetValue(sourceKey.SourceId, out version)) { return version; } } return -1; }
private void AddOrUpdatePublishedVersionToMemory(SourceKey sourceKey, int startVersion, int endVersion) { var sourceTypeCode = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName).GetHashCode(); _versionCache.GetOrAdd(sourceTypeCode, typeCode => new ConcurrentDictionary<string, int>()) .AddOrUpdate(sourceKey.SourceId, key => endVersion, (key, version) => { if (version + 1 == startVersion) return version; return endVersion; }); }
/// <summary> /// 根据主键获取聚合根实例。 /// </summary> public IEventSourced Find(Type aggregateRootType, object aggregateRootId) { if (!aggregateRootType.IsAssignableFrom(typeof(IEventSourced))) { } var aggregateRoot = _cache.Get(aggregateRootType, aggregateRootId) as IEventSourced; if (aggregateRoot != null) { if (_logger.IsInfoEnabled) _logger.InfoFormat("find the aggregate root {0} of id {1} from cache.", aggregateRootType.FullName, aggregateRootId); return aggregateRoot; } var sourceKey = new SourceKey(aggregateRootId, aggregateRootType); try { var snapshot = _snapshotStore.GetLastest(sourceKey); if (snapshot != null) { aggregateRoot = _binarySerializer.Deserialize(snapshot.Payload, aggregateRootType) as IEventSourced; if (_logger.IsInfoEnabled) _logger.InfoFormat("find the aggregate root {0} of id {1} from snapshot. version:{2}.", aggregateRootType.FullName, aggregateRootId, aggregateRoot.Version); } } catch (Exception ex) { if (_logger.IsWarnEnabled) _logger.Warn(ex, "get the latest snapshot failed. aggregateRootId:{0},aggregateRootType:{1}.", aggregateRootId, aggregateRootType.FullName); } if (aggregateRoot == null) { aggregateRoot = _aggregateFactory.Create(aggregateRootType, aggregateRootId) as IEventSourced; } var events = _eventStore.FindAll(sourceKey, aggregateRoot.Version).Select(Deserialize).OfType<IVersionedEvent>().OrderBy(p => p.Version); if (!events.IsEmpty()) { aggregateRoot.LoadFrom(events); if (_logger.IsInfoEnabled) _logger.InfoFormat("restore the aggregate root {0} of id {1} from events. version:{2} ~ {3}", aggregateRootType.FullName, aggregateRootId, events.Min(p => p.Version), events.Max(p => p.Version)); } _cache.Set(aggregateRoot, aggregateRoot.Id); return aggregateRoot; }
/// <summary> /// 获取已发布的溯源聚合版本号 /// </summary> public override int GetPublishedVersion(SourceKey sourceKey) { var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); return Task.Factory.StartNew(() => { using (var context = _contextFactory.CreateDataContext()) { var data = context.Find<EventPublishedVersion>(aggregateRootTypeCode, sourceKey.SourceId); if (data != null) { return data.Version; } return 0; } }).Result; }
private bool CompileIfNeeded() { var state = State; if (state == RendererDataState.Compiled) { return(false); } Debug.Assert(_shader is not null); Debug.Assert(_vertexType is not null); var key = new SourceKey(_shader, _vertexType); var screen = Engine.GetValidCurrentContext(); _program = CompiledProgramCacheStore.GetCacheOrCompile(screen, key); return(true); }
public override async Task Execute() { try { await SourceContainerCmd.Execute(); await DestContainerCmd.Execute(); var source = SourceContainerCmd.Container.GetBlockBlobReference(SourceKey.ToLower()); var dest = DestContainerCmd.Container.GetBlockBlobReference(DestKey.ToLower()); dest.Properties.ContentType = source.Properties.ContentType; await dest.StartCopyAsync(source); Confirm = ActionConfirm.CreateSuccess(DestKey.ToLower()); } catch (Exception exception) { Confirm = ActionConfirm.CreateFailure(exception.Message); } }
public bool Remove(SourceKey sourceKey) { if (!_persistent) return false; var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); var task = Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { context.CreateQuery<Snapshot>() .Where(p => p.AggregateRootId == sourceKey.SourceId && p.AggregateRootTypeCode == aggregateRootTypeCode) .ToList() .ForEach(context.Delete); context.Commit(); } }); task.Wait(); return task.Exception == null; }
/// <summary> /// 添加或更新溯源聚合的版本号 /// </summary> public override void AddOrUpdatePublishedVersion(SourceKey sourceKey, int startVersion, int endVersion) { var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); Task.Factory.StartNew(() => { using (var context = _contextFactory.CreateDataContext()) { var versionData = context.Find<EventPublishedVersion>(aggregateRootTypeCode, sourceKey.SourceId); if (versionData == null) { context.Save(new EventPublishedVersion(aggregateRootTypeCode, sourceKey.SourceId, endVersion)); } else if (versionData.Version + 1 == startVersion) { versionData.Version = endVersion; } else { return; } context.Commit(); } }).Wait(); }
public bool EventPersisted(SourceKey sourceKey, string correlationId) { return this.FindAll(sourceKey, correlationId).IsEmpty(); }
/// <summary> /// 添加或更新溯源聚合的版本号 /// </summary> public virtual void AddOrUpdatePublishedVersion(SourceKey sourceKey, int startVersion, int endVersion) { }
public void RemoveAll(SourceKey sourceKey) { collection.Remove(sourceKey); }
private VersionedEventStream Convert(SourceKey source, string correlationId, IEnumerable<IVersionedEvent> events) { return new VersionedEventStream { SourceAssemblyName = source.AssemblyName, SourceNamespace = source.Namespace, SourceTypeName = source.TypeName, SourceId = source.SourceId, CommandId = correlationId, StartVersion = events.Min(item => item.Version), EndVersion = events.Max(item => item.Version), Events = events }; }
public bool Remove(SourceKey sourceKey) { return false; }
public void RemoveAll(SourceKey sourceKey) { var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { context.CreateQuery<Event>() .Where(p => p.AggregateRootId == sourceKey.SourceId && p.AggregateRootTypeCode == aggregateRootTypeCode) .ToList() .ForEach(context.Delete); context.Commit(); } }).Wait(); }
void IEventPublishedVersionStore.AddOrUpdatePublishedVersion(SourceKey sourceKey, int startVersion, int endVersion) { this.AddOrUpdatePublishedVersion(sourceKey, startVersion, endVersion); this.AddOrUpdatePublishedVersionToMemory(sourceKey, startVersion, endVersion); }
public Stream(SourceKey key, int version, byte[] payload) { this.Key = key; this.Version = version; this.Payload = payload; }
public ProcessArgumentBuilder BuildWindowsArguments(ProcessArgumentBuilder args) { //var args = new ProcessArgumentBuilder(); args.Append("/Y"); if (Pattern.IsDefined()) { args.AppendSwitchQuoted("/Pattern", ":", Pattern); } if (DestinationKey.IsDefined()) { args.AppendSwitchQuotedSecret("/DestKey", ":", DestinationKey); } if (DestinationSAS.IsDefined()) { args.AppendSwitchQuotedSecret("/DestSAS", ":", DestinationSAS); } if (SourceKey.IsDefined()) { args.AppendSwitchQuotedSecret("/SourceKey", ":", SourceKey); } if (SourceSAS.IsDefined()) { args.AppendSwitchQuotedSecret("/SourceSAS", ":", SourceSAS); } if (Recursive) { args.Append("/S"); } if (BlobType != null) { args.AppendSwitchQuoted("/BlobType", ":", BlobType.ToString()); } if (UseChecksum) { args.Append("/CheckMD5"); } if (LogFile != null) { args.AppendSwitchQuoted("/V", ":", LogFile.FullPath); } if (ParameterFiles.Any()) { foreach (var file in ParameterFiles) { args.AppendSwitchQuoted("@", ":", file.FullPath); } } if (FileHandlingBehaviour != null) { if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ArchiveOnly)) { args.Append("/A"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource)) { args.Append("/XN"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource)) { args.Append("/XO"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified)) { args.Append("/MT"); } } if (Delimiter != null) { args.AppendSwitchQuoted("/Delimiter", ":", Delimiter.ToString()); } if (ConcurrentOperations != 0) { args.AppendSwitchQuoted("/NC", ":", ConcurrentOperations.ToString()); } if (TargetContentType.IsDefined()) { args.AppendSwitchQuoted("/SetContentType", ":", TargetContentType); } if (PayloadFormat != PayloadFormat.Default) { args.AppendSwitchQuoted("/PayloadFormat", ":", PayloadFormat.ToString()); } return(args); }
public ProcessArgumentBuilder BuildLinuxArguments(ProcessArgumentBuilder args) { args.Append("--quiet"); // equivalent to /Y for some reason if (Pattern.IsDefined()) { args.AppendSwitchQuoted("--include", Pattern); } if (DestinationKey.IsDefined()) { args.AppendSwitchQuotedSecret("--dest-key", DestinationKey); } if (DestinationSAS.IsDefined()) { args.AppendSwitchQuotedSecret("--dest-sas", DestinationSAS); } if (SourceKey.IsDefined()) { args.AppendSwitchQuotedSecret("--source-key", SourceKey); } if (SourceSAS.IsDefined()) { args.AppendSwitchQuotedSecret("--source-sas", SourceSAS); } if (Recursive) { args.Append("--recursive"); } if (BlobType != null) { args.AppendSwitch("--blob-type", BlobType.ToString().ToLower()); } if (UseChecksum) { args.Append("--check-md5"); } if (ParameterFiles.Any()) { foreach (var file in ParameterFiles) { args.AppendSwitchQuoted("--config-file", file.FullPath); } } if (FileHandlingBehaviour != null) { if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource)) { args.Append("--exclude-newer"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource)) { args.Append("--exclude-older"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified)) { args.Append("--preserve-last-modified-time"); } } if (Delimiter != null) { args.AppendSwitchQuoted("--delimiter", Delimiter.ToString()); } if (ConcurrentOperations != 0) { args.AppendSwitchQuoted("--parallel-level", ConcurrentOperations.ToString()); } if (TargetContentType.IsDefined()) { args.AppendSwitchQuoted("--set-content-type", TargetContentType); } return(args); }
public Stream GetLastest(SourceKey sourceKey) { return null; }
private EventStream Convert(SourceKey source, string correlationId, IEnumerable<IVersionedEvent> events) { return new EventStream { SourceAssemblyName = source.AssemblyName, SourceNamespace = source.Namespace, SourceTypeName = source.TypeName, SourceId = source.SourceId, CommandId = correlationId, StartVersion = events.Min(item => item.Version), EndVersion = events.Max(item => item.Version), Events = events.Select(item => new EventStream.Stream(item.GetType()) { Payload = _textSerializer.Serialize(item) }).ToArray() }; }
/// <summary> /// 保存聚合事件。 /// </summary> public void Save(IEventSourced aggregateRoot, string correlationId) { if (string.IsNullOrWhiteSpace(correlationId)) { if (_logger.IsWarnEnabled) _logger.Warn("Not use command to modify the state of the aggregate root."); } var aggregateRootType = aggregateRoot.GetType(); var aggregateRootId = aggregateRoot.Id; var events = aggregateRoot.GetEvents(); var key = new SourceKey(aggregateRootId, aggregateRootType); if (_eventStore.Save(key, correlationId, () => events.Select(Serialize))) { if (_logger.IsDebugEnabled) _logger.DebugFormat("Domain events persistent completed. aggregateRootId:{0}, aggregateRootType:{1}, commandId:{2}.", aggregateRootId, aggregateRootType.FullName, correlationId); _cache.Set(aggregateRoot, aggregateRoot.Id); } else { events = _eventStore.FindAll(key, correlationId).Select(Deserialize).OfType<IVersionedEvent>().OrderBy(p => p.Version); if (_logger.IsDebugEnabled) _logger.DebugFormat("The command generates events have been saved, load from storage. aggregateRootId:{0}, aggregateRootType:{1}, commandId:{2}.", aggregateRootId, aggregateRootType.FullName, correlationId); } List<IEvent> pendingEvents = new List<IEvent>(); if (string.IsNullOrWhiteSpace(correlationId)) { pendingEvents.AddRange(events); } else { pendingEvents.Add(Convert(key, correlationId, events)); } var eventPublisher = aggregateRoot as IEventPublisher; if (eventPublisher != null) { var otherEvents = eventPublisher.Events.Where(p => !(p is IVersionedEvent)); pendingEvents.AddRange(otherEvents); } _eventBus.Publish(pendingEvents); var snapshot = Serialize(key, aggregateRoot); if (!_snapshotPolicy.ShouldbeCreateSnapshot(snapshot)) return; try { if (_snapshotStore.Save(snapshot) && _logger.IsDebugEnabled) _logger.DebugFormat("make snapshot completed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); } catch (Exception ex) { if (_logger.IsWarnEnabled) _logger.Warn(ex, "snapshot persistent failed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); } }
/// <summary> /// 获取已发布的溯源聚合版本号 /// </summary> public virtual int GetPublishedVersion(SourceKey sourceKey) { return 0; }
public ProcessArgumentBuilder BuildWindowsArguments(ProcessArgumentBuilder args) { //var args = new ProcessArgumentBuilder(); args.Append("/Y"); if (Pattern.IsDefined()) { args.AppendSwitchQuoted("/Pattern", ":", Pattern); } if (DestinationKey.IsDefined()) { args.AppendSwitchQuotedSecret("/DestKey", ":", DestinationKey); } if (DestinationSAS.IsDefined()) { args.AppendSwitchQuotedSecret("/DestSAS", ":", DestinationSAS); } if (SourceKey.IsDefined()) { args.AppendSwitchQuotedSecret("/SourceKey", ":", SourceKey); } if (SourceSAS.IsDefined()) { args.AppendSwitchQuotedSecret("/SourceSAS", ":", SourceSAS); } if (Recursive) { args.Append("/S"); } if (BlobType != null) { args.AppendSwitchQuoted("/BlobType", ":", BlobType.ToString()); } if (UseChecksum) { args.Append("/CheckMD5"); } if (LogFile != null) { args.AppendSwitchQuoted("/V", ":", LogFile.FullPath); } if (ParameterFiles.Any()) { foreach (var file in ParameterFiles) { args.AppendSwitchQuoted("@", ":", file.FullPath); } } if (FileHandlingBehaviour != null) { if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ArchiveOnly)) { args.Append("/A"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource)) { args.Append("/XN"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource)) { args.Append("/XO"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified)) { args.Append("/MT"); } } if (Delimiter != null) { args.AppendSwitchQuoted("/Delimiter", ":", Delimiter.ToString()); } if (ConcurrentOperations != 0) { args.AppendSwitchQuoted("/NC", ":", ConcurrentOperations.ToString()); } if (TargetContentType != null) { // Could be present but empty if (TargetContentType.Equals(String.Empty)) { // If you specify this option without a value, then AzCopy sets each blob or file's content type according to its file extension. // https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy#setcontenttypecontent-type args.AppendSwitchQuoted("/SetContentType", String.Empty); } else { args.AppendSwitchQuoted("/SetContentType", ":", TargetContentType); } } if (PayloadFormat != PayloadFormat.Default) { args.AppendSwitchQuoted("/PayloadFormat", ":", PayloadFormat.ToString()); } return(args); }
public void Save(SourceKey sourceKey, string correlationId, IEnumerable<Stream> events) { var streams = collection.GetOrAdd(sourceKey, key => new Dictionary<Stream, string>()); events.ForEach(item => streams.Add(item, correlationId)); }
public override int GetHashCode() { unchecked { return(((TargetKey != null ? TargetKey.GetHashCode() : 0) * 397) ^ (SourceKey != null ? SourceKey.GetHashCode() : 0)); } }
public KeyNamesInfo(XmlElement xe) { if (xe.Attributes["sourceID"] != null) { SourceID = xe.GetAttribute("sourceID").ToString(); } if (xe.Attributes["key"] != null && xe.Attributes["sourceID"] == null) { Key = xe.GetAttribute("key").ToString(); } if (xe.Attributes["outPutKey"] != null) { OutPutKey = xe.GetAttribute("outPutKey").ToString(); } //将产品类型(投影等)datasourcetype中的sourceid转换成对应卫星数据的key if (xe.Attributes["key"] != null && xe.Attributes["sourceID"] != null) { //if (xe.GetAttribute("key") == "") return; XmlNode xn = xe.ParentNode.ParentNode; XmlNodeList xnl = xe.ParentNode.ParentNode.SelectNodes("RasterSourceType"); foreach (var xnode in xnl) { XmlElement xe1 = xnode as XmlElement; if (xe1.Attributes["ID"] != null && SourceID == xe1.GetAttribute("ID")) { XmlNode xnKeyNames = xe1.SelectSingleNode("KeyNames"); XmlElement xeKeyNames = xnKeyNames as XmlElement; if (xeKeyNames != null && xeKeyNames.Attributes["key"] != null) { SourceKey = xeKeyNames.GetAttribute("key").ToString(); break; } } } if (SourceKey != "" && xe.GetAttribute("key") == "") { Key = SourceKey; } else if (SourceKey != "" && xe.GetAttribute("key") != "") { Key = SourceKey + "," + xe.GetAttribute("key"); } } if (xe.Attributes["key"] == null && xe.Attributes["sourceID"] != null) { XmlNode xn = xe.ParentNode.ParentNode; XmlNodeList xnl = xe.ParentNode.ParentNode.SelectNodes("RasterSourceType"); foreach (var xnode in xnl) { XmlElement xe1 = xnode as XmlElement; if (xe1.Attributes["ID"] != null && SourceID == xe1.GetAttribute("ID")) { XmlNode xnKeyNames = xe1.SelectSingleNode("KeyNames"); XmlElement xeKeyNames = xnKeyNames as XmlElement; if (xeKeyNames != null && xeKeyNames.Attributes["key"] != null) { SourceKey = xeKeyNames.GetAttribute("key").ToString(); break; } } } if (SourceKey != null && OutPutKey != null && OutPutKey != "") { string result = ""; List <string> sourceKeyArr = SourceKey.Split(',').ToList(); string[] outPutKeyArr = OutPutKey.Split(','); foreach (var op in outPutKeyArr) { string str1 = op.Substring(0, op.IndexOf('(')); string str2 = op.Substring(op.IndexOf('(') + 1, op.IndexOf(')') - op.IndexOf('(') - 1); if (str2.Contains("+")) { //int i = Convert.ToInt32(str2.Replace("+", "")); sourceKeyArr.Add(str1); continue; } if (str2.Contains("-")) { int i = Convert.ToInt32(str2.Replace("-", "")); string delStr = sourceKeyArr[i]; if (sourceKeyArr.Contains(delStr)) { sourceKeyArr.RemoveAt(i); } continue; } if (!str2.Contains("+") && !str2.Contains("-") && (Convert.ToInt32(str2) < 100) && Convert.ToInt32(str2) < sourceKeyArr.Count) { int i = Convert.ToInt32(str2); if (i < sourceKeyArr.Count - 1 && i > 0) { sourceKeyArr[i] = str1; } continue; } if (Convert.ToInt32(str2) == 100) { sourceKeyArr.Add(str1); continue; } } for (int i = 0; i < sourceKeyArr.Count - 1; i++) { result += sourceKeyArr[i] + ","; } result = result + sourceKeyArr[sourceKeyArr.Count - 1]; Key = result; } } if (SourceKey != null && (OutPutKey == null || OutPutKey == "") && xe.Attributes["key"] == null) { Key = SourceKey; } if (xe.Attributes["suffix"] != null) { Suffix = xe.GetAttribute("suffix").ToString(); } }
public ProcessArgumentBuilder BuildLinuxArguments(ProcessArgumentBuilder args) { args.Append("--quiet"); // equivalent to /Y for some reason if (Pattern.IsDefined()) { args.AppendSwitchQuoted("--include", Pattern); } if (DestinationKey.IsDefined()) { args.AppendSwitchQuotedSecret("--dest-key", DestinationKey); } if (DestinationSAS.IsDefined()) { args.AppendSwitchQuotedSecret("--dest-sas", DestinationSAS); } if (SourceKey.IsDefined()) { args.AppendSwitchQuotedSecret("--source-key", SourceKey); } if (SourceSAS.IsDefined()) { args.AppendSwitchQuotedSecret("--source-sas", SourceSAS); } if (Recursive) { args.Append("--recursive"); } if (BlobType != null) { args.AppendSwitch("--blob-type", BlobType.ToString().ToLower()); } if (UseChecksum) { args.Append("--check-md5"); } if (ParameterFiles.Any()) { foreach (var file in ParameterFiles) { args.AppendSwitchQuoted("--config-file", file.FullPath); } } if (FileHandlingBehaviour != null) { if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource)) { args.Append("--exclude-newer"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource)) { args.Append("--exclude-older"); } if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified)) { args.Append("--preserve-last-modified-time"); } } if (Delimiter != null) { args.AppendSwitchQuoted("--delimiter", Delimiter.ToString()); } if (ConcurrentOperations != 0) { args.AppendSwitchQuoted("--parallel-level", ConcurrentOperations.ToString()); } if (TargetContentType != null) { // Could be present but empty if (TargetContentType.Equals(String.Empty)) { // If you specify this option without a value, then AzCopy sets each blob or file's content type according to its file extension. // https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy#setcontenttypecontent-type args.AppendSwitchQuoted("--set-content-type", String.Empty); } else { args.AppendSwitchQuoted("--set-content-type", TargetContentType); } } return(args); }
public bool EventPersisted(SourceKey sourceKey, string correlationId) { var aggregateRootTypeName = string.Concat(sourceKey.Namespace, ".", sourceKey.TypeName); var aggregateRootTypeCode = aggregateRootTypeName.GetHashCode(); var task = Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { return context.CreateQuery<Event>() .Any(p => p.CorrelationId == correlationId && p.AggregateRootId == sourceKey.SourceId && p.AggregateRootTypeCode == aggregateRootTypeCode); } }); task.Wait(); return task.Result; }
public static ProgramObject GetCacheOrCompile(IHostScreen screen, SourceKey key) { _dictionaries ??= new(); ref var dic = ref CollectionsMarshal.GetValueRefOrAddDefault(_dictionaries, screen, out _);
private Stream Serialize(SourceKey sourceKey, IEventSourced aggregateRoot) { return new Stream() { Key = sourceKey, Version = aggregateRoot.Version, Payload = _binarySerializer.Serialize(aggregateRoot) }; }
/// <summary> /// 保存聚合事件。 /// </summary> public void Save(IEventSourced aggregateRoot, string correlationId) { if (string.IsNullOrWhiteSpace(correlationId)) { if (_logger.IsWarnEnabled) _logger.Warn("Not use command to modify the state of the aggregate root."); } var aggregateRootType = aggregateRoot.GetType(); var aggregateRootId = aggregateRoot.Id; var events = aggregateRoot.GetEvents(); var key = new SourceKey(aggregateRootId, aggregateRootType); if (!_eventStore.EventPersisted(key, correlationId)) { _eventStore.Save(key, correlationId, events.Select(Serialize)); if (_logger.IsInfoEnabled) _logger.InfoFormat("sourcing events persistent completed. aggregateRootId:{0},aggregateRootType:{1}.", aggregateRootId, aggregateRootType.FullName); } else { events = _eventStore.FindAll(key, correlationId).Select(Deserialize).OfType<IVersionedEvent>().OrderBy(p => p.Version); if (_logger.IsInfoEnabled) _logger.InfoFormat("the command generates events have been saved, load from storage. command id:{0}", correlationId); } if (string.IsNullOrWhiteSpace(correlationId)) { _eventBus.Publish(events); } else { _eventBus.Publish(Convert(key, correlationId, events)); } var eventPublisher = aggregateRoot as IEventPublisher; if (eventPublisher != null) { eventPublisher.Events.ForEach(item => { if (item is IVersionedEvent) return; }); } //if (_logger.IsInfoEnabled) // _logger.InfoFormat("publish all events. event:{0}", _textSerializer.Serialize(events)); _cache.Set(aggregateRoot, aggregateRoot.Id); var snapshot = Serialize(key, aggregateRoot); if (!_snapshotPolicy.ShouldbeCreateSnapshot(snapshot)) return; try { if (_snapshotStore.Save(snapshot) && _logger.IsInfoEnabled) _logger.InfoFormat("make snapshot completed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); } catch (Exception ex) { if (_logger.IsWarnEnabled) _logger.Warn(ex, "snapshot persistent failed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); } }