Esempio n. 1
0
        public void AddShare(string shareId, string systemId, string directory, string name, string[] categories)
        {
            Guid id = new Guid(shareId);
            ProviderPathSegment segment = new ProviderPathSegment(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, directory, true);
            ResourcePath        path    = new ResourcePath(new[] { segment });

            _shares[id] = new Share(id, systemId, path, name, false, categories);
        }
Esempio n. 2
0
        public static Guid?GetBaseResourceProviderId(ResourcePath path)
        {
            if (!path.IsAbsolute)
            {
                return(null);
            }
            ProviderPathSegment firstProvider = path.FirstOrDefault();

            if (firstProvider == null)
            {
                return(null);
            }
            return(firstProvider.ProviderId);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                IList <string> argList = new List <string>(args);

                bool direct = false;
                if (argList.Count >= 1 && argList[0] == "--direct")
                {
                    argList.RemoveAt(0);
                    direct = true;
                }

                if (argList.Count == 0)
                {
                    Usage();
                }

                var pathManager = new PathManager();
                pathManager.InitializeDefaults();
                // Override data path which could be read from MP2-Server install folder
                pathManager.SetPath("DATA", "<COMMON_APPLICATION_DATA>\\Team MediaPortal\\MP2-DevTools");

                // Set defaults if running from VS debug console (not inside MP2-Server install folder)
                if (!pathManager.Exists("CONFIG"))
                {
                    pathManager.SetPath("CONFIG", "<DATA>\\Config");
                    pathManager.SetPath("LOG", "<DATA>\\Log");
                }
                ServiceRegistration.Set <IPathManager>(pathManager);
                ServiceRegistration.Set(_logger = new Log4NetLogger(ServiceRegistration.Get <IPathManager>().GetPath(@"<LOG>")));

                if (direct)
                {
                    if (argList.Count == 3 && argList[0] == "sources" && (argList[1] == "list" || argList[1] == "export"))
                    {
                        string file     = argList[2];
                        var    database = GetSqlDatabase(file);
                        if (argList[1] == "list")
                        {
                            ListMediaSources(GetMediaSources(database));
                        }
                        else if (argList[1] == "export")
                        {
                            ExportMediaSources(GetMediaSources(database));
                        }
                    }
                    else if (argList.Count == 2 && argList[0] == "sql")
                    {
                        string         file     = argList[1];
                        SQLiteDatabase database = GetSqlDatabase(file);
                        ShowSqlConsole(database);
                    }
                    else
                    {
                        Usage();
                    }
                }
                else
                {
                    try
                    {
                        _logger.Info("Creating client...");
                        Client client = new Client();
                        client.Connect();

                        _logger.Info("Client connected {0}", client.Connected);

                        if (client.Connected)
                        {
                            _logger.Info("Checking arg list [{0}]", string.Join(",", argList));
                            if (argList.Count == 2 && argList[0] == "sources" && (argList[1] == "list" || argList[1] == "export"))
                            {
                                _logger.Info("Media sources:");
                                if (argList[1] == "list")
                                {
                                    ListMediaSources(GetMediaSources(client));
                                }
                                else if (argList[1] == "export")
                                {
                                    ExportMediaSources(GetMediaSources(client));
                                }
                            }

                            else if (argList.Count == 6 && argList[0] == "sources" && argList[1] == "add")
                            {
                                _logger.Info("Media sources before add:");
                                ListMediaSources(GetMediaSources(client));

                                string   name       = argList[2];
                                string   type       = argList[3];
                                string   path       = argList[4];
                                string[] categories = argList[5].Split(new char[] { ',' });

                                ProviderPathSegment segment = null;
                                if (type == "LOCAL")
                                {
                                    path    = path.Replace('\\', '/');
                                    segment = new ProviderPathSegment(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, "/" + path, true);
                                }
                                else if (type == "NETWORK")
                                {
                                    segment = new ProviderPathSegment(NetworkNeighborhoodResourceProvider.NETWORK_NEIGHBORHOOD_RESOURCE_PROVIDER_ID, "/" + path, true);
                                }
                                else
                                {
                                    Console.Error.WriteLine("Invalid media source type {0}", type);
                                    Exit(1);
                                }

                                ResourcePath resourcePath = new ResourcePath(new ProviderPathSegment[] { segment });
                                Share        source       = new Share(Guid.NewGuid(), client.GetSystemId(), resourcePath, name, true, categories);

                                _logger.Info("Adding LOCAL media source name={0} path={1} categories=[{2}]", source.BaseResourcePath.BasePathSegment.Path, source.Name, string.Join(",", source.MediaCategories));
                                client.GetContentDirectory().RegisterShareAsync(source).Wait();

                                _logger.Info("Media sources after add:");
                                ListMediaSources(GetMediaSources(client));
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "delete")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));

                                _logger.Info("Media sources before delete:");
                                ListMediaSources(GetMediaSources(client));

                                foreach (Guid id in ids)
                                {
                                    client.GetContentDirectory().RemoveShareAsync(id).Wait();
                                }

                                _logger.Info("Media sources after delete:");
                                ListMediaSources(GetMediaSources(client));
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "refresh")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));
                                _logger.Info("Refreshing sources [{0}]", string.Join(",", ids));
                                foreach (Guid id in ids)
                                {
                                    _logger.Info("Refreshing source {0}", id);
                                    client.GetContentDirectory().ReImportShareAsync(id).Wait();
                                }
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "reload")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));

                                foreach (Guid id in ids)
                                {
                                    Share preSource = client.GetContentDirectory().GetShareAsync(id).Result;
                                    if (preSource == null)
                                    {
                                        _logger.Error("No media source {0} found", id);
                                        continue;
                                    }
                                    ShowMediaSource(preSource);

                                    _logger.Info("Removing old source");
                                    client.GetContentDirectory().RemoveShareAsync(preSource.ShareId).Wait();

                                    Share postSource = new Share(Guid.NewGuid(), preSource.SystemId, preSource.BaseResourcePath, preSource.Name, true, preSource.MediaCategories);

                                    _logger.Info("Adding media source name={0} path={1} categories=[{2}]", postSource.Name, postSource.BaseResourcePath.BasePathSegment.Path, string.Join(",", postSource.MediaCategories));
                                    client.GetContentDirectory().RegisterShareAsync(postSource).Wait();

                                    _logger.Info("Media source after reload:");
                                    ShowMediaSource(client.GetContentDirectory().GetShareAsync(postSource.ShareId).Result);
                                }
                            }

                            else if (argList.Count == 3 && argList[0] == "items" && argList[1] == "list")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));
                                ShowMediaItems(client, new MediaItemIdFilter(ids));
                            }

                            else if (argList.Count == 3 && argList[0] == "items" && argList[1] == "search")
                            {
                                string text = argList[2];
                                ShowMediaItems(client, new LikeFilter(MediaAspect.ATTR_TITLE, "%" + text + "%", null));
                            }

                            else if (argList.Count == 5 && argList[0] == "items" && argList[1] == "relationships")
                            {
                                string id         = argList[2];
                                string role       = argList[3];
                                string linkedRole = argList[4];
                                ShowMediaItems(client, new RelationshipFilter(new Guid(role), new Guid(linkedRole), new Guid(id)));
                            }

                            else
                            {
                                Usage();
                            }
                        }
                        else
                        {
                            _logger.Error("No server found");
                            Exit(1);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error("Oh dear", e);
                        Exit(1);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error performing operation\n{0}", e);
                Exit(1);
            }

            Exit(0);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            try
            {
                IList <string> argList = new List <string>(args);

                bool direct = false;
                if (argList.Count >= 1 && argList[0] == "--direct")
                {
                    argList.RemoveAt(0);
                    direct = true;
                }

                if (argList.Count == 0)
                {
                    Usage();
                }

                ServiceRegistration.Set <IPathManager>(new PathManager());
                ServiceRegistration.Get <IPathManager>().SetPath("CONFIG", "_DevTools/config");
                ServiceRegistration.Get <IPathManager>().SetPath("LOG", "_DevTools/log");
                ServiceRegistration.Set(_logger = new Log4NetLogger(ServiceRegistration.Get <IPathManager>().GetPath(@"<LOG>")));

                if (direct)
                {
                    if (argList.Count == 3 && argList[0] == "sources" && (argList[1] == "list" || argList[1] == "export"))
                    {
                        string file = argList[2];
                        if (!File.Exists(file))
                        {
                            Console.Error.WriteLine("Datastore {0} does not exist", argList[2]);
                            Exit(1);
                        }

                        ServiceRegistration.Get <IPathManager>().SetPath("DATABASE", Path.GetDirectoryName(file));

                        ServiceRegistration.Set <IMessageBroker>(new MessageBroker());
                        ServiceRegistration.Set <ISettingsManager>(new SettingsManager());

                        SQLiteSettings settings = new SQLiteSettings();
                        settings.PageSize         = 4096;
                        settings.DatabaseFileName = Path.GetFileName(file);
                        ServiceRegistration.Get <ISettingsManager>().Save(settings);

                        ISQLDatabase database = new SQLiteDatabase();
                        if (argList[1] == "list")
                        {
                            ListMediaSources(GetMediaSources(database));
                        }
                        else if (argList[1] == "export")
                        {
                            ExportMediaSources(GetMediaSources(database));
                        }
                    }
                    else
                    {
                        Usage();
                    }
                }
                else
                {
                    try
                    {
                        _logger.Info("Creating client...");
                        Client client = new Client();
                        client.Connect();

                        _logger.Info("Client connected {0}", client.Connected);

                        if (client.Connected)
                        {
                            _logger.Info("Checking arg list [{0}]", string.Join(",", argList));
                            if (argList.Count == 2 && argList[0] == "sources" && (argList[1] == "list" || argList[1] == "export"))
                            {
                                _logger.Info("Media sources:");
                                if (argList[1] == "list")
                                {
                                    ListMediaSources(GetMediaSources(client));
                                }
                                else if (argList[1] == "export")
                                {
                                    ExportMediaSources(GetMediaSources(client));
                                }
                            }

                            else if (argList.Count == 6 && argList[0] == "sources" && argList[1] == "add")
                            {
                                _logger.Info("Media sources before add:");
                                ListMediaSources(GetMediaSources(client));

                                string   name       = argList[2];
                                string   type       = argList[3];
                                string   path       = argList[4];
                                string[] categories = argList[5].Split(new char[] { ',' });

                                ProviderPathSegment segment = null;
                                if (type == "LOCAL")
                                {
                                    path    = path.Replace('\\', '/');
                                    segment = new ProviderPathSegment(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, "/" + path, true);
                                }
                                else if (type == "NETWORK")
                                {
                                    segment = new ProviderPathSegment(NetworkNeighborhoodResourceProvider.NETWORK_NEIGHBORHOOD_RESOURCE_PROVIDER_ID, "/" + path, true);
                                }
                                else
                                {
                                    Console.Error.WriteLine("Invalid media source type {0}", type);
                                    Exit(1);
                                }

                                ResourcePath resourcePath = new ResourcePath(new ProviderPathSegment[] { segment });
                                Share        source       = new Share(Guid.NewGuid(), client.GetSystemId(), resourcePath, name, true, categories);

                                _logger.Info("Adding LOCAL media source name={0} path={1} categories=[{2}]", source.BaseResourcePath.BasePathSegment.Path, source.Name, string.Join(",", source.MediaCategories));
                                client.GetContentDirectory().RegisterShare(source);

                                _logger.Info("Media sources after add:");
                                ListMediaSources(GetMediaSources(client));
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "delete")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));

                                _logger.Info("Media sources before delete:");
                                ListMediaSources(GetMediaSources(client));

                                foreach (Guid id in ids)
                                {
                                    client.GetContentDirectory().RemoveShare(id);
                                }

                                _logger.Info("Media sources after delete:");
                                ListMediaSources(GetMediaSources(client));
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "refresh")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));
                                _logger.Info("Refreshing sources [{0}]", string.Join(",", ids));
                                foreach (Guid id in ids)
                                {
                                    _logger.Info("Refreshing source {0}", id);
                                    client.GetContentDirectory().ReImportShare(id);
                                }
                            }

                            else if (argList.Count == 3 && argList[0] == "sources" && argList[1] == "reload")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));

                                foreach (Guid id in ids)
                                {
                                    Share preSource = client.GetContentDirectory().GetShare(id);
                                    if (preSource == null)
                                    {
                                        _logger.Error("No media source {0} found", id);
                                        continue;
                                    }
                                    ShowMediaSource(preSource);

                                    _logger.Info("Removing old source");
                                    client.GetContentDirectory().RemoveShare(preSource.ShareId);

                                    Share postSource = new Share(Guid.NewGuid(), preSource.SystemId, preSource.BaseResourcePath, preSource.Name, true, preSource.MediaCategories);

                                    _logger.Info("Adding media source name={0} path={1} categories=[{2}]", postSource.Name, postSource.BaseResourcePath.BasePathSegment.Path, string.Join(",", postSource.MediaCategories));
                                    client.GetContentDirectory().RegisterShare(postSource);

                                    _logger.Info("Media source after reload:");
                                    ShowMediaSource(client.GetContentDirectory().GetShare(postSource.ShareId));
                                }
                            }

                            else if (argList.Count == 3 && argList[0] == "items" && argList[1] == "list")
                            {
                                IList <Guid> ids = argList[2].Split(new char[] { ' ' }).ToList().ConvertAll(x => new Guid(x));
                                ShowMediaItems(client, new MediaItemIdFilter(ids));
                            }

                            else if (argList.Count == 3 && argList[0] == "items" && argList[1] == "search")
                            {
                                string text = argList[2];
                                ShowMediaItems(client, new LikeFilter(MediaAspect.ATTR_TITLE, "%" + text + "%", null));
                            }

                            else if (argList.Count == 5 && argList[0] == "items" && argList[1] == "relationships")
                            {
                                string id         = argList[2];
                                string role       = argList[3];
                                string linkedRole = argList[4];
                                ShowMediaItems(client, new RelationshipFilter(new Guid(role), new Guid(linkedRole), new Guid(id)));
                            }

                            else
                            {
                                Usage();
                            }
                        }
                        else
                        {
                            _logger.Error("No server found");
                            Exit(1);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error("Oh dear", e);
                        Exit(1);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error performing operation\n{0}", e);
                Exit(1);
            }

            Exit(0);
        }