Exemplo n.º 1
0
        public void UploadFileMusic(IFormFile file)
        {
            string idFile;

            using (var stream = file.OpenReadStream())
            {
                idFile = bucket.UploadFromStream(file.FileName, stream).ToString();
            }

            var filename         = file.FileName;
            int indexOfSubstring = filename.IndexOf("-");

            string group     = filename.Remove(indexOfSubstring - 1);
            string song      = filename.Remove(0, indexOfSubstring + 2);
            string extension = Path.GetExtension(song);

            indexOfSubstring = song.IndexOf(extension);
            song             = song.Remove(indexOfSubstring);


            Music music = new Music()
            {
                Group    = group,
                Song     = song,
                IdFile   = idFile,
                FileType = file.ContentType
            };

            music.Id = ObjectId.GenerateNewId().ToString();
            _music.InsertOne(music);
        }
Exemplo n.º 2
0
        public Task <ObjectId> AddFile(Stream stream, string fileName)
        {
            return(Task.Run(() =>
            {
                ObjectId id = ObjectId.GenerateNewId();

                gridFS.UploadFromStream(id, fileName, stream);

                return id;
            }));
        }
Exemplo n.º 3
0
        public ObjectId AddFile(string fileName, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            return(_gridFsBucket.UploadFromStream(fileName, stream));
        }
Exemplo n.º 4
0
        public static ObjectId SaveFile(IRepository <Person> repository, Stream stream, string fileName)
        {
            bucket = new GridFSBucket(repository.Database);
            ObjectId id = bucket.UploadFromStream(fileName, stream);

            return(id);
        }
Exemplo n.º 5
0
        public void UploadFileTopic(IFormFile file, string id)
        {
            try
            {
                var topicTemp = GetTopic(id);
                if (topicTemp.IconUrl != null && topicTemp.IconType != null)
                {
                    bucket.Delete(ObjectId.Parse(topicTemp.IconUrl));
                }
            }
            catch (MongoDB.Driver.GridFS.GridFSFileNotFoundException) { }

            using (var stream = file.OpenReadStream())
            {
                var idFile    = bucket.UploadFromStream(file.FileName, stream).ToString();
                var topicTemp = GetTopic(id);
                topicTemp.IconUrl  = idFile;
                topicTemp.IconType = file.ContentType;
                _topics.ReplaceOne(topic => topic.Id == id, topicTemp);
            }
        }
Exemplo n.º 6
0
        public void UploadFile(IFormFile file, string id)
        {
            try
            {
                var employerTemp = Get(id);
                if (employerTemp.IconUrl != null && employerTemp.IconType != null)
                {
                    bucket.Delete(ObjectId.Parse(employerTemp.IconUrl));
                }
            }
            catch (MongoDB.Driver.GridFS.GridFSFileNotFoundException) { }

            using (var stream = file.OpenReadStream())
            {
                var idFile = bucket.UploadFromStream(file.FileName, stream).ToString();

                var employerTemp = Get(id);
                employerTemp.IconUrl  = idFile;
                employerTemp.IconType = file.ContentType;
                _employers.ReplaceOne(employer => employer.Id == id, employerTemp);
            }
        }
