Example #1
0
 public LocalShares(Share share)
   : base(ShareEditMode.EditShare)
 {
   ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
   string localSystemName = systemResolver.GetSystemNameForSystemId(systemResolver.LocalSystemId).HostName ?? systemResolver.LocalSystemId;
   InitializePropertiesWithShare(share, localSystemName);
 }
Example #2
0
 /// <summary>
 /// Sends a message that a share was changed (<see cref="MessageType.ShareChanged"/>).
 /// </summary>
 /// <param name="share">Share which was changed.</param>
 /// <param name="relocationMode">Controls how the data of the changed share should be adapted at the server.</param>
 public static void SendShareChangedMessage(Share share, RelocationMode relocationMode)
 {
   SystemMessage msg = new SystemMessage(MessageType.ShareChanged);
   msg.MessageData[SHARE] = share;
   msg.MessageData[RELOCATION_MODE] = relocationMode;
   ServiceRegistration.Get<IMessageBroker>().Send(CHANNEL, msg);
 }
 public ServerShares(Share share) : base(ShareEditMode.EditShare)
 {
   IServerConnectionManager serverConnectionManager = ServiceRegistration.Get<IServerConnectionManager>();
   ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
   string nativeSystem = serverConnectionManager.LastHomeServerName;
   if (nativeSystem == null)
   {
     SystemName systemName = systemResolver.GetSystemNameForSystemId(serverConnectionManager.HomeServerSystemId);
     if (systemName != null)
       nativeSystem = systemName.HostName;
   }
   if (nativeSystem == null)
     nativeSystem = serverConnectionManager.HomeServerSystemId;
   InitializePropertiesWithShare(share, nativeSystem);
 }
 /// <summary>
 /// Helper method which simulates a user navigation under this view specification to the given <paramref name="targetPath"/>
 /// under the given <paramref name="localShare"/>.
 /// </summary>
 /// <param name="localShare">Client or server share which is located at the local system.</param>
 /// <param name="targetPath">Resource path to navigate to. This path must be located under the given <paramref name="localShare"/>'s base path.</param>
 /// <param name="navigateToViewDlgt">Callback which will be called for each view specification to navigate to to do the actual navigation.</param>
 public void Navigate(Share localShare, ResourcePath targetPath, NavigateToViewDlgt navigateToViewDlgt)
 {
   NavigateToLocalRootView(localShare, navigateToViewDlgt);
   IResourceAccessor startRA;
   if (!localShare.BaseResourcePath.TryCreateLocalResourceAccessor(out startRA))
     return;
   IFileSystemResourceAccessor current = startRA as IFileSystemResourceAccessor;
   if (current == null)
   {
     // Wrong path resource, cannot navigate. Should not happen if the share is based on a filesystem resource,
     // but might happen if we have found a non-standard share.
     startRA.Dispose();
     return;
   }
   while (true)
   {
     ICollection<IFileSystemResourceAccessor> children = FileSystemResourceNavigator.GetChildDirectories(current, false);
     current.Dispose();
     current = null;
     if (children != null)
       foreach (IFileSystemResourceAccessor childDirectory in children)
         using (childDirectory)
         {
           if (childDirectory.CanonicalLocalResourcePath.IsSameOrParentOf(targetPath))
           {
             current = childDirectory;
             break;
           }
         }
     if (current == null)
       break;
     ViewSpecification newVS = NavigateCreateViewSpecification(localShare.SystemId, current);
     if (newVS == null)
     {
       current.Dispose();
       return;
     }
     navigateToViewDlgt(newVS);
   }
 }
 protected void ShowShareInfo(Share share, ShareOrigin origin)
 {
   if (share == null)
     return;
   if (origin == ShareOrigin.Local)
     lock (_syncObj)
       _shareProxy = new LocalShares(share);
   else if (origin == ShareOrigin.Server)
     lock (_syncObj)
       _shareProxy = new ServerShares(share);
   IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
   workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_INFO, new NavigationContextConfig { NavigationContextDisplayLabel = share.Name });
 }
 /// <summary>
 /// According to the actual class (local media/browse media), this method simulates a user navigation to the given <paramref name="localShare"/>.
 /// </summary>
 /// <param name="localShare">Client or server share which is located at the local system.</param>
 /// <param name="navigateToViewDlgt">Callback which will be called for each view specification to navigate to to do the actual navigation.</param>
 protected abstract void NavigateToLocalRootView(Share localShare, NavigateToViewDlgt navigateToViewDlgt);
