public void UUIDGenerated_InSameNameAndNameSpace_InDifferentTimes_ShouldBeSame(HashType hashType, UUIDNameSpace nameSpace)
        {
            var name = Guid.NewGuid().ToString();

            using (var generator = new NameBasedGenerator(hashType))
            {
                var first  = generator.GenerateGuid(nameSpace, name);
                var second = generator.GenerateGuid(nameSpace, name);

                Assert.Equal(first, second);
            }
        }
        public void UUIDGenerated_InWithSameName_InDifferentCustomNameSpace_ShouldBeDifferent(HashType hashType)
        {
            var name     = Guid.NewGuid().ToString();
            var firstNs  = Guid.NewGuid();
            var secondNs = Guid.NewGuid();

            using (var generator = new NameBasedGenerator(hashType))
            {
                var first  = generator.GenerateGuid(firstNs, name);
                var second = generator.GenerateGuid(secondNs, name);

                Assert.NotEqual(first, second);
            }
        }
Beispiel #3
0
        public static string createQRCode(string sceneName, string host)
        {
            NameBasedGenerator uuidCreator = new NameBasedGenerator(HashType.SHA1);
            ImageFormat        imageFormat = ImageFormat.Png;

            string markerUUID = uuidCreator.GenerateGuid(sceneName + DateTime.Now).ToString();
            string url        = host + "/QRCode/Open?uuid=";
            string content    = url + markerUUID;
            QrCode qr         = QrCode.EncodeText(content, QrCode.Ecc.Medium);

            string dir      = Directory.GetCurrentDirectory();
            string filename = markerUUID + "." + imageFormat.ToString();

            var path = Path.Combine(
                dir, "static", "content", "marker",
                filename);

            using (var stream = new FileStream(path, FileMode.Create))
                using (var bitmap = qr.ToBitmap(40, 1))
                {
                    bitmap.Save(stream, imageFormat);
                }

            return(filename);
        }
        public void GeneratedUUID_ShouldHaveProperVersion(HashType hashType)
        {
            var name      = Guid.NewGuid().ToString();
            var nameSpace = Guid.NewGuid();

            var expectedVersion = hashType == HashType.Md5 ? 0x30 : 0x50;

            using (var generator = new NameBasedGenerator(hashType))
            {
                var guid = generator.GenerateGuid(nameSpace, name);

                var array = guid.ToByteArray();

                Assert.Equal(expectedVersion, array[7] & 0xf0);
            }
        }
Beispiel #5
0
        public Guid Generate()
        {
            var name = Guid.NewGuid().ToString("N");

            return(generator.GenerateGuid(name));
        }
Beispiel #6
0
 public static Guid Create(Guid val)
 {
     using var generator = new NameBasedGenerator(HashType.Sha1);
     return(generator.GenerateGuid(UUIDNameSpace.Url, val.ToString()));
 }
Beispiel #7
0
        public async Task <IActionResult> UploadFile(AssetSubmissionValues values)
        {
            string[] splitUserInputCourse = splitCourse(values.Course);

            //Course course = await _courses.AsQueryable().Where(c => c.CourseName.Contains(values.Course) && c.Term.Contains(values.Course)).FirstAsync();
            Course course = await _courses.AsQueryable().Where(c => c.CourseName.Equals(splitUserInputCourse[1])).FirstAsync();

            Asset newAsset = new Asset();

            newAsset._id = new ObjectId();

            if (values.AssetFile == null || values.AssetFile.Length == 0)
            {
                return(Content("file not selected"));
            }

            string extension         = Path.GetExtension(values.AssetFile.FileName);
            string filename          = uuidCreator.GenerateGuid(values.AssetFile.FileName + DateTime.Now) + extension;
            var    thumbnailUUID     = uuidCreator.GenerateGuid(values.ThumbnailBase64 + DateTime.Now);
            string thumbnailFilename = thumbnailUUID + ".png";

            string dir = Directory.GetCurrentDirectory();

            var path = Path.Combine(
                dir, "static", "content", "assets",
                filename);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await values.AssetFile.CopyToAsync(stream);
            }

            // prepare body for convert request
            var formValues = new Dictionary <string, string> {
                { "filename", filename }
            };

            // create json string from dictionary
            var content = new StringContent(JsonSerializer.Serialize(formValues), Encoding.UTF8, "application/json");

            // post to converter service
            string usdzConnectionString = "http://" +
                                          Backend.USDZHost + ":" +
                                          Backend.USDZPort + "/local-convert";

            client.PostAsync(usdzConnectionString, content);

            Creator creator = await _creators.AsQueryable().
                              Where(c => c.CreatorName == values.Creator).
                              FirstOrDefaultAsync();

            if (creator == default)
            {
                creator = new Creator {
                    _id = new ObjectId(), CreatorName = values.Creator, Assets = new List <ObjectId>()
                };
                await _creators.InsertOneAsync(creator);
            }

            //integrate into backend functionality
            var thumbPath = Path.Combine(
                dir, "static", "content", "thumbnails",
                thumbnailFilename);

            String base64Str = values.ThumbnailBase64;

            base64Str = base64Str.Split(",")[1];
            byte[] bytes = Convert.FromBase64String(base64Str);

            using (var stream = new FileStream(thumbPath, FileMode.Create))
            {
                await stream.WriteAsync(bytes);
            }
            // ...

            newAsset.Creator           = creator._id;
            newAsset.Course            = course._id;
            newAsset.AssetName         = values.AssetName;
            newAsset.AssetFilename     = filename; //with uuid
            newAsset.AssetType         = Backend.getAssetTypeFromFilename(filename);
            newAsset.ExternalLink      = null;
            newAsset.ThumbnailFilename = Convert.ToString(thumbnailUUID) + ".png";
            newAsset.CreationDate      = DateTime.Now;
            newAsset.Deleted           = false;

            if (ModelState.IsValid)
            {
                await _assets.InsertOneAsync(newAsset);
            }

            //add the new asset to the creators asset property
            creator.Assets.Add(newAsset._id);
            var crUpdate = Builders <Creator> .Update.Set(s => s.Assets, creator.Assets);

            var crOptions = new UpdateOptions();

            crOptions.IsUpsert = true;
            await _creators.UpdateOneAsync(c => c._id == creator._id, crUpdate, crOptions);

            //add the new asset to the courses asset property
            course.Assets.Add(newAsset._id);
            var coUpdate = Builders <Course> .Update.Set(s => s.Assets, course.Assets);

            var coOptions = new UpdateOptions();

            coOptions.IsUpsert = true;
            await _courses.UpdateOneAsync(c => c._id == course._id, coUpdate, coOptions);

            return(RedirectToAction("About", "Home"));
        }