Пример #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);
        }
Пример #3
0
        /// <summary>
        /// Method to delete the orphan data from open shifts mapping entity.
        /// </summary>
        /// <param name="entity">The mapping entity to be deleted.</param>
        /// <returns>A unit of execution to say whether or not the delete happened successfully.</returns>
        public async Task DeleteOrphanDataFromOpenShiftMappingAsync(AllOpenShiftMappingEntity entity)
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            await this.DeleteEntityAsync(entity).ConfigureAwait(false);
        }
Пример #4
0
        /// <summary>
        /// Method to delete the orphan data from open shifts mapping entity.
        /// </summary>
        /// <param name="entity">The mapping entity to be deleted.</param>
        /// <returns>A unit of execution to say whether or not the delete happened successfully.</returns>
        public Task DeleteOrphanDataFromOpenShiftMappingAsync(AllOpenShiftMappingEntity entity)
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(this.DeleteEntityAsync(entity));
        }
Пример #5
0
        private async Task<TableResult> StoreOrUpdateEntityAsync(AllOpenShiftMappingEntity entity)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false);

            var storeOrUpdateEntityProps = new Dictionary<string, string>()
            {
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
            };

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

            TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(entity);
            return await this.openShiftEntityMappingCloudTable.ExecuteAsync(addOrUpdateOperation).ConfigureAwait(false);
        }
Пример #6
0
        private async Task<TableResult> DeleteEntityAsync(AllOpenShiftMappingEntity entity)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false);

            var deleteEntityProps = new Dictionary<string, string>()
            {
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
                { "RecordToDelete", entity.ToString() },
            };

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

            TableOperation deleteOperation = TableOperation.Delete(entity);
            return await this.openShiftEntityMappingCloudTable.ExecuteAsync(deleteOperation).ConfigureAwait(false);
        }
        /// <summary>
        /// Creates and stores a open shift mapping entity.
        /// </summary>
        /// <param name="openShift">An open shift from Shifts.</param>
        /// <param name="mappedTeam">A team mapping entity.</param>
        /// <param name="monthPartitionKey">The partition key for the shift.</param>
        /// <param name="openShiftOrgJobPath">The org job path of the open shift.</param>
        /// <returns>A task.</returns>
        private async Task CreateAndStoreOpenShiftMapping(Models.IntegrationAPI.OpenShiftIS openShift, TeamToDepartmentJobMappingEntity mappedTeam, string monthPartitionKey, string openShiftOrgJobPath)
        {
            var kronosUniqueId = this.utility.CreateOpenShiftInTeamsUniqueId(openShift, mappedTeam.KronosTimeZone, openShiftOrgJobPath);

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

            AllOpenShiftMappingEntity openShiftMappingEntity = new AllOpenShiftMappingEntity
            {
                PartitionKey            = monthPartitionKey,
                RowKey                  = openShift.Id,
                KronosOpenShiftUniqueId = kronosUniqueId,
                KronosSlots             = openShift.SharedOpenShift.OpenSlotCount,
                OrgJobPath              = openShiftOrgJobPath,
                OpenShiftStartDate      = startDateTime,
            };

            await this.openShiftMappingEntityProvider.SaveOrUpdateOpenShiftMappingEntityAsync(openShiftMappingEntity).ConfigureAwait(false);
        }
