예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            KnowledgeInfo knowledgeInfo = (KnowledgeInfo)button.Tag;

            switch (knowledgeInfo.Type)
            {
            case ActionType.Gif:
                ShowGif(knowledgeInfo);
                break;

            case ActionType.Text:
                ShowSolution(knowledgeInfo);
                break;

            case ActionType.Soft:
                SoftExecute(knowledgeInfo);
                break;

            case ActionType.Link:
                StartBrowser(knowledgeInfo);
                break;
            }
        }
예제 #2
0
        internal void UpdateLocalKnowledgeTimeStamp(long timeStamp, string synchronizationId, Dictionary <string, object> customInfo, List <string> log, object transaction)
        {
            bool isNewlyCreated = false;

            List <KnowledgeInfo> infos = GetAllKnowledgeInfos(synchronizationId, customInfo);
            KnowledgeInfo        localKnowledgeInfo = infos.Where(w => w.IsLocal).FirstOrDefault();

            if (localKnowledgeInfo == null)
            {
                isNewlyCreated     = true;
                localKnowledgeInfo = new KnowledgeInfo()
                {
                    DatabaseInstanceId = Guid.NewGuid().ToString(),
                    IsLocal            = true
                };
            }
            else
            {
                isNewlyCreated = false;
            }
            localKnowledgeInfo.MaxTimeStamp = timeStamp;
            CreateOrUpdateKnowledgeInfo(localKnowledgeInfo, synchronizationId, customInfo);

            if (isNewlyCreated)
            {
                ProvisionExistingData(log, timeStamp, transaction, OperationType.ProvisionKnowledge, synchronizationId, customInfo);
            }
        }
예제 #3
0
        private void SoftExecute(KnowledgeInfo knowledgeInfo)
        {
            Type   execute = typeof(SoftExecute);
            Object obj     = Activator.CreateInstance(execute);//实例化

            execute.GetMethod(knowledgeInfo.Id)?.Invoke(obj, null);
        }
예제 #4
0
        protected override GetKnowledgeDetailRD ProcessRequest(DTO.Base.APIRequest <GetKnowledgeDetailRP> pRequest)
        {
            GetKnowledgeDetailRD rd = new GetKnowledgeDetailRD();
            var bll    = new KnowledgeBLL(CurrentUserInfo);
            var entity = bll.GetByID(pRequest.Parameters.ID);

            if (entity == null)
            {
                throw new APIException(string.Format("未找到ID:{0}的文章", pRequest.Parameters.ID))
                      {
                          ErrorCode = 340
                      };
            }
            var info = new KnowledgeInfo
            {
                Author        = entity.Author,
                ClickCount    = entity.ClickCount,
                Content       = entity.Content,
                Description   = entity.Remark,
                EvaluateCount = entity.EvaluateCount,
                ID            = entity.KnowIedgeId,
                ImageUrl      = entity.ImageUrl,
                KeepCount     = entity.KeepCount,
                PraiseCount   = entity.PraiseCount,
                ShareCount    = entity.ShareCount,
                Title         = entity.Title,
                TreadCount    = entity.TreadCount
            };

            rd.KnowledgeInfo = info;
            return(rd);
        }
예제 #5
0
        private void ShowSolution(KnowledgeInfo knowledgeInfo)
        {
            StreamWriter sw = new StreamWriter("Solution.txt");

            sw.WriteLine(knowledgeInfo.Solution.Replace("|", Environment.NewLine));
            sw.Close();
            sw.Dispose();

            Process.Start("Solution.txt");
        }
예제 #6
0
        private bool ChangeItemVisibility(KnowledgeInfo knowledgeInfo)
        {
            var result = false;

            if (knowledgeInfo.KeyWords.ToLower().Contains(KnowledgeKey.ToLower()))
            {
                result = true;
            }

            knowledgeInfo.Visibility = result ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
            return(result);
        }
예제 #7
0
        public override void CreateOrUpdateKnowledgeInfo(KnowledgeInfo knowledgeInfo, string synchronizationId, Dictionary <string, object> customInfo)
        {
            Knowledge knowledge = Realm.All <Knowledge>().Where(w => w.DatabaseInstanceId == knowledgeInfo.DatabaseInstanceId).FirstOrDefault();

            if (knowledge == null)
            {
                knowledge = new Knowledge();
                knowledge.DatabaseInstanceId = knowledgeInfo.DatabaseInstanceId;
                Realm.Add(knowledge);
                knowledge = Realm.All <Knowledge>().Where(w => w.DatabaseInstanceId == knowledgeInfo.DatabaseInstanceId).First();
            }
            knowledge.IsLocal      = knowledgeInfo.IsLocal;
            knowledge.MaxTimeStamp = knowledgeInfo.MaxTimeStamp;
        }
