예제 #1
0
        public void DeleteFile(IFileInfo file)
        {
            string lockReason;

            if (FileLockingController.Instance.IsFileLocked(file, out lockReason))
            {
                throw new FileLockedException(Localization.GetExceptionMessage(lockReason, "File locked. The file cannot be updated. Reason: " + lockReason));
            }

            FileVersionController.Instance.DeleteAllUnpublishedVersions(file, false);
            try
            {
                var folderMapping = FolderMappingController.Instance.GetFolderMapping(file.PortalId, file.FolderMappingID);
                FolderProvider.Instance(folderMapping.FolderProviderType).DeleteFile(file);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new FolderProviderException(Localization.GetExceptionMessage("DeleteFileUnderlyingSystemError", "The underlying system threw an exception. The file has not been deleted."), ex);
            }

            this.DeleteFileData(file);

            DataCache.RemoveCache("GetFileById" + file.FileId);
        }
        private bool AreMappedPathsSupported(int folderMappingId)
        {
            if (MappedPathsSupported.ContainsKey(folderMappingId))
            {
                return((bool)MappedPathsSupported[folderMappingId]);
            }
            var result = FolderProvider.Instance(FolderMappingController.Instance.GetFolderMapping(folderMappingId).FolderProviderType).SupportsMappedPaths;

            MappedPathsSupported.Add(folderMappingId, result);
            return(result);
        }
예제 #3
0
        private string GetFileUrl(string fileUrl)
        {
            if (Regex.IsMatch(fileUrl, "^\\d+$"))
            {
                IFileInfo         file      = FileManager.Instance.GetFile(int.Parse(fileUrl, NumberStyles.Integer));
                FolderMappingInfo mapFolder = FolderMappingController.Instance.GetFolderMapping(file.FolderMappingID);
                return(FolderProvider.Instance(mapFolder.FolderProviderType).GetFileUrl(file));
            }

            return(fileUrl);
        }
예제 #4
0
        /// <summary>
        /// Loads concrete settings.
        /// </summary>
        /// <param name="folderMappingSettings">The Hashtable containing the folder mapping settings.</param>
        public override void LoadSettings(Hashtable folderMappingSettings)
        {
            var folderProvider = FolderProvider.Instance(Constants.FolderProviderType);

            if (folderMappingSettings.ContainsKey(Constants.AccountName))
            {
                this.tbAccountName.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, Constants.AccountName);
            }

            if (folderMappingSettings.ContainsKey(Constants.AccountKey))
            {
                this.tbAccountKey.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, Constants.AccountKey);
            }

            if (this.tbAccountName.Text.Length > 0 && this.tbAccountKey.Text.Length > 0)
            {
                var bucketName = string.Empty;

                if (folderMappingSettings.ContainsKey(Constants.Container))
                {
                    bucketName = folderMappingSettings[Constants.Container].ToString();
                }

                this.LoadContainers();

                var bucket = this.ddlContainers.Items.FindByText(bucketName);

                if (bucket != null)
                {
                    this.ddlContainers.SelectedIndex = this.ddlContainers.Items.IndexOf(bucket);
                }
            }

            if (folderMappingSettings.ContainsKey(Constants.UseHttps))
            {
                this.chkUseHttps.Checked = bool.Parse(folderMappingSettings[Constants.UseHttps].ToString());
            }

            this.chkDirectLink.Checked = !folderMappingSettings.ContainsKey(Constants.DirectLink) || folderMappingSettings[Constants.DirectLink].ToString().ToLowerInvariant() == "true";

            if (folderMappingSettings.ContainsKey(Constants.CustomDomain))
            {
                this.tbCustomDomain.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, Constants.CustomDomain);
            }

            if (folderMappingSettings.ContainsKey(Constants.SyncBatchSize) && folderMappingSettings[Constants.SyncBatchSize] != null)
            {
                this.tbSyncBatchSize.Text = folderMappingSettings[Constants.SyncBatchSize].ToString();
            }
            else
            {
                this.tbSyncBatchSize.Text = Constants.DefaultSyncBatchSize.ToString();
            }
        }
