Пример #1
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 progress indicator
                performContext.WriteLine("Processing " + OldTable);

                // create serializer and serialize xml file
                XmlSerializer            ser          = new XmlSerializer(typeof(ImportModels.DumpTruck[]), new XmlRootAttribute(rootAttr));
                MemoryStream             memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, sourceLocation, rootAttr);
                ImportModels.DumpTruck[] legacyItems  = (ImportModels.DumpTruck[])ser.Deserialize(memoryStream);

                // no fields to mask for dump truck - straight copy
                performContext.WriteLine("Writing " + XmlFileName + " to " + destinationLocation);

                // write out the array
                FileStream fs = ImportUtility.GetObfuscationDestination(XmlFileName, destinationLocation);
                ser.Serialize(fs, legacyItems);
                fs.Close();
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Import Service 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;
                performContext.WriteLine("Processing Service Areas");
                IProgressBar progress = performContext.WriteProgressBar();
                progress.SetValue(0);

                // create serializer and serialize xml file
                XmlSerializer ser = new XmlSerializer(typeof(ImportModels.ServiceArea[]), new XmlRootAttribute(rootAttr));
                ser.UnknownAttribute += ImportUtility.UnknownAttribute;
                ser.UnknownElement   += ImportUtility.UnknownElement;
                MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.ServiceArea[] legacyItems = (ImportModels.ServiceArea[])ser.Deserialize(memoryStream);

                Debug.WriteLine("Importing ServiceArea Data. Total Records: " + legacyItems.Length);

                foreach (ImportModels.ServiceArea item in legacyItems.WithProgress(progress))
                {
                    // see if we have this one already
                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == item.Service_Area_Id.ToString());

                    // new entry
                    if (importMap == null && item.Service_Area_Cd != "000")
                    {
                        HetServiceArea serviceArea = null;
                        CopyToInstance(dbContext, item, ref serviceArea, systemId);
                        ImportUtility.AddImportMap(dbContext, OldTable, item.Service_Area_Id.ToString(), NewTable, serviceArea.ServiceAreaId);
                    }
                }

                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;
            }
        }
