Example #1
0
        public void GetAllProgressesTest()
        {
            ProgressRepository repository = new ProgressRepository(resConnect);
            List <Progress>    loadList   = new List <Progress>();
            string             query      = "SELECT *  from dbo.Progress";

            using (SqlConnection connection =
                       new SqlConnection(resConnect))
            {
                SqlCommand command = new SqlCommand(query, connection);

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    loadList.Add(
                        new Progress(
                            idProgress: (int)reader[0],
                            statusProgress: (string)reader[1]
                            )
                        );
                }
                reader.Close();
            }

            int count = repository.GetAllProgresses().Count;

            Assert.AreEqual(count, loadList.Count);
        }
        public void Post([FromBody] Progress progresUpdate)
        {
            var identity = HttpContext.User.Identity as ClaimsIdentity;
            var userId   = identity.FindFirst(ClaimTypes.Name).Value;

            if (identity == null)
            {
                Response.StatusCode = 404;
            }
            int ID = Int32.Parse(userId);

            ProgressRepository.AddProgress(progresUpdate, ID);
        }
        public List <Progress> Get()
        {
            var identity = HttpContext.User.Identity as ClaimsIdentity;
            var userId   = identity.FindFirst(ClaimTypes.Name).Value;

            if (identity == null)
            {
                Response.StatusCode = 404;
            }
            int ID = Int32.Parse(userId);

            return(ProgressRepository.GetProgress(ID));
        }
Example #4
0
        public NoteViewModel(Note note, NoteRepository noteRepository, DateTime selectedDate)
        {
            this._note          = note;
            this.noteRepository = noteRepository;
            this.selectedDate   = selectedDate;

            typeJobRepository   = new TypeJobRepository(Properties.Resources.ConnectCommand);
            progressRepository  = new ProgressRepository(Properties.Resources.ConnectCommand);
            relevanceRepository = new RelevanceRepository(Properties.Resources.ConnectCommand);

            TimeStartHours   = note.TimeStart.Hours.ToString();
            TimeStartMinutes = note.TimeStart.Minutes.ToString();

            TimeFinishHours   = note.TimeFinish.Hours.ToString();
            TimeFinishMinutes = note.TimeFinish.Minutes.ToString();
        }
Example #5
0
        public void GenerateNotes(
            NoteRepository noteRepository,
            int countNotes
            )
        {
            if (noteRepository == null || countNotes < 1)
            {
                throw new ArgumentException("noteRepository is null or countNotes <0");
            }

            Random   saintRandom = new Random();
            DateTime dateNote    = DateTime.Now.AddDays(-1);

            List <TypeJob>   typeJobs   = new TypeJobRepository(Properties.Resources.ConnectCommand).GetAllTypeJobs();
            List <Relevance> relevances = new RelevanceRepository(Properties.Resources.ConnectCommand).GetAllRelevances();
            List <Progress>  progresses = new ProgressRepository(Properties.Resources.ConnectCommand).GetAllProgresses();


            for (int i = 0; i < countNotes; i++)
            {
                noteRepository.RemoveNotes(dateNote);

                int[] timeLines = GetTimeLines();
                for (int j = 0; j < timeLines.Length - 1; j += 1)
                {
                    Note note = new Note();

                    note.NoteDate   = dateNote;
                    note.TypeJob    = typeJobs[saintRandom.Next(1, 6)];
                    note.Relevance  = relevances[saintRandom.Next(1, 4)];
                    note.Progress   = progresses[saintRandom.Next(1, 4)];
                    note.TimeStart  = new TimeSpan(timeLines[j], 1, 0);
                    note.TimeFinish = new TimeSpan(timeLines[j + 1], 0, 0);

                    noteRepository.AddNote(note);
                }

                dateNote = dateNote.AddDays(-1);
            }
        }
        public IProgressRepository GetProgressRepository()
        {
            IProgressRepository progressRepository = new ProgressRepository(_session);

            return(progressRepository);
        }
