Exemplo n.º 1
0
        public static void AddOverrideVersion(string oldVersion, string newVersion)
        {
            string tempOldVersion = oldVersion.Replace("*", "-1");

            //check if there is already an dictionary key which contains the oldversion
            var dictKeys = CompatibleVersions.Keys;

            if (dictKeys.Contains(tempOldVersion))
            {
                //add an additional new version to the list of compatible versions
                CompatibleVersions[tempOldVersion].AddCompatibleWithVersion(newVersion);
                CfgUpdated = true;
                return;
            }

            //If the key doesn't match, we have to create a whole new dictionary entry
            //Basically the same code which is used to load the config
            CompatVersions cv = new CompatVersions();

            cv.currentVersion        = tempOldVersion;
            cv.curVersion            = new VersionInfo(cv.currentVersion);
            cv.compatibleWithVersion = new List <string>();
            cv.compatWithVersion     = new List <VersionInfo>();

            cv.compatibleWithVersion.Add(newVersion);
            cv.compatWithVersion.Add(new VersionInfo(newVersion));
            CompatibleVersions.Add(cv.currentVersion, cv);
            CfgUpdated = true;
        }
        public async Task <GetCompatibilityVersionResponse> Handle(GetCompatibilityVersionRequest request, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(request, nameof(request));

            CompatibleVersions compatibleVersions = await _schemaDataStore.GetLatestCompatibleVersionsAsync(cancellationToken);

            return(new GetCompatibilityVersionResponse(compatibleVersions));
        }
Exemplo n.º 3
0
 public static void DeleteFinally()
 {
     if (ToDelete.Count > 0)
     {
         foreach (string version in ToDelete)
         {
             CompatibleVersions.Remove(version);
         }
         ToDelete.Clear();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a deep clone of the PowerShell data object.
 /// </summary>
 public object Clone()
 {
     return(new PowerShellData()
     {
         Edition = Edition,
         GitCommitId = GitCommitId,
         ProcessArchitecture = ProcessArchitecture,
         RemotingProtocolVersion = RemotingProtocolVersion,
         SerializationVersion = SerializationVersion,
         Version = Version,
         WSManStackVersion = WSManStackVersion,
         CompatibleVersions = (Version[])CompatibleVersions.Clone()
     });
 }
        /////////


        public static void LoadCfg()
        {
            Logger.Log("LoadCfg");
            OverridePriority = LocalRemotePriority.none;
            SimplePriority   = LocalRemotePriority.none;
            Logger.Log("KSP-AVC node count: " + GameDatabase.Instance.GetConfigNodes("KSP-AVC").Length);
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("KSP-AVC"))
            {
                if (node.HasValue("OVERRIDE_PRIORITY"))
                {
                    try
                    {
                        OverridePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("OVERRIDE_PRIORITY"));
                        Logger.Log("OverridePriority: " + OverridePriority);
                    }
                    catch { }
                }
                if (node.HasValue("SIMPLE_PRIORITY"))
                {
                    try
                    {
                        SimplePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("SIMPLE_PRIORITY"));
                        Logger.Log("SimplePriority: " + SimplePriority);
                    }
                    catch { }
                }
                var compatVerList = node.GetValuesList("COMPATIBLE_VERSION_OVERRIDE");
                foreach (var a in compatVerList)
                {
                    CompatVersions cv = new CompatVersions();
                    var            ar = a.Split(',');

                    cv.currentVersion        = ar[0];
                    cv.curVersion            = new VersionInfo(cv.currentVersion);
                    cv.compatibleWithVersion = new List <string>();
                    for (int i = 1; i < ar.Length; i++)
                    {
                        cv.compatibleWithVersion.Add(ar[i]);
                        cv.compatWithVersion.Add(new VersionInfo(ar[i]));
                        Logger.Log("COMPATIBLE_VERSION_OVERRIDE, currentVersion: " + ar[0] + ", compatibleWithVersion: " + ar[i]);
                    }
                    CompatibleVersions.Add(cv.currentVersion, cv);
                }
            }
            CfgLoaded = true;
            Logger.Flush();
        }
