Esempio n. 1
0
        public ExportConfig Clone()
        {
            ExportConfig newExportConfig = new ExportConfig();

            foreach (KeyValuePair <string, object> config in this.configs)
            {
                newExportConfig.Set(config.Key, config.Value);
            }
            return(newExportConfig);
        }
Esempio n. 2
0
 public void Dispose()
 {
     this.Close();
     httpClient = null;
     if (exportConfig != null)
     {
         exportConfig.Dispose();
         exportConfig = null;
     }
 }
        public Dictionary <string, Stream> ExportAsStream(ExportConfig exportConfig)
        {
            MemoryStream ms = (MemoryStream)ExportChart(exportConfig, "", false, true);

            Dictionary <string, Stream> files = new Dictionary <string, Stream>();

            using (Ionic.Zip.ZipFile z = Ionic.Zip.ZipFile.Read(ms))
            {
                foreach (Ionic.Zip.ZipEntry zEntry in z)
                {
                    MemoryStream tempS = new MemoryStream();
                    zEntry.Extract(tempS);
                    tempS.Seek(0, SeekOrigin.Begin);
                    files.Add(zEntry.FileName, tempS);
                }
            }

            return(files);
        }
        private object ExportChart(ExportConfig exportConfig, string outputDir = "", bool unzip = true, bool ExportAsStream = false)
        {
            exporter.ExportConfig = exportConfig;
            string       zipPath = string.Empty;
            MemoryStream ms      = null;

            if (!ExportAsStream)
            {
                zipPath = exporter.Start();
            }
            else
            {
                ms = exporter.AsStream();
                return(ms);
            }

            if (string.IsNullOrEmpty(outputDir))
            {
                outputDir = Utils.Utils.GetBaseDirectory();
            }

            DirectoryInfo dirInfo = new DirectoryInfo(outputDir);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            if (!unzip)
            {
                FileInfo fn           = new FileInfo(zipPath);
                string   fileFullName = Path.Combine(outputDir, fn.Name);
                fn.CopyTo(fileFullName, true);

                return(new List <string>(new string[] { fileFullName }));
            }
            else
            {
                return(Utils.Utils.ExtractZipInDirectory(zipPath, outputDir));
            }
        }
Esempio n. 5
0
        public MultipartFormDataContent GetFormattedConfigs(Boolean exportServerMinifyResources)
        {
            this.minifyResources = exportServerMinifyResources;
            MultipartFormDataContent formDataContent = new MultipartFormDataContent();

            using (ExportConfig clonedSelf = this.CloneWithProcessedProperties())
            {
                foreach (var config in clonedSelf.configs)
                {
                    if (config.Key.Equals(ExportConfig.PAYLOAD))
                    {
                        using (StreamContent streamContent = new StreamContent(File.Open(config.Value.ToString(), FileMode.Open)))
                        {
                            formDataContent.Add(Utils.Utils.CloneStreamContent(streamContent), config.Key, "file");
                        }
                    }
                    else
                    {
                        formDataContent.Add(new StringContent(config.Value.ToString().Replace("\n", "").Replace("\r", "")), config.Key);
                    }
                }
            }
            return(formDataContent);
        }
 public MemoryStream ExportAsStream(ExportConfig exportConfig, string outputDir, bool unzip)
 {
     return((MemoryStream)ExportChart(exportConfig, outputDir, unzip));
 }
 public MemoryStream ExportAsStream(ExportConfig exportConfig, bool unzip)
 {
     return((MemoryStream)ExportChart(exportConfig, null, unzip));
 }
 public MemoryStream ExportAsStream(ExportConfig exportConfig, string outputDir)
 {
     return((MemoryStream)ExportChart(exportConfig, outputDir, true));
 }
 public List <string> Export(ExportConfig exportConfig, string outputDir, bool unzip, Boolean exportBulk = true)
 {
     exportConfig.Set("exportBulk", exportBulk);
     return((List <string>)ExportChart(exportConfig, outputDir, unzip));
 }
 public List <string> Export(ExportConfig exportConfig, bool unzip)
 {
     return((List <string>)ExportChart(exportConfig, null, unzip, false));
 }
 public List <string> Export(ExportConfig exportConfig, string outputDir)
 {
     return((List <string>)ExportChart(exportConfig, outputDir, true));
 }
 public List <string> Export(ExportConfig exportConfig)
 {
     return((List <string>)ExportChart(exportConfig));
 }
