/**
         * extracts value from modelitem, returns null if there is no value
         */
        public string Convert(ModelItem modelItem)
        {
            var currentValue         = modelItem?.GetCurrentValue() as InArgument <string>;
            Literal <string> literal = currentValue?.Expression as Literal <string>;

            return(literal?.Value);
        }
        public override object TranslatePropertyValue(ModelItem item, PropertyIdentifier identifier, object value)
        {
            MessageBox.Show($"name: {identifier.Name}\r\n" +
                            $"value: {value}\r\n" +
                            $"type: {value?.GetType()}\r\n" +
                            $"item.View: {item.View}\r\n" +
                            $"item.GetCurrentValue(): {item.GetCurrentValue()}");
            if (identifier.DeclaringType == BackgroundPropertyIdentifier.DeclaringType)
            {
                using (var editingScope = item.BeginEdit())
                {
                    var button = item.GetCurrentValue() as Button;
                    button?.SetValue(Control.BackgroundProperty, value);
                }

                return value;
            }

            return base.TranslatePropertyValue(item, identifier, value);
        }
 public override void OnSelectionChanged(ModelItem oldItem, ModelItem newItem)
 {
     if (oldItem?.GetCurrentValue() is TDev2TOFn dto && dto.CanRemove())
     {
         // old row is blank so remove
         var index = Collection.IndexOf(dto) + 1;
         RemoveDto(dto, index);
     }
     if (newItem != null)
     {
         CurrentModelItem = newItem;
     }
 }
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        /// <param name="value">The value that is produced by the binding target.</param><param name="targetType">The type to convert to.</param><param name="parameter">The converter parameter to use.</param><param name="culture">The culture to use in the converter.</param>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                ModelItem modelItem = value as ModelItem;

                if (modelItem != null)
                {
                    Activity act = modelItem.GetCurrentValue() as Activity;
                    return(act);
                }
            }
            return(null);
        }
Exemple #5
0
        public DynamicArgumentWrapperObject(string argumentName, ModelItem argumentItem)
        {
            Fx.Assert(argumentItem != null, "argumentItem canot be null");
            this.isInitializing = true;
            this.IsValidating   = false;
            Argument argument = (Argument)argumentItem.GetCurrentValue();

            this.Name                  = argumentName;
            this.Direction             = argument.Direction;
            this.UseLocationExpression = (this.Direction != ArgumentDirection.In);
            this.Type                  = argument.ArgumentType;
            this.Expression            = argumentItem.Properties[ExpressionPropertyName].Value;
            this.isInitializing        = false;
        }
Exemple #6
0
        protected override IEnumerable <IActionableErrorInfo> ValidateCollectionItem(ModelItem mi)
        {
            var dto = mi.GetCurrentValue() as GatherSystemInformationTO;

            if (dto == null)
            {
                yield break;
            }

            foreach (var error in dto.GetRuleSet("Result", _getDatalistString?.Invoke()).ValidateRules("", () => mi.SetProperty("IsResultFocused", true)))
            {
                yield return(error);
            }
        }
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            Azure.QueryBlobs modelItem = (Azure.QueryBlobs)ModelItem.GetCurrentValue();

            AttributeCollection   attributes            = TypeDescriptor.GetProperties(modelItem)["ThrowOnError"].Attributes;
            DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

            defaultValueAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

            if (modelItem.ThrowOnError == null && defaultValueAttribute != null)
            {
                chkThrowOnError.IsChecked = (bool)defaultValueAttribute.Value;
            }
        }
Exemple #8
0
        private void DeleteModelItem(ModelItem modelItem)
        {
            if (modelItem != null)
            {
                BreakpointTypes breakpointType;
                if (this.breakpoints.TryGetValue(modelItem, out breakpointType))
                {
                    this.transientBreakpoints[modelItem] = breakpointType; // cache it in case it's added later (move case).
                    SetBreakpointType(modelItem, BreakpointTypes.None);    // clear breakpoint
                }

                DeleteFromMapping(modelItem.GetCurrentValue());
            }
        }
