Esempio n. 1
0
        public static List <InputContentInfo> GetInputContentsByCsvFile(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                                        InputInfo inputInfo)
        {
            var contentInfoList = new List <InputContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count > 0)
            {
                var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent,
                                                                               publishmentSystemInfo.PublishmentSystemId, inputInfo.InputID);
                var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent,
                                                                                 DataProvider.InputContentDao.TableName, relatedidentityes);

                var nameValueCollection = new NameValueCollection();

                foreach (var styleInfo in tableStyleInfoList)
                {
                    nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
                }

                nameValueCollection["回复"]   = InputContentAttribute.Reply.ToLower();
                nameValueCollection["添加时间"] = InputContentAttribute.AddDate.ToLower();

                var attributeNames = new List <string>();
                foreach (var columnName in head)
                {
                    if (!string.IsNullOrEmpty(nameValueCollection[columnName]))
                    {
                        attributeNames.Add(nameValueCollection[columnName]);
                    }
                    else
                    {
                        attributeNames.Add(columnName);
                    }
                }

                foreach (var row in rows)
                {
                    if (row.Count != attributeNames.Count)
                    {
                        continue;
                    }

                    var contentInfo = new InputContentInfo(0, inputInfo.InputID, 0, true, string.Empty, string.Empty,
                                                           DateTime.Now, string.Empty);

                    for (var i = 0; i < attributeNames.Count; i++)
                    {
                        var attributeName = attributeNames[i];
                        if (!string.IsNullOrEmpty(attributeName))
                        {
                            var value = row[i];
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
Esempio n. 2
0
        public void Main(int publishmentSystemId, int inputId)
        {
            var body = new RequestBody();

            var       publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);
            InputInfo inputInfo             = null;

            if (inputId > 0)
            {
                inputInfo = DataProvider.InputDao.GetInputInfo(inputId);
            }
            if (inputInfo != null)
            {
                var relatedIdentities = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent, publishmentSystemId, inputInfo.InputId);

                var ipAddress = PageUtils.GetIpAddress();

                var contentInfo = new InputContentInfo(0, inputInfo.InputId, 0, inputInfo.IsChecked, body.UserName, ipAddress, DateTime.Now, string.Empty);

                try
                {
                    if (!inputInfo.Additional.IsAnomynous && !body.IsUserLoggin)
                    {
                        throw new Exception("请先登录系统!");
                    }

                    InputTypeParser.AddValuesToAttributes(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, publishmentSystemInfo, relatedIdentities, HttpContext.Current.Request.Form, contentInfo.Attributes, false);

                    if (HttpContext.Current.Request.Files.Count > 0)
                    {
                        foreach (var attributeName in HttpContext.Current.Request.Files.AllKeys)
                        {
                            var myFile = HttpContext.Current.Request.Files[attributeName];
                            if (myFile == null || "" == myFile.FileName)
                            {
                                continue;
                            }

                            var fileUrl = UploadFile(publishmentSystemInfo, myFile);
                            contentInfo.SetExtendedAttribute(attributeName, fileUrl);
                        }
                    }

                    contentInfo.Id = DataProvider.InputContentDao.Insert(contentInfo);

                    if (inputInfo.Additional.IsAdministratorSmsNotify)
                    {
                        var keys =
                            TranslateUtils.StringCollectionToStringList(inputInfo.Additional.AdministratorSmsNotifyKeys);
                        if (keys.Count > 0)
                        {
                            var parameters = new NameValueCollection();
                            if (keys.Contains(InputContentAttribute.Id))
                            {
                                parameters.Add(InputContentAttribute.Id, contentInfo.Id.ToString());
                            }
                            if (keys.Contains(InputContentAttribute.AddDate))
                            {
                                parameters.Add(InputContentAttribute.AddDate, DateUtils.GetDateAndTimeString(contentInfo.AddDate));
                            }
                            var styleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, relatedIdentities);
                            foreach (var styleInfo in styleInfoList)
                            {
                                if (keys.Contains(styleInfo.AttributeName))
                                {
                                    var value = contentInfo.GetExtendedAttribute(styleInfo.AttributeName);
                                    parameters.Add(styleInfo.AttributeName, value);
                                }
                            }

                            string errorMessage;
                            SmsManager.SendNotify(inputInfo.Additional.AdministratorSmsNotifyMobile,
                                                  inputInfo.Additional.AdministratorSmsNotifyTplId, parameters, out errorMessage);
                        }
                    }

                    HttpContext.Current.Response.Write(StlInput.GetPostMessageScript(inputId, true));
                    HttpContext.Current.Response.End();
                }
                catch (Exception)
                {
                    HttpContext.Current.Response.Write(StlInput.GetPostMessageScript(inputId, false));
                    HttpContext.Current.Response.End();
                }
            }
        }
