private void EncodeMessage(EncodeRequestDto request, Bitmap image)
        {
            var protector        = Provider.CreateProtector(GetType().FullName, request.UserId.ToString(), "-", request.Username);
            var protectedMessage = protector.Protect(Encoding.UTF8.GetBytes(request.Message));

            EncodeService.EnocodeMessage(image, protectedMessage);
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Post([FromBody] EncodeMessageInfo encodeInformation)
        {
            if (encodeInformation == null)
            {
                return(BadRequest());
            }

            if (encodeInformation.SendingPMode == null)
            {
                return(BadRequest());
            }

            encodeInformation.SigningCertificatePassword = CertificateInfoRetriever.RetrieveCertificatePassword(this.Request).SigningPassword;

            var service = new EncodeService();

            var result = await service.CreateAS4Message(encodeInformation);

            if (result == null)
            {
                return(BadRequest());
            }

            if (result.Exception != null)
            {
                return(InternalServerError(result.Exception));
            }

            return(Ok(CreateEncodeResultFromContext(result)));
        }
Esempio n. 3
0
 public ActionResult Encode(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         var encodeService = new EncodeService();
         var dbService     = new DbService();
         var urlId         = GetUniqueId();
         var shortUrl      = "http://" + Request.Url.Authority + "/" + encodeService.Encode(urlId);
         dbService.WriteUrlData(urlId, url, shortUrl);
         return(View("MyList"));
     }
     return(View());
 }
Esempio n. 4
0
        public void DecodeData()
        {
            int number        = 0;
            var encodeService = new EncodeService();
            var encodedNumber = encodeService.Encode(testNumber);

            for (int i = 0, len = encodedNumber.Length; i < len; i++)
            {
                number = number * baseType + alphabet.IndexOf(encodedNumber[(i)]);
            }

            Assert.Equal(testNumber, number);
        }
Esempio n. 5
0
        public void Base64Encode_ShouldEncodeString()
        {
            // Arrange
            string text    = "random text";
            var    service = new EncodeService();

            // Act
            var expectedResult = "cmFuZG9tIHRleHQ="; // string text - encoded using an online encoder.
            var actualResult   = service.Base64Encode(text);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 6
0
        public void Base64Decode_ShouldDecodeString()
        {
            // Arrange
            string encodedText = "cmFuZG9tIHRleHQ=";
            var    service     = new EncodeService();

            // Act
            var expectedResult = "random text"; // The decoded version of the encodedText.
            var actualResult   = service.Base64Decode(encodedText);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var fileService   = new FileService();
            var encodeService = new EncodeService();
            var linUcbService = new LinUcbService();
            var uiService     = new UIService();

            var t = fileService.ReadFile();
            var c = encodeService.Encode(t);

            linUcbService.Learn(c);

            uiService.DisplayApplication();
            var V      = Vector <double> .Build;
            var vector = V.DenseOfArray(new double[] { 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0 });

            var recomenndation = linUcbService.RecommendMovie(vector);
        }
Esempio n. 8
0
        public DiffController GetMockedDiffController(Json json)
        {
            var jsonId = "99";

            var mockRepository = new Mock <IJsonRepository>();

            mockRepository.Setup(x => x.GetById(jsonId)).Returns(Task.FromResult(json));
            mockRepository.Setup(x => x.AddOrUpdate(It.IsAny <Json>()));
            mockRepository.Setup(x => x.SaveChanges());

            var diffService   = new DiffService();
            var encodeService = new EncodeService();
            var logger        = new Logger <DiffController>(new LoggerFactory());

            var controller = new DiffController(mockRepository.Object, diffService, encodeService, logger);

            return(controller);
        }
Esempio n. 9
0
        public async Task UploadFileAsync_WithValidFile_ShouldUploadFile()
        {
            // Arrange
            var directory     = Directory.GetCurrentDirectory();
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(directory)
                                .AddJsonFile("appsettings.Development.json", false)
                                .Build();

            var config        = Options.Create(configuration.GetSection("Cloudinary").Get <CloudinaryConfig>());
            var encodeService = new EncodeService();
            var service       = new CloudinaryService(config, encodeService);

            var fileMock = this.SetupMockFile();
            var file     = fileMock.Object;

            // Act
            var result = await service.UploadFileAsync(file, "random-string-for-id");

            bool urlExists = result.SecureUri.ToString().Length > 0;

            // Assert
            Assert.True(urlExists);
        }