예제 #1
0
            public Encoded EncodeVideo(VideoFile input, string encodingCommand, string outputFile, bool getVideoThumbnail)
            {
                Encoded encoded = new Encoded();

                Params = string.Format(@"-i ""{0}"" {1} ""{2}""", input.Path, "-y -b 300k", outputFile);
                string output = FFMPEG(Params);

                encoded.EncodingLog      = output;
                encoded.EncodedVideoPath = outputFile;

                if (File.Exists(outputFile))
                {
                    encoded.Success = true;

                    //get thumbnail?
                    if (getVideoThumbnail)
                    {
                        string saveThumbnailTo = outputFile + "_thumb.jpg";

                        if (GetVideoThumbnail(input, saveThumbnailTo))
                        {
                            encoded.ThumbnailPath = saveThumbnailTo;
                        }
                    }
                }
                else
                {
                    encoded.Success = false;
                }

                return(encoded);
            }
예제 #2
0
        public async Task <Response> Update(CollaboratorViewModel model)
        {
            try
            {
                Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null;
                var     _entity  = new Collaborator(model);
                _entity.SetActive(true);
                _entity.SetUpdatedAt(DateTime.UtcNow.AddHours(-3));

                if (_encoded != null)
                {
                    _entity.SetPassword(_encoded.Encrypted);
                }

                if (_entity.IsValid())
                {
                    return(Ok(await this._repository.Update(_entity), HttpMessage.Updated_Successfully));
                }
                else
                {
                    return(BadRequest(_entity.GetValidationResults()));
                }
            }
            catch (Exception except)
            {
                return(await InternalServerError(except.Message));
            }
        }
예제 #3
0
        public async Task <IActionResult> SetProfile([FromBody]  Encoded image)
        {
            var user = await _userManager.FindByIdAsync(image.Id);

            if (image.Name == null)
            {
                return(ErrorNote("ProfilePicture of type image is required"));
            }

            SaveFile(image.Data, $"{image.Name}{".PNG"}");

            var pic = new FileStorage
            {
                Name        = $"{Path.GetFileName(image.Name)}{".PNG"}",
                FilePath    = $"{Path.GetFileName(image.Name)}{".PNG"}",
                ContentType = image.Type,
            };

            user.ProfileImage = $"{Path.GetFileName(image.Name)}{".PNG"}";
            var result = await _userManager.UpdateAsync(user);

            _context.FileStorage.Add(pic);
            _context.SaveChanges();
            return(Ok());
        }
 void Parse_QueuedType(TreeNode inner)
 {
     for (int n = 0; n < _queue.Count; n++)
     {
         Encoded ec = (Encoded)_queue[n];
         XmlSchemaComplexType st = GetComplexTypeByName(ec.Element.SchemaTypeName);
         Parse_ComplexType(inner, st, ec.Element.SchemaTypeName, n + 1);
     }
 }
예제 #5
0
        public void html_encode()
        {
            Assert.Throws <ArgumentNullException>(() => StringExtensions.HtmlEncode(null));

            Assert.True(ReferenceEquals(string.Empty.HtmlEncode(), string.Empty));

            const string Decoded = "<p>5 is < 10 and > 1</p>";
            const string Encoded = "<p>5 is &lt; 10 and &gt; 1</p>";

            Assert.Equal(Decoded, Encoded.HtmlDecode());
            Assert.Equal(Decoded, Decoded.HtmlEncode().HtmlDecode());
        }
예제 #6
0
    public static Encoded encode3(double [] data)
    {
        Encoded encoded;
        double  elementsVerified, i, e;
        bool    isWithinBounds, isWhole;

        encoded = new Encoded();
        /* Init*/
        encoded.data         = new char [4];
        encoded.data[0]      = 'A';
        encoded.data[1]      = 'A';
        encoded.data[2]      = 'A';
        encoded.data[3]      = 'A';
        encoded.errorMessage = new char [0];
        encoded.success      = false;

        /* Check.*/
        if (data.Length == 3d)
        {
            elementsVerified = 0d;
            for (i = 0d; i < data.Length; i = i + 1d)
            {
                e = data[(int)(i)];
                isWithinBounds = (e >= 0d) && (e < Pow(2d, 8d));
                isWhole        = (e % 1d) == 0d;
                if (isWithinBounds && isWhole)
                {
                    elementsVerified = elementsVerified + 1d;
                }
                else
                {
                    encoded.errorMessage = "Input number is too high, too low or is not a whole number.".ToCharArray();
                    encoded.success      = false;
                }
            }
            if (elementsVerified == data.Length)
            {
                encode3NoChecks(encoded, data);
                encoded.success = true;
            }
        }
        else
        {
            encoded.errorMessage = "Input must contain 3 numbers.".ToCharArray();
            encoded.success      = false;
        }

        return(encoded);
    }