Exemple #9
0
        public static ImageSource GetImageSourceForTool(this ModelItem modelItem)
        {
            var computedValue = modelItem.GetCurrentValue();

            if (computedValue is FlowStep && modelItem.Content?.Value != null)
            {
                computedValue = modelItem.Content.Value.GetCurrentValue();
            }

            var type  = computedValue.GetType();
            var image = GetImageSourceForToolFromType(type);

            return(image);
        }
Exemple #10
0
        /// <summary>
        /// Handles the Loaded event of the ExecuteXamlWorkflowDesigner control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        public void ExecuteXamlWorkflowDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            this.ModelItem.PropertyChanged += new PropertyChangedEventHandler(this.ModelItem_PropertyChanged);

            ModelItem modelItem = this.ModelItem.Properties["ChildArguments"].Dictionary;

            if (modelItem == null)
            {
                argumentDictionary = new Dictionary <string, Argument>();
            }
            else
            {
                argumentDictionary = (Dictionary <string, Argument>)modelItem.GetCurrentValue();
            }
        }
        private string GetExpressionEditorType()
        {
            object root = null;

            if (this.OwnerActivity != null)
            {
                ModelItem rootItem = this.Context.Services.GetService <ModelService>().Root;
                if (rootItem != null)
                {
                    root = rootItem.GetCurrentValue();
                }
            }

            return(this.ViewModel.GetExpressionEditorType(this.ExpressionActivityEditor, root, WorkflowDesigner.GetTargetFramework(this.Context)));
        }
        private static string LiteralValueTranslateItem(ActivityTranslator translator, ModelItem item)
        {
            var temp = item.GetCurrentValue() as sae.Literal <DynamicValue>;

            if (null != temp)
            {
                DynamicValue id         = temp.Value;
                DynamicValue validValue = GetValidValue(item, id);
                if (null != validValue.Value)
                {
                    return(validValue.ToString());
                }
            }
            return(translator.Translate(item.Properties[IMConstants.ValuePropertyName].Value));
        }
        /// <summary>
        /// Acquire a reference by the SourceLocation of the object.
        /// Notice this method will automatically register the object to listen to SourceLocationUpdated, if available.
        /// </summary>
        /// <param name="startLine">The start line of the object.</param>
        /// <param name="startColumn">The start column of the object.</param>
        /// <param name="endLine">The end line of the object.</param>
        /// <param name="endColumn">The end column of the object.</param>
        /// <returns>The object reference.</returns>
        public Guid AcquireObjectReference(int startLine, int startColumn, int endLine, int endColumn)
        {
            if (this.modelSearchService != null)
            {
                ModelItem modelItem = this.modelSearchService.FindModelItem(startLine, startColumn, endLine, endColumn);
                if (modelItem != null)
                {
                    object searchObject = modelItem.GetCurrentValue();
                    Guid   result       = this.AcquireObjectReference(searchObject);
                    this.SubscribedForSourceLocationChanges.Add(result);
                    return(result);
                }
            }

            return(Guid.Empty);
        }
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                ModelItem modelItem = value as ModelItem;

                if (value != null)
                {
                    InArgument <string> inArgument = modelItem.GetCurrentValue() as InArgument <string>;

                    if (inArgument != null && inArgument.Expression as Literal <string> != null)
                    {
                        return((inArgument.Expression as Literal <string>).Value);
                    }
                }

                return(string.Empty);
            }