예제 #8
0
        internal void GetChangesByKnowledge(GetChangesByKnowledgeParameter parameter, ref GetChangesByKnowledgeResult result)
        {
            if (parameter == null)
            {
                throw new NullReferenceException(nameof(parameter));
            }
            result = new GetChangesByKnowledgeResult(parameter.PayloadAction, parameter.SynchronizationId, parameter.CustomInfo);

            parameter.Log.Add($"Get Changes By Knowledge");
            parameter.Log.Add($"Local Knowledge Count: {parameter.LocalKnowledgeInfos.Count}");
            for (int i = 0; i < parameter.LocalKnowledgeInfos.Count; i++)
            {
                parameter.Log.Add($"{i + 1}. {parameter.LocalKnowledgeInfos[i].ToString()}");
            }
            parameter.Log.Add($"Remote Knowledge Count: {parameter.RemoteKnowledgeInfos.Count}");
            for (int i = 0; i < parameter.RemoteKnowledgeInfos.Count; i++)
            {
                parameter.Log.Add($"{i + 1}. {parameter.RemoteKnowledgeInfos[i].ToString()}");
            }
            if (parameter.LocalKnowledgeInfos.Where(w => w.IsLocal).Count() != 1)
            {
                throw new SyncEngineConstraintException($"{nameof(parameter.LocalKnowledgeInfos)} must have 1 IsLocal property equals to true");
            }
            if (parameter.RemoteKnowledgeInfos.Where(w => w.IsLocal).Count() != 1)
            {
                throw new SyncEngineConstraintException($"{nameof(parameter.RemoteKnowledgeInfos)} must have 1 IsLocal property equals to true");
            }
            KnowledgeInfo localInfo = parameter.LocalKnowledgeInfos.Where(w => w.IsLocal).First();

            parameter.Log.Add($"SyncTypes Count: {SyncConfiguration.SyncTypes.Count}");
            for (int i = 0; i < SyncConfiguration.SyncTypes.Count; i++)
            {
                Type syncType = SyncConfiguration.SyncTypes[i];
                parameter.Log.Add($"Processing Type: {syncType.Name} ({i + 1} of {SyncConfiguration.SyncTypes.Count})");
                (JObject typeChanges, int typeChangesCount, List <SyncLog.SyncLogData> typeLogChanges) = GetTypeChangesByKnowledge(syncType, localInfo.DatabaseInstanceId, parameter.RemoteKnowledgeInfos, parameter.SynchronizationId, parameter.CustomInfo);
                parameter.Log.Add($"Type Changes Count: {typeChangesCount}");
                if (typeChangesCount != 0 && typeChanges != null)
                {
                    result.Changes.Add(typeChanges);
                }
                result.LogChanges.AddRange(typeLogChanges);
                parameter.Log.Add($"Type: {syncType.Name} Processed");
            }
        }
예제 #9
0
        public override void CreateOrUpdateKnowledgeInfo(KnowledgeInfo knowledgeInfo, string synchronizationId, Dictionary <string, object> customInfo)
        {
            Knowledge knowledge = databaseContext.Knowledges.Where(w => w.SynchronizationID == synchronizationId && w.DatabaseInstanceId == knowledgeInfo.DatabaseInstanceId).FirstOrDefault();

            if (knowledge == null)
            {
                knowledge    = new Knowledge();
                knowledge.ID = Guid.NewGuid();
                knowledge.SynchronizationID  = synchronizationId;
                knowledge.DatabaseInstanceId = knowledgeInfo.DatabaseInstanceId;
                databaseContext.Add(knowledge);
                databaseContext.SaveChanges();
                knowledge = databaseContext.Knowledges.Where(w => w.SynchronizationID == synchronizationId && w.DatabaseInstanceId == knowledgeInfo.DatabaseInstanceId).First();
            }
            knowledge.IsLocal      = knowledgeInfo.IsLocal;
            knowledge.MaxTimeStamp = knowledgeInfo.MaxTimeStamp;
            databaseContext.Update(knowledge);
            databaseContext.SaveChanges();
        }
