Exemple #1
0
        /// <summary>
        /// 复制节点属性
        /// </summary>
        private void PasteNode()
        {
            VisualDesignFile vdFile = new VisualDesignFile(TemplateGroup, FileName);
            var node = vdFile.GetElementById(NextId);

            //for (int i = 0; i < node.Attributes.Count; i++)
            //{
            //    if (WidgetParameter.ContainsKey(node.Attributes[i].Name) && (string.Compare(node.Attributes[i].Name, "id", true) != 0))
            //    {
            //        node.Attributes[i].Value = WidgetParameter[node.Attributes[i].Name].ToString();
            //    }

            //}
            foreach (KeyValuePair <string, object> item in WidgetParameter)
            {
                if (item.Key != "id")
                {
                    if (node.Attributes.Contains(item.Key))
                    {
                        node.Attributes[item.Key].Value = item.Value.ToString();
                    }
                    else
                    {
                        node.Attributes.Add(item.Key, item.Value.ToString());
                    }
                }
            }
            vdFile.Replace(NextId, node);
            vdFile.SaveDraft(true);
        }
Exemple #2
0
        /// <summary>
        /// 添加布局DOM到文件
        /// </summary>
        protected void AddNode()
        {
            VisualDesignFile vdFile = new VisualDesignFile(TemplateGroup, FileName);

            string layoutHtml = GetLayoutHtml();
            var    newNode    = HtmlNode.CreateNode(layoutHtml);

            vdFile.Insert(Target, newNode, NextId, null);
            vdFile.SaveDraft();
        }
Exemple #3
0
        /// <summary>
        /// 添加节点到文件
        /// </summary>
        private void AddNode()
        {
            string           tagName = Path.GetFileNameWithoutExtension(WidgetParameter["filename"].ToString()).Replace(".", "_");
            VisualDesignFile vdFile  = new VisualDesignFile(TemplateGroup, FileName);
            var node = vdFile.CreateNode("wew", tagName, WidgetParameter);

            vdFile.Insert(Target, node, NextId, null);

            ///添加样式
            vdFile.Styles(ConvertControlPathToStylePath(WidgetParameter["filename"].ToString()));

            vdFile.SaveDraft(true);
        }
Exemple #4
0
        /// <summary>
        /// 修改节点到文件
        /// </summary>
        private void EditNode()
        {
            string           tagName = Path.GetFileNameWithoutExtension(WidgetParameter["filename"].ToString()).Replace(".", "_");
            VisualDesignFile vdFile  = new VisualDesignFile(TemplateGroup, FileName);
            var newNode = vdFile.CreateNode("wew", tagName, WidgetParameter);

            var originalId = RequestHelper.Get <string>("original");

            vdFile.Replace(originalId, newNode);

            ///添加样式
            vdFile.Styles(ConvertControlPathToStylePath(WidgetParameter["filename"].ToString()));

            vdFile.SaveDraft(true);
        }