Exemplo n.º 7
0
        public void MBCreateImage()
        {
            int imageWidth  = 100;
            int imageHeight = 100;

            Bitmap bmp = new Bitmap(imageWidth, imageHeight);

            double cx          = 0;
            double cy          = 0;
            double x_step      = (_request.max_x - _request.min_x) / imageWidth;
            double y_step      = (_request.max_y - _request.min_y) / imageHeight;
            double escapeCount = 0;
            double logMax      = Math.Log(1000 * _request.depth);

            Console.WriteLine($"Thread: {Task.CurrentId.ToString()} started building image for connection {_request.connectionId}, {_request.display_x}, {_request.display_y}");


            //run through each pixel in the bitmap, and calculate whether each pixel is in the mandelbrot set or not
            //based on the co-ordinates of the request.
            for (int x = 0; x <= imageWidth - 1; x++)
            {
                cx = _request.min_x + x * x_step;

                for (int y = 0; y <= imageHeight - 1; y++)
                {
                    cy = _request.min_y + y * y_step;

                    // calcuate the number of iterations to escape at this point in the set.

                    escapeCount = EscapeCount(cx, cy, _request.depth);

                    if (escapeCount < (1000 * _request.depth))
                    {
                        // use a log scale to get some nice grading in the colours
                        escapeCount = (Math.Log(escapeCount) / logMax);

                        // get a nice colour from looking up the hue of the escape count.
                        // note the test for zero puts a border around the image
                        ColorRGB colorRGB;
                        ColorRGB colourRGB;

                        if (x == 0 | y == 0)
                        {
                            colorRGB = HSL2RGB(escapeCount, 0.5, 0.55);
                        }
                        else
                        {
                            colorRGB = HSL2RGB(escapeCount, 0.5, 0.5);
                        }

                        // switch the colours around to make it a bit more interesting.
                        switch (_request.depth % 4)
                        {
                        case 0:
                        { colourRGB.R = colorRGB.G; colourRGB.G = colorRGB.R; colourRGB.B = colorRGB.B; break; }

                        case 1:
                        { colourRGB.R = colorRGB.B; colourRGB.G = colorRGB.G; colourRGB.B = colorRGB.R; break; }

                        case 2:
                        { colourRGB.R = colorRGB.R; colourRGB.G = colorRGB.B; colourRGB.B = colorRGB.G; break; }

                        default:
                        { colourRGB.R = colorRGB.R; colourRGB.G = colorRGB.G; colourRGB.B = colorRGB.B; break; }
                        }

                        // set the pixel colour
                        bmp.SetPixel(x, y, Color.FromArgb(colourRGB.R, colourRGB.B, colourRGB.G));
                    }
                    else
                    {
                        if (x == 0 | y == 0)
                        {
                            // set it to grey.
                            bmp.SetPixel(x, y, Color.FromArgb(25, 25, 25));
                        }
                        else
                        {
                            // set it to black.
                            bmp.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                        }
                    }
                }
            }

            // assuming everything kafka and mongo is threadsafe....

            if (toFile)
            {
                // create a new file and write the image to the file in jpeg format.
                // get rid of this when the upload to Mongo works!
                string     filename   = $"./Images/Image{_request.display_x.ToString()}-{_request.display_y.ToString()}.jpg";
                FileStream fileStream = File.Create(filename);
                bmp.Save(fileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                fileStream.Close();
            }
            else
            {
                // upload the bmp to mongoDB as a Jpeg
                MemoryStream tmpStream = new MemoryStream();
                bmp.Save(tmpStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                tmpStream.Position = 0;
                var id = _bucket.UploadFromStream("filename", tmpStream);
                bmp.Dispose();


                var _response = new imageResponse();
                _response.display_x    = _request.display_x;
                _response.display_y    = _request.display_y;
                _response.url          = id.ToString();
                _response.connectionId = _request.connectionId;

                // send the image Id back to the client
                _producer.ProduceAsync("imageResponse", new Message <Null, imageResponse> {
                    Value = _response
                });
                _producer.Flush();
            }

            Console.WriteLine($"Thread: {Task.CurrentId.ToString()} finished building image for connection {_request.connectionId}, {_request.display_x}, {_request.display_y}");
        }
Exemplo n.º 8
0
        public string StoreImage(Stream imageStream, string imageName)
        {
            ObjectId imageId = gridFS.UploadFromStream(imageName, imageStream);

            return(imageId.ToString());
        }
Exemplo n.º 9
0
        public string Put(Stream stream, TimeSpan timeToBeReceived)
        {
            var key = _fs.UploadFromStream(Guid.NewGuid().ToString(), stream);

            return(key.ToString());
        }
Exemplo n.º 10
0
 public ObjectId UploadFromStream(string filename, Stream source) =>
 _bucket.UploadFromStream(filename, source);