Esempio n. 1
0
        public async Task <ShardData> UpdateDataAsync(ShardData data)
        {
            data.ShardType = data.GetType().Name;
            switch (data)
            {
            case User t1:
                throw new Exception();

            //return await _users.Upda(t1);
            case BotKey t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));

            case GlobalValue t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));

            case Workflow t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));

            case Step t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));

            case ExecutionTemplate t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));

            case ExecutionSchedule t1:
                return(await _entitiesRepository.Update(e => e.Id == data.Id, t1));
            }
            throw new Exception("Object type " + data.ShardType + " has no supported update operations");
        }
Esempio n. 2
0
        public async Task <ShardData> InsertDataAsync(ShardData data)
        {
            data.ShardType = data.GetType().Name;
            try
            {
                switch (data)
                {
                case User t1:
                    return(await _entitiesRepository.Insert(t1));

                case BotKey t1:
                    return(await _entitiesRepository.Insert(t1));

                case GlobalValue t1:
                    return(await _entitiesRepository.Insert(t1));

                case StepTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case WorkflowTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case Metric t1:
                    return(await _entitiesRepository.Insert(t1));

                case MetricTick t1:
                    return(await _entitiesRepository.Insert(t1));

                case Step t1:
                    return(await _entitiesRepository.Insert(t1));

                case Workflow t1:
                    return(await _entitiesRepository.Insert(t1));

                case ExecutionTemplate t1:
                    return(await _entitiesRepository.Insert(t1));

                case ExecutionSchedule t1:
                    return(await _entitiesRepository.Insert(t1));
                }
                throw new Exception("Object type " + data.ShardType + "has no supported operations");
            }
            catch (Exception e)
            {
                if (e.Message.Contains("E11000 duplicate key error collection"))
                {
                    Console.WriteLine("Detected that there was a duplicate record in the database... Updating existing record and continueing");
                    try
                    {
                        return(await UpdateDataAsync(data));
                    }
                    catch (Exception updateError)
                    {
                        if (updateError.Message.Contains("has no supported update operations"))
                        {
                            return(data);
                        }
                        else
                        {
                            throw updateError;
                        }
                    }
                }
                throw e;
            }
        }