예제 #10
0
        private void ShowGif(KnowledgeInfo knowledgeInfo)
        {
            string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string path = BaseDirectoryPath + "Gif\\" + knowledgeInfo.Id + ".gif";

            if (File.Exists(path))
            {
                Application.Current.MainWindow.WindowState = WindowState.Maximized;
                DemonstrateWindow window = new DemonstrateWindow(path, knowledgeInfo.Knowledge);
                window.WindowState           = WindowState.Maximized;
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                (Application.Current.MainWindow as WindowX).IsMaskVisible = true;
                window.ShowDialog();
                (Application.Current.MainWindow as WindowX).IsMaskVisible = false;
            }
            else
            {
                MessageBoxHelper.MessageBoxShowWarning("文件不存在!");
            }
        }
예제 #11
0
        internal (Type localSyncType, List <object> appliedIds, List <object> deletedIds) ApplyTypeChanges(List <string> log, List <SyncLog.SyncLogData> inserts, List <SyncLog.SyncLogData> updates, List <SyncLog.SyncLogData> deletes, List <SyncLog.SyncLogConflict> conflicts, JObject typeChanges, string synchronizationId, Dictionary <string, object> customInfo, string sourceDatabaseInstanceId, string destinationDatabaseInstanceId)
        {
            if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
            {
                if (!string.IsNullOrEmpty(sourceDatabaseInstanceId) || !string.IsNullOrEmpty(destinationDatabaseInstanceId))
                {
                    throw new Exception($"{SyncConfiguration.TimeStampStrategy.ToString()} must have {nameof(sourceDatabaseInstanceId)} and {nameof(destinationDatabaseInstanceId)} equals to null");
                }
            }
            else if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
            {
                if (string.IsNullOrEmpty(sourceDatabaseInstanceId) || string.IsNullOrEmpty(destinationDatabaseInstanceId))
                {
                    throw new Exception($"{SyncConfiguration.TimeStampStrategy.ToString()} must have {nameof(sourceDatabaseInstanceId)} and {nameof(destinationDatabaseInstanceId)} both not null");
                }
            }
            else
            {
                throw new NotImplementedException(SyncConfiguration.TimeStampStrategy.ToString());
            }

            List <object>             appliedIds = new List <object>();
            List <object>             deletedIds = new List <object>();
            Dictionary <string, long> databaseInstanceMaxTimeStamps = new Dictionary <string, long>();

            if (inserts == null)
            {
                inserts = new List <SyncLog.SyncLogData>();
            }
            if (updates == null)
            {
                updates = new List <SyncLog.SyncLogData>();
            }
            if (deletes == null)
            {
                deletes = new List <SyncLog.SyncLogData>();
            }
            if (conflicts == null)
            {
                conflicts = new List <SyncLog.SyncLogConflict>();
            }
            string  syncTypeName      = typeChanges["syncType"].Value <string>();
            JObject jObjectSchemaInfo = typeChanges["schemaInfo"].Value <JObject>();

            SyncConfiguration.SchemaInfo schemaInfo = SyncConfiguration.SchemaInfo.FromJObject(jObjectSchemaInfo);
            string localSyncTypeName = syncTypeName;

            if (!string.IsNullOrEmpty(schemaInfo.SyncSchemaAttribute.MapToClassName))
            {
                localSyncTypeName = schemaInfo.SyncSchemaAttribute.MapToClassName;
            }
            Type localSyncType = SyncConfiguration.SyncTypes.Where(w => w.Name == localSyncTypeName).FirstOrDefault();

            if (localSyncType == null)
            {
                throw new SyncEngineConstraintException($"Unable to find SyncType: {localSyncTypeName} in SyncConfiguration");
            }
            SyncConfiguration.SchemaInfo localSchemaInfo = GetSchemaInfo(SyncConfiguration, localSyncType);

            OperationType operationType = OperationType.ApplyChanges;
            object        transaction   = StartTransaction(localSyncType, operationType, synchronizationId, customInfo);

            try
            {
                IQueryable queryable = InvokeGetQueryable(localSyncType, transaction, operationType, synchronizationId, customInfo);
                JArray     datas     = typeChanges["datas"].Value <JArray>();
                log.Add($"Data Count: {datas.Count}");
                for (int i = 0; i < datas.Count; i++)
                {
                    JObject jObjectData = datas[i].Value <JObject>();
                    JValue  id          = jObjectData[schemaInfo.PropertyInfoId.Name].Value <JValue>();
                    long    lastUpdated = jObjectData[schemaInfo.PropertyInfoLastUpdated.Name].Value <long>();

                    long?  deletedGlobalTimeStamp   = null;
                    bool   deletedDatabaseTimeStamp = false;
                    string databaseInstanceId       = null;
                    if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
                    {
                        deletedGlobalTimeStamp = jObjectData[schemaInfo.PropertyInfoDeleted.Name].Value <long?>();
                    }
                    if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                    {
                        deletedDatabaseTimeStamp = jObjectData[schemaInfo.PropertyInfoDeleted.Name].Value <bool>();
                        databaseInstanceId       = jObjectData[schemaInfo.PropertyInfoDatabaseInstanceId.Name].Value <string>();
                    }

                    object  localId     = TransformIdType(localSyncType, id, transaction, operationType, synchronizationId, customInfo);
                    dynamic dynamicData = queryable.Where($"{localSchemaInfo.PropertyInfoId.Name} == @0", localId).FirstOrDefault();
                    object  localData   = (object)dynamicData;

                    if (localData == null)
                    {
                        object newData = InvokeDeserializeJsonToNewData(localSyncType, jObjectData, transaction, operationType, synchronizationId, customInfo);
                        newData.GetType().GetProperty(localSchemaInfo.PropertyInfoId.Name).SetValue(newData, localId);
                        newData.GetType().GetProperty(localSchemaInfo.PropertyInfoLastUpdated.Name).SetValue(newData, lastUpdated);

                        if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
                        {
                            newData.GetType().GetProperty(localSchemaInfo.PropertyInfoDeleted.Name).SetValue(newData, deletedGlobalTimeStamp);
                        }
                        if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                        {
                            newData.GetType().GetProperty(localSchemaInfo.PropertyInfoDeleted.Name).SetValue(newData, deletedDatabaseTimeStamp);
                            newData.GetType().GetProperty(localSchemaInfo.PropertyInfoDatabaseInstanceId.Name).SetValue(newData, GetCorrectDatabaseInstanceId(databaseInstanceId, sourceDatabaseInstanceId, destinationDatabaseInstanceId, databaseInstanceMaxTimeStamps, lastUpdated));
                        }

                        PersistData(localSyncType, newData, true, transaction, operationType, synchronizationId, customInfo);
                        if (!appliedIds.Contains(localId))
                        {
                            appliedIds.Add(localId);
                        }
                        inserts.Add(SyncLog.SyncLogData.FromJObject(InvokeSerializeDataToJson(localSyncType, newData, localSchemaInfo, transaction, operationType, synchronizationId, customInfo), localSyncType, localSchemaInfo));
                    }
                    else
                    {
                        bool isDeleted = false;
                        if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
                        {
                            if (deletedGlobalTimeStamp != null)
                            {
                                isDeleted = true;
                            }
                        }
                        if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                        {
                            if (deletedDatabaseTimeStamp)
                            {
                                isDeleted = true;
                            }
                        }

                        if (!isDeleted)
                        {
                            ConflictType updateConflictType = ConflictType.NoConflict;
                            long         localLastUpdated   = (long)localData.GetType().GetProperty(localSchemaInfo.PropertyInfoLastUpdated.Name).GetValue(localData);
                            if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
                            {
                                if (localLastUpdated > lastUpdated)
                                {
                                    updateConflictType = ConflictType.ExistingDataIsNewerThanIncomingData;
                                }
                            }
                            if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                            {
                                string localDatabaseInstanceId   = (string)localData.GetType().GetProperty(localSchemaInfo.PropertyInfoDatabaseInstanceId.Name).GetValue(localData);
                                string correctDatabaseInstanceId = GetCorrectDatabaseInstanceId(databaseInstanceId, sourceDatabaseInstanceId, destinationDatabaseInstanceId, null, 0);
                                if (localDatabaseInstanceId == correctDatabaseInstanceId)
                                {
                                    if (localLastUpdated > lastUpdated)
                                    {
                                        updateConflictType = ConflictType.ExistingDataIsNewerThanIncomingData;
                                    }
                                }
                                else
                                {
                                    updateConflictType = ConflictType.ExistingDataIsUpdatedByDifferentDatabaseInstanceId;
                                }
                            }

                            object existingData = InvokeDeserializeJsonToExistingData(localSyncType, jObjectData, localData, localId, transaction, operationType, updateConflictType, synchronizationId, customInfo, localSchemaInfo);
                            if (existingData == null && updateConflictType == ConflictType.NoConflict)
                            {
                                throw new SyncEngineConstraintException($"{nameof(DeserializeJsonToExistingData)} must not return null for conflictType equals to {ConflictType.NoConflict.ToString()}");
                            }
                            if (existingData != null)
                            {
                                existingData.GetType().GetProperty(localSchemaInfo.PropertyInfoLastUpdated.Name).SetValue(existingData, lastUpdated);
                                if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                                {
                                    existingData.GetType().GetProperty(localSchemaInfo.PropertyInfoDatabaseInstanceId.Name).SetValue(existingData, GetCorrectDatabaseInstanceId(databaseInstanceId, sourceDatabaseInstanceId, destinationDatabaseInstanceId, databaseInstanceMaxTimeStamps, lastUpdated));
                                }
                                PersistData(localSyncType, existingData, false, transaction, operationType, synchronizationId, customInfo);
                                if (!appliedIds.Contains(localId))
                                {
                                    appliedIds.Add(localId);
                                }
                                updates.Add(SyncLog.SyncLogData.FromJObject(InvokeSerializeDataToJson(localSyncType, existingData, localSchemaInfo, transaction, operationType, synchronizationId, customInfo), localSyncType, localSchemaInfo));
                            }
                            else
                            {
                                log.Add($"CONFLICT Detected: {updateConflictType.ToString()}. Id: {id}");
                                conflicts.Add(new SyncLog.SyncLogConflict(updateConflictType, SyncLog.SyncLogData.FromJObject(jObjectData, localSyncType, schemaInfo)));
                            }
                        }
                        else
                        {
                            object existingData = InvokeDeserializeJsonToExistingData(localSyncType, jObjectData, localData, localId, transaction, operationType, ConflictType.NoConflict, synchronizationId, customInfo, localSchemaInfo);

                            if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp)
                            {
                                existingData.GetType().GetProperty(localSchemaInfo.PropertyInfoDeleted.Name).SetValue(existingData, deletedGlobalTimeStamp);
                            }
                            if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                            {
                                existingData.GetType().GetProperty(localSchemaInfo.PropertyInfoDeleted.Name).SetValue(existingData, deletedDatabaseTimeStamp);
                                existingData.GetType().GetProperty(localSchemaInfo.PropertyInfoDatabaseInstanceId.Name).SetValue(existingData, GetCorrectDatabaseInstanceId(databaseInstanceId, sourceDatabaseInstanceId, destinationDatabaseInstanceId, databaseInstanceMaxTimeStamps, lastUpdated));
                            }

                            PersistData(localSyncType, existingData, false, transaction, operationType, synchronizationId, customInfo);
                            if (!appliedIds.Contains(localId))
                            {
                                appliedIds.Add(localId);
                            }
                            if (!deletedIds.Contains(localId))
                            {
                                deletedIds.Add(localId);
                            }
                            deletes.Add(SyncLog.SyncLogData.FromJObject(InvokeSerializeDataToJson(localSyncType, existingData, localSchemaInfo, transaction, operationType, synchronizationId, customInfo), localSyncType, localSchemaInfo));
                        }
                    }
                }
                if (SyncConfiguration.TimeStampStrategy == SyncConfiguration.TimeStampStrategyEnum.DatabaseTimeStamp)
                {
                    foreach (var item in databaseInstanceMaxTimeStamps)
                    {
                        KnowledgeInfo knowledgeInfo = GetAllKnowledgeInfos(synchronizationId, customInfo).Where(w => w.DatabaseInstanceId == item.Key).FirstOrDefault();
                        if (knowledgeInfo != null && knowledgeInfo.MaxTimeStamp > item.Value)
                        {
                            continue;
                        }
                        if (knowledgeInfo == null && item.Key == destinationDatabaseInstanceId)
                        {
                            throw new SyncEngineConstraintException("Unexpected Knowledge Info State on Destination. Destination is not provisioned yet.");
                        }
                        if (knowledgeInfo == null)
                        {
                            knowledgeInfo = new KnowledgeInfo()
                            {
                                DatabaseInstanceId = item.Key,
                                IsLocal            = false
                            };
                        }
                        knowledgeInfo.MaxTimeStamp = item.Value;
                        CreateOrUpdateKnowledgeInfo(knowledgeInfo, synchronizationId, customInfo);
                    }
                }
                CommitTransaction(localSyncType, transaction, operationType, synchronizationId, customInfo);
            }
            catch (Exception)
            {
                RollbackTransaction(localSyncType, transaction, operationType, synchronizationId, customInfo);
                throw;
            }
            finally
            {
                EndTransaction(localSyncType, transaction, operationType, synchronizationId, customInfo);
            }

            return(localSyncType, appliedIds, deletedIds);
        }