Exemple #15
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type type = value as Type;

            if (type == null)
            {
                ModelItem modelItem = value as ModelItem;
                if (modelItem != null)
                {
                    type = modelItem.GetCurrentValue() as Type;
                }
            }

            bool fullName = bool.Parse(parameter.ToString());

            return(TypeNameHelper.GetDisplayName(type, fullName));
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int actualDisplayNameLength = MaxDisplayNameLength;

            // default to root item's typename
            string breadCrumbText = "<null>";

            if (values[0] is ModelItem)
            {
                ModelItem boundModelItem = values[0] as ModelItem;
                breadCrumbText = boundModelItem.ItemType.Name;
            }
            else if (LocalAppContextSwitches.UseLegacyAccessibilityFeatures && values[0] is DesignerView.BreadCrumbObjectSeparator)
            {
                breadCrumbText = SR.BreadCrumbObjectSeparator;
            }

            // if there is a display name property on root use that as the file name.
            if (values[1] is ModelItem)
            {
                ModelItem displayNameProperty = (ModelItem)values[1];
                if (typeof(string) == displayNameProperty.ItemType)
                {
                    values[1] = displayNameProperty.GetCurrentValue();
                }
            }
            if (values[1] is string)
            {
                string displayName = (string)values[1];
                if (!displayName.Equals(string.Empty))
                {
                    breadCrumbText = displayName;
                }
            }
            if (values.Length == 3 && values[2] is double)
            {
                double actualControlWidth = (double)values[2];
                actualDisplayNameLength = (int)Math.Max(MaxDisplayNameLength, actualControlWidth / pixelsPerChar);
            }
            if (breadCrumbText.Length > actualDisplayNameLength)
            {
                breadCrumbText = breadCrumbText.Substring(0, actualDisplayNameLength - 3) + "...";
            }
            return(breadCrumbText);
        }
Exemple #17
0
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            Activities.Vsdbcmd modelItem = (Activities.Vsdbcmd)ModelItem.GetCurrentValue();

            bool?defaultValue = (bool?)DesignerHelper.GetDefaultValueAttributeValue(modelItem, "AlwaysCreateNewDatabase");

            if (modelItem.AlwaysCreateNewDatabase == null && defaultValue != null)
            {
                chkAlwaysCreateNewDatabase.IsChecked = defaultValue.Value;
            }

            defaultValue = (bool?)DesignerHelper.GetDefaultValueAttributeValue(modelItem, "BackupBeforeDeploy");

            if (modelItem.BackupBeforeDeploy == null && defaultValue != null)
            {
                chkBackupBeforeDeploy.IsChecked = defaultValue.Value;
            }
        }
Exemple #18
0
        protected override IEnumerable <IActionableErrorInfo> ValidateCollectionItem(ModelItem mi)
        {
            var dto = mi.GetCurrentValue() as ActivityDTO;

            if (dto == null)
            {
                yield break;
            }

            foreach (var error in dto.GetRuleSet("FieldName", GetDatalistString()).ValidateRules("'Variable'", () => mi.SetProperty("IsFieldNameFocused", true)))
            {
                yield return(error);
            }
            foreach (var error in dto.GetRuleSet("FieldValueAndCalculate", GetDatalistString()).ValidateRules("'New Value'", () => mi.SetProperty("IsFieldValueFocused", true)))
            {
                yield return(error);
            }
        }
        protected override IEnumerable<IActionableErrorInfo> ValidateCollectionItem(ModelItem mi)
        {
            var dto = mi.GetCurrentValue() as JsonMappingTo;
            if(dto == null)
            {
                yield break;
            }

            foreach (var error in dto.GetRuleSet("SourceName", GetDatalistString()).ValidateRules("'Data'", () => mi.SetProperty("IsSourceNameFocused", true)))
            {
                yield return error;
            } 
            
            foreach (var error in dto.GetRuleSet("DestinationName", GetDatalistString()).ValidateRules("'Name'", () => mi.SetProperty("IsDestinationNameFocused", true)))
            {
                yield return error;
            }            
        }
        protected override IEnumerable <IActionableErrorInfo> ValidateCollectionItem(ModelItem mi)
        {
            var dto = mi.GetCurrentValue() as XPathDTO;

            if (dto == null)
            {
                yield break;
            }

            foreach (var error in dto.GetRuleSet("OutputVariable", GetDatalistString()).ValidateRules("'Results'", () => mi.SetProperty("IsOutputVariableFocused", true)))
            {
                yield return(error);
            }
            foreach (var error in dto.GetRuleSet("XPath", GetDatalistString()).ValidateRules("'XPath'", () => mi.SetProperty("IsXpathVariableFocused", true)))
            {
                yield return(error);
            }
        }
