/// <summary>
        /// 推送数据到目标地址
        /// </summary>
        public void Push()
        {
            //取出设置
            String  QueryString  = BPM.Settings["PowerForms_Push_QueryString"] != null && !string.IsNullOrEmpty(BPM.Settings["PowerForms_Push_QueryString"].ToString()) ? Convert.ToString(BPM.Settings["PowerForms_Push_QueryString"]) : "";
            Boolean Asynchronous = BPM.Settings["PowerForms_Push_Asynchronous"] != null && !string.IsNullOrEmpty(BPM.Settings["PowerForms_Push_Asynchronous"].ToString()) ? Convert.ToBoolean(BPM.Settings["PowerForms_Push_Asynchronous"]) : true;
            Int32   FormMethod   = BPM.Settings["PowerForms_Push_FormMethod"] != null && !string.IsNullOrEmpty(BPM.Settings["PowerForms_Push_FormMethod"].ToString()) ? Convert.ToInt32(BPM.Settings["PowerForms_Push_FormMethod"]) : (Int32)EnumFormMethod.POST;

            if (!String.IsNullOrEmpty(TransferUrl))//推送的目标地址不能为空
            {
                //构造查询的字符串
                QueryStrings = CreateQueryStrings();

                //将值转换到键值对中存储
                if (ContentList != null && ContentList.Count > 0)
                {
                    TemplateFormat xf = new TemplateFormat(BPM);
                    foreach (DNNGo_PowerForms_ContentItem item in ContentList)
                    {
                        if (String.IsNullOrEmpty(QueryStrings.Get(item.FieldName)))//不存在该键值时才能进入
                        {
                            QueryStrings.Add(item.FieldName, xf.ViewContentValue2(item));
                        }
                    }
                }



                //设置中设置的查询参数
                if (!String.IsNullOrEmpty(QueryString))
                {
                    List <String> ListQuery = WebHelper.GetList(QueryString, "\r\n");
                    foreach (String query in ListQuery)
                    {
                        List <String> nvs = WebHelper.GetList(query, "=");
                        if (nvs != null && nvs.Count == 2 && !String.IsNullOrEmpty(nvs[0]) && !String.IsNullOrEmpty(nvs[1]))
                        {
                            if (String.IsNullOrEmpty(QueryStrings.Get(nvs[0])))//不存在该键值时才能进入
                            {
                                QueryStrings.Add(nvs[0], nvs[1]);
                            }
                        }
                    }
                }


                //将提交的表单实体转换
                Type           t         = typeof(DNNGo_PowerForms_Content);
                PropertyInfo[] Propertys = t.GetProperties();
                //循环字段列表
                foreach (PropertyInfo Property in Propertys)
                {
                    if (String.IsNullOrEmpty(_QueryStrings.Get(Property.Name)))//不存在该键值时才能进入
                    {
                        if (Property.Name != "Item" && Property.Name != "ContentValue")
                        {
                            object o = Property.GetValue(SubmitContent, null);
                            if (Property.Name == "UserName")
                            {
                                _QueryStrings.Add("DisplayName", o.ToString());
                            }
                            else
                            {
                                _QueryStrings.Add(Property.Name, o.ToString());
                            }
                        }
                    }
                }


                //移除模块编号和页面编号
                if (_QueryStrings[DNNGo_PowerForms_Content._.ModuleId] != null)
                {
                    _QueryStrings.Remove(DNNGo_PowerForms_Content._.ModuleId);
                }
                if (_QueryStrings[DNNGo_PowerForms_Content._.PortalId] != null)
                {
                    _QueryStrings.Remove(DNNGo_PowerForms_Content._.PortalId);
                }



                if (Asynchronous)
                {
                    //异步推送
                    ManagedThreadPool.QueueUserWorkItem(new WaitCallback(ThreadUploadValues), this);
                }
                else
                {
                    //webX.UploadValues(new Uri(TransferUrl), EnumHelper.GetEnumTextVal(FormMethod, typeof(EnumFormMethod)), QueryStrings);
                    PushData();
                }
            }
        }