예제 #12
0
        internal (JObject typeChanges, int typeChangesCount, List <SyncLog.SyncLogData> logChanges) GetTypeChangesByKnowledge(Type syncType, string localDatabaseInstanceId, List <KnowledgeInfo> remoteKnowledgeInfos, string synchronizationId, Dictionary <string, object> customInfo)
        {
            if (string.IsNullOrEmpty(synchronizationId))
            {
                throw new NullReferenceException(nameof(synchronizationId));
            }
            if (customInfo == null)
            {
                customInfo = new Dictionary <string, object>();
            }

            List <SyncLog.SyncLogData> logChanges = new List <SyncLog.SyncLogData>();

            SyncConfiguration.SchemaInfo schemaInfo = GetSchemaInfo(SyncConfiguration, syncType);
            JObject typeChanges = null;
            JArray  datas       = new JArray();

            OperationType operationType = OperationType.GetChanges;
            object        transaction   = StartTransaction(syncType, operationType, synchronizationId, customInfo);

            try
            {
                IQueryable queryable = InvokeGetQueryable(syncType, transaction, operationType, synchronizationId, customInfo);

                string predicate        = "";
                string predicateUnknown = "";
                for (int i = 0; i < remoteKnowledgeInfos.Count; i++)
                {
                    KnowledgeInfo info = remoteKnowledgeInfos[i];

                    string knownDatabaseInstanceId = null;
                    if (info.DatabaseInstanceId == localDatabaseInstanceId)
                    {
                        knownDatabaseInstanceId = "null";
                    }
                    else
                    {
                        knownDatabaseInstanceId = $"\"{info.DatabaseInstanceId}\"";
                    }

                    if (!string.IsNullOrEmpty(predicate))
                    {
                        predicate += " || ";
                    }
                    predicate += "(";
                    predicate += $"{schemaInfo.PropertyInfoDatabaseInstanceId.Name} = {knownDatabaseInstanceId} ";
                    predicate += $" && {schemaInfo.PropertyInfoLastUpdated.Name} > {info.MaxTimeStamp}";
                    predicate += ")";

                    if (!string.IsNullOrEmpty(predicateUnknown))
                    {
                        predicateUnknown += " && ";
                    }
                    predicateUnknown += $"{schemaInfo.PropertyInfoDatabaseInstanceId.Name} != {knownDatabaseInstanceId}";
                }
                queryable = queryable.Where($"{predicate} || ({predicateUnknown})");
                queryable = queryable.OrderBy($"{schemaInfo.PropertyInfoDeleted.Name}, {schemaInfo.PropertyInfoLastUpdated.Name}");
                List <dynamic> dynamicDatas = queryable.ToDynamicList();
                if (dynamicDatas.Count > 0)
                {
                    typeChanges = new JObject();
                    typeChanges[nameof(syncType)]   = syncType.Name;
                    typeChanges[nameof(schemaInfo)] = schemaInfo.ToJObject();
                    foreach (dynamic dynamicData in dynamicDatas)
                    {
                        JObject jObjectData = InvokeSerializeDataToJson(syncType, dynamicData, schemaInfo, transaction, operationType, synchronizationId, customInfo);
                        datas.Add(jObjectData);
                        logChanges.Add(SyncLog.SyncLogData.FromJObject(jObjectData, syncType, schemaInfo));
                    }
                    typeChanges[nameof(datas)] = datas;
                }
                CommitTransaction(syncType, transaction, operationType, synchronizationId, customInfo);
            }
            catch (Exception)
            {
                RollbackTransaction(syncType, transaction, operationType, synchronizationId, customInfo);
                throw;
            }
            finally
            {
                EndTransaction(syncType, transaction, operationType, synchronizationId, customInfo);
            }
            return(typeChanges, datas.Count, logChanges);
        }
예제 #13
0
 private void StartBrowser(KnowledgeInfo knowledgeInfo)
 {
     Process.Start(new ProcessStartInfo(knowledgeInfo.Solution));
 }
예제 #14
0
 public virtual void CreateOrUpdateKnowledgeInfo(KnowledgeInfo knowledgeInfo, string synchronizationId, Dictionary <string, object> customInfo)
 {
     //must implement if SyncConfiguration.TimeStampStrategy = UseEachDatabaseInstanceTimeStamp
     throw new NotImplementedException();
 }