Exemplo n.º 1
0
        /// <summary>
        /// 将文件输出到站点目录
        /// </summary>
        /// <param name="assDirPath"></param>
        /// <param name="pluAssembly"></param>
        /// <param name="resourceUrl"></param>
        /// <param name="fwAss"></param>
        public void WriteResourceToSiteDir(string assDirPath, Assembly pluAssembly, ref IResourceUrl resourceUrl, IPlusAssemblyInfo fwAss)
        {
            assDirPath.CreateDirectoryIfNotExist();
            if (resourceUrl.ManifestResourceName.EndsWith(".config"))
            {
                resourceUrl.HasWrittenToSiteDir = false;
                return;
            }
            #region 根据命名空间创建目录
            var childPath = resourceUrl.ManifestResourceName.Replace(fwAss.Name, string.Empty).Trim('.');
            var childDirs = childPath.Split('.');
            var fileName  = string.Empty;
            if (childDirs.Length >= 2)
            {
                childPath = childDirs
                            .Where((str, index) =>
                                   index < childDirs.Length - 2)
                            .Aggregate(assDirPath, Path.Combine);
                childPath.CreateDirectoryIfNotExist();
                fileName = string.Format("{0}.{1}", childDirs[childDirs.Length - 2], childDirs[childDirs.Length - 1]);
            }
            #endregion

            //如果没有父级命名空间
            if (childDirs.Length == 1)
            {
                fileName = childPath;
            }
            if (!fileName.IsNotEmpty())
            {
                return;
            }
            var filePath = Path.Combine(childPath, fileName);
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //获取相对路径
            resourceUrl.SiteRelativeUrl = filePath.Replace(GlobalApplicationObject.Current.ApplicationContext.SitePaths.SiteRootDirPath, string.Empty)
                                          .Replace("\\", "/");

            #region 压缩Js和Css
            var ext = Path.GetExtension(fileName);
            if ((ext == ".js" || ext == ".css"))
            {
                var content = ManifestResourceManager.GetWebResourceAsString(pluAssembly, resourceUrl.ManifestResourceName);
                if (!resourceUrl.ManifestResourceName.ToLower().Contains(".min."))
                {
                    #region 判断是否压缩脚本或者样式文件
                    var configManager = GlobalApplicationObject.Current.ApplicationContext.ConfigManager;
                    var sysConfig     = configManager.GetConfig <SystemConfigInfo>();
                    if (ext == ".js" && sysConfig.IsMinJs)
                    {
                        content = MinHelper.MinJs(content);
                    }
                    else if (ext == ".css" && sysConfig.IsMinCss)
                    {
                        content = MinHelper.MinCss(content);
                    }
                    #endregion
                }
                //写文件
                File.WriteAllText(filePath, content, Encoding.UTF8);
            }
            else
            {
                using (var stream = ManifestResourceManager.GetManifestResourceStream(pluAssembly, resourceUrl.ManifestResourceName))
                {
                    var buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);  //将流的内容读到缓冲区
                    using (var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        fs.Write(buffer, 0, buffer.Length);
                        fs.Flush();
                    }
                }
            }
            #endregion
            resourceUrl.FileWriteTicks = AssemblyManager.GetFileWriteTicks(filePath);
        }
Exemplo n.º 2
0
        private static void FormatMaxMinValueOutput(Dictionary<int, Dictionary<string, float[]>> valuesMap,
            FlightDataEntities.FlightParameter[] parameters)
        {
            var keys = from onekey in parameters
                       select onekey.ParameterID;

            Dictionary<string, MaxHelper> maxHelperMap = new Dictionary<string, MaxHelper>();
            Dictionary<string, MinHelper> minHelperMap = new Dictionary<string, MinHelper>();

            foreach (var key in (from k in valuesMap.Keys orderby k ascending select k).Take(valuesMap.Keys.Count - 1))
            {
                var oneSecMap = valuesMap[key];
                foreach (var one in oneSecMap.Keys)
                {
                    if (maxHelperMap.ContainsKey(one))
                    {
                        MaxHelper helper = maxHelperMap[one];
                        float max = oneSecMap[one].Max();
                        if (max > helper.Value)
                        {
                            helper.Value = max;
                            helper.Second = key;
                            maxHelperMap[one] = helper;
                        }
                    }
                    else
                    {
                        MaxHelper helper = new MaxHelper() { ParameterID = one, Second = key, Value = oneSecMap[one].Max() };
                        maxHelperMap.Add(one, helper);
                    }

                    if (minHelperMap.ContainsKey(one))
                    {
                        MinHelper helper = minHelperMap[one];
                        float min = oneSecMap[one].Min();
                        if (min < helper.Value)
                        {
                            helper.Value = min;
                            helper.Second = key;
                            minHelperMap[one] = helper;
                        }
                    }
                    else
                    {
                        MinHelper helper = new MinHelper() { ParameterID = one, Second = key, Value = oneSecMap[one].Min() };
                        minHelperMap.Add(one, helper);
                    }
                }
            }

            string headers = string.Empty;
            //foreach (string kk in keys)
            //{
            //    headers += kk;
            //headers += "\t";
            headers += "MaxValue";
            headers += "\t";
            headers += "Second";
            headers += "\t";
            headers += "MinValue";
            headers += "\t";
            headers += "Second";
            headers += "\t";
            //}

            System.Diagnostics.Debug.WriteLine(string.Empty);
            System.Diagnostics.Debug.WriteLine("MaxMin Value Report_____________________________________________________________________________________________________________________________________");
            System.Diagnostics.Debug.WriteLine(string.Empty);
            string header = string.Format("ParameterID\t{0}", headers);
            System.Diagnostics.Debug.WriteLine(header);

            foreach (string paramID in keys)
            {
                StringBuilder output = new StringBuilder();
                output.Append(paramID);
                output.Append("\t");

                var max = maxHelperMap[paramID];
                output.Append(max.Value);
                output.Append("\t");
                output.Append(max.Second);
                output.Append("\t");
                var min = minHelperMap[paramID];
                output.Append(min.Value);
                output.Append("\t");
                output.Append(min.Second);
                output.Append("\t");

                System.Diagnostics.Debug.WriteLine(output.ToString());
            }
        }