Beispiel #1
0
        /// <summary>
        /// Method that will create a new Open Shift Entity Mapping that conforms to the newest schema.
        /// </summary>
        /// <param name="responseModel">The OpenShift response from MS Graph.</param>
        /// <param name="uniqueId">The Kronos Unique Id.</param>
        /// <param name="monthPartitionKey">The monthwise partition key.</param>
        /// <param name="orgJobPath">The Kronos Org Job Path.</param>
        /// <returns>The new AllOpenShiftMappingEntity which conforms to schema.</returns>
        private AllOpenShiftMappingEntity CreateNewOpenShiftMappingEntity(
            Models.Response.OpenShifts.GraphOpenShift responseModel,
            string uniqueId,
            string monthPartitionKey,
            string orgJobPath)
        {
            var createNewOpenShiftMappingEntityProps = new Dictionary <string, string>()
            {
                { "GraphOpenShiftId", responseModel.Id },
                { "GraphOpenShiftEtag", responseModel.ETag },
                { "KronosUniqueId", uniqueId },
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
            };

            AllOpenShiftMappingEntity openShiftMappingEntity = new AllOpenShiftMappingEntity
            {
                PartitionKey      = monthPartitionKey,
                RowKey            = uniqueId,
                TeamsOpenShiftId  = responseModel.Id,
                KronosSlots       = Constants.KronosOpenShiftsSlotCount,
                SchedulingGroupId = responseModel.SchedulingGroupId,
                OrgJobPath        = orgJobPath,
            };

            this.telemetryClient.TrackTrace(Resource.CreateNewOpenShiftMappingEntity, createNewOpenShiftMappingEntityProps);

            return(openShiftMappingEntity);
        }
        /// <summary>
        /// Method that will create a new Open Shift Entity Mapping that conforms to the newest schema.
        /// </summary>
        /// <param name="responseModel">The OpenShift response from MS Graph.</param>
        /// <param name="uniqueId">The Kronos Unique Id.</param>
        /// <param name="monthPartitionKey">The monthwise partition key.</param>
        /// <param name="orgJobPath">The Kronos Org Job Path.</param>
        /// <returns>The new AllOpenShiftMappingEntity which conforms to schema.</returns>
        private AllOpenShiftMappingEntity CreateNewOpenShiftMappingEntity(
            Models.Response.OpenShifts.GraphOpenShift responseModel,
            string uniqueId,
            string monthPartitionKey,
            string orgJobPath)
        {
            var createNewOpenShiftMappingEntityProps = new Dictionary <string, string>()
            {
                { "GraphOpenShiftId", responseModel.Id },
                { "GraphOpenShiftEtag", responseModel.ETag },
                { "KronosUniqueId", uniqueId },
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
            };

            var startDateTime = DateTime.SpecifyKind(responseModel.SharedOpenShift.StartDateTime.DateTime, DateTimeKind.Utc);

            AllOpenShiftMappingEntity openShiftMappingEntity = new AllOpenShiftMappingEntity
            {
                PartitionKey            = monthPartitionKey,
                RowKey                  = responseModel.Id,
                KronosOpenShiftUniqueId = uniqueId,
                KronosSlots             = responseModel.SharedOpenShift.OpenSlotCount,
                OrgJobPath              = orgJobPath,
                OpenShiftStartDate      = startDateTime,
            };

            this.telemetryClient.TrackTrace(Resource.CreateNewOpenShiftMappingEntity, createNewOpenShiftMappingEntityProps);

            return(openShiftMappingEntity);
        }
Beispiel #3
0
        /// <summary>
        /// This method creates the expected shift hash using the open shift details.
        /// </summary>
        /// <param name="openShift">The open shift from Graph.</param>
        /// <param name="userAadObjectId">The AAD Object ID of the user.</param>
        /// <returns>A string that represents the expected hash of the new shift that is to be created.</returns>
        public string CreateUniqueId(
            Models.Response.OpenShifts.GraphOpenShift openShift,
            string userAadObjectId)
        {
            if (openShift is null)
            {
                throw new ArgumentNullException(nameof(openShift));
            }

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

            var sb = new StringBuilder();

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

            var stringToHash = $"{this.CalculateStartDateTime(openShift.SharedOpenShift.StartDateTime).ToString(CultureInfo.InvariantCulture)}-{this.CalculateEndDateTime(openShift.SharedOpenShift.EndDateTime).ToString(CultureInfo.InvariantCulture)}{sb.ToString()}{openShift.SharedOpenShift.Notes}{userAadObjectId}";

            this.telemetryClient.TrackTrace($"String to create hash - OpenShift: {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("CreateUniqueId-ExpectedShiftHash", outputHashResult);

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

                return(outputHashResult);
            }
        }