Exemple #1
0
        internal async Task RunFileBrowserCloseTask(FileBrowserCloseParams fileBrowserParams, RequestContext <FileBrowserCloseResponse> requestContext)
        {
            FileBrowserCloseResponse result = new FileBrowserCloseResponse();

            try
            {
                FileBrowserOperation operation = null;
                ConnectionInfo       connInfo;
                ownerToFileBrowserMap.TryGetValue(fileBrowserParams.OwnerUri, out operation);
                this.ConnectionServiceInstance.TryFindConnection(fileBrowserParams.OwnerUri, out connInfo);

                if (operation != null && connInfo != null)
                {
                    if (!operation.FileTreeCreated)
                    {
                        operation.Cancel();
                    }

                    // Clear queued items
                    this.fileBrowserQueue.ClearQueuedItems();

                    // Queue operation to clean up resources
                    QueueItem queueItem = fileBrowserQueue.QueueBindingOperation(
                        key: fileBrowserQueue.AddConnectionContext(connInfo, this.serviceName),
                        bindingTimeout: DefaultTimeout,
                        waitForLockTimeout: DefaultTimeout,
                        bindOperation: (bindingContext, cancelToken) =>
                    {
                        FileBrowserOperation removedOperation = null;
                        ownerToFileBrowserMap.TryRemove(fileBrowserParams.OwnerUri, out removedOperation);
                        if (removedOperation != null)
                        {
                            removedOperation.Dispose();
                        }
                        result.Succeeded = true;
                        return(result);
                    });

                    queueItem.ItemProcessed.WaitOne();
                    if (queueItem.GetResultAsT <FileBrowserCloseResponse>() != null)
                    {
                        result = queueItem.GetResultAsT <FileBrowserCloseResponse>();
                    }

                    this.fileBrowserQueue.CloseConnections(connInfo.ConnectionDetails.ServerName, connInfo.ConnectionDetails.DatabaseName, DefaultTimeout);
                }
            }
            catch (Exception ex)
            {
                Logger.Write(TraceEventType.Error, "Unexpected exception while closing file browser: " + ex.Message);
                result.Message = ex.Message;
            }

            await requestContext.SendEvent(FileBrowserClosedNotification.Type, result);
        }
Exemple #2
0
        internal async Task RunFileBrowserExpandTask(FileBrowserExpandParams fileBrowserParams, RequestContext <bool> requestContext)
        {
            FileBrowserExpandedParams result = new FileBrowserExpandedParams();

            try
            {
                FileBrowserOperation operation = null;
                ConnectionInfo       connInfo;
                ownerToFileBrowserMap.TryGetValue(fileBrowserParams.OwnerUri, out operation);
                this.ConnectionServiceInstance.TryFindConnection(fileBrowserParams.OwnerUri, out connInfo);

                if (operation != null && connInfo != null)
                {
                    QueueItem queueItem = fileBrowserQueue.QueueBindingOperation(
                        key: fileBrowserQueue.AddConnectionContext(connInfo, this.serviceName),
                        bindingTimeout: DefaultTimeout,
                        waitForLockTimeout: DefaultTimeout,
                        bindOperation: (bindingContext, cancelToken) =>
                    {
                        result.ExpandPath = fileBrowserParams.ExpandPath;
                        result.Children   = operation.GetChildren(fileBrowserParams.ExpandPath).ToArray();
                        result.OwnerUri   = fileBrowserParams.OwnerUri;
                        result.Succeeded  = true;
                        return(result);
                    });

                    queueItem.ItemProcessed.WaitOne();

                    if (queueItem.GetResultAsT <FileBrowserExpandedParams>() != null)
                    {
                        result = queueItem.GetResultAsT <FileBrowserExpandedParams>();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            await requestContext.SendEvent(FileBrowserExpandedNotification.Type, result);
        }
Exemple #3
0
        internal async Task RunFileBrowserOpenTask(FileBrowserOpenParams fileBrowserParams, RequestContext <bool> requestContext)
        {
            FileBrowserOpenedParams result  = new FileBrowserOpenedParams();
            FileBrowserOperation    browser = null;
            bool isCancelRequested          = false;

            try
            {
                ConnectionInfo connInfo;
                this.ConnectionServiceInstance.TryFindConnection(fileBrowserParams.OwnerUri, out connInfo);
                if (connInfo != null)
                {
                    QueueItem queueItem = fileBrowserQueue.QueueBindingOperation(
                        key: fileBrowserQueue.AddConnectionContext(connInfo, this.serviceName),
                        bindingTimeout: DefaultTimeout,
                        waitForLockTimeout: DefaultTimeout,
                        bindOperation: (bindingContext, cancelToken) =>
                    {
                        if (!fileBrowserParams.ChangeFilter)
                        {
                            browser = new FileBrowserOperation(bindingContext.ServerConnection, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters);
                        }
                        else
                        {
                            ownerToFileBrowserMap.TryGetValue(fileBrowserParams.OwnerUri, out browser);
                            if (browser != null)
                            {
                                browser.Initialize(fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters);
                            }
                        }

                        if (browser != null)
                        {
                            ownerToFileBrowserMap.AddOrUpdate(fileBrowserParams.OwnerUri, browser, (key, value) => browser);

                            // Create file browser tree
                            browser.PopulateFileTree();

                            if (browser.IsCancellationRequested)
                            {
                                isCancelRequested = true;
                            }
                            else
                            {
                                result.OwnerUri  = fileBrowserParams.OwnerUri;
                                result.FileTree  = browser.FileTree;
                                result.Succeeded = true;
                            }
                        }

                        return(result);
                    });

                    queueItem.ItemProcessed.WaitOne();

                    if (queueItem.GetResultAsT <FileBrowserOpenedParams>() != null)
                    {
                        result = queueItem.GetResultAsT <FileBrowserOpenedParams>();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            if (!isCancelRequested)
            {
                await requestContext.SendEvent(FileBrowserOpenedNotification.Type, result);
            }
        }