Exemplo n.º 6
0
        public async Task WhenRequestingSchema_GivenGetMethodAndCompatibilityPathAndInstanceSchemaTableIsEmpty_TheServerShouldReturnsNotFound()
        {
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(_client.BaseAddress, "_schema/compatibility"),
            };

            HttpResponseMessage response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            string responseBodyAsString = await response.Content.ReadAsStringAsync();

            CompatibleVersions jsonList = JsonConvert.DeserializeObject <CompatibleVersions>(responseBodyAsString);

            Assert.NotNull(jsonList);
        }
Exemplo n.º 7
0
        public async Task <CompatibleVersions> GetLatestCompatibleVersionsAsync(CancellationToken cancellationToken)
        {
            CompatibleVersions compatibleVersions;

            using (SqlConnectionWrapper sqlConnectionWrapper = await _sqlConnectionWrapperFactory.ObtainSqlConnectionWrapperAsync(cancellationToken: cancellationToken))
                using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand())
                {
                    SchemaShared.SelectCompatibleSchemaVersions.PopulateCommand(sqlCommandWrapper);

                    using (var dataReader = await sqlCommandWrapper.ExecuteReaderAsync(cancellationToken))
                    {
                        if (dataReader.Read())
                        {
                            compatibleVersions = new CompatibleVersions(ConvertToInt(dataReader.GetValue(0)), ConvertToInt(dataReader.GetValue(1)));
                        }
                        else
                        {
                            throw new SqlRecordNotFoundException(Resources.CompatibilityRecordNotFound);
                        }
                    }

                    return(compatibleVersions);
                }

            int ConvertToInt(object o)
            {
                if (o == DBNull.Value)
                {
                    throw new SqlRecordNotFoundException(Resources.CompatibilityRecordNotFound);
                }
                else
                {
                    return(Convert.ToInt32(o));
                }
            }
        }
Exemplo n.º 8
0
        public GetCompatibilityVersionResponse(CompatibleVersions versions)
        {
            EnsureArg.IsNotNull(versions, nameof(versions));

            CompatibleVersions = versions;
        }
