public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var TypeId = UMC.Data.Utility.Guid(Web.UIDialog.AsyncDialog("Id", d =>
            {
                return(new LinkDialog()
                {
                    IsPage = true, Title = "连接列表"
                });
            }), true);

            var cateEntity = Database.Instance().ObjectEntity <UMC.Data.Entities.Link>();


            cateEntity.Where.And().Equal(new UMC.Data.Entities.Link
            {
                Id = TypeId ?? Guid.Empty
            });
            var link = cateEntity.Single() ?? new Data.Entities.Link();


            var userValue = this.AsyncDialog("User", d =>
            {
                var fdlg   = new Web.UIFormDialog();
                fdlg.Title = "网页连接";

                if (link.Id.HasValue == false)
                {
                    link.Id = Guid.NewGuid();
                    request.Arguments["Id"] = link.Id.ToString();
                }
                fdlg.AddFile("图片", "_Header", Data.WebResource.Instance().ImageResolve(link.Id.Value, "1", 5))
                .Command("Design", "Picture", new UMC.Web.WebMeta().Put("id", link.Id).Put("seq", "1"));
                fdlg.AddText("网址", "Url", link.Url).Put("tip", "");
                fdlg.AddText("网址标题", "Caption", link.Caption);
                fdlg.AddText("所属组", "GroupBy", link.GroupBy);


                fdlg.Submit("确认", this.Context.Request, "Settings.Link");
                return(fdlg);
            });

            UMC.Data.Reflection.SetProperty(link, userValue.GetDictionary());
            if (link.Id.HasValue)
            {
                link.ModifiedTime = DateTime.Now;
                cateEntity.Update(link);
            }
            else
            {
                link.IsMenu       = true;
                link.Times        = 0;
                link.CreationTime = DateTime.Now;
                link.ModifiedTime = DateTime.Now;
                link.Favs         = 0;
                link.Id           = TypeId;// Guid.NewGuid();
                cateEntity.Insert(link);
            }
            this.Prompt("更新成功", false);
            this.Context.Send(new UMC.Web.WebMeta().Put("type", "Settings.Link"), true);
        }
