Exemple #1
0
        public static bool create_icon(Guid?applicationId, Guid iconId, IconType iconType,
                                       byte[] fileContent, ref string errorMessage, ref IconMeta meta)
        {
            int width = 100, height = 100, highQualityWidth = 600, highQualityHeight = 600;

            FolderNames imageFolder            = FolderNames.ProfileImages,
                        highQualityImageFolder = FolderNames.HighQualityProfileImage;

            bool isValid                       = DocumentUtilities.get_icon_parameters(applicationId, iconType, ref width, ref height,
                                                                                       ref highQualityWidth, ref highQualityHeight, ref imageFolder, ref highQualityImageFolder);

            if (!isValid)
            {
                return(false);
            }

            DocFileInfo highQualityFile = new DocFileInfo()
            {
                FileID = iconId, Extension = "jpg", FolderName = highQualityImageFolder
            };
            DocFileInfo file = new DocFileInfo()
            {
                FileID = iconId, Extension = "jpg", FolderName = imageFolder
            };

            byte[] hqContent = new byte[0];

            bool succeed = RVGraphics.make_thumbnail(applicationId,
                                                     fileContent, highQualityFile, ref hqContent, highQualityWidth, highQualityHeight,
                                                     width, height, ref errorMessage, highQualityFile.Extension, dontStore: false);

            return(succeed && hqContent != null && hqContent.Length > 0 &&
                   RVGraphics.extract_thumbnail(applicationId, highQualityFile, hqContent,
                                                file, -1, -1, -1, -1, width, height, ref errorMessage, ref meta));
        }
        public bool store(Guid?applicationId, byte[] fileContent)
        {
            try
            {
                //Check for Encryption
                List <FolderNames> targetFolders =
                    new[] { FolderNames.TemporaryFiles, FolderNames.Attachments, FolderNames.WikiContent }.ToList();

                bool needsEncryption = targetFolders.Any(t => FolderName == t) &&
                                       RaaiVanSettings.FileEncryption(applicationId) &&
                                       ((Size.HasValue ? Size.Value : 0) / (1024 * 1024)) > 10;
                //end of Check for Encryption

                if (needsEncryption)
                {
                    fileContent = DocumentUtilities.encrypt_bytes_aes(fileContent);
                }

                bool   isPublic = false;
                string address  = get_address(applicationId, ref isPublic, encrypted: needsEncryption);

                if (CephMode)
                {
                    if (!CephStorage.add_file(address, fileContent, isPublic))
                    {
                        return(false);
                    }
                }
                else
                {
                    string folderPath = get_folder_address(applicationId);
                    if (string.IsNullOrEmpty(folderPath))
                    {
                        return(false);
                    }

                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }

                    using (FileStream fs = new FileStream(address, FileMode.Create))
                        using (BinaryWriter bw = new BinaryWriter(fs))
                            bw.Write(fileContent);
                }

                _Encrypted = needsEncryption;

                return(true);
            }
            catch { return(false); }
        }
        public byte[] toByteArray(Guid?applicationId)
        {
            try
            {
                string fileAddress = get_real_address(applicationId);

                if (string.IsNullOrEmpty(fileAddress))
                {
                    return(new byte[0]);
                }
                else if (CephMode)
                {
                    return(CephStorage.get_file(fileAddress));
                }
                else
                {
                    return(is_encrypted(applicationId) ?
                           DocumentUtilities.decrypt_bytes_aes(File.ReadAllBytes(fileAddress)) : File.ReadAllBytes(fileAddress));
                }
            }
            catch { return(new byte[0]); }
        }
Exemple #4
0
        public string toJson(Guid?currentUserId = null, bool icon = false, bool highQualityIcon = false)
        {
            string iconUrl = !icon || !ApplicationID.HasValue ? string.Empty :
                             DocumentUtilities.get_application_icon_url(ApplicationID.Value);
            string highQualityIconUrl = !highQualityIcon || !ApplicationID.HasValue ? string.Empty :
                                        DocumentUtilities.get_application_icon_url(ApplicationID.Value, highQuality: true);

            return("{\"ApplicationID\":\"" + (!ApplicationID.HasValue ? string.Empty : ApplicationID.ToString()) + "\"" +
                   ",\"Title\":\"" + Base64.encode(string.IsNullOrEmpty(Title) ? Name : Title) + "\"" +
                   ",\"Description\":\"" + Base64.encode(Description) + "\"" +
                   (string.IsNullOrEmpty(AvatarName) ? string.Empty :
                    ",\"AvatarName\":\"" + AvatarName + "\"") +
                   (!icon ? string.Empty :
                    ",\"IconURL\":\"" + (string.IsNullOrEmpty(iconUrl) ? "" : iconUrl) + "\"") +
                   (!highQualityIcon ? string.Empty :
                    ",\"HighQualityIconURL\":\"" + highQualityIconUrl + "\"") +
                   (!currentUserId.HasValue ? string.Empty :
                    ",\"Removable\":" + (CreatorUserID.HasValue && CreatorUserID == currentUserId).ToString().ToLower()) +
                   (!currentUserId.HasValue ? string.Empty :
                    ",\"Editable\":" + (CreatorUserID.HasValue && CreatorUserID == currentUserId).ToString().ToLower()) +
                   "}");
        }
        private static void init_login()
        {
            if (Username != null || Password != null)
            {
                return;
            }

            Username = Password = "";

            string path = PublicMethods.map_path(PublicConsts.LicenseFilePath);

            if (!File.Exists(path))
            {
                return;
            }

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) {
                byte[] data = new byte[fs.Length];
                fs.Read(data, 0, (int)fs.Length);
                fs.Close();
                fs.Dispose();

                Dictionary <string, object> dic = PublicMethods.fromJSON(Base64.decode(
                                                                             Encoding.ASCII.GetString(DocumentUtilities.decrypt_bytes_aes_native(data))));

                if (dic.ContainsKey("username"))
                {
                    Username = (string)dic["username"];
                }
                if (dic.ContainsKey("password"))
                {
                    Password = (string)dic["password"];
                }
            }
        }