Пример #3
0
        /// <summary>
        /// Import Equipment Attachments
        /// </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 maxEquipAttachIndex = 0;

            if (dbContext.HetEquipmentAttachment.Any())
            {
                maxEquipAttachIndex = dbContext.HetEquipmentAttachment.Max(x => x.EquipmentAttachmentId);
            }

            try
            {
                string rootAttr = "ArrayOf" + OldTable;

                // create 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.EquipAttach[]), new XmlRootAttribute(rootAttr));
                MemoryStream  memoryStream             = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.EquipAttach[] legacyItems = (ImportModels.EquipAttach[])ser.Deserialize(memoryStream);

                int ii = startPoint;

                // skip the portion already processed
                if (startPoint > 0)
                {
                    legacyItems = legacyItems.Skip(ii).ToArray();
                }

                Debug.WriteLine("Importing Equipment Attachment Data. Total Records: " + legacyItems.Length);

                foreach (ImportModels.EquipAttach item in legacyItems.WithProgress(progress))
                {
                    // see if we have this one already. We used old combine because item.Equip_Id is not unique
                    string oldKeyCombined = (item.Equip_Id ?? 0 * 100 + item.Attach_Seq_Num ?? 0).ToString();

                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == oldKeyCombined);

                    // new entry
                    if (importMap == null && item.Equip_Id > 0)
                    {
                        HetEquipmentAttachment instance = null;
                        CopyToInstance(dbContext, item, ref instance, systemId, ref maxEquipAttachIndex);
                        ImportUtility.AddImportMap(dbContext, OldTable, oldKeyCombined, NewTable, instance.EquipmentAttachmentId);
                    }

                    // save change to database periodically to avoid frequent writing to the database
                    if (++ii % 1000 == 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 (EquipmentAttachmentIndex: {0}): {1}", maxEquipAttachIndex, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #4
0
        /// <summary>
        /// Create Last Called
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="systemId"></param>
        public static void ProcessLastCalled(PerformContext performContext, DbAppContext dbContext, string systemId)
        {
            try
            {
                performContext.WriteLine("*** Recreating Last Called ***");
                Debug.WriteLine("Recreating Last Called");

                int    ii = 0;
                string _oldTableProgress = "LastCalled_Progress";
                string _newTable         = "LastCalled";

                // check if the last called has already been completed
                int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, _oldTableProgress, BcBidImport.SigId, _newTable);

                if (startPoint == BcBidImport.SigId)    // this means the assignment job is complete
                {
                    performContext.WriteLine("*** Recreating Last Called is complete from the former process ***");
                    return;
                }

                // ************************************************************
                // get all last called records
                // ************************************************************
                List <HetLocalAreaRotationList> rotationList = dbContext.HetLocalAreaRotationList.AsNoTracking()
                                                               .Distinct()
                                                               .ToList();

                // ************************************************************************
                // iterate the data and create rotation requests
                // ************************************************************************
                Debug.WriteLine("Recreating Last Called - Rotation List Record Count: " + rotationList.Count);

                // get status
                int?statusIdComplete = StatusHelper.GetStatusId(HetRentalRequest.StatusComplete, "rentalRequestStatus", dbContext);

                if (statusIdComplete == null)
                {
                    throw new DataException("Status Id cannot be null");
                }

                foreach (HetLocalAreaRotationList listItem in rotationList)
                {
                    HetRentalRequest request = new HetRentalRequest
                    {
                        LocalAreaId               = listItem.LocalAreaId,
                        DistrictEquipmentTypeId   = listItem.DistrictEquipmentTypeId,
                        RentalRequestStatusTypeId = (int)statusIdComplete,
                        ExpectedStartDate         = DateTime.Now,
                        ExpectedEndDate           = DateTime.Now,
                        EquipmentCount            = 1,
                        ExpectedHours             = 0,
                        AppCreateUserid           = systemId,
                        AppCreateTimestamp        = DateTime.UtcNow,
                        AppLastUpdateUserid       = systemId,
                        AppLastUpdateTimestamp    = DateTime.UtcNow
                    };

                    dbContext.HetRentalRequest.Add(request);

                    // save change to database
                    if (ii++ % 100 == 0)
                    {
                        Debug.WriteLine("Recreating Last Called - Index: " + ii);
                        ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, ii.ToString(), BcBidImport.SigId, _newTable);
                        dbContext.SaveChangesForImport();
                    }
                }

                // save remaining requests
                dbContext.SaveChangesForImport();

                // ************************************************************************
                // iterate the data and create "last called" records
                // ************************************************************************
                foreach (HetLocalAreaRotationList listItem in rotationList)
                {
                    // get request
                    HetRentalRequest request = dbContext.HetRentalRequest.AsNoTracking()
                                               .FirstOrDefault(x => x.LocalAreaId == listItem.LocalAreaId &&
                                                               x.DistrictEquipmentTypeId == listItem.DistrictEquipmentTypeId);

                    if (request == null)
                    {
                        throw new DataException("Rental request cannot be null");
                    }

                    // block 1
                    if (listItem.AskNextBlock1Id != null)
                    {
                        // create last call record
                        HetRentalRequestRotationList rotation = new HetRentalRequestRotationList
                        {
                            RentalRequestId       = request.RentalRequestId,
                            EquipmentId           = listItem.AskNextBlock1Id,
                            BlockNumber           = 1,
                            RotationListSortOrder = 1,
                            AskedDateTime         = DateTime.Now,
                            WasAsked              = true,
                            OfferResponse         = "Yes",
                            OfferResponseDatetime = DateTime.Now,
                            IsForceHire           = false,
                            Note                   = "CONVERSION",
                            AppCreateUserid        = systemId,
                            AppCreateTimestamp     = DateTime.UtcNow,
                            AppLastUpdateUserid    = systemId,
                            AppLastUpdateTimestamp = DateTime.UtcNow
                        };

                        dbContext.HetRentalRequestRotationList.Add(rotation);
                    }

                    // block 2
                    if (listItem.AskNextBlock2Id != null)
                    {
                        // create last call record
                        HetRentalRequestRotationList rotation = new HetRentalRequestRotationList
                        {
                            RentalRequestId       = request.RentalRequestId,
                            EquipmentId           = listItem.AskNextBlock2Id,
                            BlockNumber           = 2,
                            RotationListSortOrder = 2,
                            AskedDateTime         = DateTime.Now,
                            WasAsked              = true,
                            OfferResponse         = "Yes",
                            OfferResponseDatetime = DateTime.Now,
                            IsForceHire           = false,
                            Note                   = "CONVERSION",
                            AppCreateUserid        = systemId,
                            AppCreateTimestamp     = DateTime.UtcNow,
                            AppLastUpdateUserid    = systemId,
                            AppLastUpdateTimestamp = DateTime.UtcNow
                        };

                        dbContext.HetRentalRequestRotationList.Add(rotation);
                    }

                    // open block
                    if (listItem.AskNextBlockOpenId != null)
                    {
                        // get equipment record
                        HetEquipment equipment = dbContext.HetEquipment.AsNoTracking()
                                                 .FirstOrDefault(x => x.EquipmentId == listItem.AskNextBlockOpenId);

                        if (equipment == null)
                        {
                            throw new DataException("Equipment cannot be null");
                        }

                        // create last call record
                        HetRentalRequestRotationList rotation = new HetRentalRequestRotationList
                        {
                            RentalRequestId       = request.RentalRequestId,
                            EquipmentId           = listItem.AskNextBlockOpenId,
                            BlockNumber           = equipment.BlockNumber,
                            RotationListSortOrder = 3,
                            AskedDateTime         = DateTime.Now,
                            WasAsked              = true,
                            OfferResponse         = "Yes",
                            OfferResponseDatetime = DateTime.Now,
                            IsForceHire           = false,
                            Note                   = "CONVERSION",
                            AppCreateUserid        = systemId,
                            AppCreateTimestamp     = DateTime.UtcNow,
                            AppLastUpdateUserid    = systemId,
                            AppLastUpdateTimestamp = DateTime.UtcNow
                        };

                        dbContext.HetRentalRequestRotationList.Add(rotation);
                    }

                    // save change to database
                    if (ii++ % 100 == 0)
                    {
                        Debug.WriteLine("Recreating Last Called - Index: " + ii);
                        ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, ii.ToString(), BcBidImport.SigId, _newTable);
                        dbContext.SaveChangesForImport();
                    }
                }

                // save remaining requests
                dbContext.SaveChangesForImport();

                // ************************************************************
                // save final set of updates
                // ************************************************************
                try
                {
                    performContext.WriteLine("*** Recreating Last Called is Done ***");
                    Debug.WriteLine("Recreating Last Called is Done");
                    ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, _newTable);
                    dbContext.SaveChangesForImport();
                }
                catch (Exception e)
                {
                    string temp = string.Format("Error saving data (Record: {0}): {1}", ii, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #5
0
        /// <summary>
        /// Import Users
        /// </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;
            }

            // manage the id value for new user records
            int maxUserIndex = 0;

            if (dbContext.HetUser.Any())
            {
                maxUserIndex = dbContext.HetUser.Max(x => x.UserId);
                maxUserIndex = maxUserIndex + 1;
            }

            try
            {
                string rootAttr = "ArrayOf" + OldTable;

                // create 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.UserHets[]), new XmlRootAttribute(rootAttr));
                MemoryStream            memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.UserHets[] legacyItems  = (ImportModels.UserHets[])ser.Deserialize(memoryStream);

                int ii = startPoint;

                // skip the portion already processed
                if (startPoint > 0)
                {
                    legacyItems = legacyItems.Skip(ii).ToArray();
                }

                // create an array of names using the created by and modified by values in the data
                performContext.WriteLine("Extracting first and last names");
                progress.SetValue(0);

                Dictionary <string, string> firstNames = new Dictionary <string, string>();
                Dictionary <string, string> lastNames  = new Dictionary <string, string>();

                foreach (ImportModels.UserHets item in legacyItems.WithProgress(progress))
                {
                    string name = item.Created_By;
                    GetNameParts(name, ref firstNames, ref lastNames);

                    name = item.Modified_By;
                    GetNameParts(name, ref firstNames, ref lastNames);
                }

                // import the data
                performContext.WriteLine("Importing User Data");
                progress.SetValue(0);

                foreach (ImportModels.UserHets item in legacyItems.WithProgress(progress))
                {
                    string tempId = item.Popt_Id + "-" + item.Service_Area_Id;

                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == tempId);

                    if (importMap == null)
                    {
                        string username  = NormalizeUserCode(item.User_Cd).ToUpper();
                        string firstName = GetNamePart(username, firstNames);
                        string lastName  = GetNamePart(username, lastNames);

                        HetUser user = null;
                        username = username.ToLower();

                        CopyToInstance(dbContext, item, ref user, systemId, username, firstName, lastName, ref maxUserIndex);

                        if (user != null)
                        {
                            ImportUtility.AddImportMap(dbContext, OldTable, tempId, NewTable, user.UserId);
                            dbContext.SaveChangesForImport();
                        }
                    }
                }

                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 (UserIndex: {0}): {1}", maxUserIndex, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #6
0
        /// <summary>
        /// Import Rotation Doc Records Records
        /// </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.    // 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 maxIndex = startPoint;

            try
            {
                string rootAttr = "ArrayOf" + OldTable;

                // create 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.RotationDoc[]), new XmlRootAttribute(rootAttr));
                MemoryStream  memoryStream             = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.RotationDoc[] legacyItems = (ImportModels.RotationDoc[])ser.Deserialize(memoryStream);

                int ii = startPoint;

                // skip the portion already processed
                if (startPoint > 0)
                {
                    legacyItems = legacyItems.Skip(ii).ToArray();
                }

                Debug.WriteLine("Importing Rotation Doc Data. Total Records: " + legacyItems.Length);

                foreach (ImportModels.RotationDoc item in legacyItems.WithProgress(progress))
                {
                    // see if we have this one already.
                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == item.Note_Id.ToString());

                    // new entry
                    if (importMap == null)
                    {
                        BcbidRotationDoc rotationDoc = null;
                        CopyToInstance(dbContext, item, ref rotationDoc, systemId, ref maxIndex);
                        ImportUtility.AddImportMap(dbContext, OldTable, item.Note_Id.ToString(), NewTable, rotationDoc.NoteId);
                    }

                    // save change to database
                    if (++ii % 2000 == 0)
                    {
                        ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, ii.ToString(), BcBidImport.SigId, NewTable);
                        dbContext.SaveChangesForImport();
                    }
                }

                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 (Index: {0}): {1}", maxIndex, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #7