Esempio n. 3
0
        public void ImportInput(bool overwrite)
        {
            if (!DirectoryUtils.IsDirectoryExists(_directoryPath))
            {
                return;
            }
            var filePaths = DirectoryUtils.GetFilePaths(_directoryPath);

            foreach (var filePath in filePaths)
            {
                var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(filePath));

                var inputInfo = new InputInfo
                {
                    InputName           = AtomUtility.GetDcElementContent(feed.AdditionalElements, "InputName"),
                    PublishmentSystemId = _publishmentSystemId,
                    AddDate             = DateTime.Now,
                    IsChecked           =
                        TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsChecked")),
                    IsReply     = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsReply")),
                    Taxis       = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(feed.AdditionalElements, "Taxis")),
                    SettingsXml =
                        AtomUtility.Decrypt(AtomUtility.GetDcElementContent(feed.AdditionalElements, "SettingsXML"))
                };

                var srcInputInfo = DataProvider.InputDao.GetInputInfo(inputInfo.InputName, _publishmentSystemId);
                if (srcInputInfo != null)
                {
                    if (overwrite)
                    {
                        DataProvider.InputDao.Delete(srcInputInfo.InputId);
                    }
                    else
                    {
                        inputInfo.InputName = DataProvider.InputDao.GetImportInputName(inputInfo.InputName, _publishmentSystemId);
                    }
                }

                var inputId = DataProvider.InputDao.Insert(inputInfo);

                var styleDirectoryPath = PathUtils.Combine(_directoryPath, AtomUtility.GetDcElementContent(feed.AdditionalElements, "InputID"));
                TableStyleIe.SingleImportTableStyle(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, styleDirectoryPath, inputId);

                foreach (AtomEntry entry in feed.Entries)
                {
                    var contentInfo = new InputContentInfo
                    {
                        InputId   = inputId,
                        IsChecked = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, InputContentAttribute.IsChecked)),
                        UserName  = AtomUtility.GetDcElementContent(entry.AdditionalElements, InputContentAttribute.UserName),
                        AddDate   = DateTime.Now,
                        Reply     = AtomUtility.GetDcElementContent(entry.AdditionalElements, InputContentAttribute.Reply)
                    };
                    var attributes = AtomUtility.GetDcElementNameValueCollection(entry.AdditionalElements);
                    foreach (string entryName in attributes.Keys)
                    {
                        if (!InputContentAttribute.AllAttributes.Contains(entryName.ToLower()))
                        {
                            contentInfo.SetExtendedAttribute(entryName, attributes[entryName]);
                        }
                    }
                    DataProvider.InputContentDao.Insert(contentInfo);
                }
            }
        }
Esempio n. 4
0
        public void Main(int publishmentSystemId, int inputId)
        {
            var body = new RequestBody();

            var       publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);
            InputInfo inputInfo             = null;

            if (inputId > 0)
            {
                inputInfo = DataProvider.InputDao.GetInputInfo(inputId);
            }
            if (inputInfo != null)
            {
                var relatedIdentities = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent, publishmentSystemId, inputInfo.InputId);

                var ipAddress = PageUtils.GetIpAddress();

                var contentInfo = new InputContentInfo(0, inputInfo.InputId, 0, inputInfo.IsChecked, body.UserName, ipAddress, DateTime.Now, string.Empty);

                try
                {
                    if (!inputInfo.Additional.IsAnomynous && !body.IsUserLoggin)
                    {
                        throw new Exception("请先登录系统!");
                    }

                    InputTypeParser.AddValuesToAttributes(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, publishmentSystemInfo, relatedIdentities, HttpContext.Current.Request.Form, contentInfo.Attributes, false);

                    if (HttpContext.Current.Request.Files.Count > 0)
                    {
                        foreach (var attributeName in HttpContext.Current.Request.Files.AllKeys)
                        {
                            var myFile = HttpContext.Current.Request.Files[attributeName];
                            if (myFile == null || "" == myFile.FileName)
                            {
                                continue;
                            }

                            var fileUrl = UploadFile(publishmentSystemInfo, myFile);
                            contentInfo.SetExtendedAttribute(attributeName, fileUrl);
                        }
                    }

                    DataProvider.InputContentDao.Insert(contentInfo);

                    string message;
                    if (string.IsNullOrEmpty(HttpContext.Current.Request.Form["successTemplateString"]))
                    {
                        if (string.IsNullOrEmpty(inputInfo.Additional.MessageSuccess))
                        {
                            message = "表单提交成功,正在审核。";
                            if (contentInfo.IsChecked)
                            {
                                message = "表单提交成功。";
                            }
                        }
                        else
                        {
                            message = inputInfo.Additional.MessageSuccess;
                        }
                    }
                    else
                    {
                        message = TranslateUtils.DecryptStringBySecretKey(HttpContext.Current.Request.Form["successTemplateString"]);
                    }

                    HttpContext.Current.Response.Write(InputTemplate.GetInputCallbackScript(publishmentSystemInfo, inputId, true, message));
                    HttpContext.Current.Response.End();

                    //if (contentInfo.IsChecked == EBoolean.True)
                    //{
                    //    FileSystemObject FSO = new FileSystemObject(base.PublishmentSystemID);
                    //    FSO.CreateImmediately(EChangedType.Add, ETemplateTypeUtils.GetEnumType(templateType), channelID, contentID, fileTemplateID);
                    //}
                }
                catch (Exception ex)
                {
                    string message;
                    if (string.IsNullOrEmpty(HttpContext.Current.Request.Form["failureTemplateString"]))
                    {
                        if (string.IsNullOrEmpty(inputInfo.Additional.MessageFailure))
                        {
                            message = "表单提交失败," + ex.Message;
                        }
                        else
                        {
                            message = inputInfo.Additional.MessageFailure;
                        }
                    }
                    else
                    {
                        message = TranslateUtils.DecryptStringBySecretKey(HttpContext.Current.Request.Form["failureTemplateString"]);
                    }

                    HttpContext.Current.Response.Write(InputTemplate.GetInputCallbackScript(publishmentSystemInfo, inputId, false, message));
                    HttpContext.Current.Response.End();
                }
            }
        }