Пример #1
0
        public IResourceAccessor CreateAccessor()
        {
            ISystemResolver   systemResolver = ServiceRegistration.Get <ISystemResolver>();
            IResourceAccessor result;

            if (_nativeResourcePath.IsNetworkResource)
            {
                if (_nativeResourcePath.TryCreateLocalResourceAccessor(out result))
                {
                    return(result);
                }
            }
            SystemName nativeSystem = systemResolver.GetSystemNameForSystemId(_nativeSystemId);

            if (nativeSystem == null)
            {
                throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}': System is not available", _nativeResourcePath, _nativeSystemId);
            }
            // Try to access resource locally. This might work if we have the correct resource providers installed.
            if (nativeSystem.IsLocalSystem() && _nativeResourcePath.IsValidLocalPath && _nativeResourcePath.TryCreateLocalResourceAccessor(out result))
            {
                return(result);
            }
            IFileSystemResourceAccessor fsra;

            if (RemoteFileSystemResourceAccessor.ConnectFileSystem(_nativeSystemId, _nativeResourcePath, out fsra))
            {
                return(fsra);
            }
            throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}'", _nativeResourcePath, _nativeSystemId);
        }
        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
        }
 protected void UpdateProperties_NoLock()
 {
     lock (_syncObj)
     {
         if (_updatingProperties)
         {
             return;
         }
         _updatingProperties = true;
     }
     try
     {
         IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
         IsHomeServerConnected = serverConnectionManager.IsHomeServerConnected;
         SystemName homeServerSystem = serverConnectionManager.LastHomeServerSystem;
         IsLocalHomeServer = homeServerSystem != null && homeServerSystem.IsLocalSystem();
         lock (_syncObj)
         {
             _isAttached         = homeServerSystem != null;
             _enableLocalShares  = !IsLocalHomeServer;
             _enableServerShares = IsHomeServerConnected;
         }
     }
     finally
     {
         lock (_syncObj)
             _updatingProperties = false;
     }
 }
Пример #4
0
        public bool TryCreateResourceAccessor(string path, out IResourceAccessor result)
        {
            string       nativeSystemId;
            ResourcePath nativeResourcePath;

            if (!TryExtractSystemAndPath(path, out nativeSystemId, out nativeResourcePath))
            {
                throw new InvalidDataException("Path '{0}' is not a valid path for remote resource provider", path);
            }
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            SystemName      nativeSystem   = systemResolver.GetSystemNameForSystemId(nativeSystemId);

            if (nativeSystem == null)
            {
                throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}': System is not available", nativeResourcePath, nativeSystemId);
            }
            // Try to access resource locally. This might work if we have the correct resource providers installed.
            if (nativeSystem.IsLocalSystem() && nativeResourcePath.IsValidLocalPath && nativeResourcePath.TryCreateLocalResourceAccessor(out result))
            {
                return(true);
            }
            IFileSystemResourceAccessor fsra;

            if (RemoteFileSystemResourceAccessor.ConnectFileSystem(nativeSystemId, nativeResourcePath, out fsra))
            {
                result = fsra;
                return(true);
            }
            result = null;
            return(false);
        }
Пример #5
0
        public void Execute()
        {
            IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
            SystemName homeServerSystem    = serverConnectionManager.LastHomeServerSystem;
            bool       localHomeServer     = homeServerSystem != null && homeServerSystem.IsLocalSystem();
            bool       homeServerConnected = serverConnectionManager.IsHomeServerConnected;

            if (localHomeServer && !homeServerConnected)
            {
                // Our home server is local, i.e. all shares of this system must be configured at the server, but the server is not online at the moment.
                IDialogManager dialogManager = ServiceRegistration.Get <IDialogManager>();
                dialogManager.ShowDialog(Consts.RES_CANNOT_ADD_SHARES_TITLE, Consts.RES_CANNOT_ADD_SHARE_LOCAL_HOME_SERVER_NOT_CONNECTED, DialogType.OkDialog, false,
                                         DialogButtonType.Ok);
                return;
            }
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePush(Consts.WF_STATE_ID_SHARE_ADD_CHOOSE_SYSTEM);
        }
Пример #6
0
        public void Execute()
        {
            IWorkflowManager         workflowManager         = ServiceRegistration.Get <IWorkflowManager>();
            IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        contentDirectory        = serverConnectionManager.ContentDirectory;
            SystemName homeServerSystem   = serverConnectionManager.LastHomeServerSystem;
            bool       localHomeServer    = homeServerSystem == null ? false : homeServerSystem.IsLocalSystem();
            bool       homeServerConncted = contentDirectory != null;

            ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();

            if (localHomeServer)
            {
                if (homeServerConncted && contentDirectory.GetShares(null, SharesFilter.All).Count == 0)
                {
                    contentDirectory.SetupDefaultServerShares();
                }
                // Update of shares lists is only necessary in case the shares are managed by our home server because
                // in this case, we don't get a notification about the change in the set of shares.
                // Maybe we should add such a notification later...
                SharesConfigModel model = workflowManager.GetModel(SharesConfigModel.MODEL_ID_SHARESCONFIG) as SharesConfigModel;
                if (model != null)
                {
                    model.UpdateSharesLists_NoLock(false);
                }
            }
            else
            {
                if (localSharesManagement.Shares.Count == 0)
                {
                    localSharesManagement.SetupDefaultShares();
                }
                // The shares config model listens to update events from the local shares management, so we don't need to
                // trigger an update of the shares lists here
            }
        }
Пример #7
0
        protected static bool IsSingleSeat(IServerConnectionManager serverConnectionManager)
        {
            SystemName             homeServerSystem      = serverConnectionManager.LastHomeServerSystem;
            bool                   isLocalHomeServer     = homeServerSystem != null && homeServerSystem.IsLocalSystem();
            IServerController      serverController      = serverConnectionManager.ServerController;
            ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();
            ICollection <Share>    localClientShares     = localSharesManagement.Shares.Values;

            return(serverController != null && serverController.GetAttachedClients().Count == 1 && isLocalHomeServer && localClientShares.Count == 0);
        }
        protected void GetShares(out ICollection <Share> localServerShares, out ICollection <Share> localClientShares)
        {
            IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
            SystemName             homeServerSystem          = serverConnectionManager.LastHomeServerSystem;
            bool                   isLocalHomeServer         = homeServerSystem != null && homeServerSystem.IsLocalSystem();
            IContentDirectory      cd = serverConnectionManager.ContentDirectory;
            ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();

            localServerShares = (isLocalHomeServer && cd != null) ? cd.GetShares(serverConnectionManager.HomeServerSystemId, SharesFilter.All) : new List <Share>();
            localClientShares = localSharesManagement.Shares.Values;
        }
Пример #9
0
        protected internal async Task UpdateShareLists_NoLock(bool create)
        {
            lock (_syncObj)
            {
                if (_updatingProperties)
                {
                    return;
                }
                _updatingProperties = true;
                if (create)
                {
                    _serverSharesList = new ItemsList();
                    _localSharesList  = new ItemsList();
                }
            }
            try
            {
                ILocalSharesManagement sharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();
                var shares = sharesManagement.Shares.Values;
                _localSharesList.Clear();
                foreach (Share share in shares)
                {
                    ListItem item = new ListItem();
                    item.SetLabel(Consts.KEY_NAME, share.Name);
                    item.AdditionalProperties[Consts.KEY_SHARE] = share;
                    if (UserProxy != null)
                    {
                        item.Selected = UserProxy.SelectedShares.Contains(share.ShareId);
                    }
                    lock (_syncObj)
                        _localSharesList.Add(item);
                }

                IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
                if (scm == null || scm.ContentDirectory == null)
                {
                    return;
                }

                // add users to expose them
                shares = await scm.ContentDirectory.GetSharesAsync(scm.HomeServerSystemId, SharesFilter.All);

                _serverSharesList.Clear();
                foreach (Share share in shares)
                {
                    ListItem item = new ListItem();
                    item.SetLabel(Consts.KEY_NAME, share.Name);
                    item.AdditionalProperties[Consts.KEY_SHARE] = share;
                    if (UserProxy != null)
                    {
                        item.Selected = UserProxy.SelectedShares.Contains(share.ShareId);
                    }
                    lock (_syncObj)
                        _serverSharesList.Add(item);
                }
                SystemName homeServerSystem = scm.LastHomeServerSystem;
                IsLocalHomeServer     = homeServerSystem != null && homeServerSystem.IsLocalSystem();
                IsHomeServerConnected = homeServerSystem != null;
                ShowLocalShares       = !IsLocalHomeServer || _localSharesList.Count > 0;
                AnyShareAvailable     = _serverSharesList.Count > 0 || _localSharesList.Count > 0;
            }
            catch (NotConnectedException)
            {
                throw;
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Problems updating shares", e);
            }
            finally
            {
                lock (_syncObj)
                    _updatingProperties = false;
            }
        }