0
        /// <summary>
        /// Import Equipment Usage
        /// </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 completed for all the records in this file
            {
                performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***");
                return;
            }

            int maxTimeSheetIndex = 0;

            if (dbContext.HetTimeRecord.Any())
            {
                maxTimeSheetIndex = dbContext.HetTimeRecord.Max(x => x.TimeRecordId);
            }

            try
            {
                string rootAttr = "ArrayOf" + OldTable;

                // create 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.EquipUsage[]), new XmlRootAttribute(rootAttr));
                MemoryStream              memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.EquipUsage[] legacyItems  = (ImportModels.EquipUsage[])ser.Deserialize(memoryStream);

                int ii = startPoint;

                // skip the portion already processed
                if (startPoint > 0)
                {
                    legacyItems = legacyItems.Skip(ii).ToArray();
                }

                Debug.WriteLine("Importing TimeSheet Data. Total Records: " + legacyItems.Length);

                foreach (ImportModels.EquipUsage item in legacyItems.WithProgress(progress))
                {
                    // see if we have this one already
                    string oldProjectKey  = item.Project_Id.ToString();
                    string oldEquipKey    = item.Equip_Id.ToString();
                    string oldCreatedDate = item.Created_Dt;

                    string oldKey = string.Format("{0}-{1}-{2}", oldProjectKey, oldEquipKey, oldCreatedDate);

                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == oldKey);

                    // new entry
                    if (importMap == null && item.Equip_Id > 0 && item.Project_Id > 0)
                    {
                        HetTimeRecord instance = null;
                        CopyToTimeRecorded(dbContext, item, ref instance, systemId, ref maxTimeSheetIndex);

                        if (instance != null)
                        {
                            ImportUtility.AddImportMap(dbContext, OldTable, oldKey, NewTable, instance.TimeRecordId);
                        }

                        // save change to database
                        if (++ii % 2000 == 0)
                        {
                            ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, ii.ToString(), BcBidImport.SigId, NewTable);
                            dbContext.SaveChanges();
                        }
                    }
                }

                try
                {
                    performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***");
                    ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable);
                    dbContext.SaveChanges();
                }
                catch (Exception e)
                {
                    string temp = string.Format("Error saving data (TimeRecordIndex: {0}): {1}", maxTimeSheetIndex, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #8
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 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(ImportUtility.CleanString(item.Contact_Person));
                    item.Comment          = ImportUtility.ScrambleString(ImportUtility.CleanString(item.Comment));
                    item.WCB_Num          = ImportUtility.ScrambleString(ImportUtility.CleanString(item.WCB_Num));
                    item.CGL_Company      = ImportUtility.ScrambleString(ImportUtility.CleanString(item.CGL_Company));
                    item.CGL_Policy       = ImportUtility.ScrambleString(ImportUtility.CleanString(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;
            }
        }
Пример #9
0
        /// <summary>
        /// Generate secret keys
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        public static void GenerateSecretKeys(PerformContext performContext, DbAppContext dbContext)
        {
            try
            {
                performContext.WriteLine("*** Generating New Secret Keys ***");
                Debug.WriteLine("Generating New Secret Keys");

                int    ii = 0;
                string _oldTableProgress = "SecretKeys_Progress";
                string _newTable         = "SecretKeys";

                // check if the secret keys have already been completed
                int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, _oldTableProgress, BcBidImport.SigId, _newTable);

                if (startPoint == BcBidImport.SigId)    // this means the assignment job is complete
                {
                    performContext.WriteLine("*** Generating New Secret Key is complete from the former process ***");
                    return;
                }

                // get records
                List <HetOwner> owners = dbContext.HetOwner.AsNoTracking()
                                         .Where(x => x.BusinessId == null)
                                         .ToList();

                int i = 0;

                foreach (HetOwner owner in owners)
                {
                    i++;
                    string key = SecretKeyHelper.RandomString(8, owner.OwnerId);

                    string temp = owner.OwnerCode;

                    if (string.IsNullOrEmpty(temp))
                    {
                        temp = SecretKeyHelper.RandomString(4, owner.OwnerId);
                    }

                    key = temp + "-" + DateTime.UtcNow.Year + "-" + key;

                    // get owner and update
                    HetOwner ownerRecord = dbContext.HetOwner.First(x => x.OwnerId == owner.OwnerId);
                    ownerRecord.SharedKey = key;

                    if (i % 500 == 0)
                    {
                        dbContext.SaveChangesForImport();
                    }

                    // save change to database
                    if (ii++ % 100 == 0)
                    {
                        try
                        {
                            Debug.WriteLine("Generating New Secret Keys - Index: " + ii);
                            ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, ii.ToString(), BcBidImport.SigId, _newTable);
                            dbContext.SaveChangesForImport();
                        }
                        catch (Exception e)
                        {
                            performContext.WriteLine("Error saving data " + e.Message);
                        }
                    }
                }

                // ************************************************************
                // save final set of updates
                // ************************************************************
                try
                {
                    performContext.WriteLine("*** Done generating New Secret Keys ***");
                    Debug.WriteLine("Generating New Secret Keys is Done");
                    ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, _newTable);
                    dbContext.SaveChangesForImport();
                }
                catch (Exception e)
                {
                    string temp = string.Format("Error saving data (Record: {0}): {1}", ii, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Пример #10
0
        /// <summary>
        /// Recalculate the block assignment for each piece of equipment
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="seniorityScoringRules"></param>
        /// <param name="dbContext"></param>
        /// <param name="systemId"></param>
        public static void ProcessBlocks(PerformContext performContext, string seniorityScoringRules, DbAppContext dbContext, string systemId)
        {
            try
            {
                performContext.WriteLine("*** Recalculating Equipment Block Assignment ***");
                Debug.WriteLine("Recalculating Equipment Block Assignment");

                int    ii = 0;
                string _oldTableProgress = "BlockAssignment_Progress";
                string _newTable         = "BlockAssignment";

                // check if the block assignment has already been completed
                int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, _oldTableProgress, BcBidImport.SigId, _newTable);

                if (startPoint == BcBidImport.SigId)    // this means the assignment job is complete
                {
                    performContext.WriteLine("*** Recalculating Equipment Block Assignment is complete from the former process ***");
                    return;
                }

                // ************************************************************
                // cleanup old block assignment status records
                // ************************************************************
                List <HetImportMap> importMapList = dbContext.HetImportMap
                                                    .Where(x => x.OldTable == _oldTableProgress &&
                                                           x.NewTable == _newTable)
                                                    .ToList();

                foreach (HetImportMap importMap in importMapList)
                {
                    dbContext.HetImportMap.Remove(importMap);
                }

                dbContext.SaveChangesForImport();

                // ************************************************************
                // get processing rules
                // ************************************************************
                SeniorityScoringRules scoringRules = new SeniorityScoringRules(seniorityScoringRules);

                // ************************************************************
                // get all local areas
                // (using active equipment to minimize the results)
                // ************************************************************
                List <HetLocalArea> localAreas = dbContext.HetEquipment.AsNoTracking()
                                                 .Include(x => x.EquipmentStatusType)
                                                 .Include(x => x.LocalArea)
                                                 .Where(x => x.EquipmentStatusType.EquipmentStatusTypeCode == HetEquipment.StatusApproved &&
                                                        x.ArchiveCode == "N")
                                                 .Select(x => x.LocalArea)
                                                 .Distinct()
                                                 .ToList();

                // ************************************************************************
                // iterate the data and update the assignment blocks
                // (seniority is already calculated)
                // ************************************************************************
                Debug.WriteLine("Recalculating Equipment Block Assignment - Local Area Record Count: " + localAreas.Count);

                foreach (HetLocalArea localArea in localAreas)
                {
                    IQueryable <HetDistrictEquipmentType> equipmentTypes = dbContext.HetEquipment.AsNoTracking()
                                                                           .Include(x => x.EquipmentStatusType)
                                                                           .Include(x => x.DistrictEquipmentType)
                                                                           .Where(x => x.EquipmentStatusType.EquipmentStatusTypeCode == HetEquipment.StatusApproved &&
                                                                                  x.ArchiveCode == "N" &&
                                                                                  x.LocalArea.LocalAreaId == localArea.LocalAreaId)
                                                                           .Select(x => x.DistrictEquipmentType)
                                                                           .Distinct();

                    foreach (HetDistrictEquipmentType districtEquipmentType in equipmentTypes)
                    {
                        // get the associated equipment type
                        HetEquipmentType equipmentTypeRecord = dbContext.HetEquipmentType.AsNoTracking()
                                                               .FirstOrDefault(x => x.EquipmentTypeId == districtEquipmentType.EquipmentTypeId);

                        if (equipmentTypeRecord == null)
                        {
                            throw new DataException(string.Format("Invalid District Equipment Type. No associated Equipment Type record (District Equipment Id: {0})", districtEquipmentType.DistrictEquipmentTypeId));
                        }

                        // get rules
                        int blockSize   = equipmentTypeRecord.IsDumpTruck ? scoringRules.GetBlockSize("DumpTruck") : scoringRules.GetBlockSize();
                        int totalBlocks = equipmentTypeRecord.IsDumpTruck ? scoringRules.GetTotalBlocks("DumpTruck") : scoringRules.GetTotalBlocks();

                        // assign blocks
                        SeniorityListHelper.AssignBlocks(localArea.LocalAreaId, districtEquipmentType.DistrictEquipmentTypeId, blockSize, totalBlocks, dbContext, false);

                        // save change to database
                        if (ii++ % 100 == 0)
                        {
                            try
                            {
                                Debug.WriteLine("Recalculating Equipment Block Assignment - Index: " + ii);
                                ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, ii.ToString(), BcBidImport.SigId, _newTable);
                                dbContext.SaveChangesForImport();
                            }
                            catch (Exception e)
                            {
                                performContext.WriteLine("Error saving data " + e.Message);
                            }
                        }
                    }
                }

                // ************************************************************
                // save final set of updates
                // ************************************************************
                try
                {
                    performContext.WriteLine("*** Recalculating Equipment Block Assignment is Done ***");
                    Debug.WriteLine("Recalculating Equipment Block Assignment is Done");
                    ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, _newTable);
                    dbContext.SaveChangesForImport();
                }
                catch (Exception e)
                {
                    string temp = string.Format("Error saving data (Record: {0}): {1}", ii, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Пример #11
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 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.Equip[]), new XmlRootAttribute(rootAttr));
                MemoryStream         memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, sourceLocation, rootAttr);
                ImportModels.Equip[] legacyItems  = (ImportModels.Equip[])ser.Deserialize(memoryStream);

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

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

                foreach (ImportModels.Equip item in legacyItems.WithProgress(progress))
                {
                    item.Created_By = systemId;
                    if (item.Modified_By != null)
                    {
                        item.Modified_By = systemId;
                    }

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

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

                    importMapRecords.Add(importMapRecordOrganization);

                    item.Serial_Num = newSerialNum;
                    item.Addr1      = ImportUtility.ScrambleString(item.Addr1);
                    item.Addr2      = ImportUtility.ScrambleString(item.Addr2);
                    item.Addr3      = ImportUtility.ScrambleString(item.Addr3);
                    item.Addr4      = ImportUtility.ScrambleString(item.Addr4);
                    item.Postal     = ImportUtility.ScrambleString(item.Postal);
                    item.Licence    = ImportUtility.ScrambleString(ImportUtility.CleanString(item.Licence));
                    item.Operator   = ImportUtility.ScrambleString(item.Operator);
                }

                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;
            }
        }