Ejemplo n.º 1
0
 private void ClearStructures()
 {
     collectionDescriptions.Clear();
     operationAndId.Clear();
     InitalizeCollectionDescriptions();
     deltaCD = new DeltaCD();
     counter = 0;
 }
Ejemplo n.º 2
0
        public DeltaCD FillDeltaCD(Dictionary <int, List <Operations> > operationAndId, Dictionary <int, CollectionDescription> collectionDescriptions)
        {
            if (operationAndId == null || collectionDescriptions == null)
            {
                throw new ArgumentNullException("Parameters cannot be null");
            }
            int     cnt;
            DeltaCD deltaCD = new DeltaCD();

            lock (syncLock)
            {
                Logger.WriteLog("Converting to Delta CD", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
            }
            for (int i = 1; i < 6; i++)
            {
                cnt = 0;
                List <Operations> ops = operationAndId[i];
                foreach (DumpingProperty dp in collectionDescriptions[i].DumpingPropertyCollection.DumpingProperties)
                {
                    switch (ops[cnt++])
                    {
                    case Operations.ADD:
                        deltaCD.Add[i].Dataset = collectionDescriptions[i].Dataset;
                        deltaCD.Add[i].DumpingPropertyCollection.DumpingProperties.Add(dp);
                        deltaCD.Add[i].Id = collectionDescriptions[i].Id;
                        break;

                    case Operations.UPDATE:
                        deltaCD.Update[i].Dataset = collectionDescriptions[i].Dataset;
                        deltaCD.Update[i].DumpingPropertyCollection.DumpingProperties.Add(dp);
                        deltaCD.Update[i].Id = collectionDescriptions[i].Id;
                        break;

                    case Operations.REMOVE:
                        deltaCD.Remove[i].Dataset = collectionDescriptions[i].Dataset;
                        deltaCD.Remove[i].DumpingPropertyCollection.DumpingProperties.Add(dp);
                        deltaCD.Remove[i].Id = collectionDescriptions[i].Id;
                        break;
                    }
                }
            }
            return(deltaCD);
        }
Ejemplo n.º 3
0
        public void WriteToDumpingBuffer(Operations op, Codes code, Value val)
        {
            if (val == null)
            {
                throw new ArgumentNullException("Value cannot be null");
            }
            if ((int)code < 0 || (int)code > 9)
            {
                throw new ArgumentException("Code must be in interval 0-9!");
            }
            if ((int)op < 0 || (int)op > 2)
            {
                throw new ArgumentException("Operation invalid");
            }

            //check Val.Consumption and the resto of the properties if they are valid
            DumpingProperty dp      = new DumpingProperty(code, val);
            int             dataset = historical.CheckDataset(code);

            if (dataset == -1)
            {
                //something wrong with dataset
            }
            bool updated = false;

            lock (syncLock)
            {
                Logger.WriteLog("Writing to dumping buffer", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
            }

            updated = CheckUpdate(dataset, dp);

            if (!updated)
            {                                                                                        //data does not exist, i need to add id
                collectionDescriptions[dataset].Dataset = dataset;
                collectionDescriptions[dataset].DumpingPropertyCollection.DumpingProperties.Add(dp); //i can make a new dp here also
                collectionDescriptions[dataset].Id = dataset;
                AddToOperationsAndId(collectionDescriptions[dataset].Id, op);                        //operation can be add,remove or update
                counter++;
                //UPDATE HAS HAPPEND in the CHECKUPDATE function
            }
            //data added need to check dp.COunt;
            if (CheckDumpingPropertyCount() && counter < 3)
            {
                // FillDeltaCD(); //pack data into deltaCD component
                deltaCD = converter.FillDeltaCD(operationAndId, collectionDescriptions);
                //send data to historical (make a converter or something)
                SendToHistorical();
                //clear dictonarys
                ClearStructures();
            }
            else if (counter >= 10)
            {
                //we have enough data, add into deltaCD and send and clear
                /*FillDeltaCD(); */
                deltaCD = converter.FillDeltaCD(operationAndId, collectionDescriptions);

                //send data to historical (make a converter or something)
                SendToHistorical();
                //clear dictonarys
                ClearStructures();
            }
        }
        public void SetDataToDumpingBuffer()
        {
            databaseDB.Create();
            databaseDB.Connect();
            using (sw)
            {
                propertyCollection    = new DumpingPropertyCollection();
                collectionDescription = new CollectionDescription();

                while (count < 10)
                {
                    sw.WriteLine("******************************************");


                    code  = writer.WriteToDumpinBuffer().code;
                    value = writer.WriteToDumpinBuffer().value;

                    sw.WriteLine("CODE: " + code);
                    sw.WriteLine("VALUE:" + value);

                    Console.WriteLine("******************");
                    Console.WriteLine("DumpingBuffer code: " + code);
                    Console.WriteLine("DumpingBuffer value:" + value);
                    DumpingProperty dumpingProperty = new DumpingProperty();
                    dumpingProperty.Code         = code;
                    dumpingProperty.DumpingValue = value;

                    dataset = GetDataset(code);
                    //ako ne postoji nijedan cd
                    if (collectionDescriptions.Count == 0)
                    {
                        CreateCD(dumpingProperty);//kreiramo
                        databaseDB.WriteToDatabase();
                    }
                    else
                    {
                        foreach (CollectionDescription cd in collectionDescriptions.ToList())
                        {
                            //da li u CDs postoji CD sa tim dataset-om
                            if (cd.Dataset == dataset)//ako postoji
                            {
                                isDatasetExist = true;
                                foreach (DumpingProperty dp in cd.PropertyCollection.DumpingProperties.ToList())
                                {
                                    if (dp.Code == code)//provera da li postoji taj code
                                    {
                                        isEqualsCode    = true;
                                        dp.DumpingValue = value;//ako postoji, azuruiranje vrednosti
                                        databaseDB.WriteToDatabase();
                                    }
                                }
                                if (!isEqualsCode)
                                {
                                    cd.PropertyCollection.DumpingProperties.Add(dumpingProperty);//ako ne, dodajemo
                                    databaseDB.WriteToDatabase();
                                    if (deltaCDs.Count() == 0)
                                    {
                                        DeltaCD deltaCD = new DeltaCD();
                                        deltaCD.TranscationID            = ++trId;
                                        deltaCD.CollectionDescriptionAdd = cd;
                                        collectionDescriptions.Remove(cd);
                                        deltaCDs.Add(deltaCD);
                                    }
                                }
                            }
                        }
                        //ako ne postoji CD, napravimo ga
                        if (!isDatasetExist)
                        {
                            CreateCD(dumpingProperty);
                            databaseDB.WriteToDatabase();
                        }
                        isDatasetExist = false;
                        isEqualsCode   = false;
                    }
                    count++;

                    Read();

                    if (count == 10)
                    {
                        if (deltaCDs.Count == 0)
                        {
                            count = 0;
                        }
                    }
                    Thread.Sleep(2000);
                }

                count = 0;
            }

            databaseDB.sqlConnection.Close();
        }