Ejemplo n.º 2
0
        public Int32 SynchronizeAllFiles(FileInfo SynchronizeFile)
        {
            Int32 SynchronizeFileCount = 0;


            DNNGo_PowerForms_Files PhotoItem = new DNNGo_PowerForms_Files();

            PhotoItem.ModuleId = ModuleId;
            PhotoItem.PortalId = PortalId;


            PhotoItem.FileName = SynchronizeFile.Name;
            PhotoItem.FileSize = Convert.ToInt32(SynchronizeFile.Length / 1024);
            PhotoItem.FileMate = FileSystemUtils.GetContentType(Path.GetExtension(PhotoItem.FileName).Replace(".", ""));

            PhotoItem.FileExtension = System.IO.Path.GetExtension(PhotoItem.FileName).Replace(".", "");
            PhotoItem.Name          = System.IO.Path.GetFileName(PhotoItem.FileName).Replace(Path.GetExtension(PhotoItem.FileName), "");

            PhotoItem.Status = (Int32)EnumFileStatus.Approved;

            try
            {
                if (("png,gif,jpg,jpeg,bmp").IndexOf(PhotoItem.FileExtension) >= 0)
                {
                    //图片的流
                    System.Drawing.Image image = System.Drawing.Image.FromFile(SynchronizeFile.FullName);
                    PhotoItem.ImageWidth  = image.Width;
                    PhotoItem.ImageHeight = image.Height;

                    PhotoItem.Exif = Common.Serialize <EXIFMetaData.Metadata>(new EXIFMetaData().GetEXIFMetaData(image));
                }
            }
            catch
            {
            }

            PhotoItem.LastTime = xUserTime.UtcTime();
            PhotoItem.LastIP   = WebHelper.UserHost;
            PhotoItem.LastUser = UserInfo.UserID;

            //将文件存储的路径整理好
            String fileName = PhotoItem.FileName; //文件名称
            String WebPath  = String.Format("PowerForms/uploads/{0}/{1}/{2}/", xUserTime.UtcTime().Year, xUserTime.UtcTime().Month, xUserTime.UtcTime().Day);
            //检测文件存储路径是否有相关的文件
            FileInfo fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));

            //检测文件夹是否存在
            if (!System.IO.Directory.Exists(fInfo.Directory.FullName))
            {
                System.IO.Directory.CreateDirectory(fInfo.Directory.FullName);
            }
            else
            {
                Int32 j = 1;
                while (fInfo.Exists)
                {
                    //文件已经存在了
                    fileName = String.Format("{0}_{1}", PhotoItem.Name, j);
                    fInfo    = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));
                    j++;
                }
            }

            PhotoItem.FilePath = String.Format("{0}{1}.{2}", WebPath, fileName, PhotoItem.FileExtension);
            PhotoItem.FileName = String.Format("{0}.{1}", fileName, PhotoItem.FileExtension);

            try
            {
                if (!fInfo.Directory.Exists)
                {
                    fInfo.Directory.Create();
                }
                //异步移动文件到文件夹中
                List <String> SynchronizeFileQueue = new List <string>();
                SynchronizeFileQueue.Add(SynchronizeFile.FullName);
                SynchronizeFileQueue.Add(fInfo.FullName);
                ManagedThreadPool.QueueUserWorkItem(new WaitCallback(ThreadMoveTo), SynchronizeFileQueue);
            }
            catch (Exception ex)
            {
            }

            //给上传的相片设置初始的顺序
            QueryParam qp = new QueryParam();

            qp.ReturnFields = qp.Orderfld = DNNGo_PowerForms_Files._.Sort;
            qp.OrderType    = 1;
            qp.Where.Add(new SearchParam(DNNGo_PowerForms_Files._.PortalId, PhotoItem.PortalId, SearchType.Equal));
            PhotoItem.Sort = Convert.ToInt32(DNNGo_PowerForms_Files.FindScalar(qp)) + 2;
            Int32 PhotoId = PhotoItem.Insert();

            if (PhotoId > 0)
            {
                SynchronizeFileCount++;
            }


            return(SynchronizeFileCount);
        }