Пример #8
0
        /// <summary>
        /// Method implementation to be able to store or update the OpenShiftMapppingEntity.
        /// </summary>
        /// <param name="entity">The open shift mapping entity.</param>
        /// <returns>A unit of execution.</returns>
        public async Task SaveOrUpdateOpenShiftMappingEntityAsync(
            AllOpenShiftMappingEntity entity)
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var saveOrUpdateShiftMappingProps = new Dictionary <string, string>()
            {
                { "TeamsOpenShiftId", entity.TeamsOpenShiftId },
                { "KronosSlots", entity.KronosSlots },
                { "CallingAssembly", Assembly.GetCallingAssembly().GetName().Name },
            };

            this.telemetryClient.TrackTrace(MethodBase.GetCurrentMethod().Name, saveOrUpdateShiftMappingProps);
            await this.StoreOrUpdateEntityAsync(entity).ConfigureAwait(false);
        }
        /// <summary>
        /// Delete an open shift entity from Teams.
        /// </summary>
        /// <param name="allRequiredConfiguration">The required configuration details.</param>
        /// <param name="openShiftMapping">The open shift entity to delete.</param>
        /// <param name="mappedTeam">The team details.</param>
        /// <returns>A unit of execution.</returns>
        private async Task <HttpResponseMessage> DeleteOpenShiftInTeams(SetupDetails allRequiredConfiguration, AllOpenShiftMappingEntity openShiftMapping, TeamToDepartmentJobMappingEntity mappedTeam)
        {
            var httpClient = this.httpClientFactory.CreateClient("ShiftsAPI");

            httpClient.DefaultRequestHeaders.Add("X-MS-WFMPassthrough", allRequiredConfiguration.WFIId);

            var requestUrl = $"teams/{mappedTeam.TeamId}/schedule/openShifts/{openShiftMapping.RowKey}";

            var response = await this.graphUtility.SendHttpRequest(allRequiredConfiguration.GraphConfigurationDetails, httpClient, HttpMethod.Delete, requestUrl).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var successfulDeleteProps = new Dictionary <string, string>()
                {
                    { "ResponseCode", response.StatusCode.ToString() },
                    { "ResponseHeader", response.Headers.ToString() },
                    { "MappedTeamId", mappedTeam?.TeamId },
                    { "OpenShiftIdToDelete", openShiftMapping.RowKey },
                };

                this.telemetryClient.TrackTrace(Resource.DeleteOrphanDataOpenShiftsEntityMappingAsync, successfulDeleteProps);

                await this.openShiftMappingEntityProvider.DeleteOrphanDataFromOpenShiftMappingAsync(openShiftMapping).ConfigureAwait(false);
            }
            else
            {
                var errorDeleteProps = new Dictionary <string, string>()
                {
                    { "ResponseCode", response.StatusCode.ToString() },
                    { "ResponseHeader", response.Headers.ToString() },
                    { "MappedTeamId", mappedTeam?.TeamId },
                    { "OpenShiftIdToDelete", openShiftMapping.RowKey },
                };

                this.telemetryClient.TrackTrace(Resource.DeleteOrphanDataOpenShiftsEntityMappingAsync, errorDeleteProps);
            }

            return(response);
        }
        /// <summary>
        /// Retrieve an open shift from Teams by Team open shift Id.
        /// </summary>
        /// <param name="allRequiredConfigurations">The required configuration details.</param>
        /// <param name="mappedOrgJobEntity">The team details.</param>
        /// <param name="mappingEntityToDecrement">The mapping entity conatianing the details of the OS we want to retrieve.</param>
        /// <returns>A Graph open shift object.</returns>
        private async Task <GraphOpenShift> GetOpenShiftFromTeams(SetupDetails allRequiredConfigurations, TeamToDepartmentJobMappingEntity mappedOrgJobEntity, AllOpenShiftMappingEntity mappingEntityToDecrement)
        {
            var httpClient = this.httpClientFactory.CreateClient("ShiftsAPI");
            var requestUrl = $"teams/{mappedOrgJobEntity.TeamId}/schedule/openShifts/{mappingEntityToDecrement.RowKey}";

            var response = await this.graphUtility.SendHttpRequest(allRequiredConfigurations.GraphConfigurationDetails, httpClient, HttpMethod.Get, requestUrl).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(JsonConvert.DeserializeObject <GraphOpenShift>(responseContent));
            }
            else
            {
                this.telemetryClient.TrackTrace($"The open shift with id {mappingEntityToDecrement.RowKey} could not be found in Teams. ");
                return(null);
            }
        }