예제 #5
0
        /// <summary>
        /// GetImageFileUrl - this method returns the valid URL for any file, regardless to folder or folder provider in use
        /// </summary>
        /// <param name="oFile">Fully loaded IFileInfo object</param>
        /// <returns></returns>
        /// <remarks>
        /// WARNING!!! This method can return exceptions. They should be caught and processed in the UI though.
        /// </remarks>
        public string GetFileUrl(IFileInfo oFile)
        {
            /*******************************************************
             * ' WARNING!!!
             * ' This method can return exceptions. They should be
             * ' caught and processed in the UI though.
             * '*******************************************************/
            FolderMappingInfo mapFolder = FolderMappingController.Instance.GetFolderMapping(oFile.FolderMappingID);

            return(FolderProvider.Instance(mapFolder.FolderProviderType).GetFileUrl(oFile));
        }
예제 #6
0
        public override int AddOrUpdateFile(FileInfo objFile, byte[] content, bool contentOnly)
        {
            var objFolder = FolderManager.Instance.GetFolder(objFile.FolderId);

            if (objFolder != null)
            {
                if (content != null && content.Length > 0)
                {
                    using (var objStream = new MemoryStream(content))
                    {
                        if (objFile.FileId > 0)
                        {
                            var toReturn = objFile.FileId;
                            if (!contentOnly)
                            {
                                toReturn = FileManager.Instance.UpdateFile(objFile, objStream).FileId;
                            }
                            //Todo: seems the updatefile does not have the proper call to that function. Should be registered as a bug.
                            FolderProvider folderProvider =
                                FolderProvider.Instance(
                                    ComponentBase <IFolderMappingController, FolderMappingController> .Instance
                                    .GetFolderMapping(objFolder.PortalID, objFolder.FolderMappingID)
                                    .FolderProviderType);
                            folderProvider.UpdateFile(objFolder, objFile.FileName, objStream);
                            return(toReturn);
                        }
                        else
                        {
                            return(FileManager.Instance.AddFile(objFolder, objFile.FileName, objStream).FileId);
                        }
                    }
                }
                else
                {
                    if (objFile.FileId > 0)
                    {
                        var toReturn = objFile.FileId;
                        if (!contentOnly)
                        {
                            toReturn = FileManager.Instance.UpdateFile(objFile).FileId;
                        }
                        return(toReturn);
                    }
                    else
                    {
                        return(FileManager.Instance.AddFile(objFolder, objFile.FileName, null).FileId);
                    }
                }
            }
            return(-1);
        }
예제 #7
0
        private string GetSetting(Hashtable settings, string name, bool encrypt = false)
        {
            if (!settings.ContainsKey(name))
            {
                return(string.Empty);
            }

            if (encrypt)
            {
                var folderProvider = FolderProvider.Instance(Constants.FolderProviderType);
                return(folderProvider.GetEncryptedSetting(settings, name));
            }

            return(settings[name].ToString());
        }
