コード例 #1
0
 // Currently not used; the shares edit workflow is started from the shares info screen calling EditCurrentShare.
 public void EditSelectedShare()
 {
     try
     {
         Share share = GetSelectedLocalShares().FirstOrDefault();
         if (share != null)
         {
             ShareProxy = new LocalShares(share);
         }
         else
         {
             share = GetSelectedServerShares().FirstOrDefault();
             if (share == null)
             {
                 // Should never happen
                 return;
             }
             ShareProxy = new ServerShares(share);
         }
         IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();
         workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_EDIT_CHOOSE_RESOURCE_PROVIDER);
     }
     catch (NotConnectedException)
     {
         DisconnectedError();
     }
     catch (Exception e)
     {
         ErrorEditShare(e);
     }
 }
コード例 #2
0
        protected void UpdateSharesList_NoLock(ItemsList list, List <Share> shareDescriptors, ShareOrigin origin, bool selectFirstItem)
        {
            list.Clear();
            bool selectShare = selectFirstItem;

            shareDescriptors.Sort((a, b) => a.Name.CompareTo(b.Name));
            foreach (Share share in shareDescriptors)
            {
                ListItem shareItem = new ListItem(Consts.KEY_NAME, share.Name);
                shareItem.AdditionalProperties[Consts.KEY_SHARE] = share;
                try
                {
                    string path = origin == ShareOrigin.Local ?
                                  LocalShares.GetLocalResourcePathDisplayName(share.BaseResourcePath) :
                                  ServerShares.GetServerResourcePathDisplayName(share.BaseResourcePath);
                    if (string.IsNullOrEmpty(path))
                    {
                        // Error case: The path is invalid
                        path = LocalizationHelper.Translate(Consts.RES_INVALID_PATH, share.BaseResourcePath);
                    }
                    shareItem.SetLabel(Consts.KEY_PATH, path);
                    Guid?firstResourceProviderId = SharesProxy.GetBaseResourceProviderId(share.BaseResourcePath);
                    if (firstResourceProviderId.HasValue)
                    {
                        ResourceProviderMetadata firstResourceProviderMetadata = origin == ShareOrigin.Local ?
                                                                                 LocalShares.GetLocalResourceProviderMetadata(firstResourceProviderId.Value) :
                                                                                 ServerShares.GetServerResourceProviderMetadata(firstResourceProviderId.Value);
                        shareItem.AdditionalProperties[Consts.KEY_RESOURCE_PROVIDER_METADATA] = firstResourceProviderMetadata;
                    }
                    string categories = StringUtils.Join(", ", share.MediaCategories);
                    shareItem.SetLabel(Consts.KEY_MEDIA_CATEGORIES, categories);
                    Share shareCopy = share;
                    shareItem.Command = new MethodDelegateCommand(() => ShowShareInfo(shareCopy, origin));
                }
                catch (NotConnectedException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("Problems building share item '{0}' (path '{1}')", e, share.Name, share.BaseResourcePath);
                }
                if (selectShare)
                {
                    selectShare        = false;
                    shareItem.Selected = true;
                }
                shareItem.SelectedProperty.Attach(OnShareItemSelectionChanged);
                lock (_syncObj)
                    list.Add(shareItem);
            }
            list.FireChange();
        }