Esempio n. 13
0
        public ExportConfig CloneWithProcessedProperties()
        {
            string internalFilePath, oldValue;

            List <ResourcePathInfo> zipBag = new List <ResourcePathInfo>();

            //var this = this.Clone();
            //this.enableTypeCheckAndConversion = false;

            this.configs[CLIENTNAME] = "C#";
            this.configs[PLATFORM]   = Environment.OSVersion.Platform.ToString();

            /*
             * if (this.Has(CHARTCONFIG))
             * {
             *  oldValue = this.Get(CHARTCONFIG).ToString();
             *  string trimmedValue = oldValue.Replace("\n", "").Replace("\t", "").Replace("\r", "");
             *  this.Remove(CHARTCONFIG);
             *
             *  if (oldValue.ToLower().EndsWith(".json"))
             *  {
             *      oldValue = ReadFileContent(oldValue, encodeBase64: false);
             *  }
             *  else if (((trimmedValue.StartsWith("{") && trimmedValue.EndsWith("}")) || (trimmedValue.StartsWith("[") && trimmedValue.EndsWith("]"))))
             *  {
             *
             *  }
             *  else
             *  {
             *      throw new Exception("Invalid Data Type: Data should be in either serialized JSON, file path of JSON file.");
             *  }
             *
             *  this.Set(CHARTCONFIG, oldValue);
             * }
             */

            if (this.Has(INPUTSVG))
            {
                oldValue = this.Get(INPUTSVG).ToString();
                this.Remove(INPUTSVG);

                internalFilePath = "inputSVG.svg";
                zipBag.Add(new ResourcePathInfo()
                {
                    internalPath = internalFilePath,
                    externalPath = oldValue
                });
                this.configs[INPUTSVG] = internalFilePath;
                //this.Set(INPUTSVG, internalFilePath);
            }

            if (this.Has(CALLBACKS))
            {
                oldValue = this.Get(CALLBACKS).ToString();
                this.Remove(CALLBACKS);

                internalFilePath = "callbackFile.js";
                zipBag.Add(new ResourcePathInfo()
                {
                    internalPath = internalFilePath,
                    externalPath = oldValue
                });

                this.configs[CALLBACKS] = internalFilePath;
            }

            if (this.Has(DASHBOARDLOGO))
            {
                oldValue = this.Get(DASHBOARDLOGO).ToString();
                this.Remove(DASHBOARDLOGO);

                var ext = new FileInfo(oldValue).Extension;
                internalFilePath = string.Format("dashboardLogo{0}", ext.StartsWith(".") ? ext : "." + ext);
                zipBag.Add(new ResourcePathInfo()
                {
                    internalPath = internalFilePath,
                    externalPath = oldValue
                });

                this.configs[DASHBOARDLOGO] = internalFilePath;
            }

            if (this.Has(OUTPUTFILEDEFINITION))
            {
                oldValue = this.Get(OUTPUTFILEDEFINITION).ToString();
                this.Remove(OUTPUTFILEDEFINITION);

                this.configs[OUTPUTFILEDEFINITION] = ReadFileContent(oldValue, encodeBase64: false);
            }

            if (this.Has(TEMPLATE))
            {
                string templatePathWithinZip;
                List <ResourcePathInfo> zipPaths;
                this.createTemplateZipPaths(out zipPaths, out templatePathWithinZip);

                this.configs[TEMPLATE] = templatePathWithinZip;

                zipBag.AddRange(zipPaths);
            }

            if (this.Has(ASYNCCAPTURE))
            {
                oldValue = this.Get(ASYNCCAPTURE).ToString();
                this.Remove(ASYNCCAPTURE);

                if (!string.IsNullOrEmpty(oldValue))
                {
                    if (Convert.ToBoolean(oldValue))
                    {
                        this.configs[ASYNCCAPTURE] = true;
                    }
                }
            }

            if (this.Has(EXPORTBULK))
            {
                oldValue = this.Get(EXPORTBULK).ToString();
                this.Remove(ASYNCCAPTURE);

                if (!string.IsNullOrEmpty(oldValue))
                {
                    if (!Convert.ToBoolean(oldValue))
                    {
                        this.configs[EXPORTBULK] = "";
                    }
                }
            }

            if (zipBag.Count > 0)
            {
                string zipFile = ExportConfig.generateZip(zipBag, this.minifyResources);
                this.configs[PAYLOAD] = zipFile;
            }
            zipBag.Clear();

            return(this);
        }
Esempio n. 14
0
        private static string generateZip(List <ResourcePathInfo> fileBag, Boolean isminify)
        {
            var tempZipFilePath = GetTempFileName();

            string[] extensions = new string[] { ".html", ".css", ".js" };
            using (ZipFile zip = new ZipFile())
            {
                foreach (var file in fileBag)
                {
                    string dirPath = file.internalPath.Replace(@"\.\", @"\");
                    string newPath;
                    string fileExtension;
                    fileExtension = Path.GetExtension(file.internalPath);
                    Boolean isHtmlJsCss = extensions.Contains(fileExtension);
                    if (isminify && isHtmlJsCss)
                    {
                        string externalDir = Path.GetDirectoryName(file.externalPath);
                        string fileName    = Path.GetFileName(file.internalPath);
                        newPath = externalDir + "/" + fileName;

                        Boolean isHtml   = fileExtension == ".html" ? true : false;
                        string  htmlFile = "";

                        if (isHtml)
                        {
                            var htmlDoc = new HtmlDocument();
                            htmlDoc.Load(file.externalPath);

                            ExportConfig.updateHtml(out htmlDoc, htmlDoc, "//link", fileBag);
                            ExportConfig.updateHtml(out htmlDoc, htmlDoc, "//script", fileBag);
                            htmlFile = externalDir + "/temp.fusionexport.html";
                            File.WriteAllText(htmlFile, htmlDoc.DocumentNode.WriteTo());
                        }


                        if (Path.GetExtension(file.externalPath).ToLower() == ".css")
                        {
                            var result = Uglify.Css(System.IO.File.ReadAllText(file.externalPath));
                            File.WriteAllText(newPath, result.Code);
                        }
                        if (Path.GetExtension(file.externalPath).ToLower() == ".js")
                        {
                            var result = Uglify.Js(System.IO.File.ReadAllText(file.externalPath));
                            File.WriteAllText(newPath, result.Code);
                        }
                        if (Path.GetExtension(file.externalPath).ToLower() == ".html")
                        {
                            var result = Uglify.Html(System.IO.File.ReadAllText(isHtml ? htmlFile : file.externalPath));
                            File.WriteAllText(newPath, result.Code);
                            if (isHtml)
                            {
                                File.Delete(htmlFile);
                            }
                        }
                    }
                    else
                    {
                        newPath = file.externalPath;
                    }
                    ZipEntry zipEntry = zip.AddFile(newPath);
                    zipEntry.FileName = dirPath;
                    //if (isminify && isHtmlJsCss) File.Delete(newPath);
                }
                zip.Save(tempZipFilePath);
            }
            return(tempZipFilePath);
        }