Esempio n. 1
0
    public bool SerializeList(CollectionDescription cd)
    {
        if (cd == null)
        {
            throw new ArgumentNullException("cd");
        }
        switch(cd.Dataset)
        {
            case 1:
                cd1 = DeserializeList(1);
                cd1.Add(cd);
                DataBase.serializer.SerializeObject<List<CollectionDescription>>(cd1, "CollectionDescription1.xml");
                return true;
            case 2:
                cd2 = DeserializeList(2);
                cd2.Add(cd);
                DataBase.serializer.SerializeObject<List<CollectionDescription>>(cd2, "CollectionDescription2.xml");
                return true;
            case 3:
                cd3 = DeserializeList(3);
                cd3.Add(cd);
                DataBase.serializer.SerializeObject<List<CollectionDescription>>(cd3, "CollectionDescription3.xml");
                return true;
            case 4:
                cd4 = DeserializeList(4);
                cd4.Add(cd);
                DataBase.serializer.SerializeObject<List<CollectionDescription>>(cd4, "CollectionDescription4.xml");
                return true;
            default:
                throw new ArgumentException("Dataset nije validan.");
        }

    }
 public void ConstructorBadParameters(int dataset)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         CollectionDescription cd = new CollectionDescription(dataset);
     });
 }
Esempio n. 3
0
        public void Dodaj(int set, DumpingProperty data, ILogovanje Loger, List <CollectionDescription> CDS)
        {
            Random r      = new Random();
            int    x      = 0;
            int    y      = 0;
            string poruka = "";
            string por2   = "";

            foreach (CollectionDescription cd in CDS)
            {
                if (cd.dataset == set)
                {
                    y = 1;
                    foreach (DumpingProperty dp in cd.DumpingPropertyCollection)
                    {
                        if (dp.kod.Equals(data.kod))
                        {
                            dp.DumpingValue = data.DumpingValue;
                            x      = 1;
                            poruka = "Azurirana vrijednost u DumpingBufferu. Dataset: " + set + " Code: " + data.kod + " Value: " + data.DumpingValue.timestamp + " " + data.DumpingValue.id + " " + data.DumpingValue.potrosnja + Environment.NewLine;
                            Loger.Loguj(poruka);
                            por2 = "Novi izgled CD-a sa ID:" + cd.id + " DataSet:" + cd.dataset + Environment.NewLine;
                            foreach (DumpingProperty item in cd.DumpingPropertyCollection)
                            {
                                por2 += "Dumping Property:" + item.kod + " " + item.DumpingValue.timestamp + " " + item.DumpingValue.id + " " + item.DumpingValue.potrosnja + Environment.NewLine;
                            }
                            Loger.Loguj(por2);
                        }
                    }
                    if (x == 0)
                    {
                        cd.DumpingPropertyCollection.Add(data);
                        poruka = "Dodat je novi DumpingProperty u postojeci CD. Dataset: " + set + " Code: " + data.kod + " Value: " + data.DumpingValue.timestamp + " " + data.DumpingValue.id + " " + data.DumpingValue.potrosnja + Environment.NewLine;
                        Loger.Loguj(poruka);
                        por2 = "Novi izgled CD-a sa ID:" + cd.id + " DataSet:" + cd.dataset + Environment.NewLine;
                        foreach (DumpingProperty item in cd.DumpingPropertyCollection)
                        {
                            por2 += "Dumping Property:" + item.kod + " " + item.DumpingValue.timestamp + " " + item.DumpingValue.id + " " + item.DumpingValue.potrosnja + Environment.NewLine;
                        }
                        Loger.Loguj(por2);
                    }
                }
            }
            if (y == 0)
            {
                List <DumpingProperty> dpc = new List <DumpingProperty>();
                dpc.Add(data);
                int id = r.Next(1000, 100000);
                CollectionDescription novi = new CollectionDescription(id, set, dpc);
                CDS.Add(novi);
                poruka = "Dodat je novi CD. ID: " + id + " DataSet: " + set + Environment.NewLine;
                Loger.Loguj(poruka);
                por2 = "Novi izgled CD-a sa ID:" + novi.id + " DataSet:" + novi.dataset + Environment.NewLine;
                foreach (DumpingProperty item in novi.DumpingPropertyCollection)
                {
                    por2 += "Dumping Property:" + item.kod + " " + item.DumpingValue.timestamp + " " + item.DumpingValue.id + " " + item.DumpingValue.potrosnja + Environment.NewLine;
                }
                Loger.Loguj(por2);
            }
        }
