Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <param name="wiki">The wiki.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
        public void Init(IHostV40 host, string config, string wiki)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            _host = host;
            _wiki = wiki;

            IFilesStorageProviderV40 filesStorageProvider = GetDefaultFilesStorageProvider();

            if (!DirectoryExists(filesStorageProvider, DefaultDirectoryName()))
            {
                filesStorageProvider.CreateDirectory("/", DefaultDirectoryName().Trim('/'));
            }

            string[] configEntries = config.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < configEntries.Length; i++)
            {
                string[] configEntryDetails = configEntries[i].Split(new string[] { "=" }, 2, StringSplitOptions.None);
                switch (configEntryDetails[0].ToLowerInvariant())
                {
                case "logoptions":
                    if (configEntryDetails[1] == "nolog")
                    {
                        _enableLogging = false;
                    }
                    else
                    {
                        LogWarning("Unknown value in 'logOptions' configuration string: " + configEntries[i] + "; supported values are: 'nolog'.");
                    }
                    break;

                default:
                    LogWarning("Unknown value in configuration string: " + configEntries[i]);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new directory.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="path">The path.</param>
        /// <param name="name">The name of the new directory.</param>
        /// <returns><c>true</c> if the directory was created, <c>false</c> otherwise.</returns>
        public static bool CreateDirectory(IFilesStorageProviderV40 provider, string path, string name)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length == 0)
            {
                path = "/";
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }

            path = NormalizeFullPath(path);
            name = name.Trim('/', ' ');

            bool done = provider.CreateDirectory(path, name);

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

            Host.Instance.OnDirectoryActivity(provider.GetType().FullName, path + name + "/", null, FileActivity.DirectoryCreated);

            return(true);
        }