Example #2
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var user    = UMC.Security.Identity.Current;
            var groupId = UMC.Data.Utility.Guid(this.AsyncDialog("id", d =>
            {
                this.Prompt("请传入参数");
                return(this.DialogValue(user.Id.ToString()));
            }), true) ?? Guid.Empty;

            var Seq = this.AsyncDialog("seq", g =>
            {
                if (request.SendValues != null)
                {
                    return(this.DialogValue(request.SendValues["Seq"] ?? "0"));
                }
                else
                {
                    return(this.DialogValue("0"));
                }
            });
            WebResource oosr     = WebResource.Instance();//as OssResource;
            var         media_id = UMC.Web.UIDialog.AsyncDialog("media_id", g =>
            {
                if (request.IsApp)
                {
                    var f = Web.UIDialog.CreateDialog("File");
                    f.Config.Put("Submit", new UIClick(new WebMeta(request.Arguments.GetDictionary()).Put(g, "Value"))
                    {
                        Command = request.Command,
                        Model   = request.Model
                    });
                    return(f);
                }
                else
                {
                    var webr = UMC.Data.WebResource.Instance();
                    var from = new Web.UIFormDialog()
                    {
                        Title = "图片上传"
                    };

                    from.AddFile("选择图片", "media_id", webr.ImageResolve(groupId, "1", 4));

                    from.Submit("确认上传", request, "image");
                    return(from);
                }
            });

            var pictureEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Picture>();

            pictureEntity.Order.Asc(new Data.Entities.Picture {
                Seq = 0
            });
            pictureEntity.Where.Reset().And().Equal(new Data.Entities.Picture {
                group_id = groupId
            });
            if (String.Equals(media_id, "none"))
            {
                var seq = UMC.Data.Utility.Parse(Seq, 0);
                if (request.IsApp == false)
                {
                    this.AsyncDialog("Confirm", s =>
                    {
                        return(new Web.UIConfirmDialog(String.Format("确认删除此组第{0}张图片吗", seq))
                        {
                            Title = "删除提示"
                        });
                    });
                }

                if (seq == 1)
                {
                    pictureEntity.Where.And().Greater(new Data.Entities.Picture {
                        Seq = 1
                    });
                    var seqs = pictureEntity.Single();
                    if (seqs != null)
                    {
                        UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Picture>()
                        .Where.And().Equal(new Data.Entities.Picture {
                            Seq = 1, group_id = groupId
                        })
                        .Entities.Update(new Data.Entities.Picture {
                            UploadDate = DateTime.Now
                        });
                        pictureEntity.Where.And().Equal(new UMC.Data.Entities.Picture {
                            Seq = seqs.Seq
                        });

                        oosr.Transfer(new Uri(oosr.ResolveUrl(seqs.group_id.Value, seqs.Seq, 0)), groupId, seq);
                    }
                    else
                    {
                        pictureEntity.Where.Reset().And().Equal(new UMC.Data.Entities.Picture
                        {
                            Seq      = 1,
                            group_id = groupId
                        });
                    }
                    pictureEntity.Delete();
                }
                else
                {
                    pictureEntity.Where.And().Equal(new UMC.Data.Entities.Picture {
                        Seq = seq
                    });
                    pictureEntity.Delete();
                }
            }
            else
            {
                var type = this.AsyncDialog("type", g => this.DialogValue("jpg"));
                var seq  = UMC.Data.Utility.Parse(Seq, -1);
                if (media_id.StartsWith("http://") || media_id.StartsWith("https://"))
                {
                    var url = new Uri(media_id);
                    if (url.Host.StartsWith("oss."))
                    {
                        if (seq > -1)
                        {
                            if (seq < 1)
                            {
                                seq = (pictureEntity.Max(new Data.Entities.Picture {
                                    Seq = 0
                                }).Seq ?? 0) + 1;
                            }

                            UploadImage(groupId, seq, request.UserHostAddress, user.Id);
                        }
                        if (url.AbsolutePath.EndsWith(type, StringComparison.CurrentCultureIgnoreCase))
                        {
                            oosr.Transfer(url, groupId, seq, type);
                        }
                        else
                        {
                            oosr.Transfer(new Uri(String.Format("{0}?x-oss-process=image/format,{1}", media_id, type)), groupId, seq, type);
                        }
                    }
                    else
                    {
                        if (seq < 1)
                        {
                            seq = (pictureEntity.Max(new Data.Entities.Picture {
                                Seq = 0
                            }).Seq ?? 0) + 1;
                        }
                        UploadImage(groupId, seq, request.UserHostAddress, user.Id);
                        oosr.Transfer(new Uri(media_id), groupId, seq);
                    }
                }
            }

            this.Context.Send(new WebMeta().Put("type", "image").Put("id", groupId.ToString()), true);
        }
