Beispiel #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 GetDirectoryPath(this CyPhy.ComponentAssembly assembly, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
        {
            var relPath = ComponentLibraryManager.EnsureComponentAssemblyFolder(assembly, ProjectDirectory);

            switch (pathConvention)
            {
            case ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT:
                return(relPath);

            case ComponentLibraryManager.PathConvention.ABSOLUTE:
                return(Path.Combine(GetRootDirectoryPath(assembly.Impl.Project), relPath));

            default:
                throw new ArgumentOutOfRangeException(String.Format("Path convention of {0} is not supported",
                                                                    pathConvention.ToString()));
            }
        }
Beispiel #2
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="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(this CyPhy.DomainModel domainModel, out string path, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_COMP_DIR)
 {
     return ComponentLibraryManager.TryGetResourcePath(domainModel, out path, pathConvention);
 }
Beispiel #3
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 GetDirectoryPath(this CyPhy.Component component, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
 {
     return ComponentLibraryManager.GetComponentFolderPath(component, pathConvention, ProjectDirectory: ProjectDirectory);
 }
Beispiel #4
0
 /// <summary>
 /// Given a CyPhy MGA project, return the root directory of the project
 /// </summary>
 /// <param name="project"></param>
 /// <returns>The absolute path to the project's root directory</returns>
 public static String GetRootDirectoryPath(this IMgaProject project)
 {
     return(ComponentLibraryManager.GetProjectRootPath(project));
 }
Beispiel #5
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="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(this CyPhy.DomainModel domainModel, out string path, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_COMP_DIR)
 {
     return(ComponentLibraryManager.TryGetResourcePath(domainModel, out path, pathConvention));
 }
Beispiel #6
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 GetDirectoryPath(this CyPhy.Component component, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
 {
     return(ComponentLibraryManager.GetComponentFolderPath(component, pathConvention, ProjectDirectory: ProjectDirectory));
 }
Beispiel #7
0
        /// <summary>
        /// Determines what action to take if a Component has been created under a Components folder.
        /// The actions are dispatched to other functions.
        /// </summary>
        /// <param name="componentFco"></param>
        private void Process(CyPhy.Component component)
        {
            var componentFco = component.Impl;

            if (Logger == null)
            {
                Logger = new CyPhyGUIs.GMELogger(componentFco.Project, this.ComponentName);
            }

            bool HasAVMID = !String.IsNullOrWhiteSpace(component.Attributes.AVMID);
            bool HasPath  = !String.IsNullOrWhiteSpace(component.Attributes.Path);

            META.ComponentLibraryManager.EnsureComponentFolder(component);

            // Get all other components that have a "Components" folder as parent.
            // For the next logic tests, we'll need this list.
            var       project = component.Impl.Project;
            MgaFilter filter  = project.CreateFilter();

            filter.Kind = "Component";

            var otherComponents = project.AllFCOs(filter)
                                  .Cast <MgaFCO>()
                                  .Where(x => x.ParentFolder != null &&
                                         x.ParentFolder.MetaBase.Name == "Components" &&
                                         x.ID != componentFco.ID)
                                  .Select(x => CyPhyClasses.Component.Cast(x));

            //bool AVMIDCollision = HasAVMID && otherComponents.Where(c => c.Attributes.AVMID == component.Attributes.AVMID).Any();

            bool PathCollision = HasPath;

            if (HasPath)
            {
                PathCollision = false;

                string myFullPath = Path.GetFullPath(component.Attributes.Path);
                foreach (var cFullPath in otherComponents.Where(c => !String.IsNullOrWhiteSpace(c.Attributes.Path))
                         .Select(c => Path.GetFullPath(c.Attributes.Path)))
                {
                    if (myFullPath == cFullPath)
                    {
                        PathCollision = true;
                    }
                }
            }

            //bool PathCollision = HasPath && otherComponents.Where(c => Path.GetFullPath(c.Attributes.Path) == Path.GetFullPath(component.Attributes.Path)).Any();

            var projectPath_Absolute = component.Impl.Project.GetRootDirectoryPath();
            var lastChar             = projectPath_Absolute.Last();

            if (lastChar != '\\' && lastChar != '/')
            {
                projectPath_Absolute += '\\';
            }

            if (HasAVMID && HasPath)
            {
                var oldCompPath_Absolute = Path.Combine(projectPath_Absolute, component.Attributes.Path);
                var folderExists         = Directory.Exists(oldCompPath_Absolute);

                if (PathCollision || !folderExists)
                {
                    var newCompPath_Absolute = ComponentLibraryManager.CreateComponentFolder(component.Impl.Project);
                    var newCompPath_Relative = ComponentLibraryManager.MakeRelativePath(projectPath_Absolute, newCompPath_Absolute);

                    newCompPath_Relative = newCompPath_Relative.Replace('\\', '/') + '/';
                    var firstChars = newCompPath_Relative.Substring(0, 2);
                    if (firstChars != ".\\" && firstChars != "./")
                    {
                        newCompPath_Relative = newCompPath_Relative.Insert(0, "./");
                    }
                    component.Attributes.Path = newCompPath_Relative;

                    if (folderExists)
                    {
                        CopyComponentFiles(oldCompPath_Absolute, newCompPath_Absolute);
                    }
                    else if (component.Children.ResourceCollection.Any())
                    {
                        WarnUserAboutMissingFiles(component);
                    }
                }
            }
            else if (HasAVMID)
            {
                var newCompPath_Absolute = ComponentLibraryManager.CreateComponentFolder(component.Impl.Project);
                var newCompPath_Relative = ComponentLibraryManager.MakeRelativePath(projectPath_Absolute, newCompPath_Absolute);

                newCompPath_Relative      = newCompPath_Relative.Replace('\\', '/') + '/';
                component.Attributes.Path = newCompPath_Relative;

                if (component.Children.ResourceCollection.Any())
                {
                    WarnUserAboutMissingFiles(component);
                }
            }
            else if (HasPath)
            {
                var oldCompPath_Absolute = Path.Combine(projectPath_Absolute, component.Attributes.Path);
                var folderExists         = Directory.Exists(oldCompPath_Absolute);

                if (PathCollision || !folderExists)
                {
                    var newCompPath_Absolute = ComponentLibraryManager.CreateComponentFolder(component.Impl.Project);
                    var newCompPath_Relative = ComponentLibraryManager.MakeRelativePath(projectPath_Absolute, newCompPath_Absolute);

                    newCompPath_Relative = newCompPath_Relative.Replace('\\', '/') + '/';
                    var firstChars = newCompPath_Relative.Substring(0, 2);
                    if (firstChars != ".\\" && firstChars != "./")
                    {
                        newCompPath_Relative = newCompPath_Relative.Insert(0, "./");
                    }
                    component.Attributes.Path = newCompPath_Relative;

                    if (folderExists)
                    {
                        CopyComponentFiles(oldCompPath_Absolute, newCompPath_Absolute);
                    }
                    else if (component.Children.ResourceCollection.Any())
                    {
                        WarnUserAboutMissingFiles(component);
                    }
                }
            }
            else
            {
                if (component.Children.ResourceCollection.Any())
                {
                    WarnUserAboutMissingFiles(component);
                }
            }
        }
Beispiel #8
0
 private static string GetRandomComponentAssemblyDir()
 {
     return(ComponentLibraryManager.GetRandomComponentAssemblyDir());
 }
 /// <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 GetDirectoryPath(this CyPhy.ComponentAssembly assembly, ComponentLibraryManager.PathConvention pathConvention = ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT, string ProjectDirectory = null)
 {
     var relPath = ComponentLibraryManager.EnsureComponentAssemblyFolder(assembly, ProjectDirectory);
     switch (pathConvention)
     {
         case ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT:
             return relPath;
         case ComponentLibraryManager.PathConvention.ABSOLUTE:
             return Path.Combine(GetRootDirectoryPath(assembly.Impl.Project), relPath);
         default:
             throw new ArgumentOutOfRangeException(String.Format("Path convention of {0} is not supported", 
                                                                 pathConvention.ToString()));
     }
 }