public void FillIp(string myip)
        {
            if (!makeguuidifnodevice())
                {
                    var mydevice = new device();

                    mydevice.UUIDDevice = Guid.NewGuid().ToString();
                    _GUIDDevice = mydevice.UUIDDevice;
                    mydevice.IP = myip+":8554";
                    mydevice.Protocol = "rtsp://";
                    mydevice.PCOwner = Environment.UserName;

                    using (var musik = new pcindexEntities())
                    {
                        musik.devices.Add(mydevice);
                        musik.SaveChanges();
                    }

                }
                else
                {
                    using (var musik = new pcindexEntities())
                    {
                        var olddevice = (from p in musik.devices select p).ToList();
                        if (myip != olddevice[0].IP)
                        {
                            olddevice[0].IP = myip+":8554";

                            musik.SaveChanges();

                        }
                    }

                }
        }
        public void Markasonline()
        {
            {
               if (!CheckIfDeviceExists())
               {
                   List<device> pcdevices;
                   using (var musik = new pcindexEntities())
                   {
                       pcdevices = (from p in musik.devices select p).ToList();
                   }

                   var nyed = pcdevices.ElementAt(0);
                   var pid = new PIDevice();
                   pid.UUIDDevice = nyed.UUIDDevice;
                   pid.IP = nyed.IP;
                   pid.PCOwner = nyed.PCOwner;
                   pid.Protocol = nyed.Protocol;
                   pid.Catagory_idCatagory = 1;
                   pid.Online = true;

                   using (var pimusik = new PiindexEntities())
                   {
                       pimusik.PIDevices.Add(pid);
                       pimusik.SaveChanges();
                   }

               }
               else
               {
                   CheckPIandFixIp();
               }
               }
        }
        private void FillPiPath()
        {
            List<filepath> pathtopi;
               List<PIFilePath> pifilepaths;

               using (var musik = new pcindexEntities())
               {
               pathtopi = (from p in musik.filepaths select p).ToList();

               }

               using (var pimusik = new PiindexEntities())
               {

               pifilepaths = (from p in pimusik.PIFilePaths select p).ToList();
               }

               pathtopi = listcompair(pathtopi, pifilepaths);

               foreach (var ele in pathtopi)
               {
                   var fil = new PIFilePath();
                   fil.Device_UUIDDevice = ele.Device_UUIDDevice;
                   fil.FilePath = ele.FilePath1;
                   fil.UUIDPath = ele.UUIDPath;
                   using (var pimusik = new PiindexEntities())
                   {
                       pimusik.PIFilePaths.Add(fil);
                       pimusik.SaveChanges();
                   }

               }
        }
        // Takes all music from Pc an adds to the Pi what it doesn't have
        private void FillMusikData()
        {
            List<musicdata> musicdatas;

               using (var musik = new pcindexEntities())
               {
               musicdatas = (from p in musik.musicdatas select p).ToList();
               }
               using (var pimusik = new PiindexEntities())
               {
               musicdatas = listcompair(musicdatas, (from p in pimusik.PIMusikDatas select p).ToList());
               }

               if(musicdatas.Count >0)
               Addmusikdata(musicdatas);
        }
        private void FillAAG()
        {
            List<string> Artist;
               List<string> Album;
               List<string> Genre;

               using (var musik = new pcindexEntities())
               {
                Artist = (from p in musik.artists select p.Artist1).ToList();
                Album = (from p in musik.albums select p.Album1).ToList();
                Genre = (from p in musik.genres select p.Genre1).ToList();
               }

               using (var pimusik = new PiindexEntities())
               {
               Artist = listcompair(Artist,(from p in pimusik.PIArtists select p.Artist).ToList());
               Album = listcompair(Album  ,(from p in pimusik.PIAlbums select p.Album).ToList());
               Genre = listcompair(Genre  ,(from p in pimusik.PIGenres select p.Genre).ToList());
               }

               if (Artist.Count > 0)
               addArtist(Artist);
               if (Album.Count > 0)
               addAlbum(Album);
               if (Genre.Count > 0)
               addGenre(Genre);
        }
        private void CheckPIandFixIp()
        {
            List<device> PCdevices;
               using (var musik = new pcindexEntities())
               {
               PCdevices = (from p in musik.devices select p).ToList();
               }

               var my = PCdevices[0];
               using (var pimusik = new PiindexEntities())
               {
               var change = (from p in pimusik.PIDevices where p.UUIDDevice == my.UUIDDevice select p).ToList();
               change[0].IP = my.IP;
               pimusik.SaveChanges();

               }
        }
 private bool CheckIfDeviceExists()
 {
     List<string> pcdevices;
     using (var musik = new pcindexEntities())
     {
       pcdevices = (from p in musik.devices select p.UUIDDevice).ToList();
     }
     using (var pimusik = new PiindexEntities())
     {
         pcdevices = listcompair(pcdevices, (from p in pimusik.PIDevices select p.UUIDDevice).ToList());
     }
     return pcdevices.Count == 0;
 }
        public void FillMusicAndPath(List<string> PathOndevice)
        {
            using (var musik = new pcindexEntities())
            {
                var pathlist = (from p in musik.filepaths
                                         select p.FilePath1
                                        ).ToList();

                PathOndevice = listcompair(PathOndevice, pathlist);

                if (PathOndevice.Count >= 1)
                {

                    foreach (var onpath in PathOndevice)
                    {
                        var path = new filepath();
                        path.Device_UUIDDevice = _GUIDDevice;
                        path.UUIDPath = Guid.NewGuid().ToString();
                        path.FilePath1 = onpath;
                        musik.filepaths.Add(path);
                        musik.SaveChanges();

                        IFileIndexer indexer = new FolderAndFileReader();
                        indexer.SetIndexPath(onpath);

                        List<IMetadataReader> mdata = indexer.GetMetaData();

                        FillAAG(mdata);
                        fillMusicdata(mdata,path.UUIDPath);

                    }

                }

            }
            //see if pathes is allready is assigned to ip
            // if not add pathes
        }
        private bool makeguuidifnodevice()
        {
            using (var musik = new pcindexEntities())
            {
                var GUIDDevice = (from p in musik.devices select p).ToList();

                if (GUIDDevice.Count == 0)
                    return false;

                _GUIDDevice = GUIDDevice[0].UUIDDevice;
                return true;

            }
        }
        private void Addgenre( List<string> liste)
        {
            //se if Genre exists if not add genre
            using (var musik = new pcindexEntities())
            {
                List<string> list2 = (from p in musik.genres

                                         select p.Genre1

                                        ).ToList();
                  liste = listcompair(liste, list2);

                if (liste.Count >= 1)
                {

                    foreach (var onpath in liste)
                    {
                        var _genre = new genre();
                        _genre.Genre1 = onpath;

                        musik.genres.Add(_genre);
                        musik.SaveChanges();

                    }

                }
            }
        }
        private void addArtist(List<string> liste)
        {
            // make artist list
            // remove duplets

            using (var musik = new pcindexEntities())
            {
                List<string> list2 = (from p in musik.artists

                                      select p.Artist1

                                        ).ToList();

                liste = listcompair(liste, list2);

                if (liste.Count >= 1)
                {

                    foreach (var onpath in liste)
                    {
                        var entity = new artist();
                        entity.Artist1 = onpath;

                        musik.artists.Add(entity);
                        musik.SaveChanges();

                    }

                }
            }
        }
        private void addAlbum(List<string> liste)
        {
            using (var musik = new pcindexEntities())
            {
                List<string> list2 = (from p in musik.albums

                                      select p.Album1

                                        ).ToList();

                liste = listcompair(liste, list2);

                if (liste.Count >= 1)
                {

                    foreach (var onpath in liste)
                    {
                        var entity = new album();
                        entity.Album1 = onpath;

                        musik.albums.Add(entity);
                        musik.SaveChanges();

                    }

                }
            }
        }
        public void fillMusicdata(List<IMetadataReader> datalist,string uuid)
        {
            using (var musik = new pcindexEntities())
            {

                foreach (var metadata in datalist)
                {
                    var nummer = new musicdata();
                    nummer.Title = metadata.Title;
                    nummer.Artist_Artist = metadata.Artist;
                    nummer.Album_Album = metadata.Album;
                    nummer.Genre_Genre = metadata.Genre;
                    nummer.NrLenth = metadata.LengthS;
                    nummer.FileName = metadata.ItemName;
                    nummer.FilePath_UUIDPath = uuid;
                    nummer.UUIDMusikData = Guid.NewGuid().ToString();

                    musik.musicdatas.Add(nummer);

                    musik.SaveChanges();
                }

            }
        }