예제 #8
0
        /// <summary>
        /// Loads concrete settings.
        /// </summary>
        /// <param name="folderMappingSettings">The Hashtable containing the folder mapping settings.</param>
        public override void LoadSettings(Hashtable folderMappingSettings)
        {
            var folderProvider = FolderProvider.Instance(FolderProviderType);

            if (folderMappingSettings.ContainsKey(AccountName))
            {
                tbAccountName.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, AccountName);
            }

            if (folderMappingSettings.ContainsKey(AccountKey))
            {
                tbAccountKey.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, AccountKey);
            }

            if (tbAccountName.Text.Length > 0 && tbAccountKey.Text.Length > 0)
            {
                var bucketName = "";

                if (folderMappingSettings.ContainsKey(Container))
                {
                    bucketName = folderMappingSettings[Container].ToString();
                }

                LoadContainers();

                var bucket = ddlContainers.Items.FindByText(bucketName);

                if (bucket != null)
                {
                    ddlContainers.SelectedIndex = ddlContainers.Items.IndexOf(bucket);
                }
            }

            if (folderMappingSettings.ContainsKey(UseHttps))
            {
                chkUseHttps.Checked = bool.Parse(folderMappingSettings[UseHttps].ToString());
            }

            chkDirectLink.Checked = !folderMappingSettings.ContainsKey(DirectLink) || folderMappingSettings[DirectLink].ToString().ToLowerInvariant() == "true";

            if (folderMappingSettings.ContainsKey(CustomDomain))
            {
                tbCustomDomain.Text = folderProvider.GetEncryptedSetting(folderMappingSettings, CustomDomain);
            }
        }
        private void BindFolderMappingSettings()
        {
            string folderProviderType;

            if (FolderMappingID != Null.NullInteger)
            {
                var folderMapping = _folderMappingController.GetFolderMapping(FolderMappingID);
                folderProviderType = folderMapping.FolderProviderType;
            }
            else
            {
                folderProviderType = FolderProvidersComboBox.SelectedValue;
            }

            if (string.IsNullOrEmpty(folderProviderType))
            {
                return;
            }

            var settingsControlVirtualPath = FolderProvider.Instance(folderProviderType).GetSettingsControlVirtualPath();

            if (String.IsNullOrEmpty(settingsControlVirtualPath))
            {
                return;
            }

            var settingsControl = LoadControl(settingsControlVirtualPath);

            if (settingsControl == null || !(settingsControl is FolderMappingSettingsControlBase))
            {
                return;
            }

            // This is important to allow settings control to be localizable
            var baseType = settingsControl.GetType().BaseType;

            if (baseType != null)
            {
                settingsControl.ID = baseType.Name;
            }

            ProviderSettingsPlaceHolder.Controls.Clear();
            ProviderSettingsPlaceHolder.Controls.Add(settingsControl);
        }
예제 #10
0
        private void BindFolderMappingSettings()
        {
            string folderProviderType;

            if (FolderMappingID != Null.NullInteger)
            {
                var folderMapping = _folderMappingController.GetFolderMapping(FolderMappingID);
                folderProviderType = folderMapping.FolderProviderType;
            }
            else
            {
                folderProviderType = cboFolderProviders.SelectedValue;
            }

            if (string.IsNullOrEmpty(folderProviderType))
            {
                return;
            }

            var settingsControlVirtualPath = FolderProvider.Instance(folderProviderType).GetSettingsControlVirtualPath();

            if (String.IsNullOrEmpty(settingsControlVirtualPath))
            {
                return;
            }

            var settingsControl = LoadControl(settingsControlVirtualPath);

            if (settingsControl == null || !(settingsControl is FolderMappingSettingsControlBase))
            {
                return;
            }

            // This is important to allow settings control to be localizable
            settingsControl.ID = Path.GetFileName(settingsControlVirtualPath);

            phProviderSettings.Controls.Clear();
            phProviderSettings.Controls.Add(settingsControl);
        }
예제 #11
0
 private string GetCustomDomain()
 {
     return(FolderProvider.Instance(FolderProviderType).EncryptValue(tbCustomDomain.Text));
 }
예제 #12
0
 private string GetAccountName()
 {
     return(FolderProvider.Instance(FolderProviderType).EncryptValue(tbAccountName.Text));
 }