Exemple #21
0
        private void ValidateNamespaceModelAndUpdateContextItem(ModelItem namespaceModel)
        {
            NamespaceData namespaceData = namespaceModel.GetCurrentValue() as NamespaceData;

            Fx.Assert(namespaceData != null, "added item has to be NamespaceData");

            if (!this.availableNamespaces.ContainsKey(namespaceData.Namespace))
            {
                namespaceModel.Properties[ErrorMessagePropertyName].SetValue(string.Format(CultureInfo.CurrentCulture, SR.CannotResolveNamespace, namespaceData.Namespace));
                namespaceModel.Properties[IsInvalidPropertyName].SetValue(true);
            }
            else
            {
                namespaceModel.Properties[ErrorMessagePropertyName].SetValue(string.Empty);
                namespaceModel.Properties[IsInvalidPropertyName].SetValue(false);
                this.importedNamespacesItem.ImportedNamespaces.Add(namespaceData.Namespace);
            }
        }
        private static List <ModelProperty> GetTypeConverterSubPropertiesHelper(ModelItem item, TypeConverter customConverter)
        {
            if (item == null)
            {
                return(null);
            }

            List <ModelProperty> subProperties = null;

            TypeConverter converter = customConverter;

            if (converter == null)
            {
                // See if there is a converter associated with the item type itself
                converter = ExtensibilityAccessor.GetTypeConverter(item);
            }

            if (converter != null)
            {
                PropertyDescriptorCollection subPropertyDescriptors =
                    converter.GetProperties(item.GetCurrentValue());

                if (subPropertyDescriptors != null && subPropertyDescriptors.Count > 0)
                {
                    foreach (PropertyDescriptor subPropertyDescriptor in subPropertyDescriptors)
                    {
                        ModelProperty subProperty = item.Properties[subPropertyDescriptor.Name];

                        // We want to expose all properties through the model regardless of whether they
                        // are browsable or not.  That distinction should be made by the UI utilizing it
                        if (subProperty != null)
                        {
                            if (subProperties == null)
                            {
                                subProperties = new List <ModelProperty>();
                            }

                            subProperties.Add(subProperty);
                        }
                    }
                }
            }
            return(subProperties);
        }
        void NavigateToError(object sourceDetail)
        {
            Fx.Assert(this.modelTreeManager != null, "ModelTreeManager is null.");
            ModelItem modelItem = this.modelTreeManager.GetModelItem(sourceDetail) ?? FindModelItem(this.modelTreeManager, sourceDetail);

            if (modelItem != null)
            {
                if (this.modelSearchService != null)
                {
                    this.modelSearchService.NavigateTo(modelItem);
                }
                else
                {
                    // For any Expression, need to focus to its parent instead.
                    Activity activity = modelItem.GetCurrentValue() as Activity;
                    if (activity != null && (activity.IsExpression()))
                    {
                        ModelItem parent = modelItem.Parent;
                        while (parent != null)
                        {
                            bool hasDesignerAttribute = this.ViewService.GetDesignerType(parent.ItemType) != null;

                            // ModelItemKeyValuePair type also has DesignerAttribute.
                            // Since we do not want to put a focus on that type, special-casing it here.
                            bool isModelItemKeyValuePair = parent.ItemType.IsGenericType &&
                                                           parent.ItemType.GetGenericTypeDefinition() == typeof(ModelItemKeyValuePair <,>);

                            if (hasDesignerAttribute && !isModelItemKeyValuePair)
                            {
                                break;
                            }

                            parent = parent.Parent;
                        }

                        if (parent != null)
                        {
                            modelItem = parent;
                        }
                    }
                    modelItem.Focus();
                }
            }
        }
        static void SetConnectorStartDotToolTip(FrameworkElement startDot, ModelItem connectorModelItem)
        {
            ModelItem triggerModelItem = connectorModelItem.Properties[TransitionDesigner.TriggerPropertyName].Value as ModelItem;
            string    triggerName      = null;

            if (triggerModelItem == null)
            {
                triggerName = "(null)";
            }
            else
            {
                ModelItem displayNameModelItem = triggerModelItem.Properties["DisplayName"].Value;
                if (displayNameModelItem != null)
                {
                    triggerName = displayNameModelItem.GetCurrentValue() as string;
                }
            }
            startDot.ToolTip = string.Format(CultureInfo.InvariantCulture, TriggerNameToolTip, triggerName) + Environment.NewLine + SR.SharedTriggerToolTip;
        }
 void SetNext(ModelItem next, ModelItem source, bool delink = false)
 {
     if (next != null)
     {
         var nextStep = next.GetCurrentValue <FlowNode>();
         if (nextStep != null)
         {
             SetNextFlowNode(next, source, nextStep, delink);
         }
     }
     else
     {
         var currentlyLinkedItem = GetNextItem(source);
         if (currentlyLinkedItem is null)
         {
             SetNextProperty(source, null);
         }
     }
 }
