Example #1
0
        /// <summary>
        /// Get the list of mapped records.
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="fileLocation"></param>
        /// <returns></returns>
        public static List <ImportMapRecord> GetImportMap(DbAppContext dbContext, string fileLocation)
        {
            List <ImportMapRecord> result = new List <ImportMapRecord>();
            string        rootAttr        = "ArrayOf" + OldTable;
            XmlSerializer ser             = new XmlSerializer(typeof(UserHets[]), new XmlRootAttribute(rootAttr));

            ser.UnknownAttribute += ImportUtility.UnknownAttribute;
            ser.UnknownElement   += ImportUtility.UnknownElement;

            MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
            XmlReader    reader       = new XmlTextReader(memoryStream);

            if (ser.CanDeserialize(reader))
            {
                UserHets[]    legacyItems = (UserHets[])ser.Deserialize(reader);
                List <string> usernames   = new List <string>();
                foreach (UserHets item in legacyItems)
                {
                    string username = NormalizeUserCode(item.User_Cd);
                    if (!usernames.Contains(username))
                    {
                        usernames.Add(username);
                    }
                }

                usernames.Sort();
                int currentUser = 0;
                foreach (string username in usernames)
                {
                    ImportMapRecord importMapRecord = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "User_cd",
                        OriginalValue = username,
                        NewValue      = "User" + currentUser
                    };

                    currentUser++;
                    result.Add(importMapRecord);
                }
            }

            return(result);
        }
Example #2
0
        public static void Obfuscate(PerformContext performContext, DbAppContext dbContext, string sourceLocation, string destinationLocation, string systemId)
        {
            int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, "Obfuscate_" + 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("*** Obfuscating " + 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(ImportModels.Owner[]), new XmlRootAttribute(rootAttr));
                MemoryStream         memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, sourceLocation, rootAttr);
                ImportModels.Owner[] legacyItems  = (ImportModels.Owner[])ser.Deserialize(memoryStream);

                performContext.WriteLine("Obfuscating owner data");
                progress.SetValue(0);

                int currentOwner = 0;

                List <ImportMapRecord> importMapRecords = new List <ImportMapRecord>();

                foreach (ImportModels.Owner item in legacyItems.WithProgress(progress))
                {
                    item.Created_By = systemId;

                    if (item.Modified_By != null)
                    {
                        item.Modified_By = systemId;
                    }

                    ImportMapRecord importMapRecordOrganization = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "OrganizationName",
                        OriginalValue = item.CGL_Company,
                        NewValue      = "Company " + currentOwner
                    };

                    importMapRecords.Add(importMapRecordOrganization);

                    ImportMapRecord importMapRecordFirstName = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Owner_First_Name",
                        OriginalValue = item.Owner_First_Name,
                        NewValue      = "OwnerFirst" + currentOwner
                    };

                    importMapRecords.Add(importMapRecordFirstName);

                    ImportMapRecord importMapRecordLastName = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Owner_Last_Name",
                        OriginalValue = item.Owner_Last_Name,
                        NewValue      = "OwnerLast" + currentOwner
                    };

                    importMapRecords.Add(importMapRecordLastName);

                    ImportMapRecord importMapRecordOwnerCode = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Owner_Cd",
                        OriginalValue = item.Owner_Cd,
                        NewValue      = "OO" + currentOwner
                    };

                    importMapRecords.Add(importMapRecordOwnerCode);

                    item.Owner_Cd         = "OO" + currentOwner;
                    item.Owner_First_Name = "OwnerFirst" + currentOwner;
                    item.Owner_Last_Name  = "OwnerLast" + currentOwner;
                    item.Contact_Person   = ImportUtility.ScrambleString(item.Contact_Person);
                    item.Comment          = ImportUtility.ScrambleString(item.Comment);
                    item.WCB_Num          = ImportUtility.ScrambleString(item.WCB_Num);
                    item.CGL_Company      = ImportUtility.ScrambleString(item.CGL_Company);
                    item.CGL_Policy       = ImportUtility.ScrambleString(item.CGL_Policy);

                    currentOwner++;
                }

                performContext.WriteLine("Writing " + XmlFileName + " to " + destinationLocation);

                // write out the array
                FileStream fs = ImportUtility.GetObfuscationDestination(XmlFileName, destinationLocation);
                ser.Serialize(fs, legacyItems);
                fs.Close();

                // write out the spreadsheet of import records
                ImportUtility.WriteImportRecordsToExcel(destinationLocation, importMapRecords, OldTable);
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Example #3
0
        public static void Obfuscate(PerformContext performContext, DbAppContext dbContext, string sourceLocation, string destinationLocation, string systemId)
        {
            int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, "Obfuscate_" + 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("*** Obfuscating " + 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(Project[]), new XmlRootAttribute(rootAttr));
                MemoryStream  memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, sourceLocation, rootAttr);
                Project[]     legacyItems  = (Project[])ser.Deserialize(memoryStream);

                performContext.WriteLine("Obfuscating Project data");
                progress.SetValue(0);

                List <ImportMapRecord> importMapRecords = new List <ImportMapRecord>();

                foreach (Project item in legacyItems.WithProgress(progress))
                {
                    item.Created_By = systemId;

                    Random random        = new Random();
                    string newProjectNum = random.Next(10000).ToString();

                    ImportMapRecord importMapRecordOrganization = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Project_Num",
                        OriginalValue = item.Project_Num,
                        NewValue      = newProjectNum
                    };

                    importMapRecords.Add(importMapRecordOrganization);

                    item.Project_Num = newProjectNum;
                    item.Job_Desc1   = ImportUtility.ScrambleString(item.Job_Desc1);
                    item.Job_Desc2   = ImportUtility.ScrambleString(item.Job_Desc2);
                }

                performContext.WriteLine("Writing " + XmlFileName + " to " + destinationLocation);

                // write out the array.
                FileStream fs = ImportUtility.GetObfuscationDestination(XmlFileName, destinationLocation);
                ser.Serialize(fs, legacyItems);
                fs.Close();

                // write out the spreadsheet of import records.
                ImportUtility.WriteImportRecordsToExcel(destinationLocation, importMapRecords, OldTable);
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
            }
        }