Esempio n. 4
0
    //skladisti objekat CD ako je validan Deadband
    public bool Serialize(CollectionDescription cd)
    {
        if (cd != null)
        {
            if (CheckDeadband(cd))
            {
                cd.timeStamp = DateTime.Now;
                if (SerializeList(cd))
                {
                    Logger.Log("\n\nCollectionDescription u Modulu2 je serijalizovan.\n");
                    return true;
                }

                return false;

            }
            else
            {
                Logger.Log("\n\nCollectionDescription u Modulu2 nije serijalizovan.\n Njegova vrednost nije 2% veca od njegove stare vrednosti.\n");
                return false;
            }
        }
        else
        {
            throw new ArgumentNullException("cd");
        }
    }
 private async Task <DocumentCollection> CreateCollection(CollectionDescription collectionDescription)
 {
     try
     {
         Uri dbUri = UriFactory.CreateDatabaseUri(_configuration.DatabaseId);
         DocumentCollection collection = new DocumentCollection
         {
             Id           = collectionDescription.Name,
             PartitionKey = new PartitionKeyDefinition {
                 Paths = new Collection <string> {
                     $"/{collectionDescription.PartitionKey}"
                 }
             }
         };
         RequestOptions options = new RequestOptions {
             OfferThroughput = 400
         };
         return(await _client?.CreateDocumentCollectionIfNotExistsAsync(dbUri, collection, options));
     }
     catch (Exception e)
     {
         _logger.LogError($"Failed creating collection {collectionDescription.Name}", e);
         throw;
     }
 }
Esempio n. 6
0
    public bool CheckDeadband(CollectionDescription primljeniPodaci)
    {

        List<CollectionDescription> procitaniPodaci = null;
        if (primljeniPodaci == null)
        {
            throw new ArgumentNullException("cd");
        }
        if (primljeniPodaci.m_HistoricalCollection.m_Modul2Property[0].Code.Equals(Code.CODE_DIGITAL))
        {
            return true;
        }
        procitaniPodaci = DeserializeList(primljeniPodaci.Dataset);

        if (procitaniPodaci.Count == 0)
            return true;

        foreach (CollectionDescription item in procitaniPodaci)
        {
            if (item.m_HistoricalCollection.m_Modul2Property[0].Code == primljeniPodaci.m_HistoricalCollection.m_Modul2Property[0].Code)
            {
                if ((primljeniPodaci.m_HistoricalCollection.m_Modul2Property[0].Modul2Value < (item.m_HistoricalCollection.m_Modul2Property[0].Modul2Value * 1.02)) && ((primljeniPodaci.m_HistoricalCollection.m_Modul2Property[0].Modul2Value > (item.m_HistoricalCollection.m_Modul2Property[0].Modul2Value * 0.98))))
                {
                    return false;
                }
                
            }
        }
        return true;
    }
Esempio n. 7
0
    public bool ReceiveFromInput(Code code, int value)
    {
            Modul2Property hp = new Modul2Property();
            m_CollectionDescription = new CollectionDescription();
            m_CollectionDescription.Id = (int)((DateTime.Now.Ticks / 10) % 1000000000);


            hp.Code = code;
            hp.Modul2Value = value;

            m_CollectionDescription.m_HistoricalCollection.m_Modul2Property[0] = hp;

            Codes codes = new Codes();
            m_CollectionDescription.Dataset = codes.GetDataset(code);

            if (ValidationCheck(m_CollectionDescription.m_HistoricalCollection.m_Modul2Property[0].Code, m_CollectionDescription.Dataset))
            {
                Logger.Log("ReceiveFromInput u Modulu2 je konvertovala primljene podatke u CollectionDescription");
                Logger.Log("CD : " + m_CollectionDescription + "\n");
                Serialize(m_CollectionDescription);
            }
            else
            {
                Logger.Log("Validacija Dataset-a u Modulu2 nije prosla.\n");
                return false;
            }
            return true;
        }