Exemple #26
0
        private void ElementCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // Only handle the event when single item is appended and it is not the first.
            if (e.NewItems != null && e.OldItems == null && e.NewItems.Count == 1 && e.NewStartingIndex > 0)
            {
                ModelItemCollection elements = ModelItem.Properties["Elements"].Collection; //NOXLATE

                // The insert position is always at the end when users add new item by clicking on hyperlike "<add text...>"
                // If the insert position is not the end, it must be 'Replace' operation. It is because ModelItemCollection
                // does not support 'Replace' operation, the operation is achieved by combination of 'remove' and 'add'.
                // Therefore you will receive an 'add' event when users are replacing an item. That is not the case we need to handle.
                if (e.NewStartingIndex == elements.Count - 1)
                {
                    bool   shouldAddSpacer   = true; // Add space by default.
                    int    previousItemIndex = e.NewStartingIndex - 1;
                    object previousValue     = elements[previousItemIndex].GetCurrentValue();
                    string previousString    = GetLiteralString(previousValue);
                    if (previousString != null)
                    {
                        // If the previous item does not end with space, we should add a space.
                        shouldAddSpacer = shouldAddSpacer && !previousString.EndsWith(Space); //NOXLATE
                    }

                    ModelItem modelItem = e.NewItems[0] as ModelItem;
                    if (modelItem != null)
                    {
                        object theValue  = modelItem.GetCurrentValue();
                        string theString = GetLiteralString(theValue);
                        if (theString != null)
                        {
                            // If the newly-added string does start with space, we should add a space.
                            shouldAddSpacer = shouldAddSpacer && !theString.StartsWith(Space);
                        }
                    }

                    if (shouldAddSpacer)                                                          //NOXLATE
                    {
                        elements.Insert(e.NewStartingIndex, StringLiteral.CreateArgument(Space)); //NOXLATE
                    }
                }
            }
        }
        private ValidationRoot GetRootElement()
        {
            Activity rootElement = null;

            Fx.Assert(this.modelService != null, "ModelService is null."); // ModelService should not be null

            ModelItem rootItem = this.modelService.Root;
            object    root     = rootItem.GetCurrentValue();
            // special case for WorkflowService - it will be returned directly
            WorkflowService workflowService = root as WorkflowService;

            if (workflowService != null)
            {
                return(new ValidationRoot(workflowService));
            }
            //special case for ActivityBuilder - its will be converted to a DynamicActivity before validation.
            ActivityBuilder activityBuilder = root as ActivityBuilder;

            if (activityBuilder != null)
            {
                ActivityBuilderExtensions.ConvertActivityBuilderToDynamicActivity(activityBuilder, this.DynamicActivityWrapper);
                rootElement = this.DynamicActivityWrapper;
            }
            else
            {
                rootElement = rootItem.GetRootActivity();
            }

            IList <AssemblyReference> references;
            IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out references);

            NamespaceHelper.SetTextExpressionNamespaces(rootElement, namespaces, references);

            if (rootElement != null)
            {
                return(new ValidationRoot(rootElement));
            }
            else
            {
                return(null);
            }
        }
 public override void OnSelectionChanged(ModelItem oldItem, ModelItem newItem)
 {
     if (oldItem != null)
     {
         var dto = oldItem.GetCurrentValue() as TDev2TOFn;
         if (dto != null && dto.CanRemove())
         {
             // old row is blank so remove
             if (ModelItemCollection != null)
             {
                 var index = ModelItemCollection.IndexOf(oldItem) + 1;
                 RemoveDto(dto, index);
             }
         }
     }
     if (newItem != null)
     {
         CurrentModelItem = newItem;
     }
 }
        protected Variable <T> AddVariable <T>(ModelItemCollection variables, Variable <T> variable)
        {
            // Get variable.
            ModelItem modelItem = variables.FirstOrDefault(
                m => ((Variable)m.GetCurrentValue()).Name == variable.Name);

            // Add into variables collection if it does not exist.
            if (modelItem == null)
            {
                variables.Add(variable);
            }

            // Assign it if it was found.
            else
            {
                variable = modelItem.GetCurrentValue() as Variable <T>;
            }

            return(variable);
        }
