예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceContext"/> struct.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="ports">The ports.</param>
 /// <param name="isExternal">if set to <c>true</c> [is external].</param>
 public ReferenceContext(ConfigurationMode mode, ReferenceScope scope, List <Guid> ports, bool isExternal)
 {
     Mode       = mode;
     Scope      = scope;
     Ports      = ports;
     IsExternal = isExternal;
 }
예제 #2
0
        /// <summary>
        /// Adds the reference.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="content">The content.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public Artifact AddReference(string fileName, ArtifactType content, ReferenceScope scope, string mode)
        {
            Artifact artifact = FindReference(fileName, content);

            if (artifact != null)
            {
                return(artifact);
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Add artifact"))
            {
                artifact = new Artifact(this.Store);

                if (System.IO.Path.IsPathRooted(fileName))
                {
                    artifact.Type            = content;
                    artifact.FileName        = System.IO.Path.GetFileName(fileName);
                    artifact.InitialFileName = fileName;
                }
                else
                {
                    artifact.Type     = content;
                    artifact.FileName = fileName;
                }

                artifact.Scope             = scope;
                artifact.ConfigurationMode = mode;
                this.Artifacts.Add(artifact);

                transaction.Commit();
                return(artifact);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the Click event of the button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ReferenceScope scope = GetReferenceScope();
                lstArtefacts.Items.Clear();

                ConfigurationMode mode   = new ConfigurationMode(cbMode.Text);
                ReferenceWalker   w      = new ReferenceWalker(scope, mode);
                string            folder = null;
                if ((string)cbAction.SelectedItem == "current solution")
                {
                    folder = @"c:\[sln]\";
                }
                ReferenceVisitor rv = new ReferenceVisitor(scope, folder);
                w.Traverse(rv, _system);
//                ReferenceContext context = new ReferenceContext(mode, scope, (ReferenceContext.ReferenceSource)cbAction.SelectedItem, CandleModel.GetInstance(((ModelElement)system).Store), "project folder\\..\\");
                foreach (string item in rv.References)
                {
                    lstArtefacts.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceItem"/> struct.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="element">The element.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="isExternal">if set to <c>true</c> [is external].</param>
 public ReferenceItem(ModelElement source, ModelElement element, ReferenceScope scope, bool isExternal)
 {
     _source     = source;
     _scope      = scope;
     _isExternal = isExternal;
     _element    = element;
     _ports      = null;
 }
예제 #5
0
        /// <summary>
        /// Checks the references.
        /// </summary>
        /// <param name="loadModelIfNotPresents">if set to <c>true</c> [load model if not presents].</param>
        /// <param name="context">The context.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="element">The element.</param>
        internal static void CheckReferences(bool loadModelIfNotPresents, ValidationContext context,
                                             ConfigurationMode mode, ReferenceScope scope, ModelElement element)
        {
            CheckReferenceVisitor visitor = new CheckReferenceVisitor(loadModelIfNotPresents, scope, context);
            ReferenceWalker       walker  = new ReferenceWalker(scope, mode);

            walker.Traverse(visitor, element);
        }
예제 #6
0
 /// <summary>
 /// Checks the scope.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public bool CheckScope(ReferenceScope value)
 {
     if (Scope == ReferenceScope.All)
     {
         return(true);
     }
     return((value & Scope) == Scope);
 }
예제 #7
0
        /// <summary>
        /// Gets the references.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="solutionFolder">The solution folder.</param>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public static ReferencesCollection GetReferences(ConfigurationMode mode, ReferenceScope scope,
                                                         string solutionFolder, ModelElement element)
        {
            ReferenceVisitor visitor = new ReferenceVisitor(scope, solutionFolder);
            ReferenceWalker  walker  = new ReferenceWalker(scope, mode);

            walker.Traverse(visitor, element);
            return(visitor.References);
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReferenceWalker"/> class.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="configuration">The configuration.</param>
        public ReferenceWalker(ReferenceScope scope, ConfigurationMode configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _scope         = scope;
            _configuration = configuration;
        }
예제 #9
0
        /// <summary>
        /// Traverses the specified layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="Scope">The scope.</param>
        /// <param name="mode">The mode.</param>
        public void Traverse(SoftwareLayer layer, ReferenceScope Scope, ConfigurationMode mode)
        {
            // Stocke les éléments traités pour éviter les doublons
            List <Guid> guids = new List <Guid>();

            if (layer is InterfaceLayer)
            {
                foreach (ServiceContract contract in ((InterfaceLayer)layer).ServiceContracts)
                {
                    foreach (Implementation impl in Implementation.GetLinksToImplementations(contract))
                    {
                        if (mode.CheckConfigurationMode(impl.ConfigurationMode) &&
                            !guids.Contains(impl.ClassImplementation.Id))
                        {
                            _visitor.Accept(impl, impl.ClassImplementation);
                            guids.Add(impl.ClassImplementation.Id);
                        }
                    }
                }
            }
            else if (layer is Layer)
            {
                foreach (ClassImplementation clazz in ((Layer)layer).Classes)
                {
                    foreach (NamedElement service in clazz.ServicesUsed)
                    {
                        IList <ClassUsesOperations> externalServiceLinks =
                            ClassUsesOperations.GetLinksToServicesUsed(clazz);
                        foreach (ClassUsesOperations link in externalServiceLinks)
                        {
                            if (mode.CheckConfigurationMode(link.ConfigurationMode) && ((link.Scope & Scope) == Scope))
                            {
                                if (service is ExternalServiceContract)
                                {
                                    _visitor.Accept(link, (ExternalServiceContract)service);
                                }
                                else if (service is ServiceContract)
                                {
                                    _visitor.Accept(link, (ServiceContract)service);
                                }
                                else if (service is ClassImplementation)
                                {
                                    _visitor.Accept(link, (ClassImplementation)service);
                                }
                                else
                                {
                                    throw new Exception("Type not implemented");
                                }
                                guids.Add(service.Id);
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Ajout d'une référence sur une couche. Cette action ne peut se faire qu'avec un composant binaire.
        /// </summary>
        /// <param name="modelId">The model id.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="modelVersion">The model version.</param>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public ExternalServiceReference AddReferenceToService(Guid modelId, string displayName, VersionInfo modelVersion, string serviceName, ReferenceScope scope, string mode)
        {
            ExternalComponent externalComponent = this.AddExternalModel(modelId, displayName, modelVersion);

            if (externalComponent != null && externalComponent.MetaData.ComponentType == ComponentType.Library)
            {
                foreach (ExternalPublicPort port in externalComponent.Ports)
                {
                    if (Utils.StringCompareEquals(serviceName, port.Name))
                    {
                        ExternalServiceReference link = ExternalServiceReference.GetLink(this, port);
                        if (link == null)
                        {
                            using (Transaction transaction = port.Store.TransactionManager.BeginTransaction("Create external service reference"))
                            {
                                link = new ExternalServiceReference(this, port);
                                transaction.Commit();
                            }
                            link.Scope = scope;
                            if (!port.IsInGac)
                            {
                                link.Scope |= ReferenceScope.Runtime;
                            }
                            link.ConfigurationMode = mode;
                        }
                        return(link);
                    }
                }
            }
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.Write("Add reference to service", String.Format("Can not create a link between {0} and {1} because the port {2} doesn't exist", this.Name, displayName, serviceName), LogType.Error);
            }
            return(null);
        }
예제 #11
0
 /// <summary>
 /// Calcul se fera à partir d'un modèle contenu dans une solution
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="solutionFolder"></param>
 public ReferenceVisitor(ReferenceScope scope, string solutionFolder)
 {
     this._scope               = scope;
     this._solutionFolder      = solutionFolder;
     _initialModelIsInSolution = !String.IsNullOrEmpty(solutionFolder);
 }
예제 #12
0
 /// <summary>
 /// Le calcul se fera à partir du repository
 /// </summary>
 /// <param name="scope"></param>
 public ReferenceVisitor(ReferenceScope scope)
     : this(scope, null)
 {
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckReferenceVisitor"/> class.
 /// </summary>
 /// <param name="loadIfNotExistsLocally">if set to <c>true</c> [load if not exists locally].</param>
 /// <param name="scope">The scope.</param>
 /// <param name="valCtx">The val CTX.</param>
 public CheckReferenceVisitor(bool loadIfNotExistsLocally, ReferenceScope scope, ValidationContext valCtx)
     : base(scope)
 {
     _loadIfNotExistsLocally = loadIfNotExistsLocally;
     _validationContext      = valCtx;
 }
예제 #14
0
        /// <summary>
        /// Validation des modifs
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnValidate_Click(object sender, EventArgs e)
        {
            if (txtFilePath.Text.Length == 0)
            {
                errorProvider.SetError(txtFilePath, "The file path is required");
                return;
            }
            int scope = 0;

            foreach (string name in lstScope.CheckedItems)
            {
                ReferenceScope val = (ReferenceScope)Enum.Parse(typeof(ReferenceScope), name);
                scope += (int)val;
            }
            if (scope == 0)
            {
                errorProvider.SetError(lstScope, "You must select at least one scope");
                return;
            }

            // Type projet : On vérifie qu'il existe
            string assemblyName = null;

            if (rbProject.Checked)
            {
                int pos = txtFilePath.Text.IndexOf('(');
                if (pos > 1)
                {
                    txtFilePath.Text = txtFilePath.Text.Substring(0, pos - 1);
                }
                Project prj = ServiceLocator.Instance.GetService <IShellHelper>().FindProjectByName(txtFilePath.Text);
                if (prj == null)
                {
                    errorProvider.SetError(txtFilePath, "Project not found in the current solution");
                    return;
                }
                else
                {
                    try
                    {
                        assemblyName = (string)prj.Properties.Item("OutputFileName").Value;
                    }
                    catch
                    {
                        errorProvider.SetError(txtFilePath, "Invalid project type");
                        return;
                    }
                }
            }

            if (_currentArtifact == null)
            {
                _currentArtifact = new Artifact(_layer.Store);
                _layer.Artifacts.Add(_currentArtifact);
            }

            // Quand on vient de resaisir un path, on reforce le chemin initial
            if (Path.IsPathRooted(txtFilePath.Text))
            {
                _currentArtifact.InitialFileName = txtFilePath.Text;
            }
            if (assemblyName != null)
            {
                _currentArtifact.InitialFileName = assemblyName;
            }

            _currentArtifact.FileName = Path.GetFileName(txtFilePath.Text);
            _currentArtifact.Type     = rbAssembly.Checked
                                        ? ArtifactType.Assembly
                                        : rbGAC.Checked
                                              ? ArtifactType.AssemblyInGac
                                              : rbProject.Checked ? ArtifactType.Project : ArtifactType.Content;
            _currentArtifact.ConfigurationMode = cbMode.SelectedItem.ToString();
            _currentArtifact.Scope             = (ReferenceScope)scope;

            if (_currentArtifact.Type == ArtifactType.Project)
            {
                _currentArtifact.FileName = Path.GetFileName(_currentArtifact.FileName);
            }

            PopulateList();
        }