Пример #1
0
        /// <summary>
        /// Given a component, ensures that the component has a backend folder
        /// for storing resources. Ensures that the Component has an AVMID unique
        /// to the project. Creates a folder if necessary.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="pathConvention">The desired convention for the path.</param>
        /// <param name="ProjectDirectory">Directory in which component files reside. Defaults to project directory of <paramref name="component"/></param>
        /// <returns>The path of the Component folder, according to the convention provided</returns>
        public static String GetComponentFolderPath(CyPhy.Component component, PathConvention pathConvention = PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
        {
            var path_RelativeToProjRoot = EnsureComponentFolder(component, ProjectDirectory: ProjectDirectory);

            if (pathConvention == PathConvention.REL_TO_PROJ_ROOT)
            {
                return(path_RelativeToProjRoot);
            }
            else if (pathConvention == PathConvention.ABSOLUTE)
            {
                var path_ProjRootDir = ProjectDirectory ?? component.Impl.Project.GetRootDirectoryPath();
                return(Path.Combine(path_ProjRootDir, path_RelativeToProjRoot));
            }
            else
            {
                throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1}",
                                                              System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                              pathConvention.ToString()));
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves the path to the component's original ACM file, stored when it was imported.
        /// Note that ANY ACM file found will be flagged as a match, even if it has been updated for some reason.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="path">The path to the ACM file, according to the PathConvention</param>
        /// <param name="pathConvention"></param>
        /// <param name="ProjectDirectory">Directory in which component files reside. Defaults to project directory of <paramref name="component"/></param>
        /// <returns>True only if an ACM was found</returns>
        public static bool TryGetOriginalACMFilePath(CyPhy.Component component, out string path, PathConvention pathConvention = PathConvention.REL_TO_COMP_DIR, string ProjectDirectory = null)
        {
            var componentPath = component.GetDirectoryPath(pathConvention, ProjectDirectory: ProjectDirectory);

            var acmFiles = Directory.EnumerateFiles(componentPath, "*.acm", SearchOption.TopDirectoryOnly);
            if (acmFiles.Any())
            {
                path = Path.Combine(componentPath, acmFiles.First());
                return true;
            }
            else if (File.Exists(Path.Combine(componentPath, "ComponentData.xml")))
            {
                path = Path.Combine(componentPath, "ComponentData.xml");
                return true;
            }

            path = "";
            return false;
        }
Пример #3
0
        /// <summary>
        /// Given a DomainModel object, find the path to the file resource.
        /// This will traverse the UsesResource connection to a Resource object,
        /// then return that Resource object's path.
        /// </summary>
        /// <param name="domainModel"></param>
        /// <param name="path">The path to the resource, relative to the component's resource folder</param>
        /// <param name="pathConvention"></param>
        /// <returns>True if the resource was found</returns>
        public static bool TryGetResourcePath(CyPhy.DomainModel domainModel, out string path, PathConvention pathConvention = PathConvention.REL_TO_COMP_DIR)
        {
            if (false == (domainModel.ParentContainer is CyPhy.Component)
                && (pathConvention == PathConvention.REL_TO_PROJ_ROOT || pathConvention == PathConvention.ABSOLUTE))
            {
                throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1} if domainModel.ParentContainer is not a CyPhy.Component",
                                                                System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                                pathConvention.ToString()));
            }

            // Starting with the DomainModel object, we'll find a Resource object to which it has a relation.
            // Then we'll return the path of that Resource object.

            List<CyPhy.Resource> l_Resources = new List<CyPhy.Resource>();
            foreach (CyPhy.UsesResource ur in domainModel.DstConnections.UsesResourceCollection)
                l_Resources.Add(ur.DstEnds.Resource);
            foreach (CyPhy.UsesResource ur in domainModel.SrcConnections.UsesResourceCollection)
                l_Resources.Add(ur.SrcEnds.Resource);

            path = "";

            // If no Resources found, return false.
            if (l_Resources.Count == 0)
            {
                return false;
            }

            // At least one Resource was found, so return the path of the first.
            var resourcePath = l_Resources.FirstOrDefault().Attributes.Path;
            if (pathConvention == PathConvention.REL_TO_COMP_DIR)
            {
                path = resourcePath;
            }
            else if (pathConvention == PathConvention.REL_TO_PROJ_ROOT)
            {
                var compDirPath = GetComponentFolderPath(domainModel.ParentContainer as CyPhy.Component);
                path = Path.Combine(compDirPath, resourcePath);
            }
            else if (pathConvention == PathConvention.ABSOLUTE)
            {
                var compDirPath = GetComponentFolderPath(domainModel.ParentContainer as CyPhy.Component);
                var projRootPath = domainModel.Impl.Project.GetRootDirectoryPath();
                path = Path.Combine(projRootPath, compDirPath, resourcePath);
            }
            else
            {
                throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1}",
                                                                System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                                pathConvention.ToString()));
            }

            return true;
        }