Exemplo n.º 9
0
        public static void LoadCfg()
        {
            Logger.Log("LoadCfg");
            OverridePriority = LocalRemotePriority.none;
            SimplePriority   = LocalRemotePriority.none;
            CfgUpdated       = false;
            //Logger.Log("KSP-AVC node count: " + GameDatabase.Instance.GetConfigNodes("KSP-AVC").Length);
            //foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("KSP-AVC"))
            if (!File.Exists(AvcConfigFile))
            {
                SaveCfg();
                return;
            }

            ConfigNode LoadNodeFromFile = ConfigNode.Load(AvcConfigFile);
            ConfigNode node             = LoadNodeFromFile.GetNode("KSP-AVC");

            //if (node.HasValue("KSP_SKIN"))
            //{
            //    try
            //    {
            //        if (node.GetValue("KSP_SKIN").ToLower() == "false")
            //            UseKspSkin = false;
            //        else
            //            UseKspSkin = true;
            //        //Logger.Log($"UseKspSkin: {UseKspSkin}");
            //    }
            //    catch { }
            //}
            if (node.HasValue("OVERRIDE_PRIORITY"))
            {
                try
                {
                    OverridePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("OVERRIDE_PRIORITY"));
                    //Logger.Log("OverridePriority: " + OverridePriority);
                }
                catch { }
            }
            if (node.HasValue("SIMPLE_PRIORITY"))
            {
                try
                {
                    SimplePriority = (LocalRemotePriority)Enum.Parse(typeof(LocalRemotePriority), node.GetValue("SIMPLE_PRIORITY"));
                    //Logger.Log("SimplePriority: " + SimplePriority);
                }
                catch { }
            }
            if (node.HasValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE"))
            {
                try
                {
                    if (node.GetValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE").ToLower() == "false")
                    {
                        OverrideIsDisabledGlobal = false;
                    }
                    else
                    {
                        OverrideIsDisabledGlobal = true;
                    }
                    //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}");
                }
                catch { }
            }
            if (node.HasValue("SHOW_DEFAULT_VALUES"))
            {
                try
                {
                    if (node.GetValue("SHOW_DEFAULT_VALUES").ToLower() == "false")
                    {
                        ShowDefaultValues = false;
                    }
                    else
                    {
                        ShowDefaultValues = true;
                    }
                    //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}");
                }
                catch { }
            }
#if STRICT
            if (node.HasValue("STRICT_VERSION"))
            {
                try
                {
                    if (node.GetValue("STRICT_VERSION").ToLower() == "false")
                    {
                        StrictVersion = false;
                    }
                    else
                    {
                        StrictVersion = true;
                    }
                    //Logger.Log($"OverrideIsDisabled: {OverrideIsDisabledGlobal}");
                }
                catch { }
            }
            else
            {
                StrictVersion = false;
            }
#endif
            if (node.HasNode("OVERRIDE_NAME"))
            {
                try
                {
                    ConfigNode _temp = new ConfigNode();
                    _temp = node.GetNode("OVERRIDE_NAME");

                    OverrideCompatibilityByName = _temp.GetValuesList("OverrideEnabled");
                }
                catch { }
            }
            if (node.HasNode("OVERRIDE_VERSION"))
            {
                try
                {
                    ConfigNode _temp = new ConfigNode();
                    _temp = node.GetNode("OVERRIDE_VERSION");
                    var compatVerList = _temp.GetValuesList("OverrideEnabled");
                    foreach (var a in compatVerList)
                    {
                        CompatVersions cv = new CompatVersions();
                        var            ar = a.Split(',').Select(x => x.Trim()).ToArray();

                        cv.currentVersion        = ar[0].Replace("*", "-1");
                        cv.curVersion            = new VersionInfo(cv.currentVersion);
                        cv.compatibleWithVersion = new List <string>();
                        cv.compatWithVersion     = new List <VersionInfo>(); //initializing the list before adding stuff to it helps to prevent a NRE :)
                        for (int i = 1; i < ar.Length; i++)
                        {
                            cv.compatibleWithVersion.Add(ar[i]);
                            cv.compatWithVersion.Add(new VersionInfo(ar[i]));
                            Logger.Log("OVERRIDE_VERSION, currentVersion: " + ar[0].Replace("-1", "*") + ", compatibleWithVersion: " + ar[i]);
                        }
                        CompatibleVersions.Add(cv.currentVersion, cv);
                    }
                }
                catch { }
            }
            if (node.HasNode("OVERRIDE_IGNORE"))
            {
                try
                {
                    ConfigNode _temp = new ConfigNode();
                    _temp = node.GetNode("OVERRIDE_IGNORE");

                    List <string> ignoredMods = _temp.GetValuesList("IgnoreOverride");
                    foreach (string modName in ignoredMods)
                    {
                        modsIgnoreOverride.Add(modName);
                        //Logger.Log($"IGNORE_OVERRIDE: {modName}");
                    }
                }
                catch { }
            }
            if (node.HasNode("INTERVAL"))
            {
                try
                {
                    ConfigNode _temp = new ConfigNode();
                    _temp = node.GetNode("INTERVAL");

                    AvcInterval = Int32.Parse(_temp.GetValue("MinTimeBetweenAvcRuns"));
                    if (!_temp.HasValue("AvcRunsNext"))
                    {
                        CfgUpdated = true;
                    }
                    NextRun = DateTime.Parse(_temp.GetValue("AvcRunsNext"));
                    Logger.Log($"INTERVAL: {AvcInterval}");
                    Logger.Log($"NextRun: {NextRun}");
                }
                catch { }
            }
            if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0)
            {
                CfgUpdated = true;
            }

            CfgLoaded = true;
            Logger.Flush();
        }