private void InnerExecute(SyncSession session) { session.SourceProvider.Reset(); //重置 session.WriteStartLog(session); session.NumerOfErrors = session.NumerOfUpdated = 0; bool success = false; try { if (session.BatchSize != 1) { this.DoBatchExecute(session); } else { this.DoOneByOneExecute(session); } success = true; } finally { session.SourceProvider.Close(); session.WriteEndLog(session, success); } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { string enumType = mapping.Parameters["enumType"]; if (string.IsNullOrEmpty(enumType)) { throw new System.Configuration.ConfigurationErrorsException("配置EnumPropertyComparer时,必须指定enumType属性"); } var type = Type.GetType(enumType); if (type == null) { throw new System.Configuration.ConfigurationErrorsException("未找到指定的枚举类型 " + enumType); } object srcValue = srcValues[mapping.SourceProperty]; string targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (string.IsNullOrEmpty(targetString) == false) { return(srcValue.Equals(int.Parse(targetString))); } else { return(false); } }
public static EntityInfo CreateServiceComponentInfo(EntityBase entity, SyncSession session) { EntityInfo Data = new EntityInfo(); Data.id = entity.ID; Data.infos = new List <ComponentInfo>(); //给有连接组件的增加Self组件 if (entity.GetExistComp(ComponentType.ConnectionComponent)) { ConnectionComponent comp = entity.GetComp <ConnectionComponent>(); if (comp.m_session == session) { ComponentInfo info = new ComponentInfo(); info.m_compName = "SelfComponent"; info.content = "{}"; Data.infos.Add(info); } else { ComponentInfo info = new ComponentInfo(); info.m_compName = "TheirComponent"; info.content = "{}"; Data.infos.Add(info); } } return(Data); }
public void UpdateSlots(SyncSession session, GestureQuickSlotsUpdateRequest request) { foreach (uint id in request.Values) { if (id == 0) { continue; } if (!_tables.Gesture.TryGetValue((ushort)id, out GestureTableEntity? gesture)) { NetworkUtils.DropBadAction(); } if (gesture !.Hero != session.Character.Hero && gesture !.Hero != Hero.None) { NetworkUtils.DropBadAction(); } } using CharacterContext context = _characterRepository.CreateDbContext(); CharacterModel model = context.Characters.First(s => s.Id == session.Character.Id); model.Gestures = request.Values.ToArray(); context.UseAndSave(c => c.Update(model)); session.SendDeferred(new CharacterGestureUpdateSlotsResponse() { Values = request.Values }); }
public void GetInfo(SyncSession session) => session .SendDeferred(new CharacterInfoResponse() { Character = ResponseHelper.GetCharacter(session), Place = ResponseHelper.GetPlace(session, _instance), }) .SendDeferred(new CharacterSkillInfoResponse() { }) .SendDeferred(new InfiniteTowerLoadInfoResponse() { }) .SendDeferred(new CharacterGestureLoadResponse() { Values = session.Gestures }) .SendDeferred(new CharacterProfileResponse() { About = session.Profile.About, Note = session.Profile.Note, Status = session.Profile.Status, }) .SendDeferred(new CharacterPostInfoResponse() { Values = Array.Empty <object>() }) .SendDeferred(new CharacterStatsUpdateResponse() { Character = session.Character.Id, Values = session.Stats.Select(s => new CharacterStatsUpdateResponse.CSUREntity() { Id = s.Id, Value = s.Value }) });
private void Button_Sync_Click(object sender, EventArgs e) { var session = this.CurrentSession; if (session == null) { var server = this.CreateServerObject(); if (server == null) { return; } session = new SyncSession(server, this.TextBox_SyncDirectory.Text); session.LogItemReceived += this.CurrentSession_LogItemReceived; var syncFrm = new SyncForm(session, true); syncFrm.FormClosed += (sender2, e2) => { if (syncFrm.DialogResult == DialogResult.OK) { // session.Start(); this.CurrentSession = session; } }; syncFrm.ShowDialogAndStart(this); } else { session.Stop(); this.CurrentSession = null; } }
public void Enter(SyncSession session, GateEnterRequest request) { if (_gate.Id != request.Gate) { NetworkUtils.DropBadAction(); } if (!_relay.Session.Contains(new RGSSessionContainsRequest { Account = request.Account, Key = request.SessionKey }).Result) { NetworkUtils.DropBadAction(); } { using AccountContext context = _accountFactory.CreateDbContext(); AccountModel model = context.Accounts.AsNoTracking().First(c => c.Id == request.Account); session.Account = new(model); session.Characters = GetCharacters(model, request.Gate); session.Background = model.CharacterBackground; session.Permission = HandlerPermission.Authorized; } session.SendDeferred(new GateEnterResponse() { AccountId = request.Account, Result = GateEnterResult.Success }); session.SendDeferred(new SWorldCurrentDataResponse()); }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(bool).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { return(((bool)srcValue).Equals(bool.Parse(targetString))); } else { return(false); // 左边对象有值,而右边对象没值 } } else if (srcValue is string) { return(string.Equals((string)srcValue, (string)targetString, StringComparison.OrdinalIgnoreCase)); } else { return(mapping.Parameters["sourceDefaultValue"] == targetString); //源对象为null或其他情形 } }
static void ReceviceCommandComponent(SyncSession session, ProtocolRequestBase e) { CommandComponent msg = new CommandComponent(); { Dictionary <string, object> data2 = (Dictionary <string, object>)e.m_data["movedir"]; SyncVector3 tmp2 = new SyncVector3(); tmp2.x = (int)data2["x"]; tmp2.y = (int)data2["y"]; tmp2.z = (int)data2["z"]; msg.moveDir = tmp2; } { Dictionary <string, object> data2 = (Dictionary <string, object>)e.m_data["skilldir"]; SyncVector3 tmp2 = new SyncVector3(); tmp2.x = (int)data2["x"]; tmp2.y = (int)data2["y"]; tmp2.z = (int)data2["z"]; msg.skillDir = tmp2; } msg.isFire = (bool)e.m_data["isfire"]; msg.id = (int)e.m_data["id"]; msg.frame = (int)e.m_data["frame"]; EventService.DispatchTypeEvent(session, msg); }
public void Execute(IEnumerable <CommandData> commands) { FieldMap fieldMap = new FieldMap(); using SyncSession session = new SyncSession(this.Options); foreach (CommandData commandData in commands.NotNull()) { Command command = new Command(commandData, fieldMap); if (string.IsNullOrWhiteSpace(commandData.CommandText)) { continue; } foreach (IDataReader reader in session.Execute(command)) { TableIdentity tableInfo = TableIdentity.FromRecord(reader); FieldData[] fields = command.GetHeading(tableInfo); MetadataIdentity[] metadata = fields.Select(f => f?.Attribute).ToArray(); var binder = FuncCache.GetFieldDataBinder(metadata, tableInfo); if (reader.Read()) { binder(reader, fields); } } } foreach (FieldData fieldData in fieldMap) { fieldData.Bind(); } }
/// <remarks/> public System.IAsyncResult BeginGetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("GetChanges", new object[] { groupMetadata, syncSession }, callback, asyncState)); }
public void RecveviceBuyCharacter(SyncSession session, PlayerBuyCharacter_s msg) { for (int i = 0; i < session.player.OwnCharacter.Count; i++) { if (session.player.OwnCharacter[i] == msg.characterID) { PlayerBuyCharacter_c result = new PlayerBuyCharacter_c(); result.code = ServiceErrorCode.c_HasOwnCharacter; ProtocolAnalysisService.SendMsg(session, result); return; } } ShopDataGenerate data = DataGenerateManager <ShopDataGenerate> .GetData(msg.characterID); if (data.m_cost <= session.player.Diamond) { session.player.Diamond -= (int)data.m_cost; session.player.OwnCharacter.Add(data.m_item_id.ToString()); PlayerBuyCharacter_c result = new PlayerBuyCharacter_c(); result.code = ServiceErrorCode.c_Success; ProtocolAnalysisService.SendMsg(session, result); } else { PlayerBuyCharacter_c result = new PlayerBuyCharacter_c(); result.code = ServiceErrorCode.c_NotEnoughDiamond; ProtocolAnalysisService.SendMsg(session, result); } }
/// <remarks/> public System.IAsyncResult BeginGetSchema(string[] tableNames, SyncSession syncSession, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("GetSchema", new object[] { tableNames, syncSession }, callback, asyncState)); }
public SyncServerInfo GetServerInfo([System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] SyncSession syncSession) { object[] results = this.Invoke("GetServerInfo", new object[] { syncSession }); return((SyncServerInfo)(results[0])); }
static void SendPlayerBuyCharacter_c(SyncSession session, PlayerBuyCharacter_c msg) { Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("code", msg.code); session.SendMsg("playerbuycharacter", data); }
public static void Jump(SyncSession session, MovementJumpRequest request) { session.Character.Place.Position = request.Position; session.Character.Place.Rotation = request.Rotation; session.Channel !.BroadcastAsync(request); }
public SyncServerInfo GetServerInfo(SyncSession syncSession) { object[] results = this.Invoke("GetServerInfo", new object[] { syncSession }); return((SyncServerInfo)(results[0])); }
public static void SendMsg(this SyncSession session, string key, Dictionary <string, object> data) { ByteArray ba = new ByteArray(); List <byte> message = GetSendByte(key, data); int len = 3 + message.Count; int method = GetMethodIndex(key); ba.WriteShort(len); ba.WriteByte((byte)(method / 100)); ba.WriteShort(method); if (message != null) { ba.bytes.AddRange(message); } else { ba.WriteInt(0); } byte[] buffer = ba.Buffer; session.Send(buffer, 0, buffer.Length); }
static void SendCommandComponent(SyncSession session, CommandComponent msg) { Dictionary <string, object> data = new Dictionary <string, object>(); { Dictionary <string, object> data2 = new Dictionary <string, object>(); data2.Add("x", msg.moveDir.x); data2.Add("y", msg.moveDir.y); data2.Add("z", msg.moveDir.z); data.Add("movedir", data2); } { Dictionary <string, object> data2 = new Dictionary <string, object>(); data2.Add("x", msg.skillDir.x); data2.Add("y", msg.skillDir.y); data2.Add("z", msg.skillDir.z); data.Add("skilldir", data2); } data.Add("element1", msg.element1); data.Add("element2", msg.element2); data.Add("isfire", msg.isFire); data.Add("id", msg.id); data.Add("frame", msg.frame); data.Add("time", msg.time); session.SendMsg("commandcomponent", data); }
static void ReceviceSyncMsg(SyncSession session, T msg) { //Debug.Log("ReceviceSyncMsg " + msg.id + " content " + Serializer.Serialize(msg)); //消息确认 AffirmMsg amsg = new AffirmMsg(); amsg.index = msg.frame; amsg.time = msg.time; ProtocolAnalysisService.SendMsg(session, amsg); ConnectionComponent connectComp = session.m_connect; if (connectComp != null) { WorldBase world = connectComp.Entity.World; if (msg.frame > world.FrameCount) { //广播这帧 BroadcastCommand(world, connectComp, msg, false); connectComp.AddCommand(msg); } else { //当成最新的一帧来处理 msg.frame = world.FrameCount; connectComp.AddCommand(msg); } ControlSpeed(connectComp, world, msg.frame); } }
static void SendPlayerSelectCharacter_c(SyncSession session, PlayerSelectCharacter_c msg) { Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("content", msg.content); session.SendMsg("playerselectcharacter", data); }
static void SendDebugMsg(SyncSession session, Protocol.DebugMsg msg) { Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("frame", msg.frame); { List <object> list2 = new List <object>(); for (int i2 = 0; i2 < msg.infos.Count; i2++) { Dictionary <string, object> data2 = new Dictionary <string, object>(); data2.Add("id", msg.infos[i2].id); { List <object> list4 = new List <object>(); for (int i4 = 0; i4 < msg.infos[i2].infos.Count; i4++) { Dictionary <string, object> data4 = new Dictionary <string, object>(); data4.Add("m_compname", msg.infos[i2].infos[i4].m_compName); data4.Add("content", msg.infos[i2].infos[i4].content); list4.Add(data4); } data2.Add("infos", list4); } list2.Add(data2); } data.Add("infos", list2); } session.SendMsg("debugmsg", data); }
static void ReceviceSameCmdMsg(SyncSession session, SameCommand msg) { //消息确认 AffirmMsg amsg = new AffirmMsg(); amsg.index = msg.frame; amsg.time = msg.time; ProtocolAnalysisService.SendMsg(session, amsg); ConnectionComponent connectComp = session.m_connect; if (connectComp != null) { WorldBase world = connectComp.Entity.World; //取上一帧的数据 T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy(); if (msg.frame > world.FrameCount) { scmd.frame = msg.frame; connectComp.AddCommand(scmd); BroadcastSameCommand(world, connectComp, msg, true); } else { scmd.frame = world.FrameCount; connectComp.AddCommand(scmd); } ControlSpeed(connectComp, world, msg.frame); } }
public void ReceviceSelectCharacter(SyncSession session, PlayerSelectCharacter_s msg) { if (session.player == null) { Debug.LogError("玩家未登录"); } bool isHave = false; //判断该角色是否在玩家的拥有角色列表 for (int i = 0; i < session.player.OwnCharacter.Count; i++) { if (session.player.OwnCharacter[i] == msg.characterID) { isHave = true; } } //如果是,替换玩家角色 if (isHave) { session.player.characterID = msg.characterID; PlayerSelectCharacter_c m = new PlayerSelectCharacter_c(); m.code = ServiceErrorCode.c_Success; ProtocolAnalysisService.SendMsg(session, m); } else { PlayerSelectCharacter_c m = new PlayerSelectCharacter_c(); m.code = ServiceErrorCode.c_DontOwnCharacter; ProtocolAnalysisService.SendMsg(session, m); } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(DateTime).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { DateTime left = (DateTime)srcValue; DateTime right = DateTime.Parse(targetString); return left.Equals(right); //完全精度匹配(几乎不可能实现) } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return ((string)srcValue) == targetString; } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
public static void SendMsg(SyncSession session, IProtocolMessageInterface msg) { string key = msg.GetType().Name.ToLower(); switch (key) { case "changecomponentmsg": SendChangeComponentMsg(session, (Protocol.ChangeComponentMsg)msg); break; case "changesingletoncomponentmsg": SendChangeSingletonComponentMsg(session, (Protocol.ChangeSingletonComponentMsg)msg); break; case "debugmsg": SendDebugMsg(session, (Protocol.DebugMsg)msg); break; case "destroyentitymsg": SendDestroyEntityMsg(session, (Protocol.DestroyEntityMsg)msg); break; case "pursuemsg": SendPursueMsg(session, (Protocol.PursueMsg)msg); break; case "startsyncmsg": SendStartSyncMsg(session, (Protocol.StartSyncMsg)msg); break; case "syncentitymsg": SendSyncEntityMsg(session, (Protocol.SyncEntityMsg)msg); break; case "commandcomponent": SendCommandComponent(session, (CommandComponent)msg); break; default: Debug.LogError("SendCommand Exception : 不支持的消息类型!" + key); break; } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(float).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { float left = (float)srcValue; float right = float.Parse(targetString); if (string.IsNullOrEmpty(mapping.Parameters["precision"])) { return left.Equals(right); //完全精度匹配(几乎不可能实现) } else { int precision = int.Parse(mapping.Parameters["precision"]); double delta = Math.Abs(left - right) * Math.Pow(10, precision); //通常两个数相差在delta范围内算相等 return delta < 1; } } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return ((string)srcValue) == targetString; } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
/// <remarks/> public System.IAsyncResult BeginApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("ApplyChanges", new object[] { groupMetadata, dataSet, syncSession}, callback, asyncState); }
static void ReceviceDebugMsg(SyncSession session, ProtocolRequestBase e) { Protocol.DebugMsg msg = new Protocol.DebugMsg(); msg.frame = (int)e.m_data["frame"]; { List <Dictionary <string, object> > data2 = (List <Dictionary <string, object> >)e.m_data["infos"]; List <Protocol.EntityInfo> list2 = new List <Protocol.EntityInfo>(); for (int i2 = 0; i2 < data2.Count; i2++) { Protocol.EntityInfo tmp2 = new Protocol.EntityInfo(); tmp2.id = (int)data2[i2]["id"]; { List <Dictionary <string, object> > data4 = (List <Dictionary <string, object> >)data2[i2]["infos"]; List <Protocol.ComponentInfo> list4 = new List <Protocol.ComponentInfo>(); for (int i4 = 0; i4 < data4.Count; i4++) { Protocol.ComponentInfo tmp4 = new Protocol.ComponentInfo(); tmp4.m_compName = data4[i4]["m_compname"].ToString(); tmp4.content = data4[i4]["content"].ToString(); list4.Add(tmp4); } tmp2.infos = list4; } list2.Add(tmp2); } msg.infos = list2; } EventService.DispatchTypeEvent(session, msg); }
public static void AnalysisAndDispatchMessage(SyncSession session, ProtocolRequestBase cmd) { switch (cmd.Key) { case "changecomponentmsg": ReceviceChangeComponentMsg(session, cmd); break; case "changesingletoncomponentmsg": ReceviceChangeSingletonComponentMsg(session, cmd); break; case "debugmsg": ReceviceDebugMsg(session, cmd); break; case "destroyentitymsg": ReceviceDestroyEntityMsg(session, cmd); break; case "pursuemsg": RecevicePursueMsg(session, cmd); break; case "startsyncmsg": ReceviceStartSyncMsg(session, cmd); break; case "syncentitymsg": ReceviceSyncEntityMsg(session, cmd); break; case "commandcomponent": ReceviceCommandComponent(session, cmd); break; default: Debug.LogError("Recevice Exception : 不支持的消息类型!" + cmd.Key); break; } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(DateTime).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { DateTime left = (DateTime)srcValue; DateTime right = DateTime.Parse(targetString); return(left.Equals(right)); //完全精度匹配(几乎不可能实现) } else { return(false); // 左边对象有值,而右边对象没值 } } else if (srcValue is string) { return(((string)srcValue) == targetString); } else { return(mapping.Parameters["sourceDefaultValue"] == targetString); //源对象为null或其他情形 } }
public static void Jump(SyncSession session, SRMJumpRequest request) { session.Character.Place.Position = request.Position; session.Character.Place.Rotation = request.Rotation; session.Channel !.BroadcastDeferred(request); }
public IList <TItem> List <TItem>(IEnumerable <QueryData> queries) { if (queries == null) { throw new ArgumentNullException(nameof(queries)); } if (this.Options.Schemas == null) { throw new InvalidOperationException("No schema store found."); } ResultAdapter <TItem> adapter = new ResultAdapter <TItem>(this.Options.Schemas); using SyncSession connection = new SyncSession(this.Options); foreach (QueryData queryData in queries.NotNull()) { Query builder = new Query(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } foreach (IDataReader dataReader in connection.Execute(builder)) { adapter.AddResult(dataReader); } } return(adapter.ToList()); }
public IEnumerable <QueryReader> Enumerate(IEnumerable <QueryData> queries) { if (queries == null) { throw new ArgumentNullException(nameof(queries)); } if (this.Options.Schemas == null) { throw new InvalidOperationException("No schema builder found."); } using SyncSession connection = new SyncSession(this.Options); foreach (QueryData queryData in queries.NotNull()) { Query query = new Query(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } foreach (IDataReader reader in connection.Execute(query)) { yield return(new QueryReader(reader, this.Options.Schemas)); } } }
public SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession) { object[] results = this.Invoke("ApplyChanges", new object[] { groupMetadata, dataSet, syncSession}); return ((SyncContext)(results[0])); }
public override void WriteEndLog(SyncSession session, bool success) { CheckLogPresent(); this.log.Status = IncomeSyncStatus.Completed; if (success == false) { this.log.Status = IncomeSyncStatus.FaultError; } this.log.EndTime = DateTime.Now; Adapters.SqlIncomeLogAdapter.Instance.Update(this.log); }
public override void WriteStartLog(SyncSession session) { var log = SqlIncomeSyncLog.CreateLogFromEnvironment(); log.LogID = UuidHelper.NewUuidString(); log.StartTime = DateTime.Now; log.EndTime = new DateTime(9999, 9, 9); log.SourceName = this.sourceName; log.Status = IncomeSyncStatus.Running; Adapters.SqlIncomeLogAdapter.Instance.Update(log); this.log = log; }
public override void WriteErrorLog(SyncSession syncSession, SchemaObjectBase scObj, Exception ex) { CheckLogPresent(); this.log.NumberOfExceptions++; var detail = new SqlIncomeSyncLogDetail(); detail.LogDetailID = UuidHelper.NewUuidString(); detail.LogID = this.log.LogID; detail.SCObjectID = scObj.ID; detail.Summary = ex.Message; detail.Detail = ex.ToString(); detail.ActionType = SqlIncomeSyncLogDetailStatus.Update; Adapters.SqlIncomeLogDetailAdapter.Instance.Update(detail); }
private void DoOneByOneExecute(SyncSession session) { DataProviderBase provider = session.SourceProvider; provider.Reset(); while (provider.MoveNext()) { string key = (string)provider.CurrentData[session.Mappings.SourceKeyProperty]; if (string.IsNullOrWhiteSpace(key)) throw new SyncException("数据源提供的对象的ID为空"); SchemaObjectBase scObj = LoadSchemaObject(key); CompareAndChange(session, provider.CurrentData, session.Mappings.AllObjectValues, scObj); } }
public void SetValue(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; if (typeof(int).IsAssignableFrom(srcValue.GetType())) { targetObj.Properties[mapping.TargetProperty].StringValue = ((int)srcValue).ToString(); } else if (srcValue is string) { targetObj.Properties[mapping.TargetProperty].StringValue = (string)srcValue; } else { //其他情况如null,DbNull等,以及不知如何转换的 targetObj.Properties[mapping.TargetProperty].StringValue = string.Empty ; } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { string enumType = mapping.Parameters["enumType"]; if (string.IsNullOrEmpty(enumType)) throw new System.Configuration.ConfigurationErrorsException("配置EnumPropertyComparer时,必须指定enumType属性"); var type = Type.GetType(enumType); if (type == null) throw new System.Configuration.ConfigurationErrorsException("未找到指定的枚举类型 " + enumType); object srcValue = srcValues[mapping.SourceProperty]; string targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (string.IsNullOrEmpty(targetString) == false) { return srcValue.Equals(int.Parse(targetString)); } else return false; }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(bool).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { return ((bool)srcValue).Equals(bool.Parse(targetString)); } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return string.Equals((string)srcValue, (string)targetString, StringComparison.OrdinalIgnoreCase); } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
private void DoBatchExecute(SyncSession session) { DataProviderBase provider = session.SourceProvider; provider.Reset(); List<NameObjectCollection> buffer = new List<NameObjectCollection>(session.BatchSize); int len; do { buffer.Clear(); len = FetchToBuffer(buffer, provider, session.BatchSize); if (len > 0) { string[] keys = new string[len]; for (int i = buffer.Count - 1; i >= 0; i--) { keys[i] = (string)buffer[i][session.Mappings.SourceKeyProperty]; if (string.IsNullOrWhiteSpace(keys[i])) throw new SyncException("数据源提供的对象的ID为空"); } SchemaObjectCollection scObjs = LoadSchemaObjects(keys); foreach (NameObjectCollection item in buffer) { string id = (string)item[session.Mappings.SourceKeyProperty]; SchemaObjectBase scObj = scObjs[id]; if (scObjs != null) { CompareAndChange(session, item, session.Mappings.AllObjectValues, scObj); } } } } while (len > 0 && len != session.BatchSize); }
public override void WriteLog(SyncSession syncSession, SchemaObjectBase scObj) { CheckLogPresent(); this.log.NumberOfModifiedItems++; }
/// <remarks/> public void GetServerInfoAsync(SyncSession syncSession) { this.GetServerInfoAsync(syncSession, null); }
/// <remarks/> public void ApplyChangesAsync(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession) { this.ApplyChangesAsync(groupMetadata, dataSet, syncSession, null); }
public virtual SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) { return this._serverSyncProvider.GetChanges(groupMetadata, syncSession); }
/// <remarks/> public void GetSchemaAsync(string[] tableNames, SyncSession syncSession) { this.GetSchemaAsync(tableNames, syncSession, null); }
public SyncServerInfo GetServerInfo(SyncSession syncSession) { object[] results = this.Invoke("GetServerInfo", new object[] { syncSession}); return ((SyncServerInfo)(results[0])); }
public SyncSchema GetSchema(string[] tableNames, SyncSession syncSession) { object[] results = this.Invoke("GetSchema", new object[] { tableNames, syncSession}); return ((SyncSchema)(results[0])); }
public SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) { object[] results = this.Invoke("GetChanges", new object[] { groupMetadata, syncSession}); return ((SyncContext)(results[0])); }
/// <remarks/> public void GetSchemaAsync(string[] tableNames, SyncSession syncSession, object userState) { if ((this.GetSchemaOperationCompleted == null)) { this.GetSchemaOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetSchemaOperationCompleted); } this.InvokeAsync("GetSchema", new object[] { tableNames, syncSession}, this.GetSchemaOperationCompleted, userState); }
/// <remarks/> public void GetChangesAsync(SyncGroupMetadata groupMetadata, SyncSession syncSession) { this.GetChangesAsync(groupMetadata, syncSession, null); }
public virtual SyncServerInfo GetServerInfo(SyncSession syncSession) { return this._serverSyncProvider.GetServerInfo(syncSession); }
public virtual SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession) { return this._serverSyncProvider.GetSchema(tableNames, syncSession); }
/// <remarks/> public void GetServerInfoAsync(SyncSession syncSession, object userState) { if ((this.GetServerInfoOperationCompleted == null)) { this.GetServerInfoOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetServerInfoOperationCompleted); } this.InvokeAsync("GetServerInfo", new object[] { syncSession}, this.GetServerInfoOperationCompleted, userState); }
public virtual SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession) { return this._serverSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession); }
/// <remarks/> public System.IAsyncResult BeginGetSchema(string[] tableNames, SyncSession syncSession, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetSchema", new object[] { tableNames, syncSession}, callback, asyncState); }
/// <remarks/> public System.IAsyncResult BeginGetServerInfo(SyncSession syncSession, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetServerInfo", new object[] { syncSession}, callback, asyncState); }
/// <remarks/> public void ApplyChangesAsync(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession, object userState) { if ((this.ApplyChangesOperationCompleted == null)) { this.ApplyChangesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnApplyChangesOperationCompleted); } this.InvokeAsync("ApplyChanges", new object[] { groupMetadata, dataSet, syncSession}, this.ApplyChangesOperationCompleted, userState); }