예제 #13
0
        public bool SaveConfig(int portalId, IDictionary <string, string> values, ref bool validated, out string customErrorMessage)
        {
            customErrorMessage = string.Empty;
            var azureAccountName   = values[Constants.AzureAccountName];
            var azureAccountKey    = values[Constants.AzureAccountKey];
            var azureContainerName = values.ContainsKey(Constants.AzureContainerName) ? values[Constants.AzureContainerName] : string.Empty;

            var emptyFields = string.IsNullOrEmpty(azureAccountKey) && string.IsNullOrEmpty(azureAccountName);

            validated = true;
            if (emptyFields)
            {
                if (this.SupportsMultiple)
                {
                    throw new Exception(Localization.GetString("ErrorRequiredFields", Constants.LocalResourceFile));
                }

                DeleteAzureFolderMapping(portalId);
                return(true);
            }

            if (!this.Validation(azureAccountName, azureAccountKey, azureContainerName))
            {
                validated = false;
                return(true);
            }

            if (this.FolderMappingNameExists(portalId, this.DisplayName,
                                             Convert.ToInt32(!string.IsNullOrEmpty(this.Id) ? this.Id : null)))
            {
                throw new Exception(Localization.GetString("ErrorMappingNameExists", Constants.LocalResourceFile));
            }

            try
            {
                var folderMappings = this.FindAzureFolderMappings(portalId);
                FolderMappingInfo folderMapping;
                if (this.SupportsMultiple && !string.IsNullOrEmpty(this.Id))
                {
                    folderMapping = folderMappings.FirstOrDefault(x => x.FolderMappingID.ToString() == this.Id);
                }
                else
                {
                    folderMapping = this.FindAzureFolderMapping(portalId);
                }

                var settings = folderMapping.FolderMappingSettings;

                var savedAccount   = this.GetSetting(settings, Constants.AzureAccountName, true);
                var savedKey       = this.GetSetting(settings, Constants.AzureAccountKey, true);
                var savedContainer = this.GetSetting(settings, Constants.AzureContainerName);

                var accountChanged = savedAccount != azureAccountName || savedKey != azureAccountKey;

                if (accountChanged)
                {
                    DeleteAzureFolderMapping(portalId, folderMapping.FolderMappingID);
                    folderMapping = this.FindAzureFolderMapping(portalId);
                    settings      = folderMapping.FolderMappingSettings;
                }
                else if (savedContainer != azureContainerName)
                {
                    DeleteAzureFolders(portalId, folderMapping.FolderMappingID);
                }

                var folderProvider = FolderProvider.Instance(Constants.FolderProviderType);

                settings[Constants.AzureAccountName] = folderProvider.EncryptValue(azureAccountName);
                settings[Constants.AzureAccountKey]  = folderProvider.EncryptValue(azureAccountKey);

                if (values.ContainsKey(Constants.AzureContainerName) && !string.IsNullOrEmpty(values[Constants.AzureContainerName]))
                {
                    settings[Constants.AzureContainerName] = values[Constants.AzureContainerName];
                }
                else
                {
                    folderMapping.FolderMappingSettings[Constants.AzureContainerName] = string.Empty;
                }

                if (!folderMapping.FolderMappingSettings.ContainsKey(Constants.DirectLink))
                {
                    folderMapping.FolderMappingSettings[Constants.DirectLink] = "True";
                }

                if (!folderMapping.FolderMappingSettings.ContainsKey(Constants.UseHttps))
                {
                    folderMapping.FolderMappingSettings[Constants.UseHttps] = "True";
                }

                if (folderMapping.MappingName != this.DisplayName && !string.IsNullOrEmpty(this.DisplayName) &&
                    this.DisplayName != DefaultDisplayName)
                {
                    folderMapping.MappingName = this.DisplayName;
                }

                if (!folderMapping.FolderMappingSettings.ContainsKey(Constants.SyncBatchSize))
                {
                    folderMapping.FolderMappingSettings[Constants.SyncBatchSize] = Constants.DefaultSyncBatchSize.ToString();
                }

                FolderMappingController.Instance.UpdateFolderMapping(folderMapping);

                return(true);
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(false);
            }
        }
예제 #14
0
 private string GetAccountKey()
 {
     return(FolderProvider.Instance(Constants.FolderProviderType).EncryptValue(this.tbAccountKey.Text));
 }