Esempio n. 8
0
        public bool Serializer(CollectionDescription collectionDescription)
        {
            if (collectionDescription == null)
            {
                Console.WriteLine("Collection is empty!");
                return(false);
            }

            switch (collectionDescription.Dataset)
            {
            case 1:
                collectionDataset1.Add(collectionDescription);
                serializer.SerializeObject <List <CollectionDescription> >(collectionDataset1, "DataSet1.xml");
                return(true);

            case 2:
                collectionDataset2.Add(collectionDescription);
                serializer.SerializeObject <List <CollectionDescription> >(collectionDataset2, "DataSet2.xml");
                return(true);

            case 3:
                collectionDataset3.Add(collectionDescription);
                serializer.SerializeObject <List <CollectionDescription> >(collectionDataset3, "DataSet3.xml");
                return(true);

            case 4:
                collectionDataset4.Add(collectionDescription);
                serializer.SerializeObject <List <CollectionDescription> >(collectionDataset4, "DataSet4.xml");
                return(true);

            default:
                return(false);
            }
        }
        public void ReceiveValueTestPackDescriptionGood(bool add, bool update, bool remove)
        {
            CollectionDescription addCD    = null;
            CollectionDescription updateCD = null;
            CollectionDescription removeCD = null;
            var dumpProp = new List <DumpingProperty>();

            AddCodeToDumpingProperty("Analog", dumpProp);
            AddCodeToDumpingProperty("Digital", dumpProp);
            if (add)
            {
                addCD = new CollectionDescription(1, 1, dumpProp);
            }
            if (update)
            {
                updateCD = new CollectionDescription(1, 1, dumpProp);
            }
            if (remove)
            {
                removeCD = new CollectionDescription(1, 1, dumpProp);
            }

            var cd = new DeltaCD(1, addCD, updateCD, removeCD);

            historical.ReceiveValue(cd);
        }
Esempio n. 10
0
 /// <summary>
 /// Konstruktor bez parametara
 /// </summary>
 public DumpingBuffer()
 {
     CD1 = new CollectionDescription();
     CD2 = new CollectionDescription();
     CD3 = new CollectionDescription();
     CD4 = new CollectionDescription();
 }