コード例 #3
0
 protected internal async Task UpdateSharesLists_NoLock(bool create)
 {
     lock (_syncObj)
     {
         if (_updatingProperties)
         {
             return;
         }
         _updatingProperties = true;
         if (create)
         {
             _localSharesList = new ItemsList();
         }
         if (create)
         {
             _serverSharesList = new ItemsList();
         }
     }
     try
     {
         List <Share> localShareDescriptors  = new List <Share>(LocalShares.GetShares());
         List <Share> serverShareDescriptors = IsHomeServerConnected ?
                                               new List <Share>(await ServerShares.GetSharesAsync()) : new List <Share>(0);
         int numShares = localShareDescriptors.Count + serverShareDescriptors.Count;
         UpdateSharesList_NoLock(_localSharesList, localShareDescriptors, ShareOrigin.Local, numShares == 1);
         try
         {
             UpdateSharesList_NoLock(_serverSharesList, serverShareDescriptors, ShareOrigin.Server, numShares == 1);
         }
         catch (NotConnectedException)
         {
             _serverSharesList.Clear();
             _serverSharesList.FireChange();
             numShares = localShareDescriptors.Count;
         }
         ShowLocalShares  = !IsLocalHomeServer || _localSharesList.Count > 0;
         IsSharesSelected = numShares == 1;
         bool anySharesAvailable;
         lock (_syncObj)
             anySharesAvailable = _serverSharesList.Count > 0 || _localSharesList.Count > 0;
         AnyShareAvailable = anySharesAvailable;
     }
     catch (Exception ex)
     {
         ServiceRegistration.Get <ILogger>().Warn("Error updating shares list", ex);
     }
     finally
     {
         lock (_syncObj)
             _updatingProperties = false;
     }
 }
コード例 #4
0
 protected internal void UpdateSharesLists_NoLock(bool create)
 {
     lock (_syncObj)
     {
         if (_updatingProperties)
         {
             return;
         }
         _updatingProperties = true;
         if (create)
         {
             _localSharesList = new ItemsList();
         }
         if (create)
         {
             _serverSharesList = new ItemsList();
         }
     }
     try
     {
         List <Share> localShareDescriptors  = new List <Share>(LocalShares.GetShares());
         List <Share> serverShareDescriptors = IsHomeServerConnected ?
                                               new List <Share>(ServerShares.GetShares()) : new List <Share>(0);
         int numShares = localShareDescriptors.Count + serverShareDescriptors.Count;
         UpdateSharesList_NoLock(_localSharesList, localShareDescriptors, ShareOrigin.Local, numShares == 1);
         if (IsHomeServerConnected)
         {
             // If our home server is not connected, don't try to update its list of shares
             try
             {
                 UpdateSharesList_NoLock(_serverSharesList, serverShareDescriptors, ShareOrigin.Server, numShares == 1);
             }
             catch (NotConnectedException)
             {
                 _serverSharesList.Clear();
                 _serverSharesList.FireChange();
                 numShares = localShareDescriptors.Count;
             }
         }
         ShowLocalShares  = !IsLocalHomeServer || _localSharesList.Count > 0;
         IsSharesSelected = numShares == 1;
         bool anySharesAvailable;
         lock (_syncObj)
             anySharesAvailable = _serverSharesList.Count > 0 || _localSharesList.Count > 0;
         AnyShareAvailable = anySharesAvailable;
     }
     finally
     {
         lock (_syncObj)
             _updatingProperties = false;
     }
 }
コード例 #5
0
 public void RemoveSelectedSharesAndFinish()
 {
     try
     {
         LocalShares.RemoveShares(GetSelectedLocalShares());
         ServerShares.RemoveShares(GetSelectedServerShares());
         NavigateBackToOverview();
     }
     catch (NotConnectedException)
     {
         DisconnectedError();
     }
     catch (Exception e)
     {
         ErrorEditShare(e);
     }
 }
コード例 #6
0
        protected void ShowShareInfo(Share share, ShareOrigin origin)
        {
            if (share == null)
            {
                return;
            }
            if (origin == ShareOrigin.Local)
            {
                ShareProxy = new LocalShares(share);
            }
            else if (origin == ShareOrigin.Server)
            {
                ShareProxy = new ServerShares(share);
            }
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_INFO, new NavigationContextConfig {
                NavigationContextDisplayLabel = share.Name
            });
        }
