public MediaServerCore(string friendlyName)
        {
            if (serverCore != null) throw new Exception("Only a single MediaServerCode instance is allowed");
            serverCore = this;

            OpenSource.Utilities.EventLogger.SetLog("Media Server", "MediaServerCode", System.Windows.Forms.Application.ProductVersion.ToString());

            DeviceInfo info = new DeviceInfo();
            info.AllowRemoteContentManagement = true;
            info.FriendlyName = friendlyName;
            info.Manufacturer = "OpenSource";
            info.ManufacturerURL = "";
            info.ModelName = "Media Server";
            info.ModelDescription = "Provides content through UPnP ContentDirectory service";
            info.ModelURL = "";
            info.ModelNumber = "0.765";
            info.LocalRootDirectory = "";
            Tags T = Tags.GetInstance();
            info.SearchCapabilities = "dc:title,dc:creator,upnp:class,upnp:album,res@protocolInfo,res@size,res@bitrate";
            info.SortCapabilities = "dc:title,dc:creator,upnp:class,upnp:album";
            info.EnableSearch = true;
            info.CacheTime = MediaServerCore.CacheTime;
            info.CustomUDN = MediaServerCore.CustomUDN;
            info.INMPR03 = MediaServerCore.INMPR;

            // encode in UTF16 instead of UTF8
            MediaObject.ENCODE_UTF8 = false;

            mediaServer = new MediaServerDevice(info, null, true, "http-get:*:*:*", "");
            mediaServer.OnStatsChanged += new MediaServerDevice.Delegate_MediaServerHandler(StatsChangedChangedSink);
            mediaServer.OnHttpTransfersChanged += new MediaServerDevice.Delegate_MediaServerHandler(HttpTransfersChangedSink);
            mediaServer.OnFileNotMapped = new MediaServerDevice.Delegate_FileNotMappedHandler(this.Handle_OnRequestUnmappedFile);
            mediaServer.OnRequestAddBranch = new MediaServerDevice.Delegate_AddBranch(this.Handle_OnRequestAddBranch);
            mediaServer.OnRequestRemoveBranch = new MediaServerDevice.Delegate_RemoveBranch(this.Handle_OnRequestRemoveBranch);
            mediaServer.OnRequestChangeMetadata = new MediaServerDevice.Delegate_ChangeMetadata(this.Handle_OnRequestChangeMetadata);
            mediaServer.OnRequestSaveBinary = new MediaServerDevice.Delegate_ModifyBinary (this.Handle_OnRequestSaveBinary);
            mediaServer.OnRequestDeleteBinary = new MediaServerDevice.Delegate_ModifyBinary(this.Handle_OnRequestDeleteBinary);

            this.ResetCoreRoot();

            this.m_DeviceWatcher = new UPnPDeviceWatcher(mediaServer._Device);
            this.m_DeviceWatcher.OnSniff += new OpenSource.UPnP.UPnPDeviceWatcher.SniffHandler(this.Sink_DeviceWatcherSniff);

            this.mediaServer.Start();
            m_Paused = false;
        }
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            if (mediaServer != null) this.OnStop();
            mediaServer = new MediaServerCore("Intel's Media Server (" + System.Windows.Forms.SystemInformation.ComputerName + ")");

            System.Collections.Specialized.ListDictionary channelProperties = new System.Collections.Specialized.ListDictionary();
            channelProperties.Add("port", 12329);

            HttpChannel channel = new HttpChannel(channelProperties,
                new SoapClientFormatterSinkProvider(),
                new SoapServerFormatterSinkProvider());

            //channel = new TcpChannel(12329);
            ChannelServices.RegisterChannel(channel);

            RemotingConfiguration.ApplicationName = "IntelUPnPMediaServer";
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(UPnPMediaServer),
                "UPnPMediaServer.soap",
                WellKnownObjectMode.Singleton);
        }
