Example #1
0
        private List <HttpResponce> GenerateHttpResponces(int count)
        {
            var result = new List <HttpResponce>();
            var rand   = new Random();

            for (int i = 0; i < count; i++)
            {
                HttpResponce newResponce = null;
                switch (rand.Next(3))
                {
                case 0:
                {
                    newResponce = new HttpTextResponce(DateTime.Now,
                                                       (MimeTypes)rand.Next(2),
                                                       rand.Next(100),
                                                       "UTF8");
                    break;
                }

                case 1:
                {
                    newResponce = new HttpImageResponce(DateTime.Now,
                                                        (MimeTypes)rand.Next(2, 4),
                                                        rand.Next(100, 1000),
                                                        new Size(480, 360),
                                                        256);
                    break;
                }

                case 2:
                {
                    newResponce = new HttpVideoResponce(DateTime.Now,
                                                        MimeTypes.Video,
                                                        rand.Next(1000, 10000),
                                                        new Size(640, 780),
                                                        new TimeSpan(0, rand.Next(1, 60), rand.Next(0, 60)),
                                                        "KMP");
                    break;
                }
                }

                if (newResponce != null)
                {
                    newResponce.Id = i;
                    result.Add(newResponce);
                }
            }

            return(result);
        }
        private void GenerateHttpResponces(int count)
        {
            var rand = new Random();

            using (var db = new HttpResponcesContext())
            {
                for (int i = 0; i < count; i++)
                {
                    HttpResponce newResponce = null;
                    switch (rand.Next(3))
                    {
                    case 0:
                    {
                        newResponce = new HttpTextResponce(DateTime.Now,
                                                           (MimeTypes)rand.Next(2),
                                                           rand.Next(100),
                                                           "UTF8");
                        break;
                    }

                    case 1:
                    {
                        newResponce = new HttpImageResponce(DateTime.Now,
                                                            (MimeTypes)rand.Next(2, 4),
                                                            rand.Next(100, 1000),
                                                            new Size(480, 360),
                                                            256);
                        break;
                    }

                    case 2:
                    {
                        newResponce = new HttpVideoResponce(DateTime.Now,
                                                            MimeTypes.Video,
                                                            rand.Next(1000, 10000),
                                                            new Size(640, 780),
                                                            new TimeSpan(0, rand.Next(1, 60), rand.Next(0, 60)),
                                                            "KMP");
                        break;
                    }
                    }
                    if (newResponce != null)
                    {
                        db.HttpResponces.Add(newResponce);
                    }
                }
                db.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// Get new Http responce
        /// </summary>
        /// <param name="id">Increment Id</param>
        /// <returns>New Http responce</returns>
        private HttpResponce GetHttpResponce(int id)
        {
            var          rand        = new Random();
            HttpResponce newResponce = null;
            int          size        = rand.Next(50, 300);

            switch (rand.Next(3))
            {
            case 0:     // Text Responce
            {
                newResponce = new HttpTextResponce(DateTime.Now,
                                                   (MimeTypes)rand.Next(2),
                                                   size,
                                                   "Unicode");
                break;
            }

            case 1:     // Image Responce
            {
                newResponce = new HttpImageResponce(DateTime.Now,
                                                    (MimeTypes)rand.Next(2, 4),
                                                    size,
                                                    new Size(rand.Next(30, 150), rand.Next(30, 150)),
                                                    rand.Next(1, 100));
                break;
            }

            case 2:     // Video Rasponce
            {
                newResponce = new HttpVideoResponce(DateTime.Now,
                                                    MimeTypes.Video,
                                                    size,
                                                    new Size(rand.Next(30, 150), rand.Next(30, 150)),
                                                    new TimeSpan(rand.Next(1000, 10000)),
                                                    "MPEG");
                break;
            }
            }
            if (newResponce != null)
            {
                newResponce.Id = id;
            }

            return(newResponce);
        }
        private void GenerateHttpResponces(int count)
        {
            try
            {
                var rand = new Random();
                using (var db = new HttpResponcesContext())
                {
                    if (db.HttpResponces.Any())
                    {
#if !RESET_DATA
                        return;
#endif
                    }

                    //Clear old data
                    db.HttpResponces.Clear();
                    db.SaveChanges();

                    for (int i = 0; i < count; i++)
                    {
                        HttpResponce newResponce = null;
                        switch (rand.Next(3))
                        {
                        case 0:
                        {
                            newResponce = new HttpTextResponce(DateTime.Now,
                                                               (MimeTypes)rand.Next(2),
                                                               rand.Next(100),
                                                               "UTF8");
                            break;
                        }

                        case 1:
                        {
                            newResponce = new HttpImageResponce(DateTime.Now,
                                                                (MimeTypes)rand.Next(2, 4),
                                                                rand.Next(100, 1000),
                                                                new Size(480, 360),
                                                                256);
                            break;
                        }

                        case 2:
                        {
                            newResponce = new HttpVideoResponce(DateTime.Now,
                                                                MimeTypes.Video,
                                                                rand.Next(1000, 10000),
                                                                new Size(640, 780),
                                                                new TimeSpan(0, rand.Next(1, 60), rand.Next(0, 60)),
                                                                "KMP");
                            break;
                        }
                        }
                        if (newResponce != null)
                        {
                            db.HttpResponces.Add(newResponce);
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception);
            }
        }