private void WizardControl_SelectedPageChanging(object sender, WizardPageChangingEventArgs e) { if (e.PrevPage == wizardPage1 && e.Direction == Direction.Forward) { e.Page = wizardPage3; } if (e.PrevPage == wizardPage2 && e.Direction == Direction.Forward) { if ((bool)radioGroup2.EditValue) { ImportMap.Description = ImportMapDescriptionEdit.Text; ImportMap.Save(); //var uow = new UnitOfWork(ObjectSpace.Session.DataLayer); //var a = uow.(ImportMap.Oid); //a.Save(); //uow.CommitTransaction(); ObjectSpace.Session.Reload(ImportMap); } } if (e.PrevPage == wizardPage3 && e.Direction == Direction.Backward) { e.Page = wizardPage1; } if (e.PrevPage == welcomeWizardPage1 && e.Direction == Direction.Forward) { MappingRadioGroup.SelectedIndex = 1; } }
public void TestWithConverter() { string trueValue = "Y"; FieldMap map = new FieldMap("source", "dest", new StringToBool(trueValue)); Assert.AreEqual(true, ImportMap.ConvertValue(trueValue, map, new BooleanAttributeMetadata(), service)); }
/// <summary> /// Import Local Areas /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BcBidImport.SigId, NewTable); if (startPoint == BcBidImport.SigId) // this means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } try { string rootAttr = "ArrayOf" + OldTable; // create Processer progress indicator performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(Area[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); Area[] legacyItems = (Area[])ser.Deserialize(memoryStream); int ii = startPoint; // skip the portion already processed if (startPoint > 0) { legacyItems = legacyItems.Skip(ii).ToArray(); } Debug.WriteLine("Importing LocalArea Data. Total Records: " + legacyItems.Length); foreach (Area item in legacyItems.WithProgress(progress)) { // see if we have this one already ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == item.Area_Id.ToString()); // new entry if (importMap == null && item.Area_Id > 0) { LocalArea localArea = null; CopyToInstance(dbContext, item, ref localArea, systemId); ImportUtility.AddImportMap(dbContext, OldTable, item.Area_Id.ToString(), NewTable, localArea.Id); } } performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); throw; } }
private void MappingRadioGroup_SelectedIndexChanged_1(object sender, EventArgs e) { ImportMapLookUp.Enabled = MappingRadioGroup.SelectedIndex == 0; GuesMappingButton.Enabled = MappingRadioGroup.SelectedIndex == 1; switch (MappingRadioGroup.SelectedIndex) { case 0: ImportMap = ObjectSpace.Session.GetObjectByKey <ImportMap>(ImportMapLookUp.EditValue, false); break; case 1: if (ImportMap != null) { //var c = new Cloner(); //var cc = c.CloneTo(ImportMap, typeof(ImportMap)); //(cc as ImportMap).Description = string.Empty; ////var im = Hellper.Clone(ImportMap, Session); ////var im = ImportMap.Clone(typeof (ImportMap)); //ImportMap = (ImportMap)cc; } else { ImportMap = new ImportMap(ObjectSpace.Session); } break; default: throw new NotImplementedException(); } }
private void BassTierNumeric_ValueChanged(object sender, EventArgs e) { BassTierPicture.Image = Program.Form.Tiers[ImportMap.GetBaseTier(Instrument.Bass, (int)BassTierNumeric.Value)]; if (Song != null) { Song.Difficulty[Instrument.Bass] = (int)BassTierNumeric.Value; } }
public void TestConstructor() { string entityname = "entity"; FieldMap fieldMapping = new FieldMap("source", "target"); ImportMap map = new ImportMap(entityname, fieldMapping); Assert.AreEqual(entityname, map.EntityName); Assert.AreEqual(fieldMapping, map.Key); }
/// <summary> /// Import existing Cities /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> private static void ImportCities(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BcBidImport.SigId, NewTable); if (startPoint == BcBidImport.SigId) // this means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } int maxCityIndex = 0; if (dbContext.Cities.Any()) { maxCityIndex = dbContext.Cities.Max(x => x.Id); } try { string rootAttr = "ArrayOf" + OldTable; performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(HetsCity[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); HetsCity[] legacyItems = (HetsCity[])ser.Deserialize(memoryStream); foreach (HetsCity item in legacyItems.WithProgress(progress)) { // see if we have this one already ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == item.City_Id.ToString()); // new entry if (importMap == null) { City city = null; CopyToInstance(dbContext, item, ref city, systemId, ref maxCityIndex); ImportUtility.AddImportMap(dbContext, OldTable, item.City_Id.ToString(), NewTable, city.Id); } } performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); throw; } }
public void ConvertToDictionaryTests() { string fieldValue = "Value"; var result = ImportMap.ConvertToDictionary(new DummyClass { DummyField = fieldValue }); Assert.IsTrue(result.ContainsKey("DummyField")); Assert.AreEqual(result["DummyField"], fieldValue); }
public static string GetImportMap(RestCommand command, int importMapID) { ImportMap importMap = ImportMaps.GetImportMap(command.LoginUser, importMapID); if (importMap.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(importMap.GetXml("ImportMap", true)); }
public void TestWithMultipleConverters() { string trueValue = "Yes"; StringMapTranslation stringMapConverter = new StringMapTranslation(new Dictionary <string, string> { ["Yes"] = "Y" }); StringToBool toBoolConverter = new StringToBool("Y"); FieldMap map = new FieldMap("source", "dest", stringMapConverter, toBoolConverter); Assert.AreEqual(true, ImportMap.ConvertValue(trueValue, map, new BooleanAttributeMetadata(), service)); }
public ActionResult DeleteConfirmed(int id) { ImportMap importMap = db.ImportMaps.Find(id); db.ImportMaps.Remove(importMap); db.SaveChanges(); if (Request.IsAjaxRequest()) { return(Content(null)); } return(RedirectToAction("Index")); }
public void TestConstructorWithHandlers() { string entityname = "entity"; IActionHandler createHandler = new EmptyHandler(); IActionHandler updateHandler = new EmptyHandler(); FieldMap fieldMapping = new FieldMap("source", "target"); ImportMap map = new ImportMap(entityname, fieldMapping, createHandler, updateHandler); Assert.AreEqual(entityname, map.EntityName); Assert.AreEqual(fieldMapping, map.Key); Assert.AreEqual(createHandler, map.CreateHandler); Assert.AreEqual(updateHandler, map.UpdateHandler); }
/// <summary> /// Utility function to add a new ImportMap to the database /// </summary> /// <param name="dbContext"></param> /// <param name="oldTable"></param> /// <param name="oldKey"></param> /// <param name="newTable"></param> /// <param name="newKey"></param> public static void AddImportMap(DbAppContext dbContext, string oldTable, string oldKey, string newTable, int newKey) { ImportMap importMap = new ImportMap { OldTable = oldTable, OldKey = oldKey, NewTable = newTable, NewKey = newKey, AppCreateTimestamp = DateTime.Now, AppLastUpdateTimestamp = DateTime.Now }; dbContext.ImportMaps.Add(importMap); }
/// <summary> /// /// Return startPoint: 0 - if ImportMap entry with oldTable == "%%%%%_Progress" does not exist /// sigId - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey = signId.toString() /// Other int - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey != signId.toString() /// The Import_Table entry for this kind of record has NewTable as BCBidImport.todayDate. /// </summary> /// <param name="dbContext"></param> /// <param name="oldTable_Progress"></param> /// <param name="sigId"></param> /// <returns></returns> static public int CheckInterMapForStartPoint(DbAppContext dbContext, string oldTable_Progress, int sigId) { int startPoint; ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == oldTable_Progress && x.NewTable == BCBidImport.todayDate && x.NewKey == sigId); if (importMap != null) { // OlkdKey is recorded where the import progress stopped last time. // When it store the value of sigId, it signal the completion of the import of the corresponding xml file. startPoint = int.Parse(importMap.OldKey); } else //If the table of Import_MAP does not have any entry (row), it means the importing process has not started yet. { startPoint = 0; } return(startPoint); }
/// <summary> /// Return startPoint: 0 - if ImportMap entry with oldTable == "%%%%%_Progress" does not exist /// sigId - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey = signId.toString() /// Other int - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey != signId.toString() /// The Import_Table entry for this kind of record has NewTable as BCBidImport.todayDate. /// </summary> /// <param name="dbContext"></param> /// <param name="oldTableProgress"></param> /// <param name="sigId"></param> /// <param name="newTable"></param> /// <returns></returns> public static int CheckInterMapForStartPoint(DbAppContext dbContext, string oldTableProgress, int sigId, string newTable) { ImportMap importMap = ( from u in dbContext.ImportMaps where u.OldTable == oldTableProgress && u.NewKey == sigId && u.NewTable == newTable orderby int.Parse(u.OldKey) descending select u) .FirstOrDefault(); // OlkdKey is recorded where the import progress stopped last time // when it stores the value of sigId, it signals the completion of the import of the corresponding xml file int startPoint = importMap != null?int.Parse(importMap.OldKey) : 0; return(startPoint); }
/// <summary> /// Creates the import mapping record. /// </summary> private void CreateImportMapping() { // Create the import map and populate a column ImportMap importMap = new ImportMap() { Name = "Original Import Mapping" + DateTime.Now.Ticks.ToString(), Source = "Import Accounts.csv", Description = "Description of data being imported", EntitiesPerFile = new OptionSetValue((int)ImportMapEntitiesPerFile.SingleEntityPerFile), EntityState = EntityState.Created }; _importMapId = _serviceProxy.Create(importMap); Console.WriteLine(String.Concat("Import map created: ", _importMapId.Value)); #region Column One Mappings // Create a column mapping for a 'text' type field ColumnMapping colMapping1 = new ColumnMapping() { // Set source properties SourceAttributeName = "name", SourceEntityName = "Account_1", // Set target properties TargetAttributeName = "name", TargetEntityName = Account.EntityLogicalName, // Relate this column mapping with the data map ImportMapId = new EntityReference(ImportMap.EntityLogicalName, _importMapId.Value), // Force this column to be processed ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process) }; // Create the mapping Guid colMappingId1 = _serviceProxy.Create(colMapping1); Console.WriteLine(String.Concat("Column mapping added SourceAttributeName: name", ", TargetAttributeName: name, TargetEntityName: account")); #endregion }
private void Open(string path) { Engine platform; Game game; if (!SelectPlatform(PlatformDetection.DetectPlaform(path), out platform, out game)) { return; } GetAsyncProgress().QueueTask(progress => { progress.NewTask("Loading content from " + platform.Name, 3); PlatformData data = platform.Create(path, game, progress); progress.Progress(); ImportMap map = new ImportMap(data.Game); map.AddSongs(data, progress); progress.Progress(); data.Mutex.WaitOne(); progress.NewTask(data.Songs.Count); foreach (FormatData song in data.Songs) { map.Populate(song.Song); progress.Progress(); } data.Mutex.ReleaseMutex(); progress.EndTask(); progress.Progress(); if (data.Game == Game.LegoRockBand) { progress.NewTask("Loading Rock Band 1 content from Lego Rock Band"); Exports.ImportRB1Lipsync(data); progress.Progress(); progress.EndTask(); } SongUpdateMutex.WaitOne(); Platforms.Add(data); SongUpdateMutex.ReleaseMutex(); UpdateSongList(); UpdatePlatformList(); progress.EndTask(); }); }
/// <summary> /// Creates the import mapping record. /// </summary> private static void CreateImportMapping(CrmServiceClient service) { // Create the import map and populate a column ImportMap importMap = new ImportMap() { Name = "Original Import Mapping" + DateTime.Now.Ticks.ToString(), Source = "Import Accounts.csv", Description = "Description of data being imported", EntitiesPerFile = new OptionSetValue((int)ImportMapEntitiesPerFile.SingleEntityPerFile), EntityState = EntityState.Created }; _importMapId = service.Create(importMap); Console.WriteLine(String.Concat("Import map created: ", _importMapId.Value)); #region Column One Mappings // Create a column mapping for a 'text' type field ColumnMapping colMapping1 = new ColumnMapping() { // Set source properties SourceAttributeName = "name", SourceEntityName = "Account_1", // Set target properties TargetAttributeName = "name", TargetEntityName = Account.EntityLogicalName, // Relate this column mapping with the data map ImportMapId = new EntityReference(ImportMap.EntityLogicalName, _importMapId.Value), // Force this column to be processed ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process) }; // Create the mapping Guid colMappingId1 = service.Create(colMapping1); Console.WriteLine(String.Concat("Column mapping added SourceAttributeName: name", ", TargetAttributeName: name, TargetEntityName: account")); #endregion }
// GET: ImportMaps/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ImportMap importMap = db.ImportMaps.Find(id); if (importMap == null) { return(HttpNotFound()); } if (Request.IsAjaxRequest()) { return(PartialView(importMap)); } return(View(importMap)); }
public IActionResult SaveMap(ImportModel model) { if (model.ImportMapId.Equals(Guid.Empty)) { var importMapEntity = new ImportMap { Description = "", ImportMapId = Guid.NewGuid(), MapCustomizations = model.MapCustomizations.UrlDecode(), MapType = 1, Name = model.Name, TargetEntityName = model.EntityName, CreatedBy = CurrentUser.SystemUserId }; _importMapService.Create(importMapEntity); model.ImportMapId = importMapEntity.ImportMapId; } return ImportData(model); }
// GET: ImportMaps/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ImportMap importMap = db.ImportMaps.Find(id); if (importMap == null) { return(HttpNotFound()); } ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", importMap.CompanyId); ViewBag.CurrencyId = new SelectList(db.Currencies, "Id", "Name", importMap.CurrencyId); if (Request.IsAjaxRequest()) { return(PartialView(importMap)); } return(View(importMap)); }
public ActionResult Create([Bind(Include = "Id,CompanyId,Name,SkipFirstRow,C_CompanyProductIdI,C_NameI,C_SkuI,C_PriceI,C_DescriptionI,C_CategoryI")] ImportMap importMap) { if (ModelState.IsValid) { db.ImportMaps.Add(importMap); db.SaveChanges(); if (Request.IsAjaxRequest()) { return(Content(null)); } return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", importMap.CompanyId); ViewBag.CurrencyId = new SelectList(db.Currencies, "Id", "Name", importMap.CurrencyId); if (Request.IsAjaxRequest()) { return(PartialView(importMap)); } return(View(importMap)); }
public ActionResult Edit(ImportMap importMap) { if (ModelState.IsValid) { db.Entry(importMap).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); if (Request.IsAjaxRequest()) { return(Content(null)); } return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", importMap.CompanyId); ViewBag.CurrencyId = new SelectList(db.Currencies, "Id", "Name", importMap.CurrencyId); if (Request.IsAjaxRequest()) { return(PartialView(importMap)); } return(View(importMap)); }
static void Main(string[] args) { ImportMap importMap = new ImportMap(); MapTransformer mapTrans = new MapTransformer(); ImportTraj importTraj = new ImportTraj(); RandomMap rand = new RandomMap(); TrajGenerator trajGenerator = new TrajGenerator(); TrajSaver trajSaver = new TrajSaver(); MapPruner mapPruner = new MapPruner(); SampleNeighbourhood sampleNeighbourhood = new SampleNeighbourhood(); MapSaver mapSaver = new MapSaver(); Evaluator eval = new Evaluator(rand, sampleNeighbourhood); Map gt = importMap.ReadMap($"Chicago/Chicago-200-directed-50-100"); Map cm = importMap.ReadMap($"Kharita/Directed/Chicago-200-50-100"); (float, float)precall = eval.EvalNeighbourhood(gt, cm); Console.WriteLine(precall); }
/// <summary> /// Return startPoint: 0 - if ImportMap entry with oldTable == "%%%%%_Progress" does not exist /// sigId - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey = signId.toString() /// Other int - if ImportMap entry with oldTable == "%%%%%_Progress" exist, and oldKey != signId.toString() /// The Import_Table entry for this kind of record has NewTable as BCBidImport.todayDate. /// </summary> /// <param name="dbContext"></param> /// <param name="oldTableProgress"></param> /// <param name="sigId"></param> /// <returns></returns> public static int CheckInterMapForStartPoint(DbAppContext dbContext, string oldTableProgress, int sigId) { int startPoint; ImportMap importMap = (from u in dbContext.ImportMaps where u.OldTable == oldTableProgress && u.NewKey == sigId orderby int.Parse(u.OldKey) descending select u).FirstOrDefault(); // OlkdKey is recorded where the import progress stopped last time // when it stores the value of sigId, it signals the completion of the import of the corresponding xml file if (importMap != null) { startPoint = int.Parse(importMap.OldKey); } else { // if the table of Import_MAP does not have any entry (row), it means the importing process has not started yet startPoint = 0; } return(startPoint); }
public ImportFile Import(Guid importFileId) { ImportFile file = _importFileService.FindById(importFileId); ImportMap map = _importMapService.FindById(file.ImportMapId); var data = new List <dynamic>().DeserializeFromJson(file.Content); this.ImportCore(file, map, data, (rowIndex, d, rowError, errorType, recordId) => { var importDataEntity = new ImportData { Data = ((JArray)d).ToString(), ErrorMessage = rowError.ToString(), HasError = rowError.Length > 0, ImportFileId = file.ImportFileId, LineNumber = rowIndex, RecordId = recordId, ErrorType = errorType }; _importDataService.Create(importDataEntity); }); return(file); }
public ImportFile RetryFailures(Guid importFileId) { ImportFile file = _importFileService.FindById(importFileId); ImportMap map = _importMapService.FindById(file.ImportMapId); var datas = _importDataService.Query(x => x.Where(f => f.ImportFileId == importFileId && f.HasError == true)); if (datas.IsEmpty()) { return(file); } var data = datas.Select(x => new object().DeserializeFromJson(x.Data)).ToList(); this.ImportCore(file, map, data, (rowIndex, d, rowError, errorType, recordId) => { var importDataEntity = datas[rowIndex - 1]; importDataEntity.ErrorMessage = rowError.ToString(); importDataEntity.HasError = rowError.Length > 0; importDataEntity.RecordId = recordId; importDataEntity.ErrorType = errorType; _importDataService.Update(importDataEntity); }); return(file); }
private void AssingMapping(ImportMap importMap) { _ignoreDtChanges = true; var dt = MappingGrid.DataSource as DataTable; if (dt == null || importMap == null) { return; } var rows = dt.Rows; for (var i = 0; i < rows.Count; i++) { if (!string.IsNullOrEmpty(rows[i][dt.Columns.Count - 1].ToString())) { continue; } var index = i; var mapping = importMap.Mappings.FirstOrDefault(p => p.Column == rows[index][0].ToString()); if (mapping != null) { var mapedTo = mapping.MapedTo; dt.Rows[i][dt.Columns.Count - 1] = mapedTo; var mappableCol = MappableColumns.FirstOrDefault(p => p.Name == mapedTo); if (mappableCol != null) { mappableCol.Mapped = true; } } dt.Rows[i][dt.Columns.Count - 1] = null; } _ignoreDtChanges = false; }
private void QueueRefresh(List <FormatData> list) { Progress.QueueTask(progress => { progress.NewTask("Refreshing Song Data", list.Count); Dictionary <Game, ImportMap> Maps = new Dictionary <Game, ImportMap>(); foreach (FormatData data in list) { data.PlatformData.Mutex.WaitOne(); Game game = data.Song.Game; if (game != Game.Unknown) { if (!Maps.ContainsKey(game)) { Maps[game] = new ImportMap(data.Song.Game); } Maps[game].Populate(data.Song); } data.PlatformData.Mutex.ReleaseMutex(); progress.Progress(); } UpdateSongList(); progress.EndTask(); }); }
/// <summary> /// Import Regions /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed string completed = DateTime.Now.ToString("d") + "-" + "Completed"; ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == completed && x.NewKey == SigId); if (importMap != null) { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } try { string rootAttr = "ArrayOf" + OldTable; performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(HetsRegion[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); HetsRegion[] legacyItems = (HetsRegion[])ser.Deserialize(memoryStream); foreach (var item in legacyItems.WithProgress(progress)) { // see if we have this one already Region reg = null; importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == item.Region_Id.ToString()); if (dbContext.LocalAreas.Count(x => String.Equals(x.Name, item.Name.Trim(), StringComparison.CurrentCultureIgnoreCase)) > 0) { reg = dbContext.Regions.FirstOrDefault(x => String.Equals(x.Name, item.Name.Trim(), StringComparison.CurrentCultureIgnoreCase)); } // new entry if (importMap == null && reg == null) { CopyToInstance(performContext, dbContext, item, ref reg, systemId); ImportUtility.AddImportMap(dbContext, OldTable, item.Region_Id.ToString(), NewTable, reg.Id); } else // update { // record was deleted if (reg == null) { CopyToInstance(performContext, dbContext, item, ref reg, systemId); // update the import map importMap.NewKey = reg.Id; dbContext.ImportMaps.Update(importMap); dbContext.SaveChangesForImport(); } else // ordinary update. { CopyToInstance(performContext, dbContext, item, ref reg, systemId); // touch the import map if (importMap != null) { importMap.LastUpdateTimestamp = DateTime.UtcNow; dbContext.ImportMaps.Update(importMap); } dbContext.SaveChangesForImport(); } } } performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMap(dbContext, OldTable, completed, NewTable, SigId); } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); } }
/// <summary> /// Import Equipment Types /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="fileLocation"></param> /// <param name="systemId"></param> public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BcBidImport.SigId, NewTable); if (startPoint == BcBidImport.SigId) // this means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***"); return; } int maxEquipTypeIndex = 0; if (dbContext.EquipmentTypes.Any()) { maxEquipTypeIndex = dbContext.EquipmentTypes.Max(x => x.Id); } try { string rootAttr = "ArrayOf" + OldTable; // create Processer progress indicator performContext.WriteLine("Processing " + OldTable); IProgressBar progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(EquipType[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr); EquipType[] legacyItems = (EquipType[])ser.Deserialize(memoryStream); int ii = startPoint; // skip the portion already processed if (startPoint > 0) { legacyItems = legacyItems.Skip(ii).ToArray(); } Debug.WriteLine("Importing EquipmentType Data. Total Records: " + legacyItems.Length); foreach (EquipType item in legacyItems.WithProgress(progress)) { // see if we have this one already ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == item.Equip_Type_Id.ToString()); // new entry (only import new records of Equipment Type) if (importMap == null && item.Equip_Type_Id > 0) { EquipmentType equipType = null; CopyToInstance(dbContext, item, ref equipType, systemId, ref maxEquipTypeIndex); if (equipType != null) { ImportUtility.AddImportMap(dbContext, OldTable, item.Equip_Type_Id.ToString(), NewTable, equipType.Id); } } // save change to database periodically to avoid frequent writing to the database if (ii++ % 500 == 0) { try { ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, ii.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("Error saving data " + e.Message); } } } try { performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***"); ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable); dbContext.SaveChangesForImport(); } catch (Exception e) { string temp = string.Format("Error saving data (EquipmentTypeIndex: {0}): {1}", maxEquipTypeIndex, e.Message); performContext.WriteLine(temp); throw new DataException(temp); } } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); throw; } }
/// <summary> /// Imports records to Microsoft Dynamics CRM from the specified .csv file. /// </summary> public void ImportRecords() { // Create an import map. ImportMap importMap = new ImportMap() { Name = "Import Map " + DateTime.Now.Ticks.ToString(), Source = "Import Accounts.csv", Description = "Description of data being imported", EntitiesPerFile = new OptionSetValue((int)ImportMapEntitiesPerFile.SingleEntityPerFile), EntityState = EntityState.Created }; Guid importMapId = _serviceProxy.Create(importMap); // Create column mappings. #region Column One Mappings // Create a column mapping for a 'text' type field. ColumnMapping colMapping1 = new ColumnMapping() { // Set source properties. SourceAttributeName = "src_name", SourceEntityName = "Account_1", // Set target properties. TargetAttributeName = "name", TargetEntityName = Account.EntityLogicalName, // Relate this column mapping with the data map. ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId), // Force this column to be processed. ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process) }; // Create the mapping. Guid colMappingId1 = _serviceProxy.Create(colMapping1); #endregion #region Column Two Mappings // Create a column mapping for a 'lookup' type field. ColumnMapping colMapping2 = new ColumnMapping() { // Set source properties. SourceAttributeName = "src_parent", SourceEntityName = "Account_1", // Set target properties. TargetAttributeName = "parentaccountid", TargetEntityName = Account.EntityLogicalName, // Relate this column mapping with the data map. ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId), // Force this column to be processed. ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process), }; // Create the mapping. Guid colMappingId2 = _serviceProxy.Create(colMapping2); // Because we created a column mapping of type lookup, we need to specify lookup details in a lookupmapping. // One lookupmapping will be for the parent account, and the other for the current record. // This lookupmapping is important because without it the current record // cannot be used as the parent of another record. // Create a lookup mapping to the parent account. LookUpMapping parentLookupMapping = new LookUpMapping() { // Relate this mapping with its parent column mapping. ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingId2), // Force this column to be processed. ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process), // Set the lookup for an account entity by its name attribute. LookUpEntityName = Account.EntityLogicalName, LookUpAttributeName = "name", LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.System) }; // Create the lookup mapping. Guid parentLookupMappingId = _serviceProxy.Create(parentLookupMapping); // Create a lookup on the current record's "src_name" so that this record can // be used as the parent account for another record being imported. // Without this lookup, no record using this account as its parent will be imported. LookUpMapping currentLookUpMapping = new LookUpMapping() { // Relate this lookup with its parent column mapping. ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingId2), // Force this column to be processed. ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process), // Set the lookup for the current record by its src_name attribute. LookUpAttributeName = "src_name", LookUpEntityName = "Account_1", LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.Source) }; // Create the lookup mapping Guid currentLookupMappingId = _serviceProxy.Create(currentLookUpMapping); #endregion #region Column Three Mappings // Create a column mapping for a 'picklist' type field ColumnMapping colMapping3 = new ColumnMapping() { // Set source properties SourceAttributeName = "src_addresstype", SourceEntityName = "Account_1", // Set target properties TargetAttributeName = "address1_addresstypecode", TargetEntityName = Account.EntityLogicalName, // Relate this column mapping with its parent data map ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId), // Force this column to be processed ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process) }; // Create the mapping Guid colMappingId3 = _serviceProxy.Create(colMapping3); // Because we created a column mapping of type picklist, we need to specify picklist details in a picklistMapping PickListMapping pickListMapping1 = new PickListMapping() { SourceValue = "bill", TargetValue = 1, // Relate this column mapping with its column mapping data map ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingId3), // Force this column to be processed ProcessCode = new OptionSetValue((int)PickListMappingProcessCode.Process) }; // Create the mapping Guid picklistMappingId1 = _serviceProxy.Create(pickListMapping1); // Need a picklist mapping for every address type code expected PickListMapping pickListMapping2 = new PickListMapping() { SourceValue = "ship", TargetValue = 2, // Relate this column mapping with its column mapping data map ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingId3), // Force this column to be processed ProcessCode = new OptionSetValue((int)PickListMappingProcessCode.Process) }; // Create the mapping Guid picklistMappingId2 = _serviceProxy.Create(pickListMapping2); #endregion // Create Import Import import = new Import() { // IsImport is obsolete; use ModeCode to declare Create or Update. ModeCode = new OptionSetValue((int)ImportModeCode.Create), Name = "Importing data" }; Guid importId = _serviceProxy.Create(import); // Create Import File. ImportFile importFile = new ImportFile() { Content = BulkImportHelper.ReadCsvFile("Import Accounts.csv"), // Read contents from disk. Name = "Account record import", IsFirstRowHeader = true, ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId), UseSystemMap = false, Source = "Import Accounts.csv", SourceEntityName = "Account_1", TargetEntityName = Account.EntityLogicalName, ImportId = new EntityReference(Import.EntityLogicalName, importId), EnableDuplicateDetection = false, FieldDelimiterCode = new OptionSetValue((int)ImportFileFieldDelimiterCode.Comma), DataDelimiterCode = new OptionSetValue((int)ImportFileDataDelimiterCode.DoubleQuote), ProcessCode = new OptionSetValue((int)ImportFileProcessCode.Process) }; // Get the current user to set as record owner. WhoAmIRequest systemUserRequest = new WhoAmIRequest(); WhoAmIResponse systemUserResponse = (WhoAmIResponse)_serviceProxy.Execute(systemUserRequest); // Set the owner ID. importFile.RecordsOwnerId = new EntityReference(SystemUser.EntityLogicalName, systemUserResponse.UserId); Guid importFileId = _serviceProxy.Create(importFile); //<snippetImportWithCreate1> // Retrieve the header columns used in the import file. GetHeaderColumnsImportFileRequest headerColumnsRequest = new GetHeaderColumnsImportFileRequest() { ImportFileId = importFileId }; GetHeaderColumnsImportFileResponse headerColumnsResponse = (GetHeaderColumnsImportFileResponse)_serviceProxy.Execute(headerColumnsRequest); // Output the header columns. int columnNum = 1; foreach (string headerName in headerColumnsResponse.Columns) { Console.WriteLine("Column[" + columnNum.ToString() + "] = " + headerName); columnNum++; } //</snippetImportWithCreate1> //<snippetImportWithCreate2> // Parse the import file. ParseImportRequest parseImportRequest = new ParseImportRequest() { ImportId = importId }; ParseImportResponse parseImportResponse = (ParseImportResponse)_serviceProxy.Execute(parseImportRequest); Console.WriteLine("Waiting for Parse async job to complete"); //</snippetImportWithCreate2> BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, parseImportResponse.AsyncOperationId); BulkImportHelper.ReportErrors(_serviceProxy, importFileId); //<snippetImportWithCreate3> // Retrieve the first two distinct values for column 1 from the parse table. // NOTE: You must create the parse table first using the ParseImport message. // The parse table is not accessible after ImportRecordsImportResponse is called. GetDistinctValuesImportFileRequest distinctValuesRequest = new GetDistinctValuesImportFileRequest() { columnNumber = 1, ImportFileId = importFileId, pageNumber = 1, recordsPerPage = 2, }; GetDistinctValuesImportFileResponse distinctValuesResponse = (GetDistinctValuesImportFileResponse)_serviceProxy.Execute(distinctValuesRequest); // Output the distinct values. In this case: (column 1, row 1) and (column 1, row 2). int cellNum = 1; foreach (string cellValue in distinctValuesResponse.Values) { Console.WriteLine("(1, " + cellNum.ToString() + "): " + cellValue); Console.WriteLine(cellValue); cellNum++; } //</snippetImportWithCreate3> //<snippetImportWithCreate4> // Retrieve data from the parse table. // NOTE: You must create the parse table first using the ParseImport message. // The parse table is not accessible after ImportRecordsImportResponse is called. RetrieveParsedDataImportFileRequest parsedDataRequest = new RetrieveParsedDataImportFileRequest() { ImportFileId = importFileId, PagingInfo = new PagingInfo() { // Specify the number of entity instances returned per page. Count = 2, // Specify the number of pages returned from the query. PageNumber = 1, // Specify a total number of entity instances returned. PagingCookie = "1" } }; RetrieveParsedDataImportFileResponse parsedDataResponse = (RetrieveParsedDataImportFileResponse)_serviceProxy.Execute(parsedDataRequest); // Output the first two rows retrieved. int rowCount = 1; foreach (string[] rows in parsedDataResponse.Values) { int colCount = 1; foreach (string column in rows) { Console.WriteLine("(" + rowCount.ToString() + "," + colCount.ToString() + ") = " + column); colCount++; } rowCount++; } //</snippetImportWithCreate4> //<snippetImportWithCreate5> // Transform the import TransformImportRequest transformImportRequest = new TransformImportRequest() { ImportId = importId }; TransformImportResponse transformImportResponse = (TransformImportResponse)_serviceProxy.Execute(transformImportRequest); Console.WriteLine("Waiting for Transform async job to complete"); //</snippetImportWithCreate5> BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, transformImportResponse.AsyncOperationId); BulkImportHelper.ReportErrors(_serviceProxy, importFileId); //<snippetImportWithCreate6> // Upload the records. ImportRecordsImportRequest importRequest = new ImportRecordsImportRequest() { ImportId = importId }; ImportRecordsImportResponse importResponse = (ImportRecordsImportResponse)_serviceProxy.Execute(importRequest); Console.WriteLine("Waiting for ImportRecords async job to complete"); //</snippetImportWithCreate6> BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, importResponse.AsyncOperationId); BulkImportHelper.ReportErrors(_serviceProxy, importFileId); }