示例#1
0
        public async Task <SourceData> Get()
        {
            var list = await SourceList();

            //TODO: Get list of known file of options/source.
            var mgr     = new SourceManager.SourceManager();
            var catalog = await mgr.GetCatalog(list, true);

            var sourcePath = Path.GetTempPath() + "\\original";

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

            sourcePath += "\\";

            for (int i = 0; i < catalog.Count; i++)
            {
                var sourceSet = catalog[i];

                var url     = sourceSet.Source.Url;
                var index   = url.LastIndexOf("/");
                var hash    = sourceSet.Code.GetHashCode();
                var name    = url.Substring(index + 1);
                var period  = name.IndexOf(".");
                var newName = name.Substring(0, period) + "-" + hash + name.Substring(period);

                sourceSet.Source.Hash = hash.ToString();


                if (!File.Exists(sourcePath + newName))
                {
                    try
                    {
                        File.WriteAllText(sourcePath + newName, sourceSet.Code);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }

            var source = new SourceData();

            source.Sources = catalog.Select(s => s.Source).ToList();
            var doc = new Documentation();

            for (int i = 0; i < source.Sources.Count; i++)
            {
                var cat = catalog[i];
                var src = source.Sources[i];
                //source.Sources[0].Parsed.Functions
                for (int j = 0; j < src.Parsed.Functions.Count; j++)
                {
                    var fn   = src.Parsed.Functions[j];
                    var item = new RenoItem();
                    item.url   = src.Url;
                    item.id    = src.Id + "." + fn.Name;
                    item.image = fn.Image;
                    item.parms = new List <RenoParm>();
                    for (int k = 0; k < fn.Parameters.Count; k++)
                    {
                        var parm = fn.Parameters[k];
                        item.parms.Add(new RenoParm {
                            id = item.id + "." + parm.Name, defaultData = parm.Default
                        });
                    }

                    doc.Add(item, cat, true);
                    fn.Snippet = doc.GetDocumentation();
                    doc.Clear();
                }
            }

            return(source);
        }
示例#2
0
        // POST api/values
        public async Task <HttpResponseMessage> Generate([FromBody] RenoData renoData)
        {
            var files = new List <string>();

            var sourcePath = Path.GetTempPath() + "\\original\\";

            var rnd     = random.Next(1000000, 9999999);
            var path    = Path.GetTempPath();
            var newPath = path + "\\reno-" + rnd;
            var folder  = Directory.CreateDirectory(newPath);

            var list = await SourceList();

            var mgr     = new SourceManager.SourceManager();
            var catalog = await mgr.GetCatalog(list, true);

            var copied = false;
            var doc    = new Documentation();

            for (int i = 0; i < renoData.Controls.Count; i++)
            {
                var item = renoData.Controls[i];
                var url  = item.url;
                var hash = item.hash;

                var index   = url.LastIndexOf("/");
                var name    = url.Substring(index + 1);
                var period  = name.IndexOf(".");
                var newName = name.Substring(0, period) + "-" + hash + name.Substring(period);

                if (File.Exists(sourcePath + newName) && !File.Exists(newPath + "\\" + newName))
                {
                    //copy to directory
                    File.Copy(sourcePath + newName, newPath + "\\" + newName);
                    files.Add(newName);

                    var catItem = catalog.FirstOrDefault(c => c.Source.Url == item.url);

                    //create documentation here
                    doc.Add(item, catItem, false);

                    copied = true;
                }
            }

            if (copied)
            {
                files.Add("winmain.js");
                File.WriteAllBytes(newPath + "\\winmain.js", Encoding.ASCII.GetBytes(doc.GetDocumentation()));

                var sb = new StringBuilder();
                sb.Append("<html>\n<head>\n</head>\n<body>\n");
                foreach (var item in files)
                {
                    sb.Append(string.Format("<script src=\"{0}\"></script>", item) + "\n");
                }

                sb.Append("</body>\n</html>");

                File.WriteAllBytes(newPath + "\\include.html", Encoding.ASCII.GetBytes(sb.ToString()));

                ZipFile.CreateFromDirectory(newPath, newPath + ".zip");

                var path2 = newPath + ".zip";
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(path2, FileMode.Open, FileAccess.Read);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");
                return(result);
            }

            return(null);

            //return new FilePathResult(newPath + ".zip", "application/zip");

            //return zip of collected sources, info on how to use (events?)
        }