Exemplo n.º 1
0
        /// <summary>
        /// This method generates the Kronos Unique Id for the Shift Entity.
        /// </summary>
        /// <param name="shift">The shift entity that is coming from the response.</param>
        /// <returns>A string that represents the Kronos Unique Id.</returns>
        public string CreateUniqueId(Models.IntegrationAPI.Shift shift)
        {
            if (shift is null)
            {
                throw new ArgumentNullException(nameof(shift));
            }

            var createUniqueIdProps = new Dictionary <string, string>()
            {
                { "StartDateTimeStamp", shift.SharedShift.StartDateTime.ToString(CultureInfo.InvariantCulture) },
                { "EndDateTimeStamp", shift.SharedShift.EndDateTime.ToString(CultureInfo.InvariantCulture) },
                { "UserId", shift.UserId },
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
                { "ExecutingAssembly", Assembly.GetExecutingAssembly().GetName().Name },
            };

            var sb = new StringBuilder();

            foreach (var item in shift.SharedShift.Activities)
            {
                sb.Append(item.DisplayName);
                sb.Append(this.CalculateEndDateTime(item.EndDateTime));
                sb.Append(this.CalculateStartDateTime(item.StartDateTime));
            }

            // From Kronos to Shifts sync, the notes are passed as an empty string.
            // Therefore, the notes are marked as empty while creating the unique ID from Shifts to Kronos.
            shift.SharedShift.Notes = string.Empty;
            var stringToHash = $"{this.CalculateStartDateTime(shift.SharedShift.StartDateTime).ToString(CultureInfo.InvariantCulture)}-{this.CalculateEndDateTime(shift.SharedShift.EndDateTime).ToString(CultureInfo.InvariantCulture)}{sb.ToString()}{shift.SharedShift.Notes}{shift.UserId}";

            this.telemetryClient.TrackTrace($"String to create hash - Shift (IntegrationAPI Model): {stringToHash}");

            // Utilizing the MD5 hash
            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
            {
                // Compute the hash from the stringToHash text.
                md5.ComputeHash(Encoding.UTF8.GetBytes(stringToHash));

                // Have the hash result in the byte array
                byte[] hashResult = md5.Hash;

                // Having the actual hash.
                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < hashResult.Length; i++)
                {
                    // Changing the result into 2 hexadecimal digits for each byte in the byte array.
                    strBuilder.Append(hashResult[i].ToString("x2", CultureInfo.InvariantCulture));
                }

                var outputHashResult = strBuilder.ToString();

                createUniqueIdProps.Add("ResultingHash", outputHashResult);

                this.telemetryClient.TrackTrace(MethodBase.GetCurrentMethod().Name, createUniqueIdProps);

                return(outputHashResult);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Having the ability to create a new TeamsShiftMappingEntity.
        /// </summary>
        /// <param name="shift">The Shift model.</param>
        /// <param name="userMappingEntity">Details of user from User Mapping Entity table.</param>
        /// <param name="kronosUniqueId">Kronos Unique Id corresponds to the shift.</param>
        /// <returns>Mapping Entity associated with Team and Shift.</returns>
        public static TeamsShiftMappingEntity CreateShiftMappingEntity(
            Models.IntegrationAPI.Shift shift,
            AllUserMappingEntity userMappingEntity,
            string kronosUniqueId)
        {
            TeamsShiftMappingEntity teamsShiftMappingEntity = new TeamsShiftMappingEntity
            {
                AadUserId          = shift?.UserId,
                KronosUniqueId     = kronosUniqueId,
                KronosPersonNumber = userMappingEntity?.RowKey,
            };

            return(teamsShiftMappingEntity);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Having the ability to create a new TeamsShiftMappingEntity.
        /// </summary>
        /// <param name="shift">The Shift model.</param>
        /// <param name="userMappingEntity">Details of user from User Mapping Entity table.</param>
        /// <param name="kronosUniqueId">Kronos Unique Id corresponds to the shift.</param>
        /// <returns>Mapping Entity associated with Team and Shift.</returns>
        public TeamsShiftMappingEntity CreateShiftMappingEntity(
            Models.IntegrationAPI.Shift shift,
            AllUserMappingEntity userMappingEntity,
            string kronosUniqueId)
        {
            TeamsShiftMappingEntity teamsShiftMappingEntity = new TeamsShiftMappingEntity
            {
                AadUserId          = shift?.UserId,
                KronosUniqueId     = kronosUniqueId,
                KronosPersonNumber = userMappingEntity?.RowKey,
                ShiftStartDate     = this.UTCToKronosTimeZone(shift.SharedShift.StartDateTime),
            };

            return(teamsShiftMappingEntity);
        }