ezet / evelib

Eve Online Library.NET is an open source C# wrapper for CCPs Eve Online API and other popular Eve Online APIs.
Apache License 2.0
71 stars 36 forks source link

AppData path in Core.Config is readonly #41

Closed ftrueck closed 8 years ago

ftrueck commented 9 years ago

It is not possible to change the AppData Path in Config, therefore the lib will not run on webservers. It would be better design, to implement a property with a setter which will reinitialise the inherited paths on change.

ezet commented 9 years ago

Use the project configuration file. It's App.config for desktop, Web has a similar but differently named file that serves the same purpose.

ezet commented 9 years ago

Relevant settings are

    <appSettings>
        <!--The folder to use for data, relative to the ApplicationData folder.-->
        <add key="eveLib.AppData" value="EveLib" />
        <!--The HTTP User Agent name that will be used for requests. Try using your application name.-->
        <add key="eveLib.UserAgent" value="EveLib-development" />
    </appSettings>
ftrueck commented 9 years ago

This will not work because of this:

    public static readonly string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                            Separator;

This will set AppData to "\" which will result in "\EveLib\Cache" as you can see here:

        string appName = ConfigurationManager.AppSettings["eveLib.AppData"];
        AppData += !string.IsNullOrEmpty(appName) ? appName : "EveLib";
        CachePath = AppData + Separator + "Cache";

So the web application will try to access the wrong path (\EveLib\Cache) which results in an .NET Exception.

The correct way would be: Server.MapPath(CachePath); Then .net will make this: C:\Inetpub\wwwroot\EveLib\Cache

Because Server.MapPath will not work in Desktop Environments it would be the best way to Provide AppPath Field as Property:

    private static string _appData;
    public static string AppData
    {
        get
        {
            if (String.IsNullOrWhiteSpace(_appData))
            {
                _appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Separator;
            }
            return _appData;
        }

        set
        {
            _appData = value;
            SetConfig();
        }
    }

    static Config() {
        SetConfig();
    }

    private static void SetConfig()
    {
        if (String.IsNullOrEmpty(UserAgent))
            UserAgent = "EveLib";
        CachePath = AppData + Separator + "Cache";
        ImagePath = AppData + Separator + "Images";
        CacheRegister = CachePath + Separator + CacheRegisterFileName;
    }

For me this works but there may be better ways. I leave this up to you guys. :)

ezet commented 8 years ago

Fixed.

Joeeigel commented 8 years ago

I'm still having this issue, looking through all remote branches this file hasn't been updated in over a year.

It may just be myself doing something wrong however and the fix has been applied somewhere

ezet commented 8 years ago

I'll have a look tomorrow and Sunday. Could you help me test it later?

Joeeigel commented 8 years ago

Would be more than happy to, I'm using a version where I've just forced it to use Server.MapPath(); for now as I know the environment my code will be ran on, but I don't mind switching it our to see if we can get this solved.

ezet commented 8 years ago

Does the most recent commit to the dev branch work for you? Set Config.AppData before instantiating EveCrest.

On Fri, Feb 19, 2016 at 5:55 PM, Joeeigel notifications@github.com wrote:

Would be more than happy to, I'm using a version where I've just forced it to use Server.MapPath(); for now as I know the environment my code will be ran on, but I don't mind switching it our to see if we can get this solved.

— Reply to this email directly or view it on GitHub https://github.com/ezet/evelib/issues/41#issuecomment-186301784.

Joeeigel commented 8 years ago

Still an issue, full stacktrace below:

Could not find a part of the path '\Cache\EveXml'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path '\Cache\EveXml'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path '\Cache\EveXml'.] System.IO.Error.WinIOError(Int32 errorCode, String maybeFullPath) +519 System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) +11960522 System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) +64 System.IO.Directory.CreateDirectory(String path) +33 eZet.EveLib.Core.Cache.d14.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.Core\Cache\EveLibFileCache.cs:65 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25 eZet.EveLib.EveXmlModule.RequestHandlers.d13`1.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.EveXml\RequestHandlers\EveXmlRequestHandler.cs:68 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 eZet.EveLib.EveXmlModule.d30.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.EveXml\ApiKey.cs:166

ezet commented 8 years ago

That makes no sense. You used this commit? 166766a37387e23c269359a4de809af831feb700 You made sure to change that before instantiating the EveXml object? Can you check the AppData, CachePath and ImagePath properties after you set it ?

On Sun, Feb 21, 2016 at 6:40 PM, Joeeigel notifications@github.com wrote:

Still an issue, full stacktrace below:

`Could not find a part of the path '\Cache\EveXml'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path '\Cache\EveXml'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path '\Cache\EveXml'.] System.IO.Error.WinIOError(Int32 errorCode, String maybeFullPath) +519 System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) +11960522 System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) +64 System.IO.Directory.CreateDirectory(String path) +33 eZet.EveLib.Core.Cache.d14.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.Core\Cache\EveLibFileCache.cs:65 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25 eZet.EveLib.EveXmlModule.RequestHandlers.d131.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.EveXml\RequestHandlers\EveXmlRequestHandler.cs:68 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 eZet.EveLib.EveXmlModule.d30.MoveNext() in C:\Dev\Eve\evelib-EveAuth_v3.0.1\evelib-EveAuth_v3.0.1\EveLib.EveXml\ApiKey.cs:166

— Reply to this email directly or view it on GitHub https://github.com/ezet/evelib/issues/41#issuecomment-186868457.

ezet commented 8 years ago

Could you please confirm that it still does not work for you ?

Joeeigel commented 8 years ago

Issue was with my end, not the lib itself.

And by my end, I mean me.

Sorry for your time <3

On 3 March 2016 at 07:57, Lars Kristian Dahl notifications@github.com wrote:

Could you please confirm that it still does not work for you ?

— Reply to this email directly or view it on GitHub https://github.com/ezet/evelib/issues/41#issuecomment-191641832.

ezet commented 8 years ago

Fixed.