public static string get_cover_photo_url(Guid?applicationId,
                                                 Guid?ownerId, bool networkAddress = false, bool highQuality = false)
        {
            if (RaaiVanSettings.SAASBasedMultiTenancy)
            {
                applicationId = null;
            }

            if (!ownerId.HasValue || ownerId == Guid.Empty)
            {
                string addr = PublicConsts.DefaultCoverPhotoURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityCoverPhoto : FolderNames.CoverPhoto;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
        public static string get_icon_url(Guid applicationId, string fileExtention, bool networkAddress = false)
        {
            string url = "~/images/extensions/" + fileExtention + ".png";
            string adr = File.Exists(PublicMethods.map_path(url)) ? url.Replace("~", "../..") : string.Empty;

            return(networkAddress ? adr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : adr);
        }
        public static string get_application_icon_url(Guid?applicationId, bool highQuality = false, bool networkAddress = false)
        {
            FolderNames folderName = highQuality ? FolderNames.HighQualityApplicationIcon : FolderNames.ApplicationIcons;

            if (!applicationId.HasValue || applicationId == Guid.Empty)
            {
                string addr = RaaiVanSettings.LogoMiniURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = applicationId,
                OwnerID    = applicationId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            if (string.IsNullOrEmpty(retUrl) && !highQuality)
            {
                retUrl = RaaiVanSettings.LogoMiniURL;
            }

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
        public static string get_icon_url(Guid applicationId, Guid ownerId,
                                          DefaultIconTypes defaultIcon = DefaultIconTypes.Node, Guid?alternateOwnerId = null, bool networkAddress = false)
        {
            if (ownerId == Guid.Empty)
            {
                return(string.Empty);
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = FolderNames.Icons
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            if (string.IsNullOrEmpty(retUrl) && alternateOwnerId.HasValue)
            {
                fi.FileID = alternateOwnerId;
                retUrl    = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;
            }

            if (string.IsNullOrEmpty(retUrl) && defaultIcon != DefaultIconTypes.None)
            {
                retUrl = get_icon_url(applicationId, defaultIcon);
            }

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
        public static string get_personal_image_address(Guid?applicationId,
                                                        Guid?userId, bool networkAddress = false, bool highQuality = false)
        {
            if (RaaiVanSettings.SAASBasedMultiTenancy)
            {
                applicationId = null;
            }

            if (!userId.HasValue || userId == Guid.Empty)
            {
                string addr = PublicConsts.DefaultProfileImageURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityProfileImage : FolderNames.ProfileImages;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = userId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string address = !fi.exists(applicationId) ?
                             (highQuality ? string.Empty : PublicConsts.DefaultProfileImageURL) : fi.url(applicationId);

            return(networkAddress ? address.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : address);
        }
        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 static string get_icon_url(Guid applicationId, Guid ownerId, string extension,
                                          bool highQuality = false, bool networkAddress = false)
        {
            if (ownerId == Guid.Empty)
            {
                return(string.Empty);
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityIcon : FolderNames.Icons;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) :
                            (highQuality ? string.Empty : get_icon_url(applicationId, DefaultIconTypes.Extension, extension));

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
        public static string get_icon_url(Guid?applicationId, DefaultIconTypes defaultIcon,
                                          string extension = "", bool networkAddress = false)
        {
            string adr = string.Empty;

            switch (defaultIcon)
            {
            case DefaultIconTypes.Document:
                adr = "../../images/archive.png";
                break;

            case DefaultIconTypes.Extension:
                adr = "../../images/extensions/" + extension + ".png";
                string path = PublicMethods.map_path("~/images/extensions") + "\\" + extension + ".png";
                adr = File.Exists(path) ? adr : "../../images/archive.png";
                break;

            default:
                adr = "../../images/Preview.png";
                break;
            }

            return(networkAddress ? adr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : adr);
        }