Exemplo n.º 1
0
        public string GetSign()
        {
            string s      = string.Empty;
            string target = this.TimeStamp + Config.AllianceID + ApiConfigManager.GetMD5(Config.ApiKey) + Config.SID + this.RequestType;

            s = ApiConfigManager.GetMD5(target);
            return(s);
        }
Exemplo n.º 2
0
        public HeaderRequest(ApiConfig config, string method)
        {
            this.Config     = config;
            this.SID        = Config.SID;
            this.AllianceID = Config.AllianceID;

            this.TimeStamp   = ApiConfigManager.GetTimeStamp().ToString();
            this.RequestType = method;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allows easy creation of KerbalData model instance with configuration.
        /// </summary>
        /// <remarks>
        /// This method has a hard wired default configuration should no configuration be available.
        /// The types used in the hard-wired configuration are static and will always be part of the KerbalData API
        /// and mainly represent the initial serializer and converters created for the API and serve as a starting point
        /// for all future configurations.
        ///
        /// TODO: Add sample .NET config to show current default config
        ///
        /// If another configuration section name is provided it will be used.
        ///
        /// This is the recommended way to quickly start using the API with minimal configuration/setup.
        /// </remarks>
        /// <example>
        /// <code language="cs" title="Starting Kerbal Data API">
        ///  var kd = KerbalData.Create(@"C:\KSP");
        /// </code>
        /// </example>
        /// <param name="installPath">root path of KSP installation</param>
        /// <param name="configSectionName">application configuration section name</param>
        /// <returns>properly configured KerbalData instance</returns>
        public static KerbalData Create(string installPath, string configSectionName = "kerbalData")
        {
            installPath = installPath.EndsWith("\\") ? installPath : installPath + "\\";
            var config = ApiConfigManager.GetConfig(configSectionName);

            if (config == null)
            {
                config = new ApiConfig()
                {
                    Processors = new ProcessorsConfig()
                    {
                        { new ProcessorConfig()
                          {
                              Index      = 0,
                              Serializer = new SerializerConfig()
                              {
                                  Type = "KerbalData.Serialization.Serializers.V018x.DataSerializer, KerbalData"
                              },
                              Converter = new ConverterConfig()
                              {
                                  Type = "KerbalData.Serialization.Serializers.V018x.JsonModelConverter`1, KerbalData"
                              }
                          } },
                        { new ProcessorConfig()
                          {
                              Index      = 1,
                              ModelType  = "Newtonsoft.Json.Linq.JObject, Newtonsoft.Json",
                              Serializer = new SerializerConfig()
                              {
                                  Type = "KerbalData.Serialization.Serializers.V018x.DataSerializer, KerbalData"
                              },
                              Converter = new ConverterConfig()
                              {
                                  Type = "KerbalData.Serialization.Serializers.V018x.JsonObjectConverter`1, KerbalData"
                              }
                          } }
                    },
                    Repositories = new RepositoriesConfig()
                    {
                        { new RepositoryConfig()
                          {
                              Index      = 0,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "Saves",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Saves\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Saves\**\persistent.sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = "persistent.sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "DirPerFile"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 1,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "Scenarios",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Saves\\scenarios\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Saves\scenarios\*.sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 2,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "TrainingScenarios",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Saves\\training\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Saves\training\*.sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".sfs"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 3,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "Parts",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Parts\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Parts\**\part.cfg"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = "part.cfg"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "DirPerFile"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 4,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "CraftInVab",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Ships\\VAB\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Ships\VAB\**\*.craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 5,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "CraftInSph",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath + "Ships\\SPH\\"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"Ships\SPH\**\*.craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 6,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "KspSettings",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "BaseUri", Value = installPath
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "Include", Value = installPath + @"*.cfg"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".cfg"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 7,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "CraftInVab-Save",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } },
                        { new RepositoryConfig()
                          {
                              Index      = 8,
                              Type       = "KerbalData.Providers.FileSystemRepository`1, KerbalData",
                              Name       = "CraftInSph-Save",
                              Parameters = new RepoParametersConfig()
                              {
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileName", Value = ".craft"
                                } },
                                  { new RepoParameterConfig()
                                {
                                    Key = "FileMode", Value = "Flat"
                                } },
                              }
                          } }
                    }
                };
            }


            return(Create(installPath, config));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessorRegistry" /> class.
 /// </summary>
 /// <param name="configSectionName">configuration section name to load</param>
 public ProcessorRegistry(string configSectionName = null)
 {
     Init(string.IsNullOrEmpty(configSectionName) ? DefaultConfig : ApiConfigManager.GetConfig(configSectionName));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a properly configured instance of the <see cref="KerbalDataManager"/> class
 /// </summary>
 /// <typeparam name="T">model type handled by the manager</typeparam>
 /// <param name="baseUri">root Uri for the manager</param>
 /// <param name="configSectionName">configuration section to use</param>
 /// <returns>configured instance</returns>
 public static T Create <T>(string baseUri, string configSectionName = "kerbalData") where T : class, IKerbalDataManager
 {
     return(Create <T>(baseUri, ApiConfigManager.GetConfig(configSectionName)));
 }