static void Main(string[] args) { var importedStructure = new Import.Import(); //var state = importedStructure.GetFullGraphFormFile(Import.Import.ReadImport( // @"D:\RiderProjects\CourseWorkOperationResearch\Import\import.json")); var state = importedStructure.GenerateOrpGraph(1000, 640, true); var greedySearchResult = new GreedySearch.GreedySearch().Run(state, 640); var c = greedySearchResult.Sum(x => x.Cost); var costay = importedStructure.Graph.OrderByDescending(x => x.Cost).Take(640).Sum(x => x.Cost); var acoResult = new AntColonyOptimizationAlgorithm.AntColonyOptimization().Run(importedStructure.Graph, state, 640); }
public void BulkImportData() { var entities = new List<Import.ImportEntity>(); var now = DateTime.Now.ToShortTimeString(); const int numberOfEntities = 1500; for (var i = 0; i < numberOfEntities; i++) { var entityGuid = Guid.Parse("00000000-0000-0000-0000-" + i.ToString("000000000000")); var entity = new Import.ImportEntity { EntityGuid = entityGuid, AttributeSetStaticName = "4e0f8568-a2fe-435c-abda-0602dddeb400", AssignmentObjectTypeId = Constants.DefaultAssignmentObjectTypeId }; entity.Values = new Dictionary<string, List<IValueImportModel>> { { "Name", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "Buchs " + now }}}, { "Live", new List<IValueImportModel>{new ValueImportModel<bool?>(entity) { Value = true }}}, { "NumberOfCards", new List<IValueImportModel>{new ValueImportModel<decimal?>(entity) { Value = 5 }}}, { "Notes", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "Test 1234567890" }}}, { "Uses2Reserve", new List<IValueImportModel>{new ValueImportModel<bool?>(entity) { Value = true }}}, { "Website", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "http://www.2sic.com" }}}, { "Email", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "*****@*****.**" }}}, { "Price", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "40.-" }}}, { "Canton", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = "SG" }}}, { "Now", new List<IValueImportModel>{new ValueImportModel<string>(entity) { Value = now }}}, }; entities.Add(entity); } var import = new Import.Import(2, 2, "BulkImportData", leaveExistingValuesUntouched: true); import.RunImport(null, entities); Assert.IsEmpty(import.ImportLog.Where(l => l.EntryType == EventLogEntryType.Error)); }
public void TestImport() { #region Prepare Date for Import var now = DateTime.Now.ToLongTimeString().Replace(":", ""); //now = "130832"; const int assignmentObjectTypeId = 3; var attributeSet1 = GetAttributeSet(1, now); var attributeSet2 = GetAttributeSet(2, now); var attributeSet3 = GetAttributeSet(3, now); var attributeSets = new List<Import.ImportAttributeSet> { attributeSet1, attributeSet2, attributeSet3 }; var entities = new List<Import.ImportEntity>(); foreach (var attributeSet in attributeSets) { var entityGuid = Guid.NewGuid(); //if (attributeSet.StaticName == "AttributeSet_130832_1") // entityGuid = new Guid("fe4ea5d9-7edc-4080-8ae3-12c4c3176b32"); // Test update existing Entity var entity1 = GetEntity(assignmentObjectTypeId, attributeSet.StaticName, Guid.NewGuid(), 123, attributeSet); var entity2 = GetEntity(assignmentObjectTypeId, attributeSet.StaticName, entityGuid, null, attributeSet, entity1.EntityGuid); entities.Add(entity1); entities.Add(entity2); } #endregion // Start the Import var import = new Import.Import(2, 2, "ImportTest"); var importTransaction = import.RunImport(attributeSets, entities, false, false); importTransaction.Commit(); //importTransaction.Rollback(); foreach (var logItem in import.ImportLog) { string message; switch (logItem.EntryType) { case EventLogEntryType.Error: message = logItem.Message; if (logItem.Exception != null) message += ". " + logItem.Exception.Message; Trace.TraceError(message); break; case EventLogEntryType.Warning: message = logItem.Message; if (logItem.Exception != null) message += ". " + logItem.Exception.Message; Trace.TraceWarning(message); break; case EventLogEntryType.Information: message = logItem.Message; if (logItem.Exception != null) message += ". " + logItem.Exception.Message; Trace.TraceInformation(message); break; default: message = logItem.Message; if (logItem.Exception != null) message += ". " + logItem.Exception.Message; Trace.WriteLine(message); break; } } Assert.IsFalse(import.ImportLog.Any(l => l.EntryType == EventLogEntryType.Error)); }
public void UpdateExistingDataMultilingual(int appId = 2, int entityId = 5449) { var db = EavContext.Instance(appId: appId); var entityGuid = db.Entities.Where(e => e.EntityID == entityId).Select(e => (Guid?)e.EntityGUID).SingleOrDefault(); var attributeSetStaticName = db.AttributeSets.Where(a => a.AppID == db.AppId && a.Name == "News").Select(a => a.StaticName).Single(); var entity = new Import.ImportEntity { EntityGuid = entityGuid, AttributeSetStaticName = attributeSetStaticName, AssignmentObjectTypeId = Constants.DefaultAssignmentObjectTypeId }; // Title first Import var titleValue = new List<IValueImportModel> { new ValueImportModel<string>(entity) { Value = "Third News en & de", ValueDimensions = new List<Import.ValueDimension> { new Import.ValueDimension {DimensionExternalKey = "en-us", ReadOnly = false}, new Import.ValueDimension {DimensionExternalKey = "de-ch", ReadOnly = false}, } } }; // title second Import if (entityGuid.HasValue) titleValue = new List<IValueImportModel> { new ValueImportModel<string>(entity) { Value = "Third News en", ValueDimensions = new List<Import.ValueDimension> { new Import.ValueDimension {DimensionExternalKey = "en-us", ReadOnly = false}, } }, new ValueImportModel<string>(entity) { Value = "Third News de", ValueDimensions = new List<Import.ValueDimension> { new Import.ValueDimension {DimensionExternalKey = "de-ch", ReadOnly = false}, } } }; entity.Values = new Dictionary<string, List<IValueImportModel>> { {"Title", titleValue}, {"Date", new List<IValueImportModel> { new ValueImportModel<DateTime?>(entity) { Value = new DateTime(2014,3,18), ValueDimensions = new List<Import.ValueDimension> { new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false}, new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = true}, } } }}, {"Short", new List<IValueImportModel> { new ValueImportModel<string>(entity) { Value = "Third news short", ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false}} }, new ValueImportModel<string>(entity) { Value = "Dritte News kurz", ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = false}} } }}, {"Long", new List<IValueImportModel> { new ValueImportModel<string>(entity) { Value = "Third news long", ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "en-US", ReadOnly = false}} }, new ValueImportModel<string>(entity) { Value = "Dritte News lang", ValueDimensions = new List<Import.ValueDimension>{ new Import.ValueDimension{ DimensionExternalKey = "de-CH", ReadOnly = false}} } }}, }; var entities = new List<Import.ImportEntity> { entity }; var import = new Import.Import(db.ZoneId, db.AppId, "UpdateExistingDataMultilingual", true); import.RunImport(null, entities); //Assert.IsEmpty(import.ImportLog); Assert.IsFalse(import.ImportLog.Any(l => l.EntryType == EventLogEntryType.Error)); }
public void UpdateExistingData() { // Update Attribute Set const string attributeSetStaticName = "AttributeSet_181655_1"; const string now = "181655"; var attributeSet = new Import.ImportAttributeSet { Attributes = GetAttributes(1, now), Description = "New Description", Name = "New Name", Scope = "New Scope", StaticName = attributeSetStaticName, }; attributeSet.Attributes.Add(new Import.ImportAttribute { StaticName = "AttributeAddedLater", Type = "String" }); attributeSet.TitleAttribute = attributeSet.Attributes.Last(); const bool overwriteExistingEntityValues = true; var import = new Import.Import(2, 2, "ImportTest2", overwriteExistingEntityValues); var attributeSets = new List<Import.ImportAttributeSet> { attributeSet }; // Update Entity const int entityId = 5483; var db = new EavContext(); var entityGuid = db.Entities.Where(e => e.EntityID == entityId).Select(e => e.EntityGUID).Single(); var entity = new Import.ImportEntity { EntityGuid = entityGuid, AttributeSetStaticName = attributeSetStaticName, KeyNumber = 999, AssignmentObjectTypeId = Constants.DefaultAssignmentObjectTypeId }; entity.Values = GetEntityValues(entity, attributeSet, isUpdate: true, now: DateTime.Now.ToLongTimeString().Replace(":", "")); var entities = new List<Import.ImportEntity> { entity }; import.RunImport(null, entities); Assert.IsEmpty(import.ImportLog); Assert.IsFalse(import.ImportLog.Any(l => l.EntryType == EventLogEntryType.Error)); }
public void UpdateEntityHavingDraft() { int appId = 2, entityId = 5454; var db = EavContext.Instance(appId: appId); var entityGuid = db.Entities.Where(e => e.EntityID == entityId && !e.ChangeLogIDDeleted.HasValue).Select(e => (Guid?)e.EntityGUID).SingleOrDefault(); var entities = new List<Import.ImportEntity> { GetSampleNewsEntity(db, entityGuid) }; var import = new Import.Import(db.ZoneId, db.AppId, "UpdateDraftEntity", true); import.RunImport(null, entities); Assert.IsFalse(import.ImportLog.Any(l => l.EntryType == EventLogEntryType.Error)); }
/// <summary> /// Save the data in memory to the repository. /// </summary> /// <param name="userId">ID of the user doing the import</param> /// <returns>True if succeeded</returns> public bool PersistImportToRepository(string userId) { if (ErrorProtocol.HasErrors) return false; if (_entityClear.IsAll()) { var entityDeleteGuids = GetEntityDeleteGuids(); foreach(var entityGuid in entityDeleteGuids) { var entityId = _contentType.GetEntity(entityGuid).EntityID; var context = EavDataController.Instance(_zoneId, _appId); if (context.Entities.CanDeleteEntity(entityId)/* context.EntCommands.CanDeleteEntity(entityId)*/.Item1) context.Entities.DeleteEntity(entityId); } } var import = new Import.Import(_zoneId, _appId, userId, dontUpdateExistingAttributeValues: false, keepAttributesMissingInImport: true); Timer.Start(); import.RunImport(null, Entities); Timer.Stop(); TimeForDbImport = Timer.ElapsedMilliseconds; return true; }
private void ImportOpMsgs() { Import.Import import = new Import.Import(); Import.Filter f = new Import.Filter(); import.filters.Clear(); //f.msg = "账户余额信息(*.mon)"; //f.ftr = "*.mon"; //import.AddFilter(f); f.msg = "操作日志文件(*.msg)"; f.ftr = "*.msg"; import.AddFilter(f); import.extension = ".msg"; import.fileNames.Clear(); //import.fileNames.Add("m.mon"); //import.fileNames.Add("mg.msg"); //import.fileNames.Add("logcat.log"); //import.destination = loginedUser.UserFolder; import.SelectItem(); string[] dess = import.source.ToArray(); //string[] srcs = import.source.ToArray(); string des; string[] src; if (dess != null && dess.Length > 0) { des = dess[0]; src = File_Operate.LoadFromHiddenTextFile(des, Encoding.Default); HistoryWin h = new HistoryWin(src); h.ShowDialog(); } else { MessageBox.Show("未能找到匹配项,无法导入!"); } //for (int index = 0; index < dess.Length; index++) //{ // des = import.destination + "\\" + dess[index]; // src = import.GetCorrespondingItem("*.msg"); // if (src != null) // { // import.ImportItem(des, src, Import.Import.ImportOptions.APPENDSTART); // } // else // { // MessageBox.Show("未能找到匹配项,无法导入!"); // break;//选择文件格式不正确 // } //} }
public Dictionary<Guid, int> SaveMany([FromUri] int appId, [FromBody] List<EntityWithHeader> items) { var entitiesToImport = new List<ImportEntity>(); // must move guid from header to entity, because we only transfer it on the header (so no duplicates) foreach (var i in items) i.Entity.Guid = i.Header.Guid; foreach (var entity in items) if (entity.Header.Group == null || !entity.Header.Group.SlotIsEmpty) // skip the ones which "shouldn't" be saved entitiesToImport.Add(CreateImportEntity(entity, appId)); // Create Import-controller & run import var importController = new Import.Import(null, appId, UserIdentityToken, dontUpdateExistingAttributeValues: false, keepAttributesMissingInImport: false, preventUpdateOnDraftEntities: false, largeImport: false); importController.RunImport(null, entitiesToImport.ToArray()); // find / update IDs of items updated to return to client var cache = DataSource.GetCache(null, appId); var foundItems = items.Select(e => { var foundEntity = cache.LightList.FirstOrDefault(c => e.Header.Guid == c.EntityGuid); if (foundEntity == null) return null; if (foundEntity.GetDraft() != null) return foundEntity.GetDraft(); return foundEntity; }).Where(e => e != null); var IdList = foundItems.ToDictionary(f => f.EntityGuid, f => f.EntityId); return IdList; }
/// <summary> /// Restore an Entity to the specified Version by creating a new Version using the Import /// </summary> public void RestoreEntityVersion(int entityId, int changeId, int? defaultCultureDimension) { // Get Entity in specified Version/ChangeId var newVersion = GetEntityVersion(entityId, changeId, defaultCultureDimension); // Restore Entity var import = new Import.Import(Context.ZoneId /* _zoneId*/,Context.AppId /* _appId*/, Context.UserName, false, false); import.RunImport(null, new List<Import.ImportEntity> { newVersion }); // Delete Draft (if any) var entityDraft = new DbLoadIntoEavDataStructure(Context).GetEavEntity(entityId).GetDraft(); if (entityDraft != null) Context.Entities.DeleteEntity(entityDraft.RepositoryId); }