Exemple #1
0
        private static Config CreateFromAppSettings(System.Collections.Specialized.NameValueCollection appSettings)
        {
            Config config = new Config();
            string maxNormalRequestLengthSetting
                = appSettings["NeatUpload.MaxNormalRequestLength"];
            if (maxNormalRequestLengthSetting != null)
            {
                config.MaxNormalRequestLength = Int64.Parse(maxNormalRequestLengthSetting) * 1024;
            }

            string maxRequestLengthSetting
                = ConfigurationSettings.AppSettings["NeatUpload.MaxRequestLength"];
            if (maxRequestLengthSetting != null)
            {
                config.MaxRequestLength = Int64.Parse(maxRequestLengthSetting) * 1024;
            }

            string tmpDir = appSettings["NeatUpload.DefaultTempDirectory"];
            if (tmpDir != null)
            {
                if (HttpContext.Current != null)
                {
                    tmpDir = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, tmpDir);
                }
                UploadStorage.LastResortProvider.TempDirectory = new DirectoryInfo(tmpDir);
            }
            return config;
        }
Exemple #2
0
 internal static Config CreateFromConfigSection(Config parent, System.Xml.XmlNode section)
 {
     if (log.IsDebugEnabled) log.Debug("In CreateFromConfigSection");
     Config config = new Config();
     if (parent != null)
     {
         config.MaxNormalRequestLength = parent.MaxNormalRequestLength;
         config.MaxRequestLength = parent.MaxRequestLength;
         config.MaxUploadRate = parent.MaxUploadRate;
         config._UseHttpModule = parent.UseHttpModule;
         config.StorageProviders = parent.StorageProviders.Clone();
         config.DefaultStorageProviderName = parent.DefaultStorageProviderName;
         config.StateStoreProviders = parent.StateStoreProviders.Clone();
         config.DefaultStateStoreProviderName = parent.DefaultStateStoreProviderName;
         config.MultiRequestUploadHandlerUrl = parent.MultiRequestUploadHandlerUrl;
         config.ResourceManager = parent.ResourceManager;
         config.DebugDirectory = parent.DebugDirectory;
         config.ValidationKey = parent.ValidationKey;
         config.EncryptionKey = parent.EncryptionKey;
         config.PostBackIDQueryParam = parent.PostBackIDQueryParam;
         config.MergeIntervalSeconds = parent.MergeIntervalSeconds;
         config.StateStaleAfterSeconds = parent.StateStaleAfterSeconds;
     }
     foreach (XmlAttribute attr in section.Attributes)
     {
         string name = attr.Name as string;
         string val = attr.Value as string;
         if (log.IsDebugEnabled) log.Debug("Processing attr " + name + "=" + val);
         if (name == "maxNormalRequestLength")
         {
             config.MaxNormalRequestLength = Int64.Parse(val) * 1024;
         }
         else if (name == "maxRequestLength")
         {
             config.MaxRequestLength = Int64.Parse(val) * 1024;
         }
         else if (name == "maxUploadRate")
         {
             config.MaxUploadRate = Int32.Parse(val) * 1024;
         }
         else if (name == "useHttpModule")
         {
             config._UseHttpModule = bool.Parse(val) && UploadHttpModule.IsInited;
         }
         else if (name == "defaultStorageProvider" || name == "defaultProvider")
         {
             config.DefaultStorageProviderName = val;
         }
         else if (name == "defaultStateStoreProvider")
         {
             config.DefaultStateStoreProviderName = val;
         }
         else if (name == "multiRequestUploadHandlerUrl")
         {
             config.MultiRequestUploadHandlerUrl = val;
         }
         else if (name == "debugDirectory")
         {
             if (HttpContext.Current != null)
             {
                 val = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,
                                         val);
             }
             config.DebugDirectory = new DirectoryInfo(val);
             if (!config.DebugDirectory.Exists)
             {
                 config.DebugDirectory.Create();
             }
         }
         else if (name == "validationKey")
         {
             if (val != "AutoGenerate")
             {
                 config.ValidationKey = FromHexString(val);
             }
         }
         else if (name == "encryptionKey")
         {
             if (val != "AutoGenerate")
             {
                 config.EncryptionKey = FromHexString(val);
             }
         }
         else if (name == "postBackIDQueryParam")
         {
             config.PostBackIDQueryParam = val;
         }
         else if (name == "stateMergeIntervalSeconds")
         {
             config.MergeIntervalSeconds = Double.Parse(val);
         }
         else if (name == "stateStaleAfterSeconds")
         {
             config.StateStaleAfterSeconds = Double.Parse(val);
         }
         else if (name.IndexOf(":") == -1 && name != "xmlns")
         {
             throw new XmlException("Unrecognized unqualified attribute: " + name);
         }
     }
     XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
     nsm.AddNamespace("nu", "http://www.brettle.com/neatupload/config/2008");
     XmlNode providersElem = section.SelectSingleNode("nu:providers | providers", nsm);
     if (providersElem != null)
     {
         foreach (XmlNode providerActionElem in providersElem.ChildNodes)
         {
             if (providerActionElem.NodeType != XmlNodeType.Element)
             {
                 continue;
             }
             string tagName = providerActionElem.LocalName;
             if (tagName == "add")
             {
                 string providerName = providerActionElem.Attributes["name"].Value;
                 object provider = CreateProvider(providerActionElem);
                 NameValueCollection configAttrs = GetProviderAttrs(providerActionElem);
                 UploadStorageProvider storageProvider = provider as UploadStorageProvider;
                 UploadStateStoreProvider stateStoreProvider = provider as UploadStateStoreProvider;
                 if (storageProvider != null)
                 {
                     storageProvider.Initialize(providerName, configAttrs);
                     config.StorageProviders.Add(storageProvider);
                 }
                 else if (stateStoreProvider != null)
                 {
                     stateStoreProvider.Initialize(providerName, configAttrs);
                     config.StateStoreProviders.Add(stateStoreProvider);
                 }
                 else
                 {
                     throw new Exception(String.Format("Provider {0} must be either an UploadStorageProvider or and UploadStateStoreProvider"));
                 }
             }
             else if (tagName == "remove")
             {
                 string providerName = providerActionElem.Attributes["name"].Value;
                 config.StorageProviders.Remove(providerName);
                 config.StateStoreProviders.Remove(providerName);
             }
             else if (tagName == "clear")
             {
                 config.StorageProviders.Clear();
                 config.StateStoreProviders.Clear();
             }
             else
             {
                 throw new XmlException("Unrecognized tag name: " + tagName);
             }
         }
     }
     return config;
 }