Example #7
0
        static async Task Main(string[] args)
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Console.WriteLine("Cancel event triggered");
                Environment.Exit(-1);
            };

            string storageConnectionString = Environment.GetEnvironmentVariable("CLIMATE_COMPARISON_STORAGE_ACCOUNT");
            var    storageAccount          = CloudStorageAccount.Parse(storageConnectionString);
            var    tableClient             = storageAccount.CreateCloudTableClient();

            var progressRepository = new ProgressRepository(tableClient);
            int start = await progressRepository.Get(OPERATION) ?? 0;

            Console.WriteLine($"Starting from {start}");

            var repository = new PrecipitationRepository(tableClient);

            string sqlConnectionString = Environment.GetEnvironmentVariable("CLIMATE_COMPARISON_ConnectionStrings__ConnectionString");

            using (var sqlConnection = new SqlConnection(sqlConnectionString))
            {
                sqlConnection.Open();

                for (; ;)
                {
                    var placeIds = GetPlaceIds(start, PLACES_BATCH_SIZE, sqlConnection).ToList();

                    if (placeIds.Count == 0)
                    {
                        break;
                    }

                    foreach (int id in placeIds)
                    {
                        double[] precipitation;
                        try
                        {
                            precipitation = GetPrecipitation(id, sqlConnection).ToArray();
                        }
                        catch (SqlException sqlException) when(sqlException.ErrorCode == -2146232060)
                        {
                            Console.WriteLine($"can't get precipitation for {id}");
                            Console.WriteLine(sqlException);
                            continue;
                        }

                        await repository.Save(id, precipitation);

                        Console.WriteLine($"Processed {id}");

                        start = id;
                    }

                    await progressRepository.Set(OPERATION, start);

                    Console.WriteLine($"Saved progress {start}");
                }
            }
        }
Example #8
0
 public ProgressesController(ProgressRepository progressRepository, AssignmentRepository assignmentRepository, UserRepository userRepository)
 {
     _progressRepository   = progressRepository;
     _assignmentRepository = assignmentRepository;
     _userRepository       = userRepository;
 }
Example #9
0
        static async Task Main(string[] args)
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Console.WriteLine("Cancel event triggered");
                Environment.Exit(-1);
            };

            string storageConnectionString = Environment.GetEnvironmentVariable("CLIMATE_COMPARISON_STORAGE_ACCOUNT");
            var    storageAccount          = CloudStorageAccount.Parse(storageConnectionString);
            var    tableClient             = storageAccount.CreateCloudTableClient();
            var    placesTable             = tableClient.GetTableReference("places");

            var progressRepository = new ProgressRepository(tableClient);
            int start = await progressRepository.Get(OPERATION) ?? 0;

            Console.WriteLine($"Starting from {start}");

            string sqlConnectionString = Environment.GetEnvironmentVariable("CLIMATE_ConnectionStrings__ConnectionString");

            using (var sqlConnection = new SqlConnection(sqlConnectionString))
            {
                sqlConnection.Open();

                for (; ;)
                {
                    var places = GetPlaces(start, PLACES_BATCH_SIZE, sqlConnection).ToList();

                    if (places.Count == 0)
                    {
                        break;
                    }

                    foreach (var place in places)
                    {
                        bool insertedRows = false;

                        var allNames = place.AltNames.Split(",").Union(new[] { place.Name })
                                       .Select(SanitizeName)
                                       .Select(it => it.ToLowerInvariant())
                                       .Where(it => !string.IsNullOrWhiteSpace(it))
                                       .Distinct();

                        var tasks = allNames.Select(async altName =>
                        {
                            var placeEntity = new PlaceEntity
                            {
                                PartitionKey = altName,
                                RowKey       = place.Id.ToString(),
                                Id           = place.Id.ToString(),
                                Name         = place.Name,
                                AltName      = altName,
                                Latitude     = place.Latitude,
                                Longitude    = place.Longitude,
                                CountryCode  = place.CountryCode,
                                Population   = place.Population
                            };

                            var getOperation = TableOperation.Retrieve <PlaceEntity>(placeEntity.PartitionKey, placeEntity.RowKey);

                            var existingRecord = await placesTable.ExecuteAsync(getOperation);

                            if (existingRecord.Result == null)
                            {
                                try
                                {
                                    var insertOperation = TableOperation.Insert(placeEntity);
                                    await placesTable.ExecuteAsync(insertOperation);
                                    insertedRows = true;
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine($"Cannot insert {place.Name} {altName}: {exception}");
                                }
                            }
                        });

                        await Task.WhenAll(tasks);

                        if (insertedRows)
                        {
                            Console.WriteLine($"{place.Name} imported");
                        }
                        else
                        {
                            Console.WriteLine($"Skipped {place.Name}");
                        }

                        start = place.Id;
                    }

                    await progressRepository.Set(OPERATION, start);

                    Console.WriteLine($"Saved progress {start}");
                }
            }

            Console.WriteLine("Done");
        }