예제 #3
0
        public MainForm(string[] args)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            OpenSource.UPnP.DText p = new OpenSource.UPnP.DText();
            p.ATTRMARK = "=";
            string[] filePaths = new string[1];

            foreach(string arg in args)
            {
                p[0] = arg;
                switch(p[1].ToUpper())
                {
                    case "-UDN":
                        MediaServerCore.CustomUDN = p[2];
                        break;
                    case "-CACHETIME":
                        MediaServerCore.CacheTime = int.Parse(p[2]);
                        break;
                    case "-INMPR":
                        MediaServerCore.INMPR = !(p[2].ToUpper()=="NO");
                        break;
                }
            }

            // Setup the UI
            transfersSplitter.Visible = viewTransfersPanelMenuItem.Checked;
            transfersListView.Visible = viewTransfersPanelMenuItem.Checked;

            try
            {
                serviceController = new ServiceController("UPnP Media Server");
                serviceStatus = serviceController.Status;
                OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"Service control mode...");
            }
            catch (System.InvalidOperationException)
            {
                serviceController = null;
                serviceStatus = ServiceControllerStatus.Stopped;
                OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"Stand alone mode...");
            }

            if (serviceController != null)
            {
                // Service controller mode
                serviceMenuItem.Visible = true;

                // Pause State
                pauseServerMenuItem.Visible = false;

                System.Collections.Specialized.ListDictionary channelProperties = new System.Collections.Specialized.ListDictionary();
                channelProperties.Add("port", 12330);
                HttpChannel channel = new HttpChannel(channelProperties,
                    new SoapClientFormatterSinkProvider(),
                    new SoapServerFormatterSinkProvider());
                ChannelServices.RegisterChannel(channel, false);
                OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"RegisterChannel");

                if (serviceStatus == ServiceControllerStatus.Running)
                {
                    OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"RegisterWellKnownClientType");
                    RemotingConfiguration.RegisterWellKnownClientType(
                        typeof(UPnPMediaServer),
                        "http://localhost:12329/UPnPMediaServer/UPnPMediaServer.soap"
                        );
                    registeredServerType = true;
                }
            }
            else
            {
                // Stand alone mode
                if (registeredServerType == true || standAloneMode == true) return;

                standAloneMode = true;
                serviceMenuItem.Visible = false;

                // Stand alone mode
                mediaServerCore = new MediaServerCore("Media Server (" + System.Windows.Forms.SystemInformation.ComputerName + ")");
                this.mediaServerCore.OnDirectoriesChanged += new MediaServerCore.MediaServerCoreEventHandler(this.Sink_OnDirectoriesChanged);
                mediaServer = new UPnPMediaServer();

                // Pause State
                pauseServerMenuItem.Checked = this.mediaServerCore.IsPaused;
            }

            UpdateServiceUI();

            foreach(string arg in args)
            {
                p[0] = arg;
                switch(p[1].ToUpper())
                {
                    case "-P":
                        filePaths[0] = p[2];
                        try
                        {
                            this.AddDirs(filePaths);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        break;
                }
            }
        }
예제 #4
0
 private void Sink_OnDirectoriesChanged(MediaServerCore sender)
 {
     this.UpdateDirectoriesUI();
 }
 public void Dispose()
 {
     rootContainer = null;
     mediaServer.Dispose();
     mediaServer = null;
     serverCore = null;
     this.m_DeviceWatcher = null;
     this.m_DeviceWatcher.OnSniff -= new OpenSource.UPnP.UPnPDeviceWatcher.SniffHandler(this.Sink_DeviceWatcherSniff);
 }
 private void MediaServerStatsChangedSink(MediaServerCore sender)
 {
     mediaServerStatsUpdateId++;
     if (mediaServerStatsUpdateId < 0) mediaServerStatsUpdateId = 1;
     if (MediaServerStatsChanged != null) MediaServerStatsChanged();
 }
 private void MediaServerCoreDebugSink(MediaServerCore sender, string msg)
 {
     if (MediaServerDebugMessage != null) MediaServerDebugMessage(msg);
 }
 private void MediaHttpTransferssChangedSink(MediaServerCore sender)
 {
     mediaHttpTransfersUpdateId++;
     if (mediaHttpTransfersUpdateId < 0) mediaHttpTransfersUpdateId = 1;
     if (MediaHttpTransfersChanged != null) MediaHttpTransfersChanged();
 }
 /// <summary>
 /// Stop this service.
 /// </summary>
 protected override void OnStop()
 {
     ChannelServices.UnregisterChannel(channel);
     channel = null;
     mediaServer.Dispose();
     mediaServer = null;
 }