Example #4
0
        /// <summary>
        /// Get the list of mapped records.
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="fileLocation"></param>
        /// <returns></returns>
        public static List <ImportMapRecord> GetImportMap(DbAppContext dbContext, string fileLocation)
        {
            List <ImportMapRecord> result = new List <ImportMapRecord>();
            string        rootAttr        = "ArrayOf" + OldTable;
            XmlSerializer ser             = new XmlSerializer(typeof(ImportModels.Owner[]), new XmlRootAttribute(rootAttr));

            ser.UnknownAttribute += ImportUtility.UnknownAttribute;
            ser.UnknownElement   += ImportUtility.UnknownElement;

            MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
            XmlReader    reader       = new XmlTextReader(memoryStream);

            if (ser.CanDeserialize(reader))
            {
                ImportModels.Owner[] legacyItems = (ImportModels.Owner[])ser.Deserialize(reader);

                List <string> keys = new List <string>();
                Dictionary <string, string> givenNames = new Dictionary <string, string>();
                Dictionary <string, string> surnames   = new Dictionary <string, string>();
                Dictionary <string, string> orgNames   = new Dictionary <string, string>();
                Dictionary <string, int>    oldkeys    = new Dictionary <string, int>();

                foreach (ImportModels.Owner item in legacyItems)
                {
                    string givenName        = item.Owner_First_Name;
                    string surname          = item.Owner_Last_Name;
                    int    oldKey           = item.Popt_Id;
                    string organizationName = "" + item.CGL_Company;
                    string key = organizationName + " " + givenName + " " + surname;

                    if (!keys.Contains(key))
                    {
                        keys.Add(key);
                        givenNames.Add(key, givenName);
                        surnames.Add(key, surname);
                        orgNames.Add(key, organizationName);
                        oldkeys.Add(key, oldKey);
                    }
                }

                keys.Sort();
                int currentOwner = 0;
                foreach (string key in keys)
                {
                    ImportMapRecord importMapRecordOrganization = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "OrganizationName",
                        OriginalValue = orgNames[key],
                        NewValue      = "OwnerFirst" + currentOwner
                    };

                    result.Add(importMapRecordOrganization);

                    ImportMapRecord importMapRecordFirstName = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Owner_First_Name",
                        OriginalValue = givenNames[key],
                        NewValue      = "OwnerFirst" + currentOwner
                    };

                    result.Add(importMapRecordFirstName);

                    ImportMapRecord importMapRecordLastName = new ImportMapRecord
                    {
                        TableName     = NewTable,
                        MappedColumn  = "Owner_Last_Name",
                        OriginalValue = givenNames[key],
                        NewValue      = "OwnerLast" + currentOwner
                    };

                    result.Add(importMapRecordLastName);

                    // now update the owner record.
                    ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == OldTable && x.OldKey == oldkeys[key].ToString());

                    if (importMap != null)
                    {
                        Owner owner = dbContext.Owners.FirstOrDefault(x => x.Id == importMap.NewKey);
                        if (owner != null)
                        {
                            owner.GivenName = "OwnerFirst" + currentOwner;
                            owner.Surname   = "OwnerLast" + currentOwner;

                            owner.RegisteredCompanyNumber = ImportUtility.ScrambleString(owner.RegisteredCompanyNumber);
                            owner.WorkSafeBCPolicyNumber  = ImportUtility.ScrambleString(owner.WorkSafeBCPolicyNumber);
                            owner.OrganizationName        = "Company " + currentOwner;

                            dbContext.Owners.Update(owner);
                            dbContext.SaveChangesForImport();
                        }
                    }

                    currentOwner++;
                }
            }

            return(result);
        }