Esempio n. 1
0
        public elementType Find<elementType>(int elementID)
            where elementType : Communicator.CommunicatorElement<elementType>
        {
            lock (mainThreadLock)
            {
                Communicator.Communicator<elementType> baseCommunicator = new Communicator.Communicator<elementType>();
                try
                {
                    baseCommunicator.NewConnection();

                    elementType toReturn = baseCommunicator.Find(elementID);

                    baseCommunicator.FinalizeBase();
                    return toReturn;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    baseCommunicator.FinalizeBase();
                }
            }
        }
Esempio n. 2
0
        public void RemoveListOfElements<elementType>(List<elementType> elementsToRemove, bool reUpload = false)
            where elementType : Communicator.CommunicatorElement<elementType>
        {
            lock (mainThreadLock)
            {
                Communicator.Communicator<elementType> baseCommunicator = new Communicator.Communicator<elementType>();
                List<elementType> bufferRemoved = new List<elementType>();
                try
                {
                    baseCommunicator.NewConnection();

                    foreach(elementType element in elementsToRemove)
                    {
                        baseCommunicator.Remove(baseCommunicator.Find(element.GetId()));
                        baseCommunicator.SaveChanges();

                        bufferRemoved.Add(element.GetCopyOfThis);
                    }
                    
                }
                catch(Exception ex)
                {
                    if (!reUpload)
                    {
                        baseCommunicator.FinalizeBase();
                        this.InsertListOfElements<elementType>(bufferRemoved, reUpload = true);
                        throw ex;
                    }  
                }
                finally
                {
                    baseCommunicator.FinalizeBase();
                }
            }
        }
Esempio n. 3
0
        public void InsertListOfElements<elementType>(List<elementType> listToInsert, bool reUpload = false) 
            where elementType : Communicator.CommunicatorElement<elementType>
        {
            lock (mainThreadLock)
            {
                Communicator.Communicator<elementType> baseCommunicator = new Communicator.Communicator<elementType>();
                List<elementType> bufferAdded = new List<elementType>();
                List<elementType> bufferModified = new List<elementType>();
                try
                {
                    baseCommunicator.NewConnection();
                    
                    foreach(elementType objToInsert in listToInsert)
                    {
                        elementType foundedElem = baseCommunicator.Find(objToInsert.GetId());
                        if (foundedElem != null)
                        {
                            elementType tmp = foundedElem.GetCopyOfThis;

                            baseCommunicator.Update(ref foundedElem, objToInsert);
                            baseCommunicator.SaveChanges();

                            bufferModified.Add(tmp);
                        }
                        else
                        {
                            baseCommunicator.Insert(objToInsert);
                            baseCommunicator.SaveChanges();

                            bufferAdded.Add(objToInsert.GetCopyOfThis);
                        } 
                    }
                    
                    
                }
                catch (Exception ex)
                {
                    if(!reUpload)
                    {
                        baseCommunicator.FinalizeBase();
                        this.RemoveListOfElements<elementType>(bufferAdded, reUpload = true);
                        this.InsertListOfElements<elementType>(bufferModified, reUpload = true);
                        throw ex;
                    }
                }
                finally
                {
                    baseCommunicator.FinalizeBase();
                }
            }
        }
Esempio n. 4
0
        public List<elementType> GetAllElements<elementType>() 
            where elementType : Communicator.CommunicatorElement<elementType>
        {
            lock (mainThreadLock)
            {
                Communicator.Communicator<elementType> baseCommunicator = new Communicator.Communicator<elementType>();
                try
                {
                    baseCommunicator.NewConnection();

                    List<elementType> toReturn = baseCommunicator.getEntireTable();
                    baseCommunicator.FinalizeBase();
                    return toReturn;
                }
                catch(Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    baseCommunicator.FinalizeBase();
                }
            }
        }