Exemple #5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save(object sender, EventArgs e)
        {
            var layoutPath = this.layoutName.Value;

            if (!layoutPath.StartsWith("~"))
            {
                layoutPath = "~" + layoutPath;
            }
            layoutPath = Server.MapPath(layoutPath);

            string folder = RequestHelper.Get <string>("folder");
            string file   = RequestHelper.Get <string>("file");
            string path   = Server.MapPath(string.Format("~/_skins/~{0}/{1}", folder, file));
            string url    = string.Format("VisualDesign.aspx?folder=" + folder + "&file=" + file + "&state=design1&virtualdata=virtualdata");

            try
            {
                //文件夹不存在则创建
                if (!System.IO.Directory.Exists(Server.MapPath(string.Format("~/_skins/~{0}/", folder))))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(string.Format("~/_skins/~{0}/", folder)));
                }
                if (FileHelper.Exists(path))
                {
                    FileHelper.DeleteFile(path);
                }

                string strHtml = FileHelper.ReadFileWithLine(layoutPath, System.Text.Encoding.UTF8);
                FileHelper.WriteFileWithEncoding(path, strHtml, System.IO.FileMode.CreateNew, System.Text.Encoding.UTF8);

                //FileHelper.Copy(layoutPath, path,true);

                VisualDesignFile vdFile = new VisualDesignFile(folder, file);

                new System.Security.Permissions.FileIOPermission
                    (System.Security.Permissions.FileIOPermissionAccess.Write, new string[] { path }).Demand();

                vdFile.AddOrUpdateThemeFile(GeneralConfigs.GetConfig().Theme);
                vdFile.SaveDraft();
                Response.Redirect(url, false);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json; charset=utf-8";

            AjaxResponse ajaxMessage = new AjaxResponse();

            try
            {
                //参数
                var    action = context.Request["action"];
                string file   = context.Request["file"];
                string folder = context.Request["folder"];


                //删除操作
                #region  除操作
                if (string.Compare("delete", action, true) == 0)
                {
                    //获取操作
                    string widgetId = context.Request["id"];

                    VisualDesignFile vd = new VisualDesignFile(folder, file);
                    vd.Delete(widgetId);
                    vd.SaveDraft(true);
                    ajaxMessage.Success = true;
                }
                #endregion
                //移动操作
                #region 移动操作
                else if (string.Compare("move", action, true) == 0)
                {
                    //获取参数
                    var target = context.Request["target"];
                    var id     = context.Request["id"];
                    var nextId = context.Request["nextid"];

                    VisualDesignFile vd = new VisualDesignFile(folder, file);
                    vd.Move(target, id, nextId);
                    vd.SaveDraft();
                }
                #endregion
                #region 编辑背景
                else if (string.Compare("editbg", action, true) == 0)
                {
                    VisualDesignFile vd = new VisualDesignFile(folder, file);
                    var bodyAttr        = Base64Helper.Decode(context.Request["bodyattr"]);
                    var containerAttr   = Base64Helper.Decode(context.Request["ccattr"]);
                    vd.ReplaceDomAttr(vd.Body, bodyAttr);
                    if (vd.PageContainer != null)
                    {
                        vd.ReplaceDomAttr(vd.PageContainer, containerAttr);
                    }
                    vd.SaveDraft();
                }
                #endregion
                //发布模板
                #region 发布模板
                else if (string.Compare("publish", action, true) == 0)
                {
                    VisualDesignFile vd = new VisualDesignFile(folder, file);
                    vd.Publish();

                    //样式整合
                    vd.CombineStyle();
                }
                #endregion
                //编辑布局
                #region 编辑布局
                else if (string.Compare("editlayout", action, true) == 0)
                {
                    var temp = context.Request["params"];

                    if (string.IsNullOrEmpty(temp))
                    {
                        throw new ArgumentNullException("params为空!");
                    }

                    temp = Base64Helper.Decode(temp);

                    var layoutParams = JsonConvert.DeserializeObject <WidgetDesign>(temp);

                    VisualDesignFile vdFile = new VisualDesignFile(folder, file);

                    for (int i = 0; i < layoutParams.Columns.Count; i++)
                    {
                        var col = layoutParams.Columns[i];

                        var node = vdFile.GetElementById(col["id"].ToString());
                        if (node.Attributes.Contains("style"))
                        {
                            node.Attributes["style"].Value = col["style"].ToString();
                        }
                        else
                        {
                            node.Attributes.Add("style", col["style"].ToString());
                        }
                        if (node.Attributes.Contains("width"))
                        {
                            node.Attributes["width"].Value = col["width"].ToString();
                        }
                        else
                        {
                            node.Attributes.Add("width", col["width"].ToString());
                        }
                        if (node.Attributes.Contains("cssclass"))
                        {
                            node.Attributes["cssclass"].Value = col["cssclass"].ToString();
                        }
                        else
                        {
                            node.Attributes.Add("cssclass", col["cssclass"].ToString());
                        }
                        if (node.Attributes.Contains("widthunit"))
                        {
                            node.Attributes["widthunit"].Value = col["widthunit"].ToString();
                        }
                        else
                        {
                            node.Attributes.Add("widthunit", col["widthunit"].ToString());
                        }
                    }
                    vdFile.SaveDraft();
                }
                #endregion
                //更换主题
                #region 更换主题
                else if (string.Compare("changetheme", action, true) == 0)
                {
                    var theme = context.Request["theme"].Trim();

                    if (string.IsNullOrEmpty(theme))
                    {
                        throw new ArgumentNullException("主题不能为空!");
                    }
                    VisualDesignFile vdFile = new VisualDesignFile(folder, file);

                    vdFile.AddOrUpdateThemeFile(theme);

                    vdFile.SaveDraft();
                }
                #endregion
                //复制
                #region  制
                else if (string.Compare("copy", action, true) == 0)
                {
                    var id       = context.Request["id"];
                    var fileName = context.Request["fileName"];

                    VisualDesignFile vdFile = new VisualDesignFile(folder, file);
                    var node = vdFile.GetElementById(id);

                    Dictionary <string, object> WidgetParameter = new Dictionary <string, object>();

                    BaseControlHelper DcHelper = new BaseControlHelper();
                    DCInfo            infoList = DcHelper.PickUp(fileName);
                    foreach (DCPartInfo partInfo in infoList.Parts)
                    {
                        List <DataControlParameter> parsList = partInfo.Params;
                        foreach (DataControlParameter par in parsList)
                        {
                            object supportCopy = par.SupportCopy;
                            if (node.Attributes.Contains(par.Name) && supportCopy.ToString() == Boolean.TrueString)
                            {
                                WidgetParameter.Add(par.Name.ToLower(), node.Attributes[par.Name].Value);
                            }
                        }
                    }
                    if (!WidgetParameter.ContainsKey("filename"))
                    {
                        WidgetParameter.Add("filename", fileName);
                    }
                    //WidgetParameter.Add("id", node.Attributes["id"].Value);
                    if (infoList.Parts.Count == 0)
                    {
                        ajaxMessage.Success = false;
                        ajaxMessage.Message = "该控件没有没有可复制的属性!";
                    }
                    else
                    {
                        ajaxMessage.Success = true;
                        ajaxMessage.Message = JsonConvert.SerializeObject(WidgetParameter);
                    }
                }
                #endregion
                #region 检查模板是否存在
                else if (String.Compare("checktempexist", action, true) == 0)
                {
                    string templateGroupName =
                        GeneralConfigs.GetConfig().DefaultTemplateGroupFileName.ToLower().Replace(".xml", "");
                    string fileName = HttpContext.Current.Server.MapPath(
                        string.Format("/_skins/~{0}/{1}.ascx", templateGroupName, file));
                    if (File.Exists(fileName))
                    {
                        ajaxMessage.Success = false;
                        ajaxMessage.Message = "已经存在此模板";
                    }
                    else
                    {
                        ajaxMessage.Success = false;
                        ajaxMessage.Message = "";
                    }
                }
                #endregion
                else
                {
                    ajaxMessage.Success = false;
                    ajaxMessage.Message = "不存在该操作!";
                }
            }
            catch (Exception ex)
            {
                ajaxMessage.Success = false;
                ajaxMessage.Message = ex.Message;
            }
            context.Response.Write(ajaxMessage.ToJson());
        }