private static ShellDescriptor GetShellDescriptorFromRecord(ShellDescriptorRecord shellDescriptorRecord) { ShellDescriptor descriptor = new ShellDescriptor { SerialNumber = shellDescriptorRecord.SerialNumber }; var descriptorFeatures = new List <ShellFeature>(); foreach (var descriptorFeatureRecord in shellDescriptorRecord.Features) { descriptorFeatures.Add(new ShellFeature { Name = descriptorFeatureRecord.Name }); } descriptor.Features = descriptorFeatures; var descriptorParameters = new List <ShellParameter>(); foreach (var descriptorParameterRecord in shellDescriptorRecord.Parameters) { descriptorParameters.Add( new ShellParameter { Component = descriptorParameterRecord.Component, Name = descriptorParameterRecord.Name, Value = descriptorParameterRecord.Value }); } descriptor.Parameters = descriptorParameters; return(descriptor); }
private ShellDescriptorRecord GetDescriptorRecord() { if (_shellDescriptorRecord == null) { return(_shellDescriptorRecord = _shellDescriptorRepository.Table.ToList().SingleOrDefault()); } return(_shellDescriptorRecord); }
public ShellDescriptor GetShellDescriptor() { ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord(); if (shellDescriptorRecord == null) { return(null); } return(GetShellDescriptorFromRecord(shellDescriptorRecord)); }
private static ShellDescriptor GetShellDescriptorFromRecord(ShellDescriptorRecord shellDescriptorRecord) { return(new ShellDescriptor { SerialNumber = shellDescriptorRecord.SerialNumber, Features = shellDescriptorRecord.Features.Select(descriptorFeatureRecord => new ShellFeature { Name = descriptorFeatureRecord.Name }).ToList(), Parameters = shellDescriptorRecord.Parameters.Select(descriptorParameterRecord => new ShellParameter { Component = descriptorParameterRecord.Component, Name = descriptorParameterRecord.Name, Value = descriptorParameterRecord.Value }).ToList() }); }
public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters) { ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord(); var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber; if (priorSerialNumber != serialNumber) { throw new InvalidOperationException("Invalid serial number for shell descriptor"); } Logger.Information("Updating shell descriptor for shell '{0}'...", _shellSettings.Name); if (shellDescriptorRecord == null) { shellDescriptorRecord = new ShellDescriptorRecord { SerialNumber = 1 }; _shellDescriptorRepository.Create(shellDescriptorRecord); } else { shellDescriptorRecord.SerialNumber++; } shellDescriptorRecord.Features.Clear(); foreach (var feature in enabledFeatures) { shellDescriptorRecord.Features.Add(new ShellFeatureRecord { Name = feature.Name, ShellDescriptorRecord = shellDescriptorRecord }); } Logger.Debug("Enabled features for shell '{0}' set: {1}.", _shellSettings.Name, String.Join(", ", enabledFeatures.Select(feature => feature.Name))); shellDescriptorRecord.Parameters.Clear(); foreach (var parameter in parameters) { shellDescriptorRecord.Parameters.Add(new ShellParameterRecord { Component = parameter.Component, Name = parameter.Name, Value = parameter.Value, ShellDescriptorRecord = shellDescriptorRecord }); } Logger.Debug("Parameters for shell '{0}' set: {1}.", _shellSettings.Name, String.Join(", ", parameters.Select(parameter => parameter.Name + "-" + parameter.Value))); Logger.Information("Shell descriptor updated for shell '{0}'.", _shellSettings.Name); _events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name); }
public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters) { ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord(); var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber; if (priorSerialNumber != serialNumber) { throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString()); } if (shellDescriptorRecord == null) { shellDescriptorRecord = new ShellDescriptorRecord { SerialNumber = 1 }; _shellDescriptorRepository.Create(shellDescriptorRecord); } else { shellDescriptorRecord.SerialNumber++; } _shellDescriptorRecord = shellDescriptorRecord; shellDescriptorRecord.Features.Clear(); foreach (var feature in enabledFeatures) { shellDescriptorRecord.Features.Add(new ShellFeatureRecord { Name = feature.Name, ShellDescriptorRecord = shellDescriptorRecord }); } shellDescriptorRecord.Parameters.Clear(); foreach (var parameter in parameters) { shellDescriptorRecord.Parameters.Add(new ShellParameterRecord { Component = parameter.Component, Name = parameter.Name, Value = parameter.Value, ShellDescriptorRecord = shellDescriptorRecord }); } _events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name); }
private static ShellDescriptor GetShellDescriptorFromRecord(ShellDescriptorRecord shellDescriptorRecord) { var descriptor = new ShellDescriptor { SerialNumber = shellDescriptorRecord.SerialNumber }; var descriptorFeatures = new List <ShellFeature>(); if (!string.IsNullOrWhiteSpace(shellDescriptorRecord.Features)) { var split = shellDescriptorRecord.Features.Split(';'); descriptorFeatures.AddRange(split.Select(str => new ShellFeature { Name = str })); } descriptor.Features = descriptorFeatures; return(descriptor); }
public ShellDescriptor GetShellDescriptor() { ShellDescriptorRecord record = _repository.TableNoTracking.FirstOrDefault(r => r.AppName == _options.AppSystemName); if (record == null) { return(null); } return(new ShellDescriptor() { ApplicationName = record.AppName, DisabledFeatures = record.DisabledFeatures.IsNullOrEmpty() ? Enumerable.Empty <String>() : JsonConvert.DeserializeObject <IEnumerable <String> >(record.DisabledFeatures), Parameters = record.Parameters.IsNullOrEmpty() ? Enumerable.Empty <ShellParameter>() : JsonConvert.DeserializeObject <IEnumerable <ShellParameter> >(record.Parameters) }); }
public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, bool throwEvent = true) { var shellDescriptorRecord = GetDescriptorRecord(); var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber; //2013-12-18: Hack //bool isFirstRun = (serialNumber == 0 && priorSerialNumber == 1) || (serialNumber == 1 && priorSerialNumber == 0); //if (!isFirstRun) //{ // if (priorSerialNumber != serialNumber) // { // throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString()); // } //} if (shellDescriptorRecord == null) { shellDescriptorRecord = new ShellDescriptorRecord { Id = Guid.NewGuid(), SerialNumber = 1, Features = string.Join(";", enabledFeatures.Select(x => x.Name)) }; shellDescriptorRepository.Insert(shellDescriptorRecord); } else { shellDescriptorRecord.SerialNumber++; shellDescriptorRecord.Features = string.Join(";", enabledFeatures.Select(x => x.Name)); shellDescriptorRepository.Update(shellDescriptorRecord); } if (throwEvent) { events.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), shellSettings.Name); } }
public void UpdateShellDescriptor(IEnumerable <string> enabledFeatures, IEnumerable <ShellParameter> parameters) { string name = _options.AppSystemName; ShellDescriptorRecord record = _repository.Table.FirstOrDefault(d => d.AppName == name); bool exsiting = (record != null); if (!exsiting) { record = new ShellDescriptorRecord(); record.AppName = name; } record.DisabledFeatures = enabledFeatures.IsNullOrEmpty() ? null : JsonConvert.SerializeObject(enabledFeatures); record.Parameters = parameters.IsNullOrEmpty() ? null : JsonConvert.SerializeObject(parameters); if (exsiting) { _repository.Update(record); } else { _repository.Insert(record); } _repository.CommitChanges(); }