Ejemplo n.º 1
0
        public async Task <Guid> CreateConnectionAsync(PowerConnection connection)
        {
            await _dbContext.PowerConnections.AddAsync(connection);

            await _dbContext.SaveChangesAsync();

            _dbContext.DeletePreviousPowerConnections();


            return(connection.Id);
        }
Ejemplo n.º 2
0
 public List <PowerPort> Resolve(PowerConnectionDto source, PowerConnection destination, List <PowerPort> destMember, ResolutionContext context)
 {
     return(source.Ports.Select <PowerPortDto, PowerPort>(powerPort =>
     {
         // use the appropriate repository method for the given type of power port
         return powerPort switch
         {
             AssetPowerPortDto _ => _powerRepo.GetAssetPowerPort(powerPort.Id),
             PduPortDto _ => _powerRepo.GetPduPort(powerPort.Id),
             _ => throw new ArgumentException($"Unsupported power port type: {powerPort.GetType()}", nameof(powerPort))
         };
     })
            .ToList());
 }
Ejemplo n.º 3
0
    public void TestPowerConnectionJsonSerialization()
    {
        PowerConnection accumulator = CreatePowerConnection();

        // serialize
        string accumulatorJson = SerializeObjectToJson(accumulator);

        // if you want to dump file to disk for visual check, uncomment this
        ////File.WriteAllText("PowerConnection.json", accumulatorJson);

        // deserialize
        PowerConnection deserializedPowerConnection = JsonConvert.DeserializeObject <PowerConnection>(accumulatorJson);

        Assert.NotNull(deserializedPowerConnection);

        Assert.AreEqual(10f, deserializedPowerConnection.Provides.Rate);
        Assert.AreEqual("cur_processed_inv", deserializedPowerConnection.RunConditions.ParamConditions[0].ParameterName);
        Assert.AreEqual(1, deserializedPowerConnection.RunConditions.ParamConditions.Count);
    }
    public void TestPowerConnectionSerialization()
    {
        PowerConnection accumulator = new PowerConnection
        {
            Provides = new PowerConnection.Info()
            {
                Rate = 10.0f, Capacity = 100.0f
            },
            Requires = new PowerConnection.Info()
            {
                ParamConditions = new System.Collections.Generic.List <BuildableComponent.ParameterCondition>()
                {
                    new BuildableComponent.ParameterCondition()
                    {
                        Condition     = BuildableComponent.ConditionType.IsGreaterThanZero,
                        ParameterName = "cur_processed_inv"
                    }
                }
            },
            ParamsDefinitions = new PowerConnection.PowerConnectionParameterDefinitions()
        };

        // serialize
        StringWriter  writer     = new StringWriter();
        XmlSerializer serializer = new XmlSerializer(typeof(BuildableComponent), new Type[] { typeof(PowerConnection) });

        serializer.Serialize(writer, accumulator);

        StringReader sr = new StringReader(writer.ToString());

        // if you want to dump file to disk for visual check, uncomment this
        ////File.WriteAllText("PowerConnection.xml", writer.ToString());

        // deserialize
        PowerConnection deserializedPowerConnection = (PowerConnection)serializer.Deserialize(sr);

        Assert.NotNull(deserializedPowerConnection);

        Assert.AreEqual(10f, deserializedPowerConnection.Provides.Rate);
        Assert.AreEqual(0f, deserializedPowerConnection.Requires.Rate);
        Assert.AreEqual(1, deserializedPowerConnection.Requires.ParamConditions.Count);
    }
Ejemplo n.º 5
0
    public void TestPowerConnectionXmlSerialization()
    {
        PowerConnection accumulator = CreatePowerConnection();

        // serialize
        StringWriter  writer     = new StringWriter();
        XmlSerializer serializer = new XmlSerializer(typeof(BuildableComponent), new Type[] { typeof(PowerConnection) });

        serializer.Serialize(writer, accumulator);

        StringReader sr = new StringReader(writer.ToString());

        // if you want to dump file to disk for visual check, uncomment this
        ////File.WriteAllText("PowerConnection.xml", writer.ToString());

        // deserialize
        PowerConnection deserializedPowerConnection = (PowerConnection)serializer.Deserialize(sr);

        Assert.NotNull(deserializedPowerConnection);

        Assert.AreEqual(10f, deserializedPowerConnection.Provides.Rate);
        Assert.AreEqual("cur_processed_inv", deserializedPowerConnection.RunConditions.ParamConditions[0].ParameterName);
        Assert.AreEqual(1, deserializedPowerConnection.RunConditions.ParamConditions.Count);
    }