Example #1
0
        protected override async Task <int> OnExecuteAsync(CommandLineApplication app)
        {
            if (TemplateName.IndexOf('/') <= 0 || TemplateName.EndsWith('/'))
            {
                Console.WriteLine("Invalid TemplateName!Please Enter As Format aspnetboilerplate/[email protected] ");
            }

            if (!Mpa && string.IsNullOrWhiteSpace(SpaType))
            {
                SpaType = Prompt.GetString(SpaTypeDesc, defaultValue: "vue");
                SpaType = SpaType.ToLower();
                if ("vue,ng,react".IndexOf(SpaType) == -1)
                {
                    SpaType = "vue";
                }
            }

            Console.WriteLine($"TemplateName\t:{TemplateName}");
            Console.WriteLine($"PlaceHolder\t:{PlaceHolder}");
            Console.WriteLine($"ProjectName\t:{ProjectName}");
            Console.WriteLine($"MPA\t\t:{Mpa}");
            Console.WriteLine($"SpaType\t\t:{SpaType}");
            Console.WriteLine($"RenameBackup\t:{RenameBackup}");

            //set project folder
            var projectFolder = Path.Combine(Directory.GetCurrentDirectory(), ProjectName);

            if (!Directory.Exists(projectFolder))
            {
                Directory.CreateDirectory(projectFolder);
            }

            //Fetch Template Zip
            Console.WriteLine($"Fetching Project Template From Github.com/{TemplateName}...");

            var filePath = Path.Combine(projectFolder, $"{ProjectName}.zip");

            var tNames   = TemplateName.Split(new char[] { '/', '@' });
            var userName = string.Empty;
            var repoName = string.Empty;
            var tagName  = "latest";

            if (tNames.Length > 1)
            {
                userName = tNames[0];
                repoName = tNames[1];
            }

            if (tNames.Length > 2)
            {
                tagName = tNames[2];
            }

            await FetchTemplateZipFile(userName, repoName, tagName, filePath);

            //Extract Zip File
            Console.WriteLine($"Extracting Project Template Zip:{filePath}...");
            Console.WriteLine($"Extracting To:{projectFolder}...");
            ExtractZipFile(filePath, projectFolder, repoName);

            //Folders To Rename
            Console.WriteLine("Cleaning Sub Dirs in Project Template Folder...");
            var excludeFolders = new List <string> {
                "./vue", "./angular", "./reactjs"
            };

            if (!Mpa)
            {
                excludeFolders.Add($"./aspnet-core/src/{PlaceHolder}.Web.Mvc");
                //TODO@personball remove web.mvc entry in vs solution file(sln).
                switch (SpaType.ToLower())
                {
                case "ng":
                    excludeFolders.Remove("./angular");
                    break;

                case "react":
                    excludeFolders.Remove("./reactjs");
                    break;

                case "vue":
                default:
                    excludeFolders.Remove("./vue");
                    break;
                }
            }

            //Delete ExcludeFolders
            foreach (var excludeFolder in excludeFolders)
            {
                var directoryToDel = Path.Combine(projectFolder, excludeFolder);
                if (Directory.Exists(directoryToDel))
                {
                    Console.WriteLine($"ExcludeFolders Delete:{directoryToDel}");
                    Directory.Delete(directoryToDel, true);
                }
            }

            //Rename Folder
            var companyNamePlaceHolder = PlaceHolder.Split('.')[0];
            var projectNamePlaceHolder = PlaceHolder.Split('.')[1];

            var newNames       = ProjectName.Split('.');
            var newCompanyName = string.Empty;
            var newProjectName = ProjectName;

            if (newNames.Length > 1)
            {
                newCompanyName = newNames[0];
                newProjectName = newNames[1];
            }
            Console.WriteLine($"Renaming {PlaceHolder} to {newCompanyName}{(newNames.Length > 1 ? "." : "")}{newProjectName}...");
            var slnRenamer = new SolutionRenamer(projectFolder, companyNamePlaceHolder, projectNamePlaceHolder, newCompanyName, newProjectName)
            {
                CreateBackup = RenameBackup
            };

            slnRenamer.Run();

            //Delete Template Zip
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            Console.WriteLine("Init Completed!");
            return(1);
        }
Example #2
0
        public TemplateInfo(byte[] templateData, GetStructAttribsReply attribs)
        {
            MemberInfo = new List <MemberInfo>();

            //Ok, this is a little confusing, there's supposed to be a header, but
            //it seems that the data returned is not in the format specified in the
            //1756-RM005 publication. There is no header data (meaning we can't
            //know how many elements are in the template), so we kinda have to
            //pick through and cheat... Luckily this data is found in the
            //GetStructAttribs reply

            //The format of the data returned is:
            //[2:Info][2:Type][4:Offset]
            //When we reach a byte that is greater than 0x00
            int offset     = 0;
            int lastMember = -1;
            int lastOffset = 0;

            for (int i = 0; i < attribs.MemberCount; i++)
            {
                MemberInfo mi = new MemberInfo();
                mi.Info         = BitConverter.ToUInt16(templateData, offset);
                offset         += 2;
                mi.MemberType   = BitConverter.ToUInt16(templateData, offset);
                offset         += 2;
                mi.MemberOffset = BitConverter.ToInt32(templateData, offset);
                if (lastMember >= 0)
                {
                    //Compute size for the last member...
                    int size = mi.MemberOffset - lastOffset;
                    MemberInfo[lastMember].MemberSize = size;
                }
                lastOffset = mi.MemberOffset;
                lastMember++;
                offset += 4;
                switch ((CIPType)(mi.MemberType & 0x00FF))
                {
                case CIPType.BOOL:
                    mi.LogixType = LogixTypes.Bool;
                    break;

                case CIPType.DINT:
                    mi.LogixType = LogixTypes.DInt;
                    break;

                case CIPType.INT:
                    mi.LogixType = LogixTypes.Int;
                    break;

                case CIPType.LINT:
                    mi.LogixType = LogixTypes.LInt;
                    break;

                case CIPType.REAL:
                    mi.LogixType = LogixTypes.Real;
                    break;

                case CIPType.SINT:
                    mi.LogixType = LogixTypes.SInt;
                    break;

                case CIPType.STRUCT:
                    mi.LogixType = LogixTypes.User_Defined;
                    break;

                default:
                    mi.LogixType = LogixTypes.Unknown;
                    break;
                }
                MemberInfo.Add(mi);
            }

            //Compute the size for the last member
            int lastSize = TagSize - lastOffset;

            MemberInfo[MemberInfo.Count - 1].MemberSize = lastSize;

            NumberOfMembers = (ushort)MemberInfo.Count;
            TemplateHandle  = attribs.Handle;
            TagSize         = attribs.MemorySize;

            //And now we have to go through the rest of the data and pick out
            //null terminated strings...
            int    start      = offset;
            string currentStr = "";
            int    idx        = -1;

            for (int i = start; i < templateData.Length; i++)
            {
                if (templateData[i] == 0x00)
                {
                    if (string.IsNullOrEmpty(currentStr))
                    {
                        continue;
                    }

                    if (idx == -1)
                    {
                        //This is the structure name...
                        TemplateName = currentStr;
                        if (TemplateName.Contains(';'))
                        {
                            TemplateName = TemplateName.Substring(0, TemplateName.IndexOf(';'));
                        }
                    }
                    else
                    {
                        MemberInfo[idx].MemberName = currentStr;
                    }

                    currentStr = string.Empty;
                    idx++;
                }
                else
                {
                    currentStr += (char)templateData[i];
                }
            }
        }