Exemple #30
0
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            Activities.CreateEventLog modelItem = (Activities.CreateEventLog)ModelItem.GetCurrentValue();

            AttributeCollection   attributes            = TypeDescriptor.GetProperties(modelItem)["TreatExistAsSuccess"].Attributes;
            DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

            if (modelItem.TreatExistAsSuccess == null && defaultValueAttribute != null)
            {
                chkTreatExistsAsSuccess.IsChecked = (bool)defaultValueAttribute.Value;
            }

            attributes            = TypeDescriptor.GetProperties(modelItem)["ThrowOnError"].Attributes;
            defaultValueAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

            if (modelItem.ThrowOnError == null && defaultValueAttribute != null)
            {
                chkThrowOnError.IsChecked = (bool)defaultValueAttribute.Value;
            }
        }
Exemple #31
0
        protected override void OnModelItemChanged(object newItem)
        {
            base.OnModelItemChanged(newItem);

            Context.Items.Subscribe <Selection>(SelectionChanged);

            _convertCollection = newItem;
            _activity          = newItem as ModelItem;

            if (_convertCollection.ConvertCollection == null || _convertCollection.ConvertCollection.Count <= 0)
            {
                _convertCollection.ConvertCollection.Add(new BaseConvertTO("", "Text", "Base 64", "", 1));
                _convertCollection.ConvertCollection.Add(new BaseConvertTO("", "Text", "Base 64", "", 2));
            }
            if (_activity != null)
            {
                var modelProperty = _activity.Properties["DisplayName"];
                if (modelProperty != null)
                {
                    modelProperty.SetValue(CreateDisplayName());
                }

                ModelItem parent = _activity.Parent;

                while (parent != null)
                {
                    if (parent.Properties["Argument"] != null)
                    {
                        break;
                    }

                    parent = parent.Parent;
                }
            }

            ICollectionActivity modelItemActivity = ModelItem.GetCurrentValue() as ICollectionActivity;

            QuickVariableInputModel model = new QuickVariableInputModel(ModelItem, modelItemActivity);

            ViewModel = new QuickVariableInputViewModel(model);
        }