Esempio n. 11
0
 public void SetupTest()
 {
     modul2                = new Modul2();
     modul2Property        = new Modul2Property();
     historicalCollection  = new HistoricalCollection();
     collectionDescription = new CollectionDescription();
 }
 public void KonstruktoriLosiParametri(int dataset)
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         CollectionDescription cd = new CollectionDescription(dataset);
     });
 }
        public HistoricalDescription ConvertCollectionDescription(CollectionDescription cd)
        {
            if (cd == null)
            {
                throw new ArgumentNullException("Parameters cannot be null");
            }
            HistoricalDescription     hd       = new HistoricalDescription();
            List <HistoricalProperty> histProp = new List <HistoricalProperty>();

            lock (syncLock)
            {
                Logger.WriteLog("Converting CollectionDescriprion", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
            }
            foreach (DumpingProperty dp in cd.DumpingPropertyCollection.DumpingProperties)
            {
                HistoricalProperty hp = new HistoricalProperty();
                hp.Code            = dp.Code;
                hp.Time            = DateTime.Now;
                hp.Id              = Guid.NewGuid().ToString();
                hp.HistoricalValue = dp.DumpingValue;
                histProp.Add(hp);
            }
            hd.HistoricalProperties = histProp;
            hd.Dataset = cd.Dataset;

            return(hd);
        }
Esempio n. 14
0
        public void TestKonstruktorCollectionDescription1(CollectionDescription cd)
        {
            CollectionDescription c = new CollectionDescription(cd.id, cd.dataset, cd.DumpingPropertyCollection);

            Assert.AreEqual(c.id, cd.id);
            Assert.AreEqual(c.dataset, cd.dataset);
            Assert.AreEqual(c.DumpingPropertyCollection, cd.DumpingPropertyCollection);
        }
        public void CollectionDescription_EmptyConstructor_ReturnsDefaults()
        {
            var result = new CollectionDescription();

            var  hcollection = new HistoricalCollection();
            bool equal       = !hcollection.ReceiverPropertyArray.Except(result.Collection.ReceiverPropertyArray).Any();

            Assert.IsTrue(result.ID == 0 && result.DataSet == 0 && equal);
        }
        public void CollectionDescription_ConstructorWithParameters_ReturnsGivenValues(int iD, int dataSet, HistoricalCollection collection)
        {
            var result = new CollectionDescription(iD, dataSet, collection);

            var hcollection = new HistoricalCollection();

            bool equal = !hcollection.ReceiverPropertyArray.Except(result.Collection.ReceiverPropertyArray).Any();

            Assert.IsTrue(result.ID == iD && result.DataSet == dataSet && equal);
        }
 public ReplicatorReceiver(Dictionary <int, Reader.Reader> rds)
 {
     readers      = rds;
     service      = new ReplicatorReceiverSvc();
     DataCD       = new CollectionDescription();
     DataDeltaCDs = new Dictionary <int, DeltaCD>();
     DataDeltaCDs.Add(1, new DeltaCD());
     DataDeltaCDs.Add(2, new DeltaCD());
     DataDeltaCDs.Add(3, new DeltaCD());
     DataDeltaCDs.Add(4, new DeltaCD());
 }
        public int AllParametersConstructor_RegularArguments_IdNotAutoAssigned(int id)
        {
            CollectionDescription description = null;

            CollectionDescription.ResetStaticClassID();
            Dataset set        = Dataset.SET1;
            var     collection = new Mock <IHistoricalCollection>().Object;

            description = new CollectionDescription(id, set, collection);

            return(description.ID);
        }
        public void Collection_Description_ToString_Test()
        {
            var list = new List <ReceiverProperty>
            {
                new ReceiverProperty(Code.CODE_ANALOG, 0),
                new ReceiverProperty(Code.CODE_DIGITAL, 7)
            };

            var result = new CollectionDescription(1, 2, new HistoricalCollection(list));

            Assert.IsTrue(result.ToString() == "[DATASET:2]:CODE_ANALOG_0 CODE_DIGITAL_7 ");
        }
        public int DefaultConstructor_MultipleObjectCreation_IdCorrect(int numberOfObjects)
        {
            CollectionDescription description = null;

            CollectionDescription.ResetStaticClassID();

            for (int i = 0; i < numberOfObjects; i++)
            {
                description = new CollectionDescription();
            }

            return(description.ID);
        }
Esempio n. 21
0
 public void StoreData(Reader.Reader reader, CollectionDescription cd, DeltaCD dcd, int dataset)
 {
     if (dataset == 1)
     {
         if (!reader.ContainsDataset1)
         {
             dcd.Add.Add(cd);
             reader.ContainsDataset1 = true;
         }
         else
         {
             dcd.Update.Add(cd);
         }
     }
     else if (dataset == 2)
     {
         if (!reader.ContainsDataset2)
         {
             dcd.Add.Add(cd);
             reader.ContainsDataset2 = true;
         }
         else
         {
             dcd.Update.Add(cd);
         }
     }
     else if (dataset == 3)
     {
         if (!reader.ContainsDataset3)
         {
             dcd.Add.Add(cd);
             reader.ContainsDataset3 = true;
         }
         else
         {
             dcd.Update.Add(cd);
         }
     }
     else //if (dataset == 4)
     {
         if (!reader.ContainsDataset4)
         {
             dcd.Add.Add(cd);
             reader.ContainsDataset4 = true;
         }
         else
         {
             dcd.Update.Add(cd);
         }
     }
 }
Esempio n. 22
0
        public void SendToHistoricalConverterRemoveBadParameters(string type, int dataset)
        {
            DumpingBuffer dbObj = dbMock.Object;
            Mock <CollectionDescription> cdMock = new Mock <CollectionDescription>(2);
            CollectionDescription        cdObj  = cdMock.Object;

            cdObj.Dpc.dumpingPropertyList[0].Code = "CODE_ANALOG";
            cdObj.Dpc.dumpingPropertyList[1].Code = "CODE_DIGITAL";

            Assert.Throws <ArgumentException>(() =>
            {
                dbObj.SendToHistoricalConverter(cdObj, type, dataset);
            });
        }
Esempio n. 23
0
 public bool checkIfTheresDataInCollectionDescription(CollectionDescription cd)
 {
     try
     {
         if (cd == null || cd.Dataset == 0 || cd.Id == 0 || cd.DumpingPropertyCollection.DumpingProperties.Count == 0)
         {
             throw new ArgumentNullException("Everything is null");
         }
         return(true);
     }
     catch {
         return(false);
     }
 }
Esempio n. 24
0
        public bool Deadband(CollectionDescription collection)
        {
            List <CollectionDescription> dataFromBase = new List <CollectionDescription>();

            if (collection == null)
            {
                throw new ArgumentNullException("Empty collection sent to chech deadband");
            }
            if (collection.m_HistoricalCollection.m_WorkerProperty[0].Code.Equals(Code.CODE_DIGITAL))
            {
                return(true);
            }
            //uzmi podatke iz baza
            //dataFromBase = Deserialization(collection.Dataset); proxy
            dataFromBase = proxy.Deserialization(collection.Dataset);

            if (dataFromBase.Count == 0)
            {
                return(true);
            }

            bool secoundExist = true;
            bool answer       = false;

            foreach (CollectionDescription item in dataFromBase)
            {
                if (item.m_HistoricalCollection.m_WorkerProperty[0].Code == collection.m_HistoricalCollection.m_WorkerProperty[0].Code)
                {
                    if (collection.m_HistoricalCollection.m_WorkerProperty[0].WorkerValue <= (item.m_HistoricalCollection.m_WorkerProperty[0].WorkerValue * 1.02) &&
                        collection.m_HistoricalCollection.m_WorkerProperty[0].WorkerValue >= item.m_HistoricalCollection.m_WorkerProperty[0].WorkerValue * 0.98)
                    {
                        //return false;
                        secoundExist = false;
                        continue;
                    }
                    else
                    {
                        answer       = true;
                        secoundExist = false;
                        break;
                    }
                }
            }
            if (secoundExist)
            {
                answer = true;
            }

            return(answer);
        }
        public int ParameterConstructor_MultipleObjectCreation_IdCorrect(int numberOfObjects)
        {
            CollectionDescription description = null;

            CollectionDescription.ResetStaticClassID();
            Dataset set        = Dataset.SET1;
            var     collection = new Mock <IHistoricalCollection>().Object;

            for (int i = 0; i < numberOfObjects; i++)
            {
                description = new CollectionDescription(set, collection);
            }

            return(description.ID);
        }
Esempio n. 26
0
        public void SendToHistoricalConverterRemoveGoodParameters(string type, int dataset)
        {
            DumpingBuffer dbObj = dbMock.Object;
            Mock <CollectionDescription> cdMock = new Mock <CollectionDescription>(dataset);
            CollectionDescription        cdObj  = cdMock.Object;

            cdObj.Dpc.dumpingPropertyList[0].Code         = "CODE_ANALOG";
            cdObj.Dpc.dumpingPropertyList[1].Code         = "CODE_DIGITAL";
            cdObj.Dpc.dumpingPropertyList[0].DumpingValue = new Value();
            cdObj.Dpc.dumpingPropertyList[1].DumpingValue = new Value();

            dbObj.SendToHistoricalConverter(cdObj, type, dataset);

            Assert.AreEqual(dbObj.DeltaCD.RemoveDic[dataset].Dpc.dumpingPropertyList[0].Code, cdObj.Dpc.dumpingPropertyList[0].Code);
            Assert.AreEqual(dbObj.DeltaCD.RemoveDic[dataset].Dpc.dumpingPropertyList[1].Code, cdObj.Dpc.dumpingPropertyList[1].Code);
        }
Esempio n. 27
0
        public void FillDeltaCDGoodParameters(string type, int dataset)
        {
            DumpingBuffer  dbObj                = dbMock.Object;
            Mock <DeltaCD> dCD_mock             = new Mock <DeltaCD>();
            DeltaCD        dCD_obj              = dCD_mock.Object;
            Mock <CollectionDescription> cdMock = new Mock <CollectionDescription>(dataset);
            CollectionDescription        cdObj  = cdMock.Object;
            Mock <Value> valMock                = new Mock <Value>("7414", 204);

            cdObj.Dpc.dumpingPropertyList[0].Code         = "CODE_ANALOG";
            cdObj.Dpc.dumpingPropertyList[1].Code         = "CODE_DIGITAL";
            cdObj.Dpc.dumpingPropertyList[0].DumpingValue = valMock.Object;
            cdObj.Dpc.dumpingPropertyList[1].DumpingValue = valMock.Object;

            dbObj.FillDeltaCD(dCD_obj, type, cdObj, dataset);
            Assert.AreEqual(dCD_obj.AddDic[dataset].Dataset, cdObj.Dataset);
        }
Esempio n. 28
0
        public void ReplicatorReceiver_EmptyConstructor_ReturnsDefaults()
        {
            var result = new ReplicatorReceiver.ReplicatorReceiver();

            var dataCD = new CollectionDescription();

            var  hcollection = dataCD.Collection;
            bool equal       = !hcollection.ReceiverPropertyArray.Except(result.DataCD.Collection.ReceiverPropertyArray).Any();


            Assert.IsTrue(result.DataCD.ID == dataCD.ID && result.DataCD.DataSet == dataCD.DataSet && equal);

            foreach (var item in result.DataDeltaCDs.Values)
            {
                Assert.AreEqual(item.Add, new List <CollectionDescription>());
                Assert.AreEqual(item.Update, new List <CollectionDescription>());
            }
        }
Esempio n. 29
0
        public void SerializeOkParameter(Code code, int value, int dataSet)
        {
            Modul2Property hp = new Modul2Property()
            {
                Code = code, Modul2Value = value
            };

            HistoricalCollection histColl = new HistoricalCollection();

            histColl.m_Modul2Property[0] = hp;

            CollectionDescription collDesc = new CollectionDescription();

            collDesc.Dataset   = dataSet;
            collDesc.Id        = 1235;
            collDesc.timeStamp = DateTime.Now;
            collDesc.m_HistoricalCollection = histColl;
            Assert.IsFalse(modul2.Serialize(collDesc));
        }
Esempio n. 30
0
        public void FillDeltaCDBadParameters(string type, int dataset)
        {
            DumpingBuffer  dbObj                = dbMock.Object;
            Mock <DeltaCD> dCD_mock             = new Mock <DeltaCD>();
            DeltaCD        dCD_obj              = dCD_mock.Object;
            Mock <CollectionDescription> cdMock = new Mock <CollectionDescription>(2);
            CollectionDescription        cdObj  = cdMock.Object;
            Mock <Value> valMock                = new Mock <Value>("7414", 204);

            cdObj.Dpc.dumpingPropertyList[0].Code         = "CODE_ANALOG";
            cdObj.Dpc.dumpingPropertyList[1].Code         = "CODE_DIGITAL";
            cdObj.Dpc.dumpingPropertyList[0].DumpingValue = valMock.Object;
            cdObj.Dpc.dumpingPropertyList[1].DumpingValue = valMock.Object;

            Assert.Throws <ArgumentException>(() =>
            {
                dbObj.FillDeltaCD(dCD_obj, type, cdObj, dataset);
            });
        }