コード例 #7
0
        private void CreateServerShareRPs(bool multipleSources, bool useCurrent = false)
        {
            ListItem     serverSystemItem = new ListItem(Consts.KEY_NAME, Consts.RES_SHARES_CONFIG_GLOBAL_SHARE);
            ServerShares proxy;

            if (useCurrent && _shareProxy is ServerShares)
            {
                proxy = (ServerShares)_shareProxy;
                proxy.SystemAffinity = ResourceProviderMetadata.SystemAffinity.Server;
            }
            else
            {
                proxy = new ServerShares {
                    SystemAffinity = ResourceProviderMetadata.SystemAffinity.Server, MultipleSources = multipleSources
                }
            };

            proxy.UpdateResourceProvidersList();
            proxy.IsResourceProviderSelectedProperty.Attach(OnResourceProviderSelected);
            serverSystemItem.AdditionalProperties[Consts.KEY_SHARES_PROXY] = proxy;
            serverSystemItem.SelectedProperty.Attach(OnSystemSelectionChanged);
            _systemsList.Add(serverSystemItem);
        }
コード例 #8
0
    public void Execute()
    {
      IServerConnectionManager serverConnectionManager = ServiceRegistration.Get<IServerConnectionManager>();
      IContentDirectory contentDirectory = serverConnectionManager.ContentDirectory;
      SystemName homeServerSystem = serverConnectionManager.LastHomeServerSystem;
      bool localHomeServer = homeServerSystem != null && homeServerSystem.IsLocalSystem();
      bool homeServerConncted = contentDirectory != null;

      ILocalSharesManagement localSharesManagement = ServiceRegistration.Get<ILocalSharesManagement>();
      if (localHomeServer)
      {
        if (homeServerConncted && contentDirectory.GetShares(null, SharesFilter.All).Count == 0)
        {
          IMediaAccessor mediaAccessor = ServiceRegistration.Get<IMediaAccessor>();
          foreach (Share share in mediaAccessor.CreateDefaultShares())
          {
            ServerShares serverShareProxy = new ServerShares(share);
            serverShareProxy.AddShare();
          }
        }
      }
      else
      {
        if (localSharesManagement.Shares.Count == 0)
          localSharesManagement.SetupDefaultShares();
      }
      // The shares config model listens to share update events from both the local shares management and the home server,
      // so we don't need to trigger an update of the shares lists here
    }
コード例 #9
0
 protected void ShowShareInfo(Share share, ShareOrigin origin)
 {
   if (share == null)
     return;
   if (origin == ShareOrigin.Local)
     ShareProxy = new LocalShares(share);
   else if (origin == ShareOrigin.Server)
     ShareProxy = new ServerShares(share);
   IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
   workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_INFO, new NavigationContextConfig { NavigationContextDisplayLabel = share.Name });
 }
コード例 #10
0
    private void CreateServerShareRPs(bool multipleSources, bool useCurrent = false)
    {
      ListItem serverSystemItem = new ListItem(Consts.KEY_NAME, Consts.RES_SHARES_CONFIG_GLOBAL_SHARE);
      ServerShares proxy;
      if (useCurrent && _shareProxy is ServerShares)
      {
        proxy = (ServerShares)_shareProxy;
        proxy.SystemAffinity = ResourceProviderMetadata.SystemAffinity.Server;
      }
      else
        proxy = new ServerShares { SystemAffinity = ResourceProviderMetadata.SystemAffinity.Server, MultipleSources = multipleSources };

      proxy.UpdateResourceProvidersList();
      proxy.IsResourceProviderSelectedProperty.Attach(OnResourceProviderSelected);
      serverSystemItem.AdditionalProperties[Consts.KEY_SHARES_PROXY] = proxy;
      serverSystemItem.SelectedProperty.Attach(OnSystemSelectionChanged);
      _systemsList.Add(serverSystemItem);
    }
コード例 #11
0
 // Currently not used; the shares edit workflow is started from the shares info screen calling EditCurrentShare.
 public void EditSelectedShare()
 {
   try
   {
     Share share = GetSelectedLocalShares().FirstOrDefault();
     if (share != null)
       ShareProxy = new LocalShares(share);
     else
     {
       share = GetSelectedServerShares().FirstOrDefault();
       if (share == null)
         // Should never happen
         return;
       ShareProxy = new ServerShares(share);
     }
     IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
     workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_EDIT_CHOOSE_RESOURCE_PROVIDER);
   }
   catch (NotConnectedException)
   {
     DisconnectedError();
   }
   catch (Exception e)
   {
     ErrorEditShare(e);
   }
 }