示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RunningStrategiesForm"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        public RunningStrategiesForm(CandleElement element)
        {
            InitializeComponent();

            btnOK.Enabled = false;

            chkPass.Items.Clear();
            chkPass.Items.Add(GenerationPass.MetaModelUpdate, true);
            chkPass.Items.Add(GenerationPass.CodeGeneration, true);
            chkPass.Items.Add(GenerationPass.ElementAdded, false);

            lstStrategies.Items.Clear();
            if (element != null)
            {
                foreach (
                    StrategyBase strategy in StrategyManager.GetInstance(element.Store).GetStrategies(element, true))
                {
                    ListViewItem item = new ListViewItem(strategy.DisplayName);
                    item.SubItems.Add(strategy.Description);
                    item.Checked = true;
                    item.Tag     = strategy;
                    lstStrategies.Items.Add(item);
                    btnOK.Enabled = true;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Récupére la liste des stratégies applicables et actives sur un modéle
        /// </summary>
        /// <param name="strategiesOwner">The strategies owner.</param>
        /// <param name="element">Elément concerné ou null pour tous</param>
        /// <returns></returns>
        internal static List <StrategyBase> GetStrategies(CandleElement strategiesOwner, ICustomizableElement element)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            List <StrategyBase> strategies = new List <StrategyBase>();

            if (strategiesOwner == null)
            {
                return(strategies);
            }

            if (element != null && logger != null)
            {
                logger.BeginStep(String.Concat("Get enabled strategies for element ", element.Name, " (id=", element.Id, ")"), LogType.Debug);
            }

            foreach (StrategyBase strategy in StrategyManager.GetInstance(strategiesOwner.Store).GetStrategies(strategiesOwner, true))
            {
                if (strategy.IsEnabled)
                {
                    strategies.Add(strategy);
                }
                else
                if (element != null && logger != null)
                {
                    logger.Write("GetStrategies", String.Concat("Strategy ", strategy.StrategyId, " ignored because it is disabled"), LogType.Debug);
                }
            }
            if (element != null && logger != null)
            {
                logger.EndStep();
            }

            return(strategies);
        }
示例#3
0
        /// <summary>
        /// Liste des stratégies disponibles
        /// </summary>
        /// <param name="sp">null si on est au niveau global</param>
        /// <param name="includeGlobalStrategies">if set to <c>true</c> [include global strategies].</param>
        /// <returns></returns>
        public List <StrategyBase> GetStrategies(CandleElement sp, bool includeGlobalStrategies)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();
            string  n      = GetStrategyOwnerName(sp);

            if (logger != null)
            {
                logger.Write("GetStrategies", String.Concat("Get all strategies for ", n), LogType.Debug);
            }
            List <StrategyBase> strategies = GetStrategies(n);

            if (sp != null && includeGlobalStrategies)
            {
                if (logger != null)
                {
                    logger.Write("GetStrategies", "Merging with globals strategies", LogType.Debug);
                }
                foreach (StrategyBase strategy in GetStrategies(GetStrategyOwnerName(null)))
                {
                    // Si la stratégie existe dèjà dans la couche, on ne la rajoute pas.
                    if (!strategies.Exists(delegate(StrategyBase currentStrategy) { return(currentStrategy.StrategyId == strategy.StrategyId); }))
                    {
                        strategies.Add(strategy);
                    }
                    else if (logger != null)
                    {
                        logger.Write("GetStrategies", String.Concat("Global strategy ", strategy.StrategyId, " ignored because this strategy is already defined in ", n), LogType.Debug);
                    }
                }
            }
            return(strategies);
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowStrategiesCommand"/> class.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="element">The element.</param>
        /// <param name="fileName">Name of the file.</param>
        public ShowStrategiesCommand(SoftwareComponent component, object element, string fileName)
        {
            this._component = component;
            PresentationElement pel = element as PresentationElement;

            if (pel != null)
            {
                this._model = pel.ModelElement as CandleElement;
            }
        }
示例#5
0
        protected override Elements.Element MakeSampleElement(TimeSeriesChart chart, PlotPane pane, CandleSample sample, int x, float minScale, float maxScale)
        {
            var elm = new CandleElement(pane, sample, x, minScale, maxScale, BlackWhite);

            if (ShowBalloons)
            {
                elm.MouseClick += elm_MouseClick;
            }

            return(elm);
        }
示例#6
0
        /// <summary>
        /// Chargement des stratégies disponibles sous forme d'arbre organisé
        /// par StrategyPath
        /// </summary>
        /// <param name="strategiesOwner">The strategies owner.</param>
        /// <param name="selectedStrategy">The selected strategy.</param>
        private void PopulateListView(CandleElement strategiesOwner, StrategyBase selectedStrategy)
        {
            this._strategiesOwner = strategiesOwner != null ? strategiesOwner.StrategiesOwner : null;

            Dictionary <string, ListViewGroup> groups = new Dictionary <string, ListViewGroup>();

            // Evite l'evenement OnItemChecked
            _initialize = true;
            lvStrategies.Items.Clear();

            //
            // Lecture de toutes les strategies disponibles
            //
            foreach (StrategyBase strategy in StrategyManager.GetInstance(_store).GetStrategies(strategiesOwner, false))
            {
                // Création du noeud de la stratégie
                ListViewItem item = new ListViewItem(strategy.DisplayName);
                //
                // Recherche si les strategies possédent des attributs de description
                //
                string strategyGroup = "Standard";
                foreach (
                    StrategyAttribute customAttribute in
                    strategy.GetType().GetCustomAttributes(typeof(StrategyAttribute), false))
                {
                    if (!String.IsNullOrEmpty(customAttribute.Description))
                    {
                        strategy.Description = customAttribute.Description;
                    }
                    if (!String.IsNullOrEmpty(customAttribute.StrategyGroup))
                    {
                        strategyGroup          = customAttribute.StrategyGroup;
                        strategy.StrategyGroup = strategyGroup;
                    }
                }
                item.Group   = FindGroup(groups, strategyGroup);
                item.Tag     = strategy;
                item.Checked = strategy.IsEnabled;
                lvStrategies.Items.Add(item);
                item.Selected = selectedStrategy != null && selectedStrategy == strategy;
            }

            _initialize = false;

            ListViewGroup[] temp = new ListViewGroup[groups.Values.Count];
            groups.Values.CopyTo(temp, 0);
            //Array.Sort(temp);
            lvStrategies.Groups.AddRange(temp);
        }
        /// <summary>
        /// </summary>
        /// <param name="e">Provides data for the ElementDeleted event.</param>
        public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            CandleElement elem = e.ModelElement as CandleElement;

            if (elem == null)
            {
                return;
            }

            if (elem.Store.InUndoRedoOrRollback)
            {
                return;
            }

            CandleModel.GetInstance(elem.Store).RegisterElementPendingDelete(elem);
        }
示例#8
0
        /// <summary>
        /// Suppresion d'une stratégie
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="strategy"></param>
        public void RemoveStrategy(CandleElement owner, StrategyBase strategy)
        {
            Debug.Assert(strategy != null);
            string n = GetStrategyOwnerName(owner);

            _strategies.RemoveAll(
                delegate(StrategyBase current)
            {
                if (current.Owner == n && current.StrategyId == strategy.StrategyId)
                {
                    DeleteStrategy(current);
                    return(true);
                }
                return(false);
            });
        }
示例#9
0
        /// <summary>
        /// Création de l'instance de la strategie contenu dans le manifest
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="manifest">Manifest contenant la stratégie</param>
        /// <returns></returns>
        public StrategyBase AddStrategy(CandleElement owner, StrategyManifest manifest)
        {
            InternalPackage package = GetPackage(manifest.PackageName);

            if (package == null)
            {
                return(null);
            }

            StrategyBase strategy = package.CreateStrategyInstance(manifest.StrategyTypeName, manifest.StrategyConfiguration);

            if (strategy != null)
            {
                strategy.Owner = GetStrategyOwnerName(owner);

                // Vérification des doublons
                foreach (StrategyBase other in _strategies)
                {
                    if (other.Owner == strategy.Owner && other.StrategyId == strategy.StrategyId)
                    {
                        return(other);
                    }
                }
                try
                {
                    strategy.OnLoading(this, new EventArgs());
                    _strategies.Add(strategy);
                }
                catch (Exception ex)
                {
                    IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                    if (ide != null)
                    {
                        ide.ShowMessageBox("Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
                        ide.LogError(false, "Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, 0, 0, "StrategyManager");
                    }
                }
            }

            return(strategy);
        }
示例#10
0
        public override void BuildElements(Chart chart, PlotPane pane, Series series)
        {
            var cdata = series as CandleTimeSeries;

            if (cdata == null)
            {
                throw new WFormsException("CandleView requires CandleTimeSeries source");
            }


            var drawData = getDataPerScroll(cdata);

            if (!drawData.Any())
            {
                return;             //nothing to draw
            }
            float minScale;
            float maxScale;

            calcMinMaxScale(drawData, out minScale, out maxScale);

            m_MinScale = minScale;
            m_MaxScale = maxScale;

            pane.SetMinMaxScale(minScale, maxScale, true);


            var x = 0;

            foreach (var candle in cdata.Data)
            {
                if (x > pane.Width)
                {
                    break;
                }
                var elm = new CandleElement(pane, candle, x, minScale, maxScale);
                elm.Visible = true;
                x          += elm.Width;
                x++;//margin
            }
        }
示例#11
0
 /// <summary>
 /// Calls the t4 template.
 /// </summary>
 /// <param name="prj">The PRJ.</param>
 /// <param name="t4TemplateName">Name of the t4 template.</param>
 /// <param name="selectedElement">The selected element.</param>
 /// <returns></returns>
 protected string CallT4Template(Project prj, string t4TemplateName, CandleElement selectedElement)
 {
     return(CallT4Template(prj, t4TemplateName, selectedElement, String.Empty, null));
 }
示例#12
0
 /// <summary>
 /// Gets the name of the strategy owner.
 /// </summary>
 /// <param name="sp">The sp.</param>
 /// <returns></returns>
 internal static string GetStrategyOwnerName(CandleElement sp)
 {
     return(sp == null ? "globals" : String.Format("{0}-{1:D}", sp.GetType().Name, sp.Id));
 }
        /// <summary>
        /// Alerts listeners that a property for an element has changed.
        /// </summary>
        /// <param name="e">Provides data for the ElementPropertyChanged event.</param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            // Teste si on est en train de charger le modèle
            // Permet d'eviter de déclencher une régle lors du chargement du modèle
            if (e.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing ||
                e.ModelElement.Store.InUndoRedoOrRollback)
            {
                return;
            }
            object value;

            // On ignore
            if (
                e.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.
                TryGetValue("CustomizableElementChangeRule_Enabled", out value) &&
                (bool)value == false)
            {
                return;
            }

            CandleElement elem = e.ModelElement as CandleElement;

            if (elem == null)
            {
                return;
            }

            // Teste l'élément
            //if (e.DomainProperty.Id == ClassImplementation.NameDomainPropertyId)
            //{
            //    if (String.IsNullOrEmpty(elem.RootName) || elem.RootName == (string)e.OldValue)
            //        elem.RootName = elem.Name;
            //}

            if (e.DomainProperty.Id == CandleElement.RootNameDomainPropertyId)
            {
                string oldValue           = (string)e.OldValue;
                ClassImplementation model = e.ModelElement as ClassImplementation;
                if (model != null)
                {
                    // NON si on force le root name, c'est qu'on veut changer le nom
                    //string oldName = String.IsNullOrEmpty(oldValue) ? null : StrategyManager.GetInstance(model.Store).NamingStrategy.CreateElementName(model.Layer, oldValue);
                    //if( String.IsNullOrEmpty(elem.Name) || elem.Name == oldName || String.IsNullOrEmpty(oldValue))
                    elem.Name =
                        StrategyManager.GetInstance(model.Store).NamingStrategy.CreateElementName(model.Layer,
                                                                                                  (string)e.NewValue);

                    if (model.Contract != null)
                    {
                        model.Contract.RootName = model.RootName;
                    }
                }

                ServiceContract contract = e.ModelElement as ServiceContract;
                if (contract != null && contract.Layer != null && contract.Name == "?")
                // Layer est null si on a à faire à un ExternalServiceContract
                {
                    //string oldName = StrategyManager.GetInstance(clazz.Store).NamingStrategy.CreateElementName(contract.Layer, (string)e.OldValue);
                    //if (String.IsNullOrEmpty(elem.Name) || elem.Name == oldName)
                    elem.Name =
                        StrategyManager.GetInstance(contract.Store).NamingStrategy.CreateElementName(contract.Layer,
                                                                                                     (string)e.NewValue);
                }

                Entity entity = e.ModelElement as Entity;
                if (entity != null)
                {
                    DataLayer modelsLayer = entity.Package.Layer;
                    string    oldName     = String.IsNullOrEmpty(oldValue)
                                         ? null
                                         : StrategyManager.GetInstance(model.Store).NamingStrategy.CreateElementName(
                        model.Layer, oldValue);
                    if (String.IsNullOrEmpty(elem.Name) || elem.Name == oldName || String.IsNullOrEmpty(oldValue))
                    {
                        elem.Name =
                            StrategyManager.GetInstance(elem.Store).NamingStrategy.CreateElementName(modelsLayer,
                                                                                                     (string)e.NewValue);
                    }
                }
            }
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StrategiesForm"/> class.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="model">The model.</param>
        public StrategiesForm(SoftwareComponent component, CandleElement model)
        {
            InitializeComponent();

            if (component != null)
            {
                _store = component.Store;
            }
            else
            {
                _store = model.Store;
            }

            specificStrategies = new List <StrategiesListControl>();
            globalsStrategies  = new StrategiesListControl();
            namingStrategy     = new NamingStrategyControl();
            languageConfig     = new LanguageConfigurationControl();

            globalsStrategies.Dock     = DockStyle.Fill;
            globalsStrategies.Name     = "globalsStrategies";
            globalsStrategies.TabIndex = 1;

            namingStrategy.Dock     = DockStyle.Fill;
            namingStrategy.Name     = "namingStrategy";
            namingStrategy.TabIndex = 1;

            languageConfig.Dock     = DockStyle.Fill;
            languageConfig.Name     = "languageConfig";
            languageConfig.TabIndex = 1;

            tabStrategies.TabPages.Clear();

            // Création des onglets (une par couche + une globale + une pour la stratégie de nommage)
            // L'onglet courant est sélectionné

            // D'abord le global
            globalsStrategies.Initialize(_store, null);
            tabGlobals.Controls.Add(globalsStrategies);
            tabStrategies.TabPages.Add(tabGlobals);

            // Puis un par couche
            int index = 1;

            foreach (SoftwareLayer layer in component.Layers)
            {
                StrategiesListControl specificStrategy = new StrategiesListControl();
                specificStrategy.Dock     = DockStyle.Fill;
                specificStrategy.Name     = String.Format("specificStrategies{0}", index);
                specificStrategy.TabIndex = 0;
                specificStrategy.Initialize(_store, layer);
                specificStrategy.StrategyRemoved += Strategies_StrategyRemoved;

                TabPage tabSpecific = new TabPage();
                tabStrategies.TabPages.Add(tabSpecific);

                tabSpecific.Location = new Point(4, 22);
                tabSpecific.Name     = String.Format("tabSpecific{0}", index);
                tabSpecific.Padding  = new Padding(3);
                tabSpecific.Size     = new Size(741, 348);
                tabSpecific.TabIndex = index;
                tabSpecific.UseVisualStyleBackColor = true;

                tabSpecific.Text = layer.Name;
                if (layer == model.StrategiesOwner)
                {
                    tabSpecific.Text         += "*";
                    tabStrategies.SelectedTab = tabSpecific;
                }
                tabSpecific.Controls.Add(specificStrategy);
            }


            // Stratégie de nommage
            namingStrategy.Initialize(StrategyManager.GetInstance(_store).NamingStrategy);
            tabNaming.Controls.Add(namingStrategy);
            tabStrategies.TabPages.Add(tabNaming);

            // Et le language
            languageConfig.Initialize(StrategyManager.GetInstance(_store).TargetLanguage);
            tabLanguage.Controls.Add(languageConfig);
            tabStrategies.TabPages.Add(tabLanguage);

            globalsStrategies.StrategyRemoved += new EventHandler <StrategyRemovedEventArgs>(Strategies_StrategyRemoved);
        }
示例#15
0
      public override void BuildElements(Chart chart, PlotPane pane, Series series)
      {
        var cdata = series as CandleTimeSeries;
        if (cdata==null) throw new WFormsException("CandleView requires CandleTimeSeries source");

      
        var drawData = getDataPerScroll(cdata);

        if (!drawData.Any()) return;//nothing to draw


        float minScale;
        float maxScale;
        calcMinMaxScale(drawData, out minScale, out maxScale);

        m_MinScale = minScale;
        m_MaxScale = maxScale;

        pane.SetMinMaxScale(minScale, maxScale, true);


        var x = 0;
        foreach(var candle in cdata.Data)
        {
          if (x > pane.Width) break;
          var elm = new CandleElement(pane, candle, x, minScale, maxScale);
          elm.Visible = true;
          x += elm.Width;
          x++;//margin
        }
      }
示例#16
0
        /// <summary>
        /// Execution d'un template
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="t4TemplateName">Nom du template (avec ou sans extension)</param>
        /// <param name="selectedElement">Modele concerné</param>
        /// <param name="outputFileName">Nom du fichier de sortie (si empty, il sera calculé si à null il sera ignoré)</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        protected string CallT4Template(Project project, string t4TemplateName, CandleElement selectedElement,
                                        string outputFileName, TemplateProperties properties)
        {
            if (!Utils.StringCompareEquals(Path.GetExtension(t4TemplateName), ".t4"))
            {
                t4TemplateName += ".t4";
            }

            // Est ce que le template existe dans le directory de la stratégie
            string templateFilePath = MapPath(t4TemplateName);

            if (!File.Exists(templateFilePath))
            {
                // On garde le relatif dans le repository
                templateFilePath = t4TemplateName;
            }

            // Nom du fichier de sortie (si <> null)
            // Calcul du nom par défaut si il n'a pas été forcé ou
            // si ce n'est pas un chemin absolu.
            // NOTA : Si outputFileName est null, c'est qu'on ne veut pas
            //        générer de fichier de sortie (on laisse comme ça)
            if (outputFileName != null &&
                (outputFileName.Length == 0 || Path.GetPathRoot(outputFileName).IndexOf(':') < 0))
            // Si ce n'est pas un chemin physique
            {
                outputFileName = CreateOutputFileName(project, selectedElement, outputFileName);
            }

            // Vérification dans les propriétés de l'extender si ce fichier
            // peut-être regénéré
            bool canRegenerate = true;

            if (outputFileName != null && File.Exists(outputFileName))
            {
                if (Mapper.Instance.GetCanGeneratePropertyValue(outputFileName) == false)
                {
                    canRegenerate = false;
                }
            }

            if (outputFileName != null && Context.IsGenerationLocked(selectedElement, this, outputFileName))
            {
                return(null);
            }

            // Génération
            Context.Template = templateFilePath;
            string data = null;

            try
            {
                if (canRegenerate)
                {
                    if (outputFileName != null && File.Exists(outputFileName))
                    {
                        ServiceLocator.Instance.ShellHelper.SuspendFileChange(true, outputFileName);
                    }

                    data = Generator.CallT4Template(selectedElement, templateFilePath, outputFileName, properties);
                }

                if (Context.GenerationPass == GenerationPass.MetaModelUpdate)
                {
                    Generator.ApplyCodeInjectionStrategies(null, selectedElement, Context);
                }

                if (data == null && canRegenerate)
                {
                    return(null);
                }

                if (outputFileName == null)
                {
                    return(data);
                }

                if (File.Exists(outputFileName) && project != null)
                {
                    // Insertion du fichier dans le projet
                    ProjectItem projectItem =
                        ServiceLocator.Instance.ShellHelper.AddFileToProject(project, outputFileName);

                    // L'association se fait sur l'id du modèle sur lequel s'exécute la strategie
                    Mapper.Instance.Associate(project.Name, outputFileName, StrategyId, CurrentElement.Id);

                    // Rechargement si ouvert dans l'éditeur
                    if (canRegenerate)
                    {
                        ServiceLocator.Instance.ShellHelper.ReloadDocument(outputFileName);
                    }

                    //
                    // Insertion des stratégies style AOP
                    //
                    Generator.ApplyCodeInjectionStrategies(projectItem, selectedElement, Context);

                    ServiceLocator.Instance.ShellHelper.SaveIfDirty(outputFileName);
                }

                return(outputFileName);
            }
            finally
            {
                if (outputFileName != null && File.Exists(outputFileName))
                {
                    if (canRegenerate)
                    {
                        ServiceLocator.Instance.ShellHelper.SuspendFileChange(false, outputFileName);
                        ServiceLocator.Instance.ShellHelper.ReloadDocument(outputFileName);
                    }
                }
            }
        }
示例#17
0
 /// <summary>
 /// Populates the specified strategies owner.
 /// </summary>
 /// <param name="strategiesOwner">The strategies owner.</param>
 /// <param name="selectedStrategy">The selected strategy.</param>
 private void Populate(CandleElement strategiesOwner, StrategyBase selectedStrategy)
 {
     PopulateListView(strategiesOwner, selectedStrategy);
 }
示例#18
0
        /// <summary>
        /// Initialisation de la liste des stratégies
        /// </summary>
        /// <param name="strategiesOwner">The strategies owner.</param>
        /// <param name="selectedStrategy">The selected strategy.</param>
        private void PopulateTreeView(CandleElement strategiesOwner, StrategyBase selectedStrategy)
        {
            this._strategiesOwner = strategiesOwner != null ? strategiesOwner.StrategiesOwner : null;
            _initialize           = true;
            tvStrategies.Nodes.Clear();

            // Remplissage à partir des stratégies liées au modèle
            TreeNode selectedNode = null;

            foreach (StrategyBase strategy in StrategyManager.GetInstance(_store).GetStrategies(strategiesOwner, false))
            {
                TreeNodeCollection nodes = tvStrategies.Nodes;

                // Insertion dans l'arbre en tenant compte du path
                if (!String.IsNullOrEmpty(strategy.StrategyPath))
                {
                    string[] pathParts = strategy.StrategyPath.Split('/');
                    // Création ou recherche de l'arborescence liée au path
                    foreach (string part in pathParts)
                    {
                        // Recherche du noeud parent pour chaque part
                        bool bFind = false;
                        foreach (TreeNode node in nodes)
                        {
                            if (Utils.StringCompareEquals(node.Text, part))
                            {
                                nodes = node.Nodes;
                                bFind = true;
                                break;
                            }
                        }

                        // Si pas trouvé, on le crèe
                        if (!bFind)
                        {
                            TreeNode parent = new TreeNode(part);
                            nodes.Add(parent);
                            nodes = parent.Nodes;
                            parent.Expand();
                        }
                    }
                }

                // Création du noeud de la stratégie
                TreeNode tmpNode = new TreeNode(strategy.DisplayName);
                tmpNode.Tag = strategy;
                nodes.Add(tmpNode);
                tmpNode.Checked = strategy.IsEnabled;
                if (selectedStrategy != null && selectedStrategy.StrategyId == strategy.StrategyId)
                {
                    selectedNode = tmpNode;
                }
            }

            if (selectedNode != null)
            {
                tvStrategies.SelectedNode = selectedNode;
            }

            _initialize = false;
        }
示例#19
0
 /// <summary>
 /// Initializes the specified store.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="strategiesOwner">The strategies owner.</param>
 public void Initialize(Store store, CandleElement strategiesOwner)
 {
     this._store = store;
     Populate(strategiesOwner, null);
 }
示例#20
0
 /// <summary>
 /// Calls the t4 template.
 /// </summary>
 /// <param name="prj">The PRJ.</param>
 /// <param name="t4TemplateName">Name of the t4 template.</param>
 /// <param name="selectedElement">The selected element.</param>
 /// <param name="outputFileName">Name of the output file.</param>
 /// <returns></returns>
 protected string CallT4Template(Project prj, string t4TemplateName, CandleElement selectedElement,
                                 string outputFileName)
 {
     return(CallT4Template(prj, t4TemplateName, selectedElement, outputFileName, null));
 }
示例#21
0
        /// <summary>
        /// Execution du wizard
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DSLFactory.Candle.SystemModel.Strategies.StrategyElementElementAddedEventArgs"/> instance containing the event data.</param>
        public void RunWizard(ModelElement sender, StrategyElementElementAddedEventArgs e)
        {
            CandleElement elem = e.ModelElement as CandleElement;

            txtRootName.Text = elem.RootName;

            if (elem is ServiceContract) // Ce cas est désactivé (voir selection du wizard)
            {
                _layer       = ((ServiceContract)e.ModelElement).Layer;
                txtName.Text =
                    StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName);
            }
            else
            {
                _layer       = ((ClassImplementation)e.ModelElement).Layer;
                _iLayer      = ((ClassImplementation)e.ModelElement).Layer.LayerPackage.InterfaceLayer;
                txtName.Text =
                    StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName);
                if (_iLayer == null)
                {
                    txtContractName.Visible = false;
                }
                else
                {
                    txtContractName.Text =
                        StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_iLayer, txtName.Text);
                }
            }

            if (elem is ServiceContract || ((ClassImplementation)elem).Layer.LayerPackage.InterfaceLayer == null)
            {
                lblContractName.Visible = false;
                txtContractName.Visible = false;
                txtContractName.Text    = null;
            }

            lblHeader.Text = String.Format(lblHeader.Text, _layer.Name);
            groupBox1.Text = _layer.Namespace;

            if (!s_dontShow)
            {
                e.UserCancel = (ShowDialog() == DialogResult.Cancel);
                if (e.UserCancel)
                {
                    return;
                }
                s_dontShow = ckDontShow.Checked;
            }

            // Ici on force les noms des classes donc on ne veut pas que la régle basée sur la modification
            // du RootName s'execute. On l'indique dans le contexte de la transaction
            if (
                !elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.ContainsKey(
                    "CustomizableElementChangeRule_Enabled"))
            {
                elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.Add(
                    "CustomizableElementChangeRule_Enabled", false);
            }
            elem.Name = txtName.Text;

            using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name"))
            {
                // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse
                // forcer le nom ensuite
                elem.RootName = txtRootName.Text;
                transaction.Commit();
            }

            // Si c'est une classe, on essaye de créer son interface
            ClassImplementation clazz = elem as ClassImplementation;

            if (clazz != null && _iLayer != null && !String.IsNullOrEmpty(txtContractName.Text))
            {
                if (clazz.Contract == null)
                {
                    // On regarde si l'interface n'existe pas
                    clazz.Contract =
                        _iLayer.ServiceContracts.Find(
                            delegate(ServiceContract c) { return(c.Name == txtContractName.Text); });

                    if (clazz.Contract == null)
                    {
                        clazz.Contract          = new ServiceContract(clazz.Store);
                        clazz.Contract.RootName = txtRootName.Text;
                        clazz.Layer.LayerPackage.InterfaceLayer.ServiceContracts.Add(clazz.Contract);
                        UnplacedModelHelper.RegisterNewModel(clazz.Store, clazz.Contract);

                        // Si la classe courante utilise un seul contract, on le recopie
                        IList <ClassUsesOperations> links = ClassUsesOperations.GetLinksToServicesUsed(clazz);
                        if (links.Count == 1)
                        {
                            ServiceContract contract = links[0].TargetService as ServiceContract;
                            if (contract != null)
                            {
                                TypeWithOperations.CopyOperations(contract, clazz.Contract);
                            }
                            else
                            {
                                ExternalServiceContract externalContract =
                                    links[0].TargetService as ExternalServiceContract;
                                if (externalContract != null)
                                {
                                    TypeWithOperations.CopyOperations(externalContract.ReferencedServiceContract,
                                                                      clazz.Contract);
                                }
                            }
                        }
                    }
                }

                using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name"))
                {
                    // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse
                    // forcer le nom ensuite
                    clazz.Contract.RootName = elem.RootName;
                    transaction.Commit();
                }

                if (clazz.Contract.Name != txtContractName.Text)
                {
                    clazz.Contract.Name = txtContractName.Text;
                }
            }

            e.CancelBubble = true;
        }