Пример #4
0
 /// <summary>
 /// Given a component, ensures that the component has a backend folder
 /// for storing resources. Ensures that the Component has an AVMID unique
 /// to the project. Creates a folder if necessary.
 /// </summary>
 /// <param name="component"></param>
 /// <param name="pathConvention">The desired convention for the path.</param>
 /// <param name="ProjectDirectory">Directory in which component files reside. Defaults to project directory of <paramref name="component"/></param>
 /// <returns>The path of the Component folder, according to the convention provided</returns>
 public static String GetComponentFolderPath(CyPhy.Component component, PathConvention pathConvention = PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
 {
     var path_RelativeToProjRoot = EnsureComponentFolder(component, ProjectDirectory: ProjectDirectory);
     if (pathConvention == PathConvention.REL_TO_PROJ_ROOT)
     {
         return path_RelativeToProjRoot;
     }
     else if (pathConvention == PathConvention.ABSOLUTE)
     {
         var path_ProjRootDir = ProjectDirectory ?? component.Impl.Project.GetRootDirectoryPath();
         return Path.Combine(path_ProjRootDir, path_RelativeToProjRoot);
     }
     else
     {
         throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1}",
                                                         System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                         pathConvention.ToString()));
     }
 }
Пример #5
0
        /// <summary>
        /// Retrieves the path to the component's original ACM file, stored when it was imported.
        /// Note that ANY ACM file found will be flagged as a match, even if it has been updated for some reason.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="path">The path to the ACM file, according to the PathConvention</param>
        /// <param name="pathConvention"></param>
        /// <param name="ProjectDirectory">Directory in which component files reside. Defaults to project directory of <paramref name="component"/></param>
        /// <returns>True only if an ACM was found</returns>
        public static bool TryGetOriginalACMFilePath(CyPhy.Component component, out string path, PathConvention pathConvention = PathConvention.REL_TO_COMP_DIR, string ProjectDirectory = null)
        {
            var componentPath = component.GetDirectoryPath(pathConvention, ProjectDirectory: ProjectDirectory);

            var acmFiles = Directory.EnumerateFiles(componentPath, "*.acm", SearchOption.TopDirectoryOnly);

            if (acmFiles.Any())
            {
                path = Path.Combine(componentPath, acmFiles.First());
                return(true);
            }
            else if (File.Exists(Path.Combine(componentPath, "ComponentData.xml")))
            {
                path = Path.Combine(componentPath, "ComponentData.xml");
                return(true);
            }

            path = "";
            return(false);
        }
Пример #6
0
        /// <summary>
        /// Given a DomainModel object, find the path to the file resource.
        /// This will traverse the UsesResource connection to a Resource object,
        /// then return that Resource object's path.
        /// </summary>
        /// <param name="domainModel"></param>
        /// <param name="path">The path to the resource, relative to the component's resource folder</param>
        /// <param name="pathConvention"></param>
        /// <returns>True if the resource was found</returns>
        public static bool TryGetResourcePath(CyPhy.DomainModel domainModel, out string path, PathConvention pathConvention = PathConvention.REL_TO_COMP_DIR)
        {
            if (false == (domainModel.ParentContainer is CyPhy.Component) &&
                (pathConvention == PathConvention.REL_TO_PROJ_ROOT || pathConvention == PathConvention.ABSOLUTE))
            {
                throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1} if domainModel.ParentContainer is not a CyPhy.Component",
                                                              System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                              pathConvention.ToString()));
            }

            // Starting with the DomainModel object, we'll find a Resource object to which it has a relation.
            // Then we'll return the path of that Resource object.

            List <CyPhy.Resource> l_Resources = new List <CyPhy.Resource>();

            foreach (CyPhy.UsesResource ur in domainModel.DstConnections.UsesResourceCollection)
            {
                l_Resources.Add(ur.DstEnds.Resource);
            }
            foreach (CyPhy.UsesResource ur in domainModel.SrcConnections.UsesResourceCollection)
            {
                l_Resources.Add(ur.SrcEnds.Resource);
            }

            path = "";

            // If no Resources found, return false.
            if (l_Resources.Count == 0)
            {
                return(false);
            }

            // At least one Resource was found, so return the path of the first.
            var resourcePath = l_Resources.FirstOrDefault().Attributes.Path;

            if (pathConvention == PathConvention.REL_TO_COMP_DIR)
            {
                path = resourcePath;
            }
            else if (pathConvention == PathConvention.REL_TO_PROJ_ROOT)
            {
                var compDirPath = GetComponentFolderPath(domainModel.ParentContainer as CyPhy.Component);
                path = Path.Combine(compDirPath, resourcePath);
            }
            else if (pathConvention == PathConvention.ABSOLUTE)
            {
                var compDirPath  = GetComponentFolderPath(domainModel.ParentContainer as CyPhy.Component);
                var projRootPath = domainModel.Impl.Project.GetRootDirectoryPath();
                path = Path.Combine(projRootPath, compDirPath, resourcePath);
            }
            else
            {
                throw new NotSupportedException(String.Format("{0} doesn't support PathConvention of type {1}",
                                                              System.Reflection.MethodBase.GetCurrentMethod().Name,
                                                              pathConvention.ToString()));
            }

            return(true);
        }