public void Activated(PluginRuntime pluginRuntime)
        {
            if (_isInitialized)
                return;

            _isInitialized = true;


            // All non-default media item aspects must be registered
            var miatr = ServiceRegistration.Get<IMediaItemAspectTypeRegistration>();
            miatr.RegisterLocallyKnownMediaItemAspectType(OnlineVideosAspect.Metadata);

            InitializeOnlineVideoSettings();

            // create a message queue for OnlineVideos to broadcast that the list of site utils was rebuild
            _messageQueue = new AsynchronousMessageQueue(this, new string[] { OnlineVideosMessaging.CHANNEL });
            _messageQueue.Start();

            // load and update sites in a background thread, it takes time and we are on the Main thread delaying MP2 startup
            ServiceRegistration.Get<IThreadPool>().Add(
                InitialSitesUpdateAndLoad,
                "OnlineVideos Initial Sites Load & Update",
                QueuePriority.Low,
                ThreadPriority.BelowNormal,
                AfterInitialLoad);
        }
Beispiel #2
0
 public void Activated(PluginRuntime pluginRuntime)
 {
   messageQueue = new AsynchronousMessageQueue(this,
     new string[] {SystemMessaging.CHANNEL, PlayerManagerMessaging.CHANNEL});
   messageQueue.MessageReceived += OnMessageReceived;
   messageQueue.Start();
 }
 public void Install()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         ServerConnectionMessaging.CHANNEL
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         RemovableMediaMessaging.CHANNEL
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
        PlayerManagerMessaging.CHANNEL
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 public CommonNotificationService()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
       {
         ImporterWorkerMessaging.CHANNEL,
       });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 void SubscribeToMessages()
 {
   if (_messageQueue == null)
   {
     _messageQueue = new AsynchronousMessageQueue(this, new[] { SystemMessaging.CHANNEL, ServerConnectionMessaging.CHANNEL });
     _messageQueue.PreviewMessage += OnMessageReceived;
     _messageQueue.Start();
   }
 }
 void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         ServerConnectionMessaging.CHANNEL
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 public ConnectionListenerService()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
       {
         ServerConnectionMessaging.CHANNEL,
         NotificationServiceMessaging.CHANNEL,
       });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 public OnlineVideosWorkflowModel()
 {
     SiteGroupsList = new ItemsList();
     SitesList = new ItemsList();
     
     // create a message queue where we listen to changes to the sites
     _messageQueue = new AsynchronousMessageQueue(this, new string[] { OnlineVideosMessaging.CHANNEL });
     _messageQueue.MessageReceived += new MessageReceivedHandler(OnlineVideosMessageReceived);
     _messageQueue.Start();
 }
 private void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         PlayerManagerMessaging.CHANNEL,
         PlayerContextManagerMessaging.CHANNEL,
         WorkflowManagerMessaging.CHANNEL,
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 public NotificationsModel()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         NotificationServiceMessaging.CHANNEL,
         WorkflowManagerMessaging.CHANNEL,
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
   Update();
 }
    public WifiConnectionModel()
    {
      _isWifiAvailableProperty = new WProperty(typeof(bool), WlanClient.Instance.Interfaces.Length > 0);
      _networkList = new ItemsList();

      _queue = new AsynchronousMessageQueue(this, new string[]
        {
            WifiConnectionMessaging.CHANNEL,
        });
      _queue.MessageReceived += OnMessageReceived;
      _queue.Start();
    }
Beispiel #14
0
 public HomeServerModel()
 {
   _homeServerProperty = new WProperty(typeof(string), string.Empty);
   _isHomeServerAttachedProperty = new WProperty(typeof(bool), false);
   _isHomeServerConnectedProperty = new WProperty(typeof(bool), false);
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
       {
         ServerConnectionMessaging.CHANNEL
       });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
   SynchronizeHomeServer();
 }
    internal void DoInstall()
    {
      RegisterKeyBindings();

      // Set initial background
      UpdateBackground();

      // Install message queue
      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
           PlayerManagerMessaging.CHANNEL,
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
    void SubscribeToMessages()
    {
      if (_messageQueue != null)
        return;
      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
           PlayerManagerMessaging.CHANNEL,
           SystemMessaging.CHANNEL
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();

      _timer = new Timer(DEFAULT_CHECK_INTERVAL);
      _timer.Elapsed += CheckVideoResolution;
      _timer.Start();
    }
 public void Activated(PluginRuntime pluginRuntime)
 {
   ISystemStateService sss = ServiceRegistration.Get<ISystemStateService>();
   if (sss.CurrentState == SystemState.Running)
   {
     _reloadSkinActions.RegisterKeyActions();
     _loadSkinThemeActions.RegisterKeyActions();
   }
   else
   {
     _messageQueue = new AsynchronousMessageQueue(typeof(ReloadSkinActions), new string[]
       {
           SystemMessaging.CHANNEL
       });
     _messageQueue.MessageReceived += OnMessageReceived;
     _messageQueue.Start();
   }
 }
 void SubscribeToMessages()
 {
   AsynchronousMessageQueue messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
        ServerConnectionMessaging.CHANNEL,
        ContentDirectoryMessaging.CHANNEL,
     });
   messageQueue.MessageReceived += OnMessageReceived;
   messageQueue.Start();
   lock (_syncObj)
     _messageQueue = messageQueue;
 }
