Esempio n. 1
0
        public FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            CustomUrlActionNodeActionToken customUrlActionNodeActionToken = (CustomUrlActionNodeActionToken)actionToken;

            CustomUrlActionNode customUrlActionNode = (CustomUrlActionNode)ActionNode.Deserialize(customUrlActionNodeActionToken.SerializedActionNode);

            string currentConsoleId = flowControllerServicesContainer.GetService <IManagementConsoleMessageService>().CurrentConsoleId;

            switch (customUrlActionNode.ViewType)
            {
            case CustomUrlActionNodeViewType.DocumentView:
            {
                string viewId = Guid.NewGuid().ToString();
                string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken, true);

                OpenViewMessageQueueItem openViewMessageQueueItem = new OpenViewMessageQueueItem()
                {
                    ViewId             = viewId,
                    EntityToken        = serializedEntityToken,
                    Label              = customUrlActionNodeActionToken.ViewLabel,
                    ToolTip            = customUrlActionNodeActionToken.ViewToolTip,
                    IconResourceHandle = customUrlActionNode.ViewIcon,
                    Url = customUrlActionNodeActionToken.Url,
                    UrlPostArguments = customUrlActionNode.PostParameters
                };
                ConsoleMessageQueueFacade.Enqueue(openViewMessageQueueItem, currentConsoleId);

                BindEntityTokenToViewQueueItem bindEntityTokenToViewQueueItem = new BindEntityTokenToViewQueueItem()
                {
                    ViewId      = viewId,
                    EntityToken = serializedEntityToken
                };
                ConsoleMessageQueueFacade.Enqueue(bindEntityTokenToViewQueueItem, currentConsoleId);
            }
            break;

            case CustomUrlActionNodeViewType.ExternalView:
            {
                string viewId = Guid.NewGuid().ToString();
                string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken, true);

                OpenExternalViewQueueItem openExternalViewQueueItem = new OpenExternalViewQueueItem(entityToken)
                {
                    ViewId             = viewId,
                    EntityToken        = serializedEntityToken,
                    Label              = customUrlActionNodeActionToken.ViewLabel,
                    ToolTip            = customUrlActionNodeActionToken.ViewToolTip,
                    IconResourceHandle = customUrlActionNode.ViewIcon,
                    Url              = customUrlActionNodeActionToken.Url,
                    ViewType         = customUrlActionNodeActionToken.ViewType,
                    UrlPostArguments = customUrlActionNode.PostParameters
                };
                ConsoleMessageQueueFacade.Enqueue(openExternalViewQueueItem, currentConsoleId);

                BindEntityTokenToViewQueueItem bindEntityTokenToViewQueueItem = new BindEntityTokenToViewQueueItem()
                {
                    ViewId      = viewId,
                    EntityToken = serializedEntityToken
                };
                ConsoleMessageQueueFacade.Enqueue(bindEntityTokenToViewQueueItem, currentConsoleId);
            }
            break;

            case CustomUrlActionNodeViewType.GenericView:
            {
                string viewId = Guid.NewGuid().ToString();
                string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken, true);

                OpenGenericViewQueueItem openGenericViewQueueItem = new OpenGenericViewQueueItem(entityToken)
                {
                    ViewId             = viewId,
                    EntityToken        = serializedEntityToken,
                    Label              = customUrlActionNodeActionToken.ViewLabel,
                    ToolTip            = customUrlActionNodeActionToken.ViewToolTip,
                    IconResourceHandle = customUrlActionNode.ViewIcon,
                    Url = customUrlActionNodeActionToken.Url,
                    UrlPostArguments = customUrlActionNode.PostParameters
                };
                ConsoleMessageQueueFacade.Enqueue(openGenericViewQueueItem, currentConsoleId);

                BindEntityTokenToViewQueueItem bindEntityTokenToViewQueueItem = new BindEntityTokenToViewQueueItem()
                {
                    ViewId      = viewId,
                    EntityToken = serializedEntityToken
                };
                ConsoleMessageQueueFacade.Enqueue(bindEntityTokenToViewQueueItem, currentConsoleId);
            }
            break;


            case CustomUrlActionNodeViewType.PageBrowser:
                Dictionary <string, string> arguments = new Dictionary <string, string>();
                arguments.Add("URL", customUrlActionNodeActionToken.Url);

                OpenHandledViewMessageQueueItem openHandledViewMessageQueueItem = new OpenHandledViewMessageQueueItem(
                    EntityTokenSerializer.Serialize(entityToken, true),
                    "Composite.Management.Browser",
                    arguments
                    );

                ConsoleMessageQueueFacade.Enqueue(openHandledViewMessageQueueItem, currentConsoleId);
                break;


            case CustomUrlActionNodeViewType.FileDownload:
                DownloadFileMessageQueueItem downloadFileMessageQueueItem = new DownloadFileMessageQueueItem(customUrlActionNodeActionToken.Url);

                ConsoleMessageQueueFacade.Enqueue(downloadFileMessageQueueItem, currentConsoleId);
                break;
            }


            return(null);
        }
        /// <exclude />
        public static GetMessagesResult GetNewMessages(string consoleId, int lastKnownChangeNumber)
        {
            ConsoleFacade.RegisterConsole(UserSettings.Username, consoleId);

            List <ConsoleAction> newMessages = new List <ConsoleAction>();

            GetMessagesResult result = new GetMessagesResult();

            result.CurrentSequenceNumber = ConsoleMessageQueueFacade.CurrentChangeNumber;

            List <ConsoleMessageQueueElement> messageQueueElements = ConsoleMessageQueueFacade.GetQueueElements(lastKnownChangeNumber, consoleId).ToList();

            if (messageQueueElements.Any() && messageQueueElements.Max(f => f.QueueItemNumber) > result.CurrentSequenceNumber)
            {
                result.CurrentSequenceNumber = messageQueueElements.Max(f => f.QueueItemNumber);
            }

            DocumentSuspectMessageRequests(consoleId, lastKnownChangeNumber, result, messageQueueElements);

            // Open views...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is OpenViewMessageQueueItem))
            {
                OpenViewMessageQueueItem openViewItem = (OpenViewMessageQueueItem)queueElement.QueueItem;

                List <KeyValuePair> arguments = new List <KeyValuePair>();
                if (openViewItem.UrlPostArguments != null)
                {
                    foreach (var entry in openViewItem.UrlPostArguments)
                    {
                        arguments.Add(new KeyValuePair(entry.Key, entry.Value));
                    }
                }

                OpenViewParams openViewParams = new OpenViewParams
                {
                    Url         = openViewItem.Url,
                    Argument    = arguments,
                    EntityToken = openViewItem.EntityToken,
                    FlowHandle  = openViewItem.FlowHandle,
                    ViewId      = openViewItem.ViewId,
                    ViewType    = openViewItem.ViewType.AsConsoleType(),
                    Label       = openViewItem.Label,
                    ToolTip     = openViewItem.ToolTip ?? openViewItem.Label
                };

                openViewParams.Image = GetImage(openViewItem.IconResourceHandle);

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.OpenView,
                    OpenViewParams = openViewParams
                });
            }


            // Open view definitions...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is OpenHandledViewMessageQueueItem))
            {
                OpenHandledViewMessageQueueItem openViewDefItem = (OpenHandledViewMessageQueueItem)queueElement.QueueItem;

                List <KeyValuePair> arguments = new List <KeyValuePair>();
                foreach (var entry in openViewDefItem.Arguments)
                {
                    arguments.Add(new KeyValuePair(entry.Key, entry.Value));
                }

                OpenViewDefinitionParams openViewDefParams = new OpenViewDefinitionParams
                {
                    ViewId      = openViewDefItem.Handle + Guid.NewGuid().ToString(),
                    EntityToken = openViewDefItem.EntityToken,
                    Handle      = openViewDefItem.Handle,
                    Argument    = arguments
                };

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber           = queueElement.QueueItemNumber,
                    ActionType               = ActionType.OpenViewDefinition,
                    OpenViewDefinitionParams = openViewDefParams
                });
            }


            // Open generic views...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is OpenGenericViewQueueItem))
            {
                OpenGenericViewQueueItem openGenericView = (OpenGenericViewQueueItem)queueElement.QueueItem;

                List <KeyValuePair> arguments = new List <KeyValuePair>();
                foreach (var entry in openGenericView.UrlPostArguments)
                {
                    arguments.Add(new KeyValuePair(entry.Key, entry.Value));
                }

                OpenGenericViewParams openGenericViewParams = new OpenGenericViewParams
                {
                    ViewId           = openGenericView.ViewId,
                    EntityToken      = openGenericView.EntityToken,
                    Label            = openGenericView.Label,
                    ToolTip          = openGenericView.ToolTip ?? openGenericView.Label,
                    Url              = openGenericView.Url,
                    UrlPostArguments = arguments
                };

                openGenericViewParams.Image = GetImage(openGenericView.IconResourceHandle);

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber        = queueElement.QueueItemNumber,
                    ActionType            = ActionType.OpenGenericView,
                    OpenGenericViewParams = openGenericViewParams
                });
            }

            // Open external views...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is OpenExternalViewQueueItem))
            {
                var openExternalView = (OpenExternalViewQueueItem)queueElement.QueueItem;

                var arguments = new List <KeyValuePair>();
                foreach (var entry in openExternalView.UrlPostArguments)
                {
                    arguments.Add(new KeyValuePair(entry.Key, entry.Value));
                }

                var openExternalViewParams = new OpenExternalViewParams
                {
                    ViewId           = openExternalView.ViewId,
                    EntityToken      = openExternalView.EntityToken,
                    Label            = openExternalView.Label,
                    ToolTip          = openExternalView.ToolTip ?? openExternalView.Label,
                    ViewType         = openExternalView.ViewType,
                    Url              = openExternalView.Url,
                    UrlPostArguments = arguments
                };

                openExternalViewParams.Image = GetImage(openExternalView.IconResourceHandle);

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber         = queueElement.QueueItemNumber,
                    ActionType             = ActionType.OpenExternalView,
                    OpenExternalViewParams = openExternalViewParams
                });
            }

            // Open slide views...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is OpenSlideViewQueueItem))
            {
                var openSlideView = (OpenSlideViewQueueItem)queueElement.QueueItem;

                var openSlideViewParams = new OpenSlideViewParams
                {
                    ViewId      = openSlideView.ViewId,
                    EntityToken = openSlideView.EntityToken,
                    Url         = openSlideView.Url
                };

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber      = queueElement.QueueItemNumber,
                    ActionType          = ActionType.OpenSlideView,
                    OpenSlideViewParams = openSlideViewParams
                });
            }


            // Download files...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is DownloadFileMessageQueueItem))
            {
                DownloadFileMessageQueueItem downloadFileItem = (DownloadFileMessageQueueItem)queueElement.QueueItem;

                DownloadFileParams downloadFileParams = new DownloadFileParams
                {
                    Url = downloadFileItem.Url,
                };

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber     = queueElement.QueueItemNumber,
                    ActionType         = ActionType.DownloadFile,
                    DownloadFileParams = downloadFileParams
                });
            }


            // Close views...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is CloseViewMessageQueueItem))
            {
                CloseViewMessageQueueItem closeViewItem = (CloseViewMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber  = queueElement.QueueItemNumber,
                    ActionType      = ActionType.CloseView,
                    CloseViewParams = new CloseViewParams
                    {
                        ViewId = closeViewItem.ViewId
                    }
                });
            }


            // Refresh tree... Ignoring requests for the same entity tokens
            var entityTokensToRefresh = new HashSet <string>();
            var refreshMessages       = new List <ConsoleAction>();

            foreach (var queueElement in messageQueueElements.Where(f => f.QueueItem is RefreshTreeMessageQueueItem)
                     .OrderByDescending(f => f.QueueItemNumber))
            {
                var refreshTreeItem = (RefreshTreeMessageQueueItem)queueElement.QueueItem;

                string serializedEntityToken = EntityTokenSerializer.Serialize(refreshTreeItem.EntityToken, true);
                if (entityTokensToRefresh.Contains(serializedEntityToken))
                {
                    continue;
                }

                entityTokensToRefresh.Add(serializedEntityToken);

                refreshMessages.Add(new ConsoleAction
                {
                    SequenceNumber    = queueElement.QueueItemNumber,
                    ActionType        = ActionType.RefreshTree,
                    RefreshTreeParams = new RefreshTreeParams
                    {
                        EntityToken = serializedEntityToken,
                    }
                });
            }

            refreshMessages.Reverse();
            newMessages.AddRange(refreshMessages);

            // Send message boxes...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is MessageBoxMessageQueueItem))
            {
                MessageBoxMessageQueueItem messageBoxItem = (MessageBoxMessageQueueItem)queueElement.QueueItem;

                DialogType clientDialogType = DialogType.Message;

                switch (messageBoxItem.DialogType)
                {
                case Composite.C1Console.Events.DialogType.Message:
                    clientDialogType = DialogType.Message;
                    break;

                case Composite.C1Console.Events.DialogType.Question:
                    clientDialogType = DialogType.Question;
                    break;

                case Composite.C1Console.Events.DialogType.Warning:
                    clientDialogType = DialogType.Warning;
                    break;

                case Composite.C1Console.Events.DialogType.Error:
                    clientDialogType = DialogType.Error;
                    break;

                default:
                    clientDialogType = DialogType.Message;
                    break;
                }


                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber   = queueElement.QueueItemNumber,
                    ActionType       = ActionType.MessageBox,
                    MessageBoxParams = new MessageBoxParams
                    {
                        DialogType = clientDialogType,
                        Title      = messageBoxItem.Title,
                        Message    = messageBoxItem.Message
                    }
                });
            }


            // Send log entries...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is LogEntryMessageQueueItem))
            {
                var logEntryItem = (LogEntryMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.LogEntry,
                    LogEntryParams = new LogEntryParams
                    {
                        SenderId = logEntryItem.Sender.Name,
                        Level    = logEntryItem.Level.AsConsoleType(),
                        Message  = logEntryItem.Message
                    }
                });
            }


            // Restart console application (like culture change)...
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is RebootConsoleMessageQueueItem))
            {
                var rebootConsoleItem = (RebootConsoleMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.Reboot
                });
            }


            // Collaps the tree and refresh
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is CollapseAndRefreshConsoleMessageQueueItem))
            {
                var collapseAndRefreshConsoleMessageQueueItem = (CollapseAndRefreshConsoleMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.CollapseAndRefresh
                });
            }


            // Close all open views
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is CloseAllViewsMessageQueueItem))
            {
                var closeAllViewsMessageQueueItem = (CloseAllViewsMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber      = queueElement.QueueItemNumber,
                    ActionType          = ActionType.CloseAllViews,
                    CloseAllViewsParams = new CloseAllViewsParams {
                        Reason = closeAllViewsMessageQueueItem.Reason
                    }
                });
            }


            // Lock the console application
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is LockSystemConsoleMessageQueueItem))
            {
                var lockSystemConsoleMessageQueueItem = (LockSystemConsoleMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.LockSystem
                });
            }


            // Lock the console application
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is BroadcastMessageQueueItem))
            {
                var broadcastMessageQueueItem = (BroadcastMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber         = queueElement.QueueItemNumber,
                    ActionType             = ActionType.BroadcastMessage,
                    BroadcastMessageParams = new BroadcastMessageParams
                    {
                        Name  = broadcastMessageQueueItem.Name,
                        Value = broadcastMessageQueueItem.Value
                    }
                });
            }


            // SaveStatus
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is SaveStatusConsoleMessageQueueItem))
            {
                var saveStatusConsoleMessageQueueItem = (SaveStatusConsoleMessageQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber   = queueElement.QueueItemNumber,
                    ActionType       = ActionType.SaveStatus,
                    SaveStatusParams = new SaveStatusParams {
                        ViewId = saveStatusConsoleMessageQueueItem.ViewId, Succeeded = saveStatusConsoleMessageQueueItem.Succeeded
                    }
                });
            }

            // BindEntityToken
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is BindEntityTokenToViewQueueItem))
            {
                var bindEntityTokenToViewQueueItem = (BindEntityTokenToViewQueueItem)queueElement.QueueItem;
                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber = queueElement.QueueItemNumber,
                    ActionType     = ActionType.BindEntityTokenToView,
                    BindEntityTokenToViewParams = new BindEntityTokenToViewParams {
                        ViewId = bindEntityTokenToViewQueueItem.ViewId, EntityToken = bindEntityTokenToViewQueueItem.EntityToken
                    }
                });
            }

            // BindEntityToken
            foreach (ConsoleMessageQueueElement queueElement in messageQueueElements.Where(f => f.QueueItem is SelectElementQueueItem))
            {
                var selectElementQueueItem = (SelectElementQueueItem)queueElement.QueueItem;

                newMessages.Add(new ConsoleAction
                {
                    SequenceNumber      = queueElement.QueueItemNumber,
                    ActionType          = ActionType.SelectElement,
                    SelectElementParams = new SelectElementParams
                    {
                        EntityToken           = selectElementQueueItem.EntityToken,
                        PerspectiveElementKey = selectElementQueueItem.PerspectiveElementKey
                    }
                });
            }

            result.ConsoleActions = newMessages.OrderBy(f => f.SequenceNumber).ToList();

            return(result);
        }