Example #3
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var Settings = this.AsyncDialog("Settings", g =>
            {
                if (request.SendValues != null && request.SendValues.ContainsKey("media_id"))
                {
                    return(this.DialogValue(new WebMeta().Put("media_id", request.SendValues["media_id"])));
                }
                var from = new Web.UIFormDialog()
                {
                    Title = this.Title ?? "文本数据导入"
                };

                from.AddFile("选择csv文件", "media_id", String.Empty).Put("Accept", "text/csv");
                from.AddRadio("文件编码", "Encoding").Put("中文操作系统标准(GB2312)", "gb2312").Put("英文操作系统标准(UTF8)", "utf-8", true);
                var opts = from.AddTextValue("必须列名");
                foreach (var s in Columns)
                {
                    opts.Add(s, "必须字段");
                }
                from.Submit("确认上传", request, "Pager");
                return(from);
            });
            var media_id = Settings["media_id"];

            if (media_id.EndsWith(".csv") == false)
            {
                this.Prompt("请上传csv文本文件");
            }

            var Key      = this.AsyncDialog("Key", Utility.Guid(Guid.NewGuid()));
            var pathFile = this.AsyncDialog("File", g =>
            {
                string path2 = UMC.Data.Utility.MapPath(String.Format("App_Data\\Static\\TEMP\\{0}\\", Utility.GetRoot(request.Url)));

                var filename = String.Format("{0}{1}.tmp", path2, Key);
                Utility.Copy(new UMC.Net.HttpClient().GetStreamAsync(media_id).Result, filename);

                return(this.DialogValue(filename));
            });

            if (pathFile.EndsWith(".csv"))
            {
                var pad = new Uri(request.Url, String.Format("/TEMP/{0}", pathFile));
                this.Context.Send(new Web.WebMeta().Put("type", "OpenUrl").Put("value", pad.AbsoluteUri), true);
            }
            var columnSettings = this.AsyncDialog("Columns", g =>
            {
                var reader = new System.IO.StreamReader(pathFile, Encoding.GetEncoding(Settings["Encoding"] ?? "utf-8"));
                var cinex  = 0;
                var from   = new Web.UIFormDialog()
                {
                    Title = "核对字段"
                };
                var csvColumns = CSV.FromCsvLine(CSV.ReadLine(reader));
                reader.Close();
                foreach (var c in this.Columns)
                {
                    var opts = from.AddSelect(c, "Col_" + cinex).Put("请选择", "");
                    for (var i = 0; i < csvColumns.Length; i++)
                    {
                        opts.Add(String.Format("{1}(第{0}列)", i + 1, csvColumns[i]), i.ToString(), String.Equals(csvColumns[i], c, StringComparison.CurrentCultureIgnoreCase));
                    }
                    cinex++;
                }
                from.Submit("确认通过");
                return(from);
            });
            var indexs   = new List <int>();
            var maxIndex = -1;

            for (var i = 0; i < this.Columns.Length; i++)
            {
                var cindex = Convert.ToInt32(columnSettings["Col_" + i]);
                if (maxIndex < cindex)
                {
                    maxIndex = cindex;
                }
                indexs.Add(cindex);
            }
            if (indexs.Count == 0)
            {
                this.Prompt("无有效的字段");
            }

            var userName = Utility.GetUsername();

            var log = new CSV.Log(Utility.GetRoot(request.Url), Key, String.Format("开始{0}", this.Title ?? "文本数据导入"));

            Data.Reflection.Start(() =>
            {
                int rowIndex = 1;
                var reader   = new System.IO.StreamReader(pathFile, Encoding.GetEncoding(Settings["Encoding"] ?? "utf-8"));
                System.IO.FileStream file = System.IO.File.Open(String.Format("{0}.csv", pathFile), System.IO.FileMode.Create);


                try
                {
                    var writer = new System.IO.StreamWriter(file, Encoding.UTF8);
                    var total  = 0;
                    var now    = DateTime.Now;


                    var header = CSV.ReadLine(reader);
                    writer.WriteLine(header);

                    int okindex = 0;

                    CSV.EachRow(reader, data =>
                    {
                        rowIndex++;
                        if (data.Length <= maxIndex)
                        {
                            log.Error(String.Format("第{0}行 数据无效", rowIndex));
                            if (okindex + 10 < rowIndex)
                            {
                                throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                            }
                            return;
                        }
                        var hash = new Hashtable();
                        for (var i = 0; i < indexs.Count; i++)
                        {
                            int index = indexs[i];
                            if (data.Length > index)
                            {
                                if (String.IsNullOrEmpty(data[index]))
                                {
                                    log.Error(String.Format("第{0}行 {1}列数据为空", rowIndex, this.Columns[i]));
                                    if (okindex + 10 < rowIndex)
                                    {
                                        throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                                    }
                                    return;
                                }
                            }
                            else
                            {
                                log.Error(String.Format("第{0}行 无{1}列数据", rowIndex, this.Columns[i]));
                                if (okindex + 10 < rowIndex)
                                {
                                    throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                                }
                                return;
                            }
                            hash[this.Columns[i]] = data[index];
                        }
                        if (Do(log, rowIndex, hash))
                        {
                            total++;
                            okindex = rowIndex;
                        }
                        else
                        {
                            foreach (var d in data)
                            {
                                UMC.Data.CSV.CSVFormat(writer, d);
                                writer.Write(",");
                            }
                            writer.WriteLine();
                            writer.Flush();
                        }
                        if (okindex + 10 < rowIndex)
                        {
                            new ArgumentException(String.Format("连续超过10条无效的数据"));
                        }
                    });
                    writer.Flush();
                    writer.Close();
                    log.End("导入数据完成");
                    log.Info(String.Format("导入成功{0}条", total));
                    log.Info(String.Format("用时{0}", DateTime.Now - now));
                }
                catch (Exception ex)
                {
                    log.End(String.Format("在{0}行导入失败", rowIndex));
                    log.Info(ex.Message);
                }
                finally
                {
                    file.Close();
                    reader.Close();
                    log.Close();
                }
            });    //.Start();

            this.Context.Send(new UISectionBuilder("System", "Log", new WebMeta("Key", Key))
                              .Builder(), true);
        }
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var user = UMC.Security.Identity.Current;

            var strId  = this.AsyncDialog("Id", g => this.DialogValue(Guid.NewGuid().ToString()));
            var itemId = Data.Utility.Guid(strId, true);//, true).Value;



            var itemsEntity = Database.Instance().ObjectEntity <Design_Item>()
                              .Where.And().Equal(new Design_Item {
                Id = itemId
            });

            var item = itemsEntity.Entities.Single();
            var name = Web.UITextDialog.AsyncDialog("Name", g =>
            {
                return(this.DialogValue("Src"));
            });


            var webr = UMC.Data.WebResource.Instance();
            var desc = Web.UITextDialog.AsyncDialog("Desc", g =>
            {
                var size = this.AsyncDialog("Size", sg =>
                {
                    return(this.DialogValue("none"));
                });
                var fm = new Web.UIFormDialog()
                {
                    Title = "上传图片"
                };


                if (String.Equals(size, "none"))
                {
                    size = "注意图片尺寸";
                }
                else
                {
                    size = String.Format("图片尺寸:{0}", size);
                }

                fm.AddFile(size, "Desc", webr.ResolveUrl(String.Format("{0}{1}/1/0.jpg!100", UMC.Data.WebResource.ImageResource, itemId)))

                .Command("Design", "Picture", new UMC.Web.WebMeta().Put("id", itemId).Put("seq", "1", "type", "jpg"));


                return(fm);
            });
            var ite = new Design_Item
            {
                Type         = UIDesigner.StoreDesignTypeCustom,
                ModifiedDate = DateTime.Now,
                Id           = itemId,
                Seq          = 0
            };
            var data = UMC.Data.JSON.Deserialize <WebMeta>(item != null ? item.Data : "") ?? new UMC.Web.WebMeta();

            if (name != "Src")
            {
                data.Put(name, desc);
            }
            ite.Data = UMC.Data.JSON.Serialize(data);

            itemsEntity.Entities.IFF(e => e.Update(ite) == 0, e =>
            {
                ite.design_id = UMC.Data.Utility.Guid("UISettings", true);
                e.Insert(ite);
            });

            this.Context.Send(new UMC.Web.WebMeta().Put("type", "DesignItem")
                              .Put("Id", strId).Put("data", data)
                              .Put("name", name).Put("data", data)
                              .Put("src", webr.ResolveUrl(String.Format("{1}{0}/1/0.jpg?{2}", ite.Id, UMC.Data.WebResource.ImageResource, this.TimeSpan(ite.ModifiedDate)))), true);
        }