Beispiel #19
0
    public MediaLibrary()
    {
      ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
      _localSystemId = systemResolver.LocalSystemId;

      _mediaBrowsingCallback = new MediaBrowsingCallback(this);
      _importResultHandler = new ImportResultHandler(this);
      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
            ImporterWorkerMessaging.CHANNEL
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
 void SubscribeToMessages()
 {
   if (_messageQueue != null)
     return;
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         LocalizationMessaging.CHANNEL,
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 protected void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new[] { WindowsMessaging.CHANNEL });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
 private void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
         ContentDirectoryMessaging.CHANNEL
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
Beispiel #23
0
 private void OnMainFormShown(object sender, System.EventArgs e)
 {
   InitializeLocalizedControls();
   _messageQueue = new AsynchronousMessageQueue("Server main form", new string[]
     {
         ClientManagerMessaging.CHANNEL,
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
    public UPnPServerControllerServiceImpl() : base(
        UPnPTypesAndIds.SERVER_CONTROLLER_SERVICE_TYPE, UPnPTypesAndIds.SERVER_CONTROLLER_SERVICE_TYPE_VERSION,
        UPnPTypesAndIds.SERVER_CONTROLLER_SERVICE_ID)
    {
      // Used for system ID strings
      DvStateVariable A_ARG_TYPE_SystemId = new DvStateVariable("A_ARG_TYPE_SystemId", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_SystemId);

      // Used for bool values
      DvStateVariable A_ARG_TYPE_Bool = new DvStateVariable("A_ARG_TYPE_Bool", new DvStandardDataType(UPnPStandardDataType.Boolean))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_Bool);

      // Used to transport a system name - contains the hostname string
      DvStateVariable A_ARG_TYPE_SystemName = new DvStateVariable("A_ARG_TYPE_SystemName", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_SystemName);

      // Used to transport an enumeration of MPClientMetadata objects
      DvStateVariable A_ARG_TYPE_ClientMetadataEnumeration = new DvStateVariable("A_ARG_TYPE_ClientMetadataEnumeration", new DvExtendedDataType(UPnPExtendedDataTypes.DtMPClientMetadataEnumeration))
        {
            SendEvents = false
        };
      AddStateVariable(A_ARG_TYPE_ClientMetadataEnumeration);

      // CSV of GUID strings
      DvStateVariable A_ARG_TYPE_UuidEnumeration = new DvStateVariable("A_ARG_TYPE_UuidEnumeration", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_UuidEnumeration);

      // CSV of system id strings
      DvStateVariable A_ARG_TYPE_SystemIdEnumeration = new DvStateVariable("A_ARG_TYPE_SystemIdEnumeration", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_SystemIdEnumeration);

      // Used to transport the import modes "Import" and "Refresh" for the ImportLocation action
      DvStateVariable A_ARG_TYPE_ImportMode = new DvStateVariable("A_ARG_TYPE_ImportMode", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_ImportMode);

      AttachedClientsChangeCounter = new DvStateVariable("AttachedClientsChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(AttachedClientsChangeCounter);

      // Csv of client's system ids
      ConnectedClientsChangeCounter = new DvStateVariable("ConnectedClientsChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(ConnectedClientsChangeCounter);

      // More state variables go here

      DvAction attachClientAction = new DvAction("AttachClient", OnAttachClient,
          new DvArgument[] {
            new DvArgument("ClientSystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(attachClientAction);

      DvAction detachClientAction = new DvAction("DetachClient", OnDetachClient,
          new DvArgument[] {
            new DvArgument("ClientSystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(detachClientAction);

      DvAction getAttachedClientsAction = new DvAction("GetAttachedClients", OnGetAttachedClients,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("AttachedClients", A_ARG_TYPE_ClientMetadataEnumeration, ArgumentDirection.Out, true),
          });
      AddAction(getAttachedClientsAction);

      DvAction getConnectedClientsAction = new DvAction("GetConnectedClients", OnGetConnectedClients,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("ConnectedClients", A_ARG_TYPE_SystemIdEnumeration, ArgumentDirection.Out, true),
          });
      AddAction(getConnectedClientsAction);

      DvAction scheduleImportsAction = new DvAction("ScheduleImports", OnScheduleImports,
          new DvArgument[] {
            new DvArgument("ShareIds", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In, true),
            new DvArgument("ImportMode", A_ARG_TYPE_ImportMode, ArgumentDirection.In, true),
          },
          new DvArgument[] {
          });
      AddAction(scheduleImportsAction);

      DvAction getSystemNameForSytemIdAction = new DvAction("GetSystemNameForSystemId", OnGetSystemNameForSytemId,
          new DvArgument[] {
            new DvArgument("SystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("SystemName", A_ARG_TYPE_SystemName, ArgumentDirection.Out),
          });
      AddAction(getSystemNameForSytemIdAction);

      // More actions go here

      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
            ClientManagerMessaging.CHANNEL,
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
 void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[] { SystemMessaging.CHANNEL });
   _messageQueue.PreviewMessage += OnMessageReceived;
   _messageQueue.Start();
 }
 void InitializeMessageQueue()
 {
   _messageQueue = new AsynchronousMessageQueue(this, GetMessageChannels());
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }
    public UPnPContentDirectoryServiceImpl() : base(
        UPnPTypesAndIds.CONTENT_DIRECTORY_SERVICE_TYPE, UPnPTypesAndIds.CONTENT_DIRECTORY_SERVICE_TYPE_VERSION,
        UPnPTypesAndIds.CONTENT_DIRECTORY_SERVICE_ID)
    {
      // Used for a boolean value
      DvStateVariable A_ARG_TYPE_Bool = new DvStateVariable("A_ARG_TYPE_Bool", new DvStandardDataType(UPnPStandardDataType.Boolean))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_Bool);

      // Used for any single GUID value
      DvStateVariable A_ARG_TYPE_Uuid = new DvStateVariable("A_ARG_TYPE_Id", new DvStandardDataType(UPnPStandardDataType.Uuid))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_Uuid);

      // CSV of GUID strings
      DvStateVariable A_ARG_TYPE_UuidEnumeration = new DvStateVariable("A_ARG_TYPE_UuidEnumeration", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_UuidEnumeration);

      // Used for a system ID string
      DvStateVariable A_ARG_TYPE_SystemId = new DvStateVariable("A_ARG_TYPE_SystemId", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_SystemId);

      // Used for several parameters and result values
      DvStateVariable A_ARG_TYPE_Count = new DvStateVariable("A_ARG_TYPE_Count", new DvStandardDataType(UPnPStandardDataType.Int))
          {
            SendEvents = false
          }; // Is int sufficient here?
      AddStateVariable(A_ARG_TYPE_Count);

      // Used to transport a resource path expression
      DvStateVariable A_ARG_TYPE_ResourcePath = new DvStateVariable("A_ARG_TYPE_ResourcePath", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_ResourcePath);

      // Used to transport an enumeration of directories data
      DvStateVariable A_ARG_TYPE_ResourcePaths = new DvStateVariable("A_ARG_TYPE_ResourcePaths", new DvExtendedDataType(UPnPExtendedDataTypes.DtResourcePathMetadataEnumeration))
        {
            SendEvents = false
        };
      AddStateVariable(A_ARG_TYPE_ResourcePaths);

      // Used to hold names for several objects
      DvStateVariable A_ARG_TYPE_Name = new DvStateVariable("A_ARG_TYPE_Name", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_Name);

      // CSV of media category strings
      DvStateVariable A_ARG_TYPE_MediaCategoryEnumeration = new DvStateVariable("A_ARG_TYPE_MediaCategoryEnumeration", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_MediaCategoryEnumeration);

      // Used to transport the data of a share structure
      DvStateVariable A_ARG_TYPE_Share = new DvStateVariable("A_ARG_TYPE_Share", new DvExtendedDataType(UPnPExtendedDataTypes.DtShare))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_Share);

      // Used to transport an enumeration of shares data
      DvStateVariable A_ARG_TYPE_ShareEnumeration = new DvStateVariable("A_ARG_TYPE_ShareEnumeration", new DvExtendedDataType(UPnPExtendedDataTypes.DtShareEnumeration))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_ShareEnumeration);

      // Used to transport a media item aspect metadata structure
      DvStateVariable A_ARG_TYPE_MediaItemAspectMetadata = new DvStateVariable("A_ARG_TYPE_MediaItemAspectMetadata", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemAspectMetadata))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_MediaItemAspectMetadata);

      // Used to give a mode of relocating media items after a share edit.
      DvStateVariable A_ARG_TYPE_MediaItemRelocationMode = new DvStateVariable("A_ARG_TYPE_MediaItemRelocationMode", new DvStandardDataType(UPnPStandardDataType.String))
          {
            SendEvents = false,
            AllowedValueList = new List<string> {"Relocate", "ClearAndReImport"}
          };
      AddStateVariable(A_ARG_TYPE_MediaItemRelocationMode);

      // Used to transport an argument of type MediaItemQuery
      DvStateVariable A_ARG_TYPE_MediaItemQuery = new DvStateVariable("A_ARG_TYPE_MediaItemQuery", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemQuery))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItemQuery);

      // Used to transport a value indicating if only online objects are referred or all.
      DvStateVariable A_ARG_TYPE_OnlineState = new DvStateVariable("A_ARG_TYPE_OnlineState", new DvStandardDataType(UPnPStandardDataType.String))
        {
            SendEvents = false,
            AllowedValueList = new List<string> {"All", "OnlyOnline"}
        };
      AddStateVariable(A_ARG_TYPE_OnlineState);

      // Used to transport a value indicating if query has to be done case sensitive or not.
      DvStateVariable A_ARG_TYPE_CapitalizationMode = new DvStateVariable("A_ARG_TYPE_CapitalizationMode", new DvStandardDataType(UPnPStandardDataType.String))
      {
        SendEvents = false,
        AllowedValueList = new List<string> { "CaseSensitive", "CaseInsensitive" }
      };
      AddStateVariable(A_ARG_TYPE_CapitalizationMode);

      // Used to transport a single media item with some media item aspects
      DvStateVariable A_ARG_TYPE_MediaItem = new DvStateVariable("A_ARG_TYPE_MediaItem", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItem))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItem);

      // Used to transport a collection of media items with some media item aspects
      DvStateVariable A_ARG_TYPE_MediaItems = new DvStateVariable("A_ARG_TYPE_MediaItems", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemEnumeration))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItems);

      // Used to transport a single media item filter
      DvStateVariable A_ARG_TYPE_MediaItemFilter = new DvStateVariable("A_ARG_TYPE_MediaItemFilter", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemsFilter))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItemFilter);

      // Used to transport a collection of media item attribute values
      DvStateVariable A_ARG_TYPE_MediaItemAttributeValues = new DvStateVariable("A_ARG_TYPE_MediaItemAttributeValues", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemAttributeValues))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItemAttributeValues);

      // Used to transport an enumeration of media item aspects for a media item specified elsewhere
      DvStateVariable A_ARG_TYPE_MediaItemAspects = new DvStateVariable("A_ARG_TYPE_MediaItemAspects", new DvExtendedDataType(UPnPExtendedDataTypes.DtMediaItemAspectEnumeration))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_MediaItemAspects);

      // Used to transport the text to be used in a simple text search
      DvStateVariable A_ARG_TYPE_SearchText = new DvStateVariable("A_ARG_TYPE_SearchText", new DvStandardDataType(UPnPStandardDataType.String))
        {
            SendEvents = false,
        };
      AddStateVariable(A_ARG_TYPE_SearchText);

      // Used to transport a value indicating if only online objects are referred or all.
      DvStateVariable A_ARG_TYPE_TextSearchMode = new DvStateVariable("A_ARG_TYPE_TextSearchMode", new DvStandardDataType(UPnPStandardDataType.String))
        {
            SendEvents = false,
            AllowedValueList = new List<string> {"Normal", "ExcludeCLOBs"}
        };
      AddStateVariable(A_ARG_TYPE_TextSearchMode);

      // Used to transport an enumeration of value group instances
      DvStateVariable A_ARG_TYPE_MLQueryResultGroupEnumeration = new DvStateVariable("A_ARG_TYPE_MLQueryResultGroupEnumeration", new DvExtendedDataType(UPnPExtendedDataTypes.DtMLQueryResultGroupEnumeration))
          {
            SendEvents = false,
          };
      AddStateVariable(A_ARG_TYPE_MLQueryResultGroupEnumeration);

      DvStateVariable A_ARG_TYPE_ProjectionFunction = new DvStateVariable("A_ARG_TYPE_ProjectionFunction", new DvStandardDataType(UPnPStandardDataType.String))
        {
            SendEvents = false,
            AllowedValueList = new List<string> {"None", "DateToYear"}
        };
      AddStateVariable(A_ARG_TYPE_ProjectionFunction);

      DvStateVariable A_ARG_TYPE_GroupingFunction = new DvStateVariable("A_ARG_TYPE_GroupingFunction", new DvStandardDataType(UPnPStandardDataType.String))
        {
            SendEvents = false,
            AllowedValueList = new List<string> {"FirstCharacter"}
        };
      AddStateVariable(A_ARG_TYPE_GroupingFunction);

      // Used to transport the data of a PlaylistContents instance
      DvStateVariable A_ARG_TYPE_PlaylistContents = new DvStateVariable("A_ARG_TYPE_PlaylistContents", new DvExtendedDataType(UPnPExtendedDataTypes.DtPlaylistContents))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_PlaylistContents);

      // Used to transport the data of a PlaylistRawData instance
      DvStateVariable A_ARG_TYPE_PlaylistRawData = new DvStateVariable("A_ARG_TYPE_PlaylistRawData", new DvExtendedDataType(UPnPExtendedDataTypes.DtPlaylistRawData))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_PlaylistRawData);

      // Used to transport an enumeration of playlist identification data (id, name) instances
      DvStateVariable A_ARG_TYPE_PlaylistIdentificationDataEnumeration = new DvStateVariable("A_ARG_TYPE_PlaylistIdentificationDataEnumeration", new DvExtendedDataType(UPnPExtendedDataTypes.DtPlaylistInformationDataEnumeration))
          {
            SendEvents = false
          };
      AddStateVariable(A_ARG_TYPE_PlaylistIdentificationDataEnumeration);

      // Used to transport an IDictionary<Guid, DateTime> such as the MediaItemAspectCreationDates
      DvStateVariable A_ARG_TYPE_DictionaryGuidDateTime = new DvStateVariable("A_ARG_TYPE_DictionaryGuidDateTime", new DvExtendedDataType(UPnPExtendedDataTypes.DtDictionaryGuidDateTime))
      {
        SendEvents = false
      };
      AddStateVariable(A_ARG_TYPE_DictionaryGuidDateTime);

      // Change event for playlists
      PlaylistsChangeCounter = new DvStateVariable("PlaylistsChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(PlaylistsChangeCounter);

      // Change event for MIA type registrations
      MIATypeRegistrationsChangeCounter = new DvStateVariable("MIATypeRegistrationsChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(MIATypeRegistrationsChangeCounter);

      // Change event for registered shares
      RegisteredSharesChangeCounter = new DvStateVariable("RegisteredSharesChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(RegisteredSharesChangeCounter);

      // Change event for currently importing shares
      CurrentlyImportingSharesChangeCounter = new DvStateVariable("CurrentlyImportingSharesChangeCounter", new DvStandardDataType(UPnPStandardDataType.Ui4))
        {
            SendEvents = true,
            Value = (uint) 0
        };
      AddStateVariable(CurrentlyImportingSharesChangeCounter);

      // More state variables go here

      // Shares management
      DvAction registerShareAction = new DvAction("RegisterShare", OnRegisterShare,
          new DvArgument[] {
            new DvArgument("Share", A_ARG_TYPE_Share, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(registerShareAction);

      DvAction removeShareAction = new DvAction("RemoveShare", OnRemoveShare,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In)
          },
          new DvArgument[] {
          });
      AddAction(removeShareAction);

      DvAction updateShareAction = new DvAction("UpdateShare", OnUpdateShare,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
            new DvArgument("BaseResourcePath", A_ARG_TYPE_ResourcePath, ArgumentDirection.In),
            new DvArgument("ShareName", A_ARG_TYPE_Name, ArgumentDirection.In),
            new DvArgument("MediaCategories", A_ARG_TYPE_MediaCategoryEnumeration, ArgumentDirection.In),
            new DvArgument("RelocateMediaItems", A_ARG_TYPE_MediaItemRelocationMode, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("NumAffectedMediaItems", A_ARG_TYPE_Count, ArgumentDirection.Out, true)
          });
      AddAction(updateShareAction);

      DvAction getSharesAction = new DvAction("GetShares", OnGetShares,
          new DvArgument[] {
            new DvArgument("SystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
            new DvArgument("SharesFilter", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("Shares", A_ARG_TYPE_ShareEnumeration, ArgumentDirection.Out, true)
          });
      AddAction(getSharesAction);

      DvAction getShareAction = new DvAction("GetShare", OnGetShare,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("Share", A_ARG_TYPE_Share, ArgumentDirection.Out, true)
          });
      AddAction(getShareAction);

      DvAction reImportShareAction = new DvAction("ReImportShare", OnReImportShare,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(reImportShareAction);

      DvAction setupDefaultServerSharesAction = new DvAction("SetupDefaultServerShares", OnSetupDefaultServerShares,
          new DvArgument[] {
          },
          new DvArgument[] {
          });
      AddAction(setupDefaultServerSharesAction);

      // Media item aspect storage management

      DvAction addMediaItemAspectStorageAction = new DvAction("AddMediaItemAspectStorage", OnAddMediaItemAspectStorage,
          new DvArgument[] {
            new DvArgument("MIAM", A_ARG_TYPE_MediaItemAspectMetadata, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(addMediaItemAspectStorageAction);

      DvAction removeMediaItemAspectStorageAction = new DvAction("RemoveMediaItemAspectStorage", OnRemoveMediaItemAspectStorage,
          new DvArgument[] {
            new DvArgument("MIAM_Id", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(removeMediaItemAspectStorageAction);

      DvAction getAllManagedMediaItemAspectTypesAction = new DvAction("GetAllManagedMediaItemAspectTypes", OnGetAllManagedMediaItemAspectTypes,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("MIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.Out, true),
          });
      AddAction(getAllManagedMediaItemAspectTypesAction);

      DvAction getAllManagedMediaItemAspectCreationDatesAction = new DvAction("GetAllManagedMediaItemAspectCreationDates", OnGetAllManagedMediaItemAspectCreationDates,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("MIACreationDates", A_ARG_TYPE_DictionaryGuidDateTime, ArgumentDirection.Out, true),
          });
      AddAction(getAllManagedMediaItemAspectCreationDatesAction);

      DvAction getMediaItemAspectMetadataAction = new DvAction("GetMediaItemAspectMetadata", OnGetMediaItemAspectMetadata,
          new DvArgument[] {
            new DvArgument("MIAM_Id", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MIAM", A_ARG_TYPE_MediaItemAspectMetadata, ArgumentDirection.Out, true),
          });
      AddAction(getMediaItemAspectMetadataAction);

      // Media query

      DvAction loadItemAction = new DvAction("LoadItem", OnLoadItem,
          new DvArgument[] {
            new DvArgument("SystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
            new DvArgument("Path", A_ARG_TYPE_ResourcePath, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("OptionalMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItem", A_ARG_TYPE_MediaItem, ArgumentDirection.Out, true),
          });
      AddAction(loadItemAction);

      DvAction browseAction = new DvAction("Browse", OnBrowse,
          new DvArgument[] {
            new DvArgument("ParentDirectory", A_ARG_TYPE_Uuid, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("OptionalMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItems", A_ARG_TYPE_MediaItems, ArgumentDirection.Out, true),
          });
      AddAction(browseAction);

      DvAction searchAction = new DvAction("Search", OnSearch,
          new DvArgument[] {
            new DvArgument("Query", A_ARG_TYPE_MediaItemQuery, ArgumentDirection.In),
            new DvArgument("OnlineState", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItems", A_ARG_TYPE_MediaItems, ArgumentDirection.Out, true),
          });
      AddAction(searchAction);

      DvAction textSearchAction = new DvAction("SimpleTextSearch", OnTextSearch,
          new DvArgument[] {
            new DvArgument("SearchText", A_ARG_TYPE_SearchText, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("OptionalMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("Filter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("SearchMode", A_ARG_TYPE_TextSearchMode, ArgumentDirection.In),
            new DvArgument("OnlineState", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
            new DvArgument("CapitalizationMode", A_ARG_TYPE_CapitalizationMode, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItems", A_ARG_TYPE_MediaItems, ArgumentDirection.Out, true),
          });
      AddAction(textSearchAction);

      DvAction getValueGroupsAction = new DvAction("GetValueGroups", OnGetValueGroups,
          new DvArgument[] {
            new DvArgument("MIAType", A_ARG_TYPE_Uuid, ArgumentDirection.In),
            new DvArgument("AttributeName", A_ARG_TYPE_Name, ArgumentDirection.In),
            new DvArgument("SelectAttributeFilter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("ProjectionFunction", A_ARG_TYPE_ProjectionFunction, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("Filter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("OnlineState", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("ValueGroups", A_ARG_TYPE_MediaItemAttributeValues, ArgumentDirection.Out, true),
          });
      AddAction(getValueGroupsAction);

      DvAction groupValueGroupsAction = new DvAction("GroupValueGroups", OnGroupValueGroups,
          new DvArgument[] {
            new DvArgument("MIAType", A_ARG_TYPE_Uuid, ArgumentDirection.In),
            new DvArgument("AttributeName", A_ARG_TYPE_Name, ArgumentDirection.In),
            new DvArgument("SelectAttributeFilter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("ProjectionFunction", A_ARG_TYPE_ProjectionFunction, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("Filter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("OnlineState", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
            new DvArgument("GroupingFunction", A_ARG_TYPE_GroupingFunction, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("ResultGroups", A_ARG_TYPE_MLQueryResultGroupEnumeration, ArgumentDirection.Out, true),
          });
      AddAction(groupValueGroupsAction);

      DvAction countMediaItemsAction = new DvAction("CountMediaItems", OnCountMediaItems,
          new DvArgument[] {
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("Filter", A_ARG_TYPE_MediaItemFilter, ArgumentDirection.In),
            new DvArgument("OnlineState", A_ARG_TYPE_OnlineState, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("NumMediaItems", A_ARG_TYPE_Count, ArgumentDirection.Out, true),
          });
      AddAction(countMediaItemsAction);

      // Playlist management

      DvAction getPlaylistsAction = new DvAction("GetPlaylists", OnGetPlaylists,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("Playlists", A_ARG_TYPE_PlaylistIdentificationDataEnumeration, ArgumentDirection.Out, true),
          });
      AddAction(getPlaylistsAction);

      DvAction savePlaylistAction = new DvAction("SavePlaylist", OnSavePlaylist,
          new DvArgument[] {
            new DvArgument("PlaylistRawData", A_ARG_TYPE_PlaylistRawData, ArgumentDirection.In)
          },
          new DvArgument[] {
          });
      AddAction(savePlaylistAction);

      DvAction deletePlaylistAction = new DvAction("DeletePlaylist", OnDeletePlaylist,
          new DvArgument[] {
            new DvArgument("PlaylistId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("Success", A_ARG_TYPE_Bool, ArgumentDirection.Out, true)
          });
      AddAction(deletePlaylistAction);

      DvAction exportPlaylistAction = new DvAction("ExportPlaylist", OnExportPlaylist,
          new DvArgument[] {
            new DvArgument("PlaylistId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("PlaylistRawData", A_ARG_TYPE_PlaylistRawData, ArgumentDirection.Out, true)
          });
      AddAction(exportPlaylistAction);

      DvAction loadCustomPlaylistAction = new DvAction("LoadCustomPlaylist", OnLoadCustomPlaylist,
          new DvArgument[] {
            new DvArgument("MediaItemIds", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("NecessaryMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
            new DvArgument("OptionalMIATypes", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItems", A_ARG_TYPE_MediaItems, ArgumentDirection.Out, true)
          });
      AddAction(loadCustomPlaylistAction);

      // Media import

      DvAction addOrUpdateMediaItemAction = new DvAction("AddOrUpdateMediaItem", OnAddOrUpdateMediaItem,
          new DvArgument[] {
            new DvArgument("ParentDirectoryId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
            new DvArgument("SystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
            new DvArgument("Path", A_ARG_TYPE_ResourcePath, ArgumentDirection.In),
            new DvArgument("UpdatedMediaItemAspects", A_ARG_TYPE_MediaItemAspects, ArgumentDirection.In),
          },
          new DvArgument[] {
            new DvArgument("MediaItemId", A_ARG_TYPE_Uuid, ArgumentDirection.Out, true),
          });
      AddAction(addOrUpdateMediaItemAction);

      DvAction deleteMediaItemOrPathAction = new DvAction("DeleteMediaItemOrPath", OnDeleteMediaItemOrPath,
          new DvArgument[] {
            new DvArgument("SystemId", A_ARG_TYPE_SystemId, ArgumentDirection.In),
            new DvArgument("Path", A_ARG_TYPE_ResourcePath, ArgumentDirection.In),
            new DvArgument("Inclusive", A_ARG_TYPE_Bool, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(deleteMediaItemOrPathAction);

      DvAction clientStartedShareImportAction = new DvAction("ClientStartedShareImport", OnClientStartedShareImport,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(clientStartedShareImportAction);

      DvAction clientCompletedShareImportAction = new DvAction("ClientCompletedShareImport", OnClientCompletedShareImport,
          new DvArgument[] {
            new DvArgument("ShareId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          },
          new DvArgument[] {
          });
      AddAction(clientCompletedShareImportAction);

      DvAction getCurrentlyImportingSharesAction = new DvAction("GetCurrentlyImportingShares", OnGetCurrentlyImportingShares,
          new DvArgument[] {
          },
          new DvArgument[] {
            new DvArgument("ShareIds", A_ARG_TYPE_UuidEnumeration, ArgumentDirection.Out, true), 
          });
      AddAction(getCurrentlyImportingSharesAction);

      // Media playback

      DvAction notifyPlaybackAction = new DvAction("NotifyPlayback", OnNotifyPlayback,
          new DvArgument[] {
            new DvArgument("MediaItemId", A_ARG_TYPE_Uuid, ArgumentDirection.In), 
          },
          new DvArgument[] {
          });
      AddAction(notifyPlaybackAction);

      // More actions go here

      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
            ContentDirectoryMessaging.CHANNEL,
            ImporterWorkerMessaging.CHANNEL,
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
Beispiel #28
0
    public SQLiteDatabase()
    {
      try
      {
        _maintenanceScheduler = new ActionBlock<bool>(async _ => await PerformDatabaseMaintenanceAsync(), new ExecutionDataflowBlockOptions { BoundedCapacity = 2 });
        _messageQueue = new AsynchronousMessageQueue(this, new[] { ContentDirectoryMessaging.CHANNEL });
        _messageQueue.MessageReceived += OnMessageReceived;
        _messageQueue.Start();

        _settings = ServiceRegistration.Get<ISettingsManager>().Load<SQLiteSettings>();
        _settings.LogSettings();

        LogVersionInformation();

        if (_settings.EnableTraceLogging)
        {
          _sqliteDebugLogger = FileLogger.CreateFileLogger(ServiceRegistration.Get<IPathManager>().GetPath(@"<LOG>\SQLiteDebug.log"), LogLevel.Debug, false, true);
          SQLiteLog.Initialize();
          SQLiteLog.RemoveDefaultHandler();
          SQLiteLog.Log += MPSQLiteLogEventHandler;
        }

        // We use our own collation sequence which is registered here to be able
        // to sort items taking into account culture specifics
        SQLiteFunction.RegisterFunction(typeof(SQLiteCultureSensitiveCollation));
        
        var pathManager = ServiceRegistration.Get<IPathManager>();
        string dataDirectory = pathManager.GetPath("<DATABASE>");
        string databaseFile = Path.Combine(dataDirectory, _settings.DatabaseFileName);

        // We use an URI instead of a simple database path and filename. The reason is that
        // only this way we can switch on the shared cache mode of SQLite in System.Data.SQLite
        // However, when using an URI, SQLite ignores the page size value specified in the connection string.
        // Therefore we have to use a workaround below to create a database file with the specified page size.
        string databaseFileForUri = databaseFile.Replace('\\', '/');
        string databaseUri = System.Web.HttpUtility.UrlPathEncode("file:///" + databaseFileForUri + "?cache=shared");

        _connectionPool = new ConnectionPool<SQLiteConnection>(CreateOpenAndInitializeConnection);

        // We are using the ConnectionStringBuilder to generate the connection string
        // This ensures code compatibility in case of changes to the SQLite connection string parameters
        // More information on the parameters can be found here: http://www.sqlite.org/pragma.html
        var connBuilder = new SQLiteConnectionStringBuilder
        {
          // Name of the database file including path as URI 
          FullUri = databaseUri,

          // Use SQLite database version 3.x  
          Version = 3,

          // Store GUIDs as binaries, not as string
          // Saves some space in the database and is said to make search queries on GUIDs faster  
          BinaryGUID = true,

          DefaultTimeout = _settings.LockTimeout,
          CacheSize = _settings.CacheSizeInPages,

          // Use the Write Ahead Log mode
          // In this journal mode write locks do not block reads
          // Needed to prevent sluggish behaviour of MP2 client when trying to read from the database (through MP2 server)
          // while MP2 server writes to the database (such as when importing shares)
          // More information can be found here: http://www.sqlite.org/wal.html
          JournalMode = SQLiteJournalModeEnum.Wal,

          // Do not use the inbuilt connection pooling of System.Data.SQLite
          // We use our own connection pool which is faster.
          Pooling = false,

          // Sychronization Mode "Normal" enables parallel database access while at the same time preventing database
          // corruption and is therefore a good compromise between "Off" (more performance) and "On"
          // More information can be found here: http://www.sqlite.org/pragma.html#pragma_synchronous
          SyncMode = SynchronizationModes.Normal,

          // MP2's database backend uses foreign key constraints to ensure referential integrity.
          // SQLite supports this, but it has to be enabled for each database connection by a PRAGMA command
          // For details see http://www.sqlite.org/foreignkeys.html
          ForeignKeys = true
        };

        if (_settings.EnableTraceLogging)
          connBuilder.Flags = SQLiteConnectionFlags.LogAll;

        _connectionString = connBuilder.ToString();
        ServiceRegistration.Get<ILogger>().Info("SQLiteDatabase: Connection String used: '{0}'", _connectionString);

        if (!File.Exists(databaseFile))
        {
          ServiceRegistration.Get<ILogger>().Info("SQLiteDatabase: Database file does not exists. Creating database file");

          if (!Directory.Exists(dataDirectory))
            Directory.CreateDirectory(dataDirectory);

          // Since we use an URI in the standard connection string and system.data.sqlite therefore
          // ignores the page size value in the connection string, this is a workaroung to make sure
          // the page size value as specified in the settings is used. When the database file does
          // not yet exists, we create a special connection string where we additionally set the
          // datasource (which overrides the URI) and the page size. We then create a connection with
          // that special connection string, open it and close it. That way the database file is created
          // with the desired page size. The page size is permanently stored in the database file so that
          // it is used when as of now we use connections with URI.
          connBuilder.DataSource = databaseFile;
          connBuilder.PageSize = _settings.PageSize;
          using (var connection = new SQLiteConnection(connBuilder.ToString()))
          {
            connection.Open();
            connection.Close();
          }
        }

        // The following is necessary to avoid the creation of of a shared memory index file
        // ("-shm"-file) when using exclusive locking mode. When WAL-mode is used, it is possible
        // to switch between normal and exclusive locking mode at any time. However, the creation
        // of a "-shm"-file can only be avoided, when exclusive locking mode is set BEFORE entering
        // WAL-mode. If this is the case, it is not possible to leave exclusive locking mode
        // without leaving WAL-mode before, because the "-shm"-file was not created.
        // The regular connections in our connection pool use WAL-mode. Therefore we have
        // to open one connection without WAL-Mode (here with JournalMode=OFF) and set locking_mode=
        // EXCLUSIVE before we create the first regular connection that goes into the pool.
        // To use exclusive locking mode, it is additionally necessary to set locking_mode=EXCLUSIVE
        // for every connection in the pool via the InitializationCommand. If "PRAGMA locking_mode=
        // EXCLUSIVE" is not in the InitializationCommand, normal locking mode is used
        // although we issue "PRAGMA locking_mode=EXCLUSIVE" at this point.
        // For details see here: http://sqlite.org/wal.html#noshm
        // Avoiding the creation of an "-shm"-file materially improves the database performance.
        if (_settings.UseExclusiveMode)
        {
          connBuilder.JournalMode = SQLiteJournalModeEnum.Off;
          using (var connection = new SQLiteConnection(connBuilder.ToString()))
          {
            connection.Open();
            using (var command = new SQLiteCommand(SQLiteSettings.EXCLUSIVE_MODE_COMMAND, connection))
              command.ExecuteNonQuery();
            connection.Close();
          }
        }

        // Just test one "regular" connection, which is the first connection in the pool
        using (var transaction = BeginTransaction())
          transaction.Rollback();
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Critical("SQLiteDatabase: Error establishing database connection", e);
        throw;
      }
    }
Beispiel #29
0
    public MainForm(ScreenManager screenManager)
    {
      _adaptToSizeEnabled = false;
      _screenManager = screenManager;

      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
      ServiceRegistration.Set<IScreenControl>(this);

      InitializeComponent();
      CheckForIllegalCrossThreadCalls = false;

      AppSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<AppSettings>();

      _previousMousePosition = new Point(-1, -1);

      Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

      _previousWindowLocation = Location;
      _previousWindowClientSize = desiredWindowedSize;
      _previousWindowState = FormWindowState.Normal;

      if (settings.FullScreen)
        SwitchToFullscreen(settings.FSScreenNum);
      else
        SwitchToWindowedSize(Location, desiredWindowedSize, false);

      SkinContext.WindowSize = ClientSize;

      // GraphicsDevice has to be initialized after the form was sized correctly
      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
      GraphicsDevice.Initialize_MainThread(this);

      // Read and apply ScreenSaver settings
      _screenSaverTimeOut = TimeSpan.FromMinutes(settings.ScreenSaverTimeoutMin);
      _isScreenSaverEnabled = settings.ScreenSaverEnabled;

      _applicationSuspendLevel = settings.SuspendLevel;
      UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

      Application.Idle += OnApplicationIdle;
      _adaptToSizeEnabled = true;

      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
            PlayerManagerMessaging.CHANNEL,
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
Beispiel #30
0
 void SubscribeToMessages()
 {
   _messageQueue = new AsynchronousMessageQueue(this, new string[]
     {
        SkinResourcesMessaging.CHANNEL,
     });
   _messageQueue.MessageReceived += OnMessageReceived;
   _messageQueue.Start();
 }