public void Salji() { Console.WriteLine("Saljem podatke DumpingBafferu..."); Bafer baf = new Bafer(); Random rand = new Random(); while (true) { int code = rand.Next(10); int podrucje = rand.Next(1000, 1000000); double vrednost = rand.Next(1000); DumpingProperty y = new DumpingProperty((Code)code, new Value(DateTime.Now, podrucje, vrednost)); string poruka = "Writer poslao podatke: Code: " + y.kod.ToString() + " Value: " + y.DumpingValue.timestamp + " " + y.DumpingValue.id + " " + y.DumpingValue.potrosnja + Environment.NewLine; string pr1 = Directory.GetCurrentDirectory(); string projectDirectory3 = Directory.GetParent(pr1).Parent.Parent.FullName; string p = Path.Combine(projectDirectory3 + @"\Biblioteka", "Loger.txt"); FileStream stream1 = new FileStream(p, FileMode.Append); StreamWriter sw = new StreamWriter(stream1); sw.WriteLine(poruka); sw.Close(); stream1.Close(); baf.Obrada(y.kod, y.DumpingValue); Thread.Sleep(2000); } }
public void TestKonstruktorDP1(DumpingProperty dp) { DumpingProperty dup = new DumpingProperty(dp.kod, dp.DumpingValue); Assert.AreEqual(dup.kod, dp.kod); Assert.AreEqual(dup.DumpingValue, dp.DumpingValue); }
public DumpingBuffer() { buffer = new List <Tuple <Codes, int> >(); dp = new DumpingProperty(); CD = new CollectionDescription(); DeltaCD = new DeltaCD(); }
public void CollectionDescriptionRemoveIfDSIsFull(DumpingProperty dp) { CD.ID = null; if (dp.Code == Codes.CODE_ANALOG || dp.Code == Codes.CODE_DIGITAL) { CD.DataSetBuffer1 = null; } else if (dp.Code == Codes.CODE_CUSTOM || dp.Code == Codes.CODE_LIMITSET) { CD.DataSetBuffer2 = null; } else if (dp.Code == Codes.CODE_SINGLENODE || dp.Code == Codes.CODE_MULTIPLENODE) { CD.DataSetBuffer3 = null; } else if (dp.Code == Codes.CODE_CONSUMER || dp.Code == Codes.CODE_SOURCE) { CD.DataSetBuffer4 = null; } else if (dp.Code == Codes.CODE_MOTION || dp.Code == Codes.CODE_SENSOR) { CD.DataSetBuffer5 = null; } else { throw new FormatException(); } }
public void ConstructorBadParameters1(Codes code) { Assert.Throws <ArgumentNullException>(() => { DumpingProperty dp = new DumpingProperty(code, null); }); }
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); } }
public void DumpingPropertyGoodParameters(string code) { Mock <Value> mockVal = new Mock <Value>(); DumpingProperty dp = new DumpingProperty(code, mockVal.Object); Assert.AreEqual(dp.Code, code); Assert.AreEqual(dp.DumpingValue, mockVal.Object); }
public void ConstructorBadParameters(Codes code) { Mock <Value> value = new Mock <Value>(); value.Object.Consumption = 14.0; value.Object.Timestamp = DateTime.Now; value.Object.GeographicalLocationId = Guid.NewGuid().ToString(); Assert.Throws <ArgumentException>(() => { DumpingProperty dp = new DumpingProperty(code, value.Object); }); }
public CollectionDescription CreateCDForDeltaCD(DumpingProperty dp) { CollectionDescription collectionDescription = new CollectionDescription(); collectionDescription.ID = id; id++; if (propertiesUnmached[0] != null) { collectionDescription.DCollection.AddRange(propertiesUnmached); } propertiesUnmached.Clear(); return(collectionDescription); }
public void ConstructorGoodParameters(Codes code) { Mock <Value> value = new Mock <Value>(); value.Object.Consumption = 14.0; value.Object.Timestamp = DateTime.Now; value.Object.GeographicalLocationId = Guid.NewGuid().ToString(); DumpingProperty dp = new DumpingProperty(code, value.Object); Assert.AreEqual(code, dp.Code); Assert.AreEqual(value.Object, dp.DumpingValue); }
public void checkFill(DumpingProperty dp) { if (CD.DataSetBuffer1[0] != null && CD.DataSetBuffer1[1] != null) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } else if (CD.DataSetBuffer2[0] != null && CD.DataSetBuffer2[1] != null) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } else if (CD.DataSetBuffer3[0] != null && CD.DataSetBuffer3[1] != null) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } else if (CD.DataSetBuffer4[0] != null && CD.DataSetBuffer4[1] != null) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } else if (CD.DataSetBuffer5[0] != null && CD.DataSetBuffer5[1] != null) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } else if (cameFromWritter == 10) { DeltaCD.TransactionID = id; DeltaCD.collectionDescription = CreateCDForDeltaCD(dp); h.ReceiveDataFromDumpingBuffer(DeltaCD); sending = true; cameFromWritter = 0; } }
public void CollectionDescriptionUpdate(DumpingProperty dumpingProperty) { switch (dumpingProperty.Code) { case Codes.CODE_ANALOG: CD.DataSetBuffer1[0].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_DIGITAL: CD.DataSetBuffer1[1].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_CUSTOM: CD.DataSetBuffer2[0].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_LIMITSET: CD.DataSetBuffer2[1].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_SINGLENODE: CD.DataSetBuffer3[0].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_MULTIPLENODE: CD.DataSetBuffer3[1].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_CONSUMER: CD.DataSetBuffer4[0].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_SOURCE: CD.DataSetBuffer4[1].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_MOTION: CD.DataSetBuffer5[0].DumpingValue = dumpingProperty.DumpingValue; break; case Codes.CODE_SENSOR: CD.DataSetBuffer5[1].DumpingValue = dumpingProperty.DumpingValue; break; } }
public void CollectionDescriptionRemoveIfAllAreSent(DumpingProperty dp) { CD.ID = null; CD.DataSetBuffer1[0] = null; CD.DataSetBuffer1[1] = null; CD.DataSetBuffer2[0] = null; CD.DataSetBuffer2[1] = null; CD.DataSetBuffer3[0] = null; CD.DataSetBuffer3[1] = null; CD.DataSetBuffer4[0] = null; CD.DataSetBuffer4[1] = null; CD.DataSetBuffer5[0] = null; CD.DataSetBuffer5[1] = null; if (propertiesUnmached[0] != null) { CD.DCollection.Clear(); } }
/// <summary> /// Pomocna funkcija /// </summary> /// <param name="code"></param> /// <param name="value"></param> public void WriteToDumpingBuffer(Codes code, float value) { int tempCode = (int)code; if (tempCode < 0 || tempCode > 7) { throw new ArgumentException("Kod mora biti izmedju 0 i 7"); } if (value < 0 || value > 10) { throw new ArgumentException("Vrednost mora biti izmedju 0 i 10"); } if (tempCode < 0 || tempCode > 7) { throw new ArgumentException("Kod mora biti izmedju 0 i 7"); } if (value < 0 || value > 10) { throw new ArgumentException("Vrednost mora biti izmedju 0 i 10"); } updated = false; dumpingProperty = new DumpingProperty(code, value); dataset = CheckDataset(code); CheckUpdate(dataset); if (!updated) { //Unique ID, Dataset & DumpingProperty switch (dataset) //na osnovu dataset-a odredjujemo u koji cemo CD da stavimo { case 1: CD1.ID = Guid.NewGuid().ToString(); CD1.Dataset = dataset; CD1.DumpingPropertyCollection.DumpingCollection.Add(dumpingProperty); break; case 2: CD2.ID = Guid.NewGuid().ToString(); CD2.Dataset = dataset; CD2.DumpingPropertyCollection.DumpingCollection.Add(dumpingProperty); break; case 3: CD3.ID = Guid.NewGuid().ToString(); CD3.Dataset = dataset; CD3.DumpingPropertyCollection.DumpingCollection.Add(dumpingProperty); break; case 4: CD4.ID = Guid.NewGuid().ToString(); CD4.Dataset = dataset; CD4.DumpingPropertyCollection.DumpingCollection.Add(dumpingProperty); break; } } //Ukoliko postoje 2 razlicita Code-a u okviru istog Dataset-a, salji Historical komponenti. if (CheckDumpingPropertyCount()) { SendToHistorical(); } }
public void Obrada(Code kod, Value vrijednost) { Random rId = new Random(); int dataset = -1; DumpingProperty dp = new DumpingProperty(kod, vrijednost); Dataset da = new Dataset(); dataset = da.GetDataset(kod); string poruka = "DumpingBuffer primio podatak.Code = " + Environment.NewLine + dp.kod.ToString() + "Value = " + dp.DumpingValue.timestamp.ToString() + " " + dp.DumpingValue.id + " " + dp.DumpingValue.potrosnja + Environment.NewLine; ILogovanje Logovanje = new DumpingLogovanje(); Logovanje.Loguj(poruka); DodajCD dodajCD = new DodajCD(); dodajCD.Dodaj(dataset, dp, Logovanje, CDS); counter++; if (counter == 10) { counter = 0; int brojac = 0; Random br = new Random(); string porukaDC = "Primljeno 10 podataka! Pocinje pakovanje." + Environment.NewLine; Logovanje.Loguj(porukaDC); List <DeltaCD> DeltaCDS = new List <DeltaCD>(); foreach (CollectionDescription c in CDS) { if (c.poslat == false && c.DumpingPropertyCollection.Count() == 2) { c.poslat = true; if (brojac == 0) { DeltaCD zaSlanje = new DeltaCD(br.Next(1000, 100000), new CollectionDescription(-1, -1, new List <DumpingProperty>()), new CollectionDescription(-1, -1, new List <DumpingProperty>()), new CollectionDescription(-1, -1, new List <DumpingProperty>())); zaSlanje.Add = c; DeltaCDS.Add(zaSlanje); brojac++; porukaDC = "Ubacen Add u DC. ID:" + zaSlanje.transactionID + Environment.NewLine + zaSlanje.Add.DumpingPropertyCollection[0].kod.ToString() + " " + zaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.timestamp.ToString() + " " + zaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.id + " " + zaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.potrosnja + Environment.NewLine + zaSlanje.Add.DumpingPropertyCollection[1].kod.ToString() + " " + zaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.timestamp.ToString() + " " + zaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.id + " " + zaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.potrosnja + Environment.NewLine; Logovanje.Loguj(porukaDC); } else if (brojac == 1) { DeltaCDS[0].Update = c; brojac++; porukaDC = "Ubacen Update u DC. ID:" + DeltaCDS[0].transactionID + Environment.NewLine + DeltaCDS[0].Update.DumpingPropertyCollection[0].kod.ToString() + " " + DeltaCDS[0].Update.DumpingPropertyCollection[0].DumpingValue.timestamp.ToString() + " " + DeltaCDS[0].Update.DumpingPropertyCollection[0].DumpingValue.id + " " + DeltaCDS[0].Update.DumpingPropertyCollection[0].DumpingValue.potrosnja + Environment.NewLine + DeltaCDS[0].Update.DumpingPropertyCollection[1].kod.ToString() + " " + DeltaCDS[0].Update.DumpingPropertyCollection[1].DumpingValue.timestamp.ToString() + " " + DeltaCDS[0].Update.DumpingPropertyCollection[1].DumpingValue.id + " " + DeltaCDS[0].Update.DumpingPropertyCollection[1].DumpingValue.potrosnja + Environment.NewLine; Logovanje.Loguj(porukaDC); } else if (brojac == 2) { DeltaCDS[0].Delete = c; brojac++; porukaDC = "Ubacen Delete u DC. ID:" + DeltaCDS[0].transactionID + Environment.NewLine + DeltaCDS[0].Delete.DumpingPropertyCollection[0].kod.ToString() + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[0].DumpingValue.timestamp.ToString() + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[0].DumpingValue.id + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[0].DumpingValue.potrosnja + Environment.NewLine + DeltaCDS[0].Delete.DumpingPropertyCollection[1].kod.ToString() + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[1].DumpingValue.timestamp.ToString() + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[1].DumpingValue.id + " " + DeltaCDS[0].Delete.DumpingPropertyCollection[1].DumpingValue.potrosnja + Environment.NewLine; Logovanje.Loguj(porukaDC); } else if (brojac == 3) { DeltaCD noviZaSlanje = new DeltaCD(br.Next(1000, 100000), new CollectionDescription(-1, -1, new List <DumpingProperty>()), new CollectionDescription(-1, -1, new List <DumpingProperty>()), new CollectionDescription(-1, -1, new List <DumpingProperty>())); noviZaSlanje.Add = c; DeltaCDS.Add(noviZaSlanje); brojac++; porukaDC = "Ubacen Add u DC. ID:" + noviZaSlanje.transactionID + Environment.NewLine + noviZaSlanje.Add.DumpingPropertyCollection[0].kod.ToString() + " " + noviZaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.timestamp.ToString() + " " + noviZaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.id + " " + noviZaSlanje.Add.DumpingPropertyCollection[0].DumpingValue.potrosnja + Environment.NewLine + noviZaSlanje.Add.DumpingPropertyCollection[1].kod.ToString() + " " + noviZaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.timestamp.ToString() + " " + noviZaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.id + " " + noviZaSlanje.Add.DumpingPropertyCollection[1].DumpingValue.potrosnja + Environment.NewLine; Logovanje.Loguj(porukaDC); } else if (brojac == 4) { DeltaCDS[1].Update = c; brojac++; porukaDC = "Ubacen Update u DC. ID:" + DeltaCDS[1].transactionID + Environment.NewLine + DeltaCDS[1].Update.DumpingPropertyCollection[0].kod.ToString() + " " + DeltaCDS[1].Update.DumpingPropertyCollection[0].DumpingValue.timestamp.ToString() + " " + DeltaCDS[1].Update.DumpingPropertyCollection[0].DumpingValue.id + " " + DeltaCDS[1].Update.DumpingPropertyCollection[0].DumpingValue.potrosnja + Environment.NewLine + DeltaCDS[1].Update.DumpingPropertyCollection[1].kod.ToString() + " " + DeltaCDS[1].Update.DumpingPropertyCollection[1].DumpingValue.timestamp.ToString() + " " + DeltaCDS[1].Update.DumpingPropertyCollection[1].DumpingValue.id + " " + DeltaCDS[1].Update.DumpingPropertyCollection[1].DumpingValue.potrosnja + Environment.NewLine; Logovanje.Loguj(porukaDC); } else { Console.WriteLine("Polaganje Res-a"); } } } BufferSender bufi = new BufferSender(); bufi.SendToHistory(DeltaCDS); DeltaCDS.Clear(); CDS.Clear(); } }
public void CollectionDescriptionAdd(DumpingProperty dumpingProperty) { if (sending == false) { checkFill(dumpingProperty); cameFromWritter++; switch (dumpingProperty.Code) { case Codes.CODE_ANALOG: if (CD.DataSetBuffer1[0] == null) { CD.DataSetBuffer1[0] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_DIGITAL: if (CD.DataSetBuffer1[1] == null) { CD.DataSetBuffer1[1] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_CUSTOM: if (CD.DataSetBuffer2[0] == null) { CD.DataSetBuffer2[0] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_LIMITSET: if (CD.DataSetBuffer2[1] == null) { CD.DataSetBuffer2[1] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_SINGLENODE: if (CD.DataSetBuffer3[0] == null) { CD.DataSetBuffer3[0] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_MULTIPLENODE: if (CD.DataSetBuffer3[1] == null) { CD.DataSetBuffer3[1] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_CONSUMER: if (CD.DataSetBuffer4[0] == null) { CD.DataSetBuffer4[0] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_SOURCE: if (CD.DataSetBuffer4[1] == null) { CD.DataSetBuffer4[1] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_MOTION: if (CD.DataSetBuffer5[0] == null) { CD.DataSetBuffer5[0] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; case Codes.CODE_SENSOR: if (CD.DataSetBuffer5[1] == null) { CD.DataSetBuffer5[1] = dumpingProperty; } else { CollectionDescriptionUpdate(dumpingProperty); } break; } } else { propertiesUnmached.Add(dumpingProperty); } }