예제 #7
0
    public static void encode3NoChecks(Encoded encoded, double [] data)
    {
        double total, i, bit6;
        char   c;

        total = 0d;
        for (i = 0d; i < data.Length; i = i + 1d)
        {
            total = total + data[(int)(data.Length - i - 1d)] * Pow(2d, i * 8d);
        }

        for (i = 0d; i < 4d; i = i + 1d)
        {
            bit6  = total % Pow(2d, 6d);
            total = (total - bit6) / Pow(2d, 6d);
            c     = getCharacter(bit6);
            encoded.data[(int)(4d - i - 1d)] = c;
        }
    }
예제 #8
0
        public async Task <Response> Save(UserViewModel model)
        {
            try
            {
                Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null;
                var     _entity  = new User(model);

                _entity.SetActive(true);
                _entity.SetCreatedAt(DateTime.UtcNow.AddHours(-3));

                if (_encoded != null)
                {
                    _entity.SetPassword(_encoded.Encrypted);
                }

                if (_entity.IsValid())
                {
                    var _isExist = await this._repository.GetByEmailAndRegistryCode(_entity.Email, _entity.RegistryCode) == null ? false : true;

                    if (!_isExist)
                    {
                        await this._repository.Save(_entity);

                        var _auth = (await this.SignIn(model)).Value;
                        return(Ok(_auth, HttpMessage.Saved_Successfully));
                    }
                    else
                    {
                        return(AlreadyExists());
                    }
                }
                else
                {
                    return(await ParametersNotProvided(_entity.GetValidationResults()));
                }
            }
            catch (Exception except)
            {
                return(await InternalServerError(except.Message));
            }
        }
예제 #9
0
    public static Encoded encode(double [] data)
    {
        Encoded encoded, encoded3;
        double  padding, triplets, i, currentTriplet, currentQuad;

        double [] data3;
        bool      done;

        encoded = new Encoded();

        padding = 0d;
        if ((data.Length % 3d) == 1d)
        {
            padding = 2d;
        }
        if ((data.Length % 3d) == 2d)
        {
            padding = 1d;
        }
        triplets = Ceiling(data.Length / 3d);

        /* Init*/
        encoded.data         = new char [(int)(triplets * 4d)];
        encoded.errorMessage = new char [0];
        encoded.success      = true;

        done = false;
        for (i = 0d; i < triplets && !done; i = i + 1d)
        {
            data3          = new double [3];
            currentTriplet = i * 3d;
            currentQuad    = i * 4d;
            if (padding > 0d && i + 1d == triplets)
            {
                if (padding == 2d)
                {
                    data3[0] = data[(int)(currentTriplet + 0d)];
                    data3[1] = 0d;
                    data3[2] = 0d;
                }
                else if (padding == 1d)
                {
                    data3[0] = data[(int)(currentTriplet + 0d)];
                    data3[1] = data[(int)(currentTriplet + 1d)];
                    data3[2] = 0d;
                }
            }
            else
            {
                data3[0] = data[(int)(currentTriplet + 0d)];
                data3[1] = data[(int)(currentTriplet + 1d)];
                data3[2] = data[(int)(currentTriplet + 2d)];
            }
            encoded3 = encode3(data3);
            if (encoded3.success)
            {
                encoded.data[(int)(currentQuad + 0d)] = encoded3.data[0];
                encoded.data[(int)(currentQuad + 1d)] = encoded3.data[1];
                if (padding > 0d && i + 1d == triplets)
                {
                    if (padding == 2d)
                    {
                        encoded.data[(int)(currentQuad + 2d)] = '=';
                        encoded.data[(int)(currentQuad + 3d)] = '=';
                    }
                    else if (padding == 1d)
                    {
                        encoded.data[(int)(currentQuad + 2d)] = encoded3.data[2];
                        encoded.data[(int)(currentQuad + 3d)] = '=';
                    }
                }
                else
                {
                    encoded.data[(int)(currentQuad + 2d)] = encoded3.data[2];
                    encoded.data[(int)(currentQuad + 3d)] = encoded3.data[3];
                }
            }
            else
            {
                encoded.success      = false;
                encoded.errorMessage = encoded3.errorMessage;
                done = true;
            }
            delete(encoded3);
        }

        return(encoded);
    }
예제 #10
0
        public async void EncodeAsync()
        {
            var(code, bytes) = await Task.Run(() => Encode());

            Encoded?.Invoke(this, new RSEventArgs(code, bytes));
        }