Example #7
0
 /// <summary>
 /// Sends a message that tells clients that a local share should be re-imported (<see cref="MessageType.ReImportShare"/>).
 /// </summary>
 /// <param name="share">Local share that should be re-imported.</param>
 public static void SendShareReimportMessage(Share share)
 {
   SystemMessage msg = new SystemMessage(MessageType.ReImportShare);
   msg.MessageData[SHARE] = share;
   ServiceRegistration.Get<IMessageBroker>().Send(CHANNEL, msg);
 }
Example #8
0
    protected void TryCancelLocalImportJobs(Share share)
    {
      IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();

      if (share.SystemId == _localSystemId)
        importerWorker.CancelJobsForPath(share.BaseResourcePath);
    }
 public void RegisterShare(Share share)
 {
   CpAction action = GetAction("RegisterShare");
   IList<object> inParameters = new List<object> {share};
   action.InvokeAction(inParameters);
 }
Example #10
0
 protected Share GetShare(ITransaction transaction, Guid shareId)
 {
   int systemIdIndex;
   int pathIndex;
   int shareNameIndex;
   ISQLDatabase database = transaction.Database;
   Share share;
   using (IDbCommand command = MediaLibrary_SubSchema.SelectShareByIdCommand(transaction, shareId, out systemIdIndex, out pathIndex, out shareNameIndex))
   using (IDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
   {
     if (!reader.Read())
       return null;
     share = new Share(shareId, database.ReadDBValue<string>(reader, systemIdIndex), ResourcePath.Deserialize(
         database.ReadDBValue<string>(reader, pathIndex)),
         database.ReadDBValue<string>(reader, shareNameIndex), null);
   }
   // Init share categories later to avoid opening new result sets inside reader loop (issue with MySQL)
   ICollection<string> mediaCategories = GetShareMediaCategories(transaction, shareId);
   CollectionUtils.AddAll(share.MediaCategories, mediaCategories);
   return share;
 }
Example #11
0
    protected void TryScheduleLocalShareImport(Share share)
    {
      IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();

      if (share.SystemId == _localSystemId)
        importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
    }
Example #12
0
 public Guid CreateShare(string systemId, ResourcePath baseResourcePath, string shareName,
     IEnumerable<string> mediaCategories)
 {
   Guid shareId = Guid.NewGuid();
   ServiceRegistration.Get<ILogger>().Info("MediaLibrary: Creating new share '{0}'", shareId);
   Share share = new Share(shareId, systemId, baseResourcePath, shareName, mediaCategories);
   RegisterShare(share);
   return shareId;
 }
Example #13
0
    public void RegisterShare(Share share)
    {
      ServiceRegistration.Get<ILogger>().Info("MediaLibrary: Registering share '{0}' at system {1}: Setting name '{2}', base resource path '{3}' and media categories '{4}'",
          share.ShareId, share.SystemId, share.Name, share.BaseResourcePath, StringUtils.Join(", ", share.MediaCategories));
      ISQLDatabase database = ServiceRegistration.Get<ISQLDatabase>();
      ITransaction transaction = database.BeginTransaction();
      try
      {
        int shareIdIndex;
        using (IDbCommand command = MediaLibrary_SubSchema.SelectShareIdCommand(
            transaction, share.SystemId, share.BaseResourcePath, out shareIdIndex))
        using (IDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
        {
          if (reader.Read())
            throw new ShareExistsException("A share with the given system '{0}' and path '{1}' already exists",
                share.SystemId, share.BaseResourcePath);
        }
        using (IDbCommand command = MediaLibrary_SubSchema.InsertShareCommand(transaction, share.ShareId, share.SystemId,
            share.BaseResourcePath, share.Name))
          command.ExecuteNonQuery();

        foreach (string mediaCategory in share.MediaCategories)
          AddMediaCategoryToShare(transaction, share.ShareId, mediaCategory);

        transaction.Commit();

        ContentDirectoryMessaging.SendRegisteredSharesChangedMessage();

        TryScheduleLocalShareImport(share);
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("MediaLibrary: Error registering share '{0}'", e, share.ShareId);
        transaction.Rollback();
        throw;
      }
    }
Example #14
0
 protected bool InitializePropertiesWithShare(Share share, string nativeSystem)
 {
   _origShare = share;
   BaseResourceProvider = GetBaseResourceProviderMetadata(share.BaseResourcePath);
   NativeSystem = nativeSystem;
   ChoosenResourcePath = share.BaseResourcePath;
   ShareName = share.Name;
   UpdateMediaCategories(share.MediaCategories);
   return true;
 }
    protected override void NavigateToLocalRootView(Share localShare, NavigateToViewDlgt navigateToViewDlgt)
    {
      // We need to simulate the logic from method ReLoadItemsAndSubViewSpecifications
      IServerConnectionManager serverConnectionManager = ServiceRegistration.Get<IServerConnectionManager>();

      if (!IsSingleSeat(serverConnectionManager))
      {
        string viewName;
        if (localShare.SystemId == serverConnectionManager.HomeServerSystemId)
          viewName = serverConnectionManager.LastHomeServerName;
        else
        {
          MPClientMetadata clientMetadata = ServerCommunicationHelper.GetClientMetadata(localShare.SystemId);
          viewName = clientMetadata == null ? null : clientMetadata.LastClientName;
        }
        if (viewName != null)
          navigateToViewDlgt(new SystemSharesViewSpecification(localShare.SystemId, viewName, _necessaryMIATypeIds, _optionalMIATypeIds));
      }

      IContentDirectory cd = serverConnectionManager.ContentDirectory;
      if (cd == null)
        return;

      MediaItem parentDirectory = cd.LoadItem(localShare.SystemId, localShare.BaseResourcePath,
          SystemSharesViewSpecification.DIRECTORY_MIA_ID_ENUMERATION, SystemSharesViewSpecification.EMPTY_ID_ENUMERATION);
      if (parentDirectory == null)
        return;
      navigateToViewDlgt(new MediaLibraryBrowseViewSpecification(localShare.Name, parentDirectory.MediaItemId,
            localShare.SystemId, localShare.BaseResourcePath, _necessaryMIATypeIds, _optionalMIATypeIds));
    }
 protected override void NavigateToLocalRootView(Share localShare, NavigateToViewDlgt navigateToViewDlgt)
 {
   // We need to simulate the logic from method ReLoadItemsAndSubViewSpecifications
   ICollection<Share> localServerShares;
   ICollection<Share> localClientShares;
   GetShares(out localServerShares, out localClientShares);
   if (localServerShares.Count > 0 && localClientShares.Count > 0)
   {
     IServerConnectionManager serverConnectionManager = ServiceRegistration.Get<IServerConnectionManager>();
     ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
     if (localShare.SystemId == serverConnectionManager.HomeServerSystemId)
       navigateToViewDlgt(new LocalSharesViewSpecification(localServerShares, Consts.RES_SERVER_SHARES_VIEW_NAME, _necessaryMIATypeIds, _optionalMIATypeIds));
     else if (localShare.SystemId == systemResolver.LocalSystemId)
       navigateToViewDlgt(new LocalSharesViewSpecification(localClientShares, Consts.RES_CLIENT_SHARES_VIEW_NAME, _necessaryMIATypeIds, _optionalMIATypeIds));
   }
   navigateToViewDlgt(new LocalDirectoryViewSpecification(localShare.Name, localShare.BaseResourcePath, _necessaryMIATypeIds, _optionalMIATypeIds));
 }
 public void ReImportShare(Share share)
 {
   IServerConnectionManager scm = ServiceRegistration.Get<IServerConnectionManager>();
   IServerController sc = scm.ServerController;
   if (sc == null)
     return;
   sc.ScheduleImports(new Guid[] { share.ShareId }, ImportJobType.Refresh);
 }
Example #18
0
 protected bool InitializePropertiesWithShare(Share share, string nativeSystem)
 {
   _origShare = share;
   BaseResourceProvider = GetBaseResourceProviderMetadata(share.BaseResourcePath);
   NativeSystem = nativeSystem;
   ChoosenResourcePath = share.BaseResourcePath;
   ShareName = share.Name;
   MediaCategories.Clear();
   CollectionUtils.AddAll(MediaCategories, share.MediaCategories);
   return true;
 }