Example #1
0
        private void WebDriveThread(object state)
        {
            do
            {
                try
                {
                    // Important - Initialize must be called before using ShellBoost (except the calls to Install and Uninstall methods)
                    Initializer.Initialize();

                    using (var server = new WebShellFolderServer())
                    {
                        var config = new ShellFolderConfiguration();
                        config.Logger = new Logger(this);

                        server.Start(config);
                        AppendText("Started listening on proxy id " + ShellFolderServer.ProxyId);

                        if (ShellFolderServer.LocationFolderId != Guid.Empty)
                        {
                            Dispatcher.BeginInvoke(() =>
                            {
                                Open.IsEnabled = true;
                            });
                        }
                        _serverStopEvent.WaitOne();
                        return;
                    }
                }
                catch (Exception e)
                {
                    AppendText(e.Message);
                    Thread.Sleep(1000);
                }
            }while (true);
        }
        private void WebDriveThread(object state)
        {
            do
            {
                try
                {
                    using (var server = new WebShellFolderServer())
                    {
                        var config = new ShellFolderConfiguration();
                        config.Logger = new Logger(this);

                        server.Start(config);
                        AppendText("Started listening on proxy id " + ShellFolderServer.ProxyId);

                        if (ShellFolderServer.LocationFolderId != Guid.Empty)
                        {
                            Dispatcher.BeginInvoke(() =>
                            {
                                Open.IsEnabled = true;
                            });
                        }
                        _serverStopEvent.WaitOne();
                        return;
                    }
                }
                catch (Exception e)
                {
                    AppendText(e.Message);
                    Thread.Sleep(1000);
                }
            }while (true);
        }
Example #3
0
        public LocalEvents(WebShellFolderServer server, int synchronizePeriod = 60000)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            Server            = server;
            SynchronizePeriod = synchronizePeriod;

            _watcher        = new LocalFileSystemWatcher(WebApi.LocalDirectory.FullName);
            _watcher.Event += OnWatcherEvent;
            _watcher.Start();

            _synchronizeTimer = new Timer(SynchronizeCallback);
            _synchronizeTimer.Change(SynchronizePeriod, Timeout.Infinite);
        }
Example #4
0
        public ServerEvents(WebShellFolderServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            Server = server;
            // build SignalR connection
            _connection = new HubConnectionBuilder()
                          .WithUrl(WebApi.RootUrl + "events")
                          .WithAutomaticReconnect()
                          .Build();

            _connection.Closed += async(error) =>
            {
                // restart
                await Task.Delay(new Random().Next(0, 5) * 1000).ConfigureAwait(false);

                await _connection.StartAsync().ConfigureAwait(false);
            };

            // must match server's IFileSystemEvents method signature
            // Change(Guid id, Guid itemId, Guid parentId, WatcherChangeTypes types, DateTime creationTimeUtc, string oldName);
            _connection.On <Guid, Guid, Guid, WatcherChangeTypes, DateTime, string, Guid?>("Change", (id, itemId, parentId, type, creationTimeUtc, oldName, oldParentId) =>
            {
                // invalidate the cache using server information
                // note we don't force files update. this will be done when the use opens it
                server.Log(System.Diagnostics.TraceLevel.Warning, "UpdateCache id: " + id + " itemId: " + itemId + " parentId: " + parentId + " type: " + type + " oldName: " + oldName + " oldParentId: " + oldParentId);
                WebApi.UpdateCache(itemId, parentId, type);

                // tell the Shell that this pidl has changed
                // which will eventually call back in views that may be opened to our folders
                var item = server.GetItem(itemId);
                if (item != null)
                {
                    if (item.IsFolder)
                    {
                        switch (type)
                        {
                        case WatcherChangeTypes.Changed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Created:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_MKDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Deleted:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RMDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Renamed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RENAMEFOLDER, 0, item.IdList);
                            break;
                        }
                    }
                    else
                    {
                        switch (type)
                        {
                        case WatcherChangeTypes.Changed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEITEM, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Created:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_CREATE, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Deleted:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_DELETE, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Renamed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RENAMEITEM, 0, item.IdList);
                            break;
                        }
                    }
                }

                item = server.GetItem(parentId);
                if (item != null)
                {
                    ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEDIR, 0, item.IdList);
                }
            });

            _connection.StartAsync();
        }