Example #1
0
        public override void Execute(object parameter)
        {
            if (ScopeIsSelectedComponent && AcceptedSelectedComponentType != null && Current.ActiveDiagramView.IsSelectedComponentOfType(AcceptedSelectedComponentType))
            {
                ScopeObject = Current.ActiveDiagramView.GetSelectedComponents().First();
            }

            CommandDialogWindow w = null;

            dialogOpened = false;
            controls     = new List <Control>();

            #region substitute scope with diagram
            if (ScopeObject == null && Diagram != null)
            {
                CommandDescriptor commandDescriptor = PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType);
                if (string.IsNullOrEmpty(ControllerCommandDescription))
                {
                    ControllerCommandDescription = commandDescriptor.CommandDescription;
                }
                commandDescriptor.ClearParameterValues();
                OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls);
                foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters)
                {
                    if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty)
                    {
                        if (parameterDescriptor.ComponentType != null &&
                            typeof(Diagram).IsAssignableFrom(parameterDescriptor.ComponentType))
                        {
                            ScopeObject = Diagram;
                        }

                        if (parameterDescriptor.ComponentType == typeof(PSMSchema) && Diagram is PSMDiagram)
                        {
                            ScopeObject = Diagram.Schema;
                        }
                    }
                }
            }
            #endregion

            if (OpenDialog)
            {
                w = new CommandDialogWindow();
                MenuHelper.CreateDialogControlsForCommand(ControllerCommandType, (ExolutioObject)ScopeObject, ProjectVersion, w.spParameters,
                                                          out controls);

                if (Diagram != null)
                {
                    foreach (Control control in controls)
                    {
                        ParameterControls.GuidLookup guidLookup = control as ParameterControls.GuidLookup;
                        if (guidLookup != null)
                        {
                            if (guidLookup.LookedUpType == typeof(PSMSchema) && Diagram is PSMDiagram)
                            {
                                guidLookup.SetSuggestedValue(Diagram.Schema);
                                guidLookup.Tag = "valueSuggested";
                                break;
                            }
                        }
                    }
                }

                w.lTitle.Content = ControllerCommandDescription;
                if (NoScope)
                {
                    w.lTarget.Content = " (global command) ";
                }
                else
                {
                    w.lTarget.Content = ScopeObject.ToString();
                }
            }

            bool dialogOk = !OpenDialog;

            if (!dialogOk)
            {
#if SILVERLIGHT
                //Current.MainWindow.FloatingWindowHost.Add(w);
                w.Closed += new EventHandler(w_Closed);
                w.Show();
#else
                w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                //w.ShowDialog();
                w.WindowStyle   = WindowStyle.ToolWindow;
                w.Topmost       = true;
                w.ShowInTaskbar = false;
                w.ShowActivated = true;
                Current.MainWindow.DisableCommands();
                w.Show();
                w.Closed += w_Closed;
#endif
                dialogOpened = true;
            }
            else
            {
                DoExecute();
            }

            //if (!OpenDialog || dialogOk)
            //{
            //    DoExecute();
            //}
        }
Example #2
0
        public static bool FetchBaseAccessRights_ByUserID(
            IBDatabaseServiceInterface _DatabaseService,
            IBMemoryServiceInterface _MemoryService,
            string _UserID,
            out List <AccessScope> _AccessScopes,
            out BWebServiceResponse _FailureResponse,
            Action <string> _ErrorMessageAction = null)
        {
            _AccessScopes    = null;
            _FailureResponse = new BWebServiceResponse();

            var InMemoryResult = _MemoryService.GetKeyValue(CommonData.MemoryQueryParameters, UserBaseAccessMEntry.M_KEY_NAME_USER_ID + _UserID, _ErrorMessageAction);

            if (InMemoryResult != null)
            {
                try
                {
                    _AccessScopes = JsonConvert.DeserializeObject <UserBaseAccessMEntry>(InMemoryResult.AsString).BaseAccessScope;
                    return(true);
                }
                catch (Exception) { }
            }

            if (!_DatabaseService.GetItem(
                    UserDBEntry.DBSERVICE_USERS_TABLE(),
                    UserDBEntry.KEY_NAME_USER_ID,
                    new BPrimitiveType(_UserID),
                    UserDBEntry.Properties,
                    out JObject UserObject,
                    _ErrorMessageAction))
            {
                _FailureResponse = BWebResponse.InternalError("Database fetch-user-info operation has failed.");
                return(false);
            }
            if (UserObject == null)
            {
                _FailureResponse = BWebResponse.NotFound("User does not exist.");
                return(false);
            }

            _AccessScopes = new List <AccessScope>();

            if (UserObject.ContainsKey(UserDBEntry.BASE_ACCESS_SCOPE_PROPERTY))
            {
                var BaseAccessScopeAsArray = (JArray)UserObject[UserDBEntry.BASE_ACCESS_SCOPE_PROPERTY];

                foreach (JObject ScopeObject in BaseAccessScopeAsArray)
                {
                    _AccessScopes.Add(JsonConvert.DeserializeObject <AccessScope>(ScopeObject.ToString()));
                }
            }

            _MemoryService.SetKeyValue(CommonData.MemoryQueryParameters, new Tuple <string, BPrimitiveType>[]
            {
                new Tuple <string, BPrimitiveType>(
                    UserBaseAccessMEntry.M_KEY_NAME_USER_ID + _UserID,
                    new BPrimitiveType(JsonConvert.SerializeObject(new UserBaseAccessMEntry()
                {
                    BaseAccessScope = _AccessScopes
                })))
            }, _ErrorMessageAction);

            return(true);
        }