Beispiel #1
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            var assembly = this.GetType().Assembly;
            var data     = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DemoAttribute>(assembly, false);

            var types = new[] { "js", "cs", "html" };

            foreach (var entry in data)
            {
                var att = entry.Value;
                foreach (var type in types)
                {
                    CreateSourceHtml(att, type);
                }
            }

            var aboutHtml = ReadAndTransformMarkdownFile(DextopUtil.MapPath("~/Demos/About.txt"));

            using (var stream = File.CreateText(DextopUtil.MapPath("~/source/About.html")))
            {
                stream.WriteLine("<html>");
                stream.WriteLine("<head>");
                stream.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />");
                stream.WriteLine("<meta name=\"robots\" content=\"noindex\">");
                stream.WriteLine("</head>");
                stream.WriteLine("<body>");
                stream.WriteLine(aboutHtml);
                stream.WriteLine("</body>");
                stream.WriteLine("</html>");
            }
        }
        public static void SaveContacts(IList <RichPerson> contacts)
        {
            var dataFilePath = DextopUtil.MapPath("rich-people.json");

            var json = JsonConvert.SerializeObject(contacts, Formatting.Indented, new JsonSerializerSettings
            {
                Converters = new[] { new Newtonsoft.Json.Converters.IsoDateTimeConverter() }
            });

            File.WriteAllText(dataFilePath, json);
        }
        public static List <RichPerson> GetContacts()
        {
            List <RichPerson> contacts = new List <RichPerson>();

            var dataFilePath = DextopUtil.MapPath("rich-people.json");

            return(JsonConvert.DeserializeObject <List <RichPerson> >(File.ReadAllText(dataFilePath), new JsonSerializerSettings
            {
                Converters = new[] { new Newtonsoft.Json.Converters.IsoDateTimeConverter() }
            }));
        }
Beispiel #4
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            BaseSrcPath = DextopUtil.MapPath("~/guides/articles/");
            OutputPath  = DextopUtil.MapPath("~/guides/html/");

            var articles = ProcessDirectory(BaseSrcPath);

            using (var tw = new StreamWriter(output))
            {
                tw.WriteLine("Ext.ns('Showcase');");
                tw.Write("Showcase.Guides = ");
                tw.Write(DextopUtil.Encode(articles.ToArray()));
                tw.WriteLine(";");
            }
        }
Beispiel #5
0
        private int GetCacheBuster(DemoAttribute att)
        {
            DateTime lastWrite = DateTime.MinValue;

            foreach (var ext in new [] { "txt", "cs", "js", "html" })
            {
                String vsource  = String.Format("{0}/{1}.{2}", att.Path, att.Id, ext);
                var    fileInfo = new FileInfo(DextopUtil.MapPath(vsource));
                if (fileInfo.Exists)
                {
                    var lw = fileInfo.LastWriteTime;
                    if (lw > lastWrite)
                    {
                        lastWrite = lw;
                    }
                }
            }
            return(Math.Abs(lastWrite.GetHashCode()));
        }
        public static List <Stock> GetStockData()
        {
            String stockCodes   = "AAPL+XOM+ORCL+MSFT+INTC+GOOG+IBM+CHL+PTR";
            String resultConfig = "snc1j1p";

            String stockRequstUrl = "http://finance.yahoo.com/d/quotes.csv?s=" + stockCodes + "&f=" + resultConfig;

            var cacheFile = DextopUtil.MapPath("Cache/stocks.csv");

            if (!File.Exists(cacheFile) || File.GetLastWriteTime(cacheFile) < DateTime.Now.AddHours(-1))
            {
                try
                {
                    WebClient client = new WebClient();
                    client.DownloadFile(stockRequstUrl, cacheFile);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            var lines = File.ReadAllLines(cacheFile);

            List <Stock> stocks = new List <Stock>();

            foreach (var line in lines)
            {
                String[] attributes = line.Split(',');
                stocks.Add(new Stock()
                {
                    Code   = attributes[0].Trim('"'),
                    Name   = attributes[1].Trim('"'),
                    Change = Decimal.Parse(attributes[2], CultureInfo.InvariantCulture) / 10,
                    Value  = Decimal.Parse(attributes[3].TrimEnd('B'), CultureInfo.InvariantCulture),
                    Price  = Decimal.Parse(attributes[4], CultureInfo.InvariantCulture)
                });
            }

            return(stocks);
        }
Beispiel #7
0
 public GdpPanel()
 {
     GdpDataProvider.CacheFilePath = DextopUtil.MapPath("Cache/gdp.json");
 }
Beispiel #8
0
        void CreateSourceHtml(DemoAttribute att, string type)
        {
            bool   plain     = (type != "html");
            String extension = plain ? String.Format("{0}.html", type) : type;

            String vsource   = String.Format("{0}/{1}.{2}", att.Path, att.Id, type);
            String vmdsource = String.Format("{0}/{1}.txt", att.Path, att.Id);
            String vdest     = String.Format("~/source/{0}.{1}", att.Id, extension);

            String source   = DextopUtil.MapPath(vsource);
            String mdsource = DextopUtil.MapPath(vmdsource);
            String dest     = DextopUtil.MapPath(vdest);

            String content = null;

            if (File.Exists(source))
            {
                if (type == "cs")
                {
                    content = StripDemoAttributes(File.ReadAllLines(source));
                }
                else
                {
                    content = File.ReadAllText(source);
                }
            }
            else if (!plain && File.Exists(mdsource))
            {
                content = ReadAndTransformMarkdownFile(mdsource);
            }


            using (var writer = new StringWriter())
            {
                writer.WriteLine("<html>");

                if (content != null)
                {
                    writer.WriteLine("<head>");
                    writer.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />");
                    writer.WriteLine("<link href=\"../client/lib/prettify/prettify.css\" type=\"text/css\" rel=\"stylesheet\" />");
                    writer.WriteLine("<meta name=\"robots\" content=\"noindex\">");
                    writer.WriteLine("</head>");


                    if (plain)
                    {
                        writer.WriteLine("<script type=\"text/javascript\" src=\"../client/lib/prettify/prettify.js\"></script>");
                        writer.WriteLine("<script type=\"text/javascript\">window['PR_TAB_WIDTH'] = 4;</script>");

                        writer.WriteLine("<body onload=\"prettyPrint()\">");
                        writer.WriteLine("<pre class=\"prettyprint\">");
                        writer.WriteLine(WebUtility.HtmlEncode(content));
                        writer.WriteLine("</pre>");
                    }
                    else
                    {
                        writer.WriteLine("<body>");
                        writer.WriteLine(content);
                    }

                    writer.WriteLine("</body>");
                }
                writer.WriteLine("</html>");

                var newContent = writer.ToString();
                if (!File.Exists(dest) || File.ReadAllText(dest) != newContent)
                {
                    File.WriteAllText(dest, newContent);
                }
            }
        }