搜索查询类型
 
  • 站内
  • 互联网
SEARCH
DNN社区论坛
HomeHome技术交流区(DNN新手,DNN...技术交流区(DNN新手,DNN...DNN Module相关DNN Module相关question about tokenreplace and also cache of dotnetnukequestion about tokenreplace and also cache of dotnetnuke
返回上一级菜单
 
下一条
新的回复
2011/1/20 4:20
 

as all known ,there is a module which name is "announcements"

now I want to change its data format

the base structure as follows:

AnnouncementsTokenReplace-->TokenReplace

the calss realized the interface IPropertyAccess

 

so user can call the method ,

 

Public Function GetProperty(ByVal strPropertyName As String, ByVal strFormat As String, ByVal formatProvider As System.Globalization.CultureInfo, ByVal AccessingUser As Entities.Users.UserInfo, ByVal AccessLevel As Services.Tokens.Scope, ByRef PropertyNotFound As Boolean) As String Implements Services.Tokens.IPropertyAccess.GetProperty

 

for now , my question is , how we can set the value of the field "strFormat"

 

when I read the core code of dotnetnuke , I find the follow code:

 

Protected Overridable Function ReplaceTokens(ByVal strSourceText As String) As String
            If strSourceText Is Nothing Then Return String.Empty
            Dim Result As New System.Text.StringBuilder
            For Each currentMatch As Match In TokenizerRegex.Matches(strSourceText)

                Dim strObjectName As String = currentMatch.Result("${object}")
                If strObjectName.Length > 0 Then
                    If strObjectName = "[" Then strObjectName = ObjectLessToken
                    Dim strPropertyName As String = currentMatch.Result("${property}")
                    Dim strFormat As String = currentMatch.Result("${format}")
                    Dim strIfEmptyReplacment As String = currentMatch.Result("${ifEmpty}")
                    Dim strConversion As String = replacedTokenValue(strObjectName, strPropertyName, strFormat)
                    If strIfEmptyReplacment.Length > 0 AndAlso strConversion.Length = 0 Then strConversion = strIfEmptyReplacment
                    Result.Append(strConversion)
                Else
                    Result.Append(currentMatch.Result("${text}"))
                End If
            Next
            Return Result.ToString()
        End Function

 

for now , I know we need to change the property of TokenizerRegex, but I know know which way is the best ?

 

so can anybody help me?

 

新的回复
2011/1/25 22:58
 

Bug fixed by myself

 share it now:

 how we should do ? just only put the code to ascx file , but not compile the whole open source project!!

 

 Private arrAnnouncements As ArrayList
   
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Try

            If Not Page.IsPostBack Then

                Me.viewtypeSelector.Visible = Me.IsEditable
                If IsEditable Then
                    Dim modified As Boolean = False
                    If Template.ItemTemplate.ToLower.IndexOf("[edit]") = -1 Then
                        Template.ItemTemplate = Regex.Replace(Template.ItemTemplate, Regex.Escape("[TITLE]"), "[EDIT][TITLE]", RegexOptions.IgnoreCase)
                        modified = True
                    End If
                    If Template.AltItemTemplate.Length > 0 AndAlso Template.AltItemTemplate.ToLower.IndexOf("[edit]") = -1 Then
                        Template.AltItemTemplate = Regex.Replace(Template.AltItemTemplate, Regex.Escape("[TITLE]"), "[EDIT][TITLE]", RegexOptions.IgnoreCase)
                        modified = True
                    End If
                    If modified Then
                        Template.UpdateTemplate()
                    End If
                    If Template.ItemTemplate.ToLower.IndexOf("[edit]") = -1 Then
                        Skins.Skin.AddModuleMessage(Me, Localization.GetString("NoEditToken.Error", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning)
                    End If
                    Dim i As [Enum]
                    For Each i In [Enum].GetValues(GetType(ViewTypes))
                        ddlViewType.Items.Add(New ListItem(Localization.GetString([Enum].GetName(GetType(ViewTypes), i), LocalResourceFile), [Enum].GetName(GetType(ViewTypes), i)))
                    Next i
                    Me.ddlViewType.SelectedValue = [Enum].GetName(GetType(ViewTypes), ViewTypes.Current)
                End If
            End If

            BindNewData()
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub
   
    'public static DateTimeFormatInfo GetFormat(Control control, int portalId)
    '    {
    '        DateTimeFormatInfo difi = new DateTimeFormatInfo();
    '        string lang = Localization.GetString(portalId.ToString(), Localization.GetResourceFile(control, "Settings"));
    '        difi = new CultureInfo(lang, false).DateTimeFormat;
    '        return difi;
    '    }
   
    Protected Function GetFormat(ByVal control As Control, ByVal portalId As Integer) As String
        Dim lang As String
        lang = Localization.GetString(portalId.ToString(), Localization.GetResourceFile(control, "Settings"))
        GetFormat = lang
    End Function
   
    Protected Sub BindNewData()
        Dim output As New StringBuilder

        ' bind data
        Dim datStartDate As Date = Null.NullDate
        Dim datEndDate As Date = Null.NullDate

        If CType(Settings("history"), String) <> "" Then
            datStartDate = DateAdd(DateInterval.Day, -(CType(Settings("history"), Double)), Now)
        End If

        Dim announcements As New AnnouncementsController

        ' get announcements, if isEditable decide based on dropdownlist selection, otherwise just get current items
        If IsEditable Then
            Select Case Me.ddlViewType.SelectedValue
                Case ViewTypes.Current.ToString
                    arrAnnouncements = announcements.GetCurrentAnnouncements(ModuleId, datStartDate)
                Case ViewTypes.Expired.ToString
                    arrAnnouncements = announcements.GetExpiredAnnouncements(ModuleId)
                Case ViewTypes.Future.ToString
                    arrAnnouncements = announcements.GetAnnouncements(ModuleId, Now, Null.NullDate)
                Case ViewTypes.All.ToString
                    arrAnnouncements = announcements.GetAnnouncements(ModuleId, Null.NullDate, Null.NullDate)
            End Select
        Else
            arrAnnouncements = announcements.GetCurrentAnnouncements(ModuleId, datStartDate)
        End If


        Dim dnnTokenReplace As DotNetNuke.Services.Tokens.TokenReplace = Nothing
       
        If Template.TokenReplaceNeeded Then
            dnnTokenReplace = New DotNetNuke.Services.Tokens.TokenReplace(Scope.DefaultSettings, CultureInfo.CurrentCulture.Name, PortalSettings, UserInfo)
        End If
        'Debugger.Break()
        Dim altItemTemplateAvailable As Boolean = Not String.IsNullOrEmpty(Template.AltItemTemplate)
        If dnnTokenReplace IsNot Nothing Then
            output.Append(dnnTokenReplace.ReplaceEnvironmentTokens(Template.HeaderTemplate))
        End If
        Dim counter As Integer = 0
        For Each announcement As AnnouncementInfo In arrAnnouncements
            'we have to pass IsEditable to the announcement, because it is used to draw the edit icon
            announcement.IsEditable = Me.IsEditable

           
            'Create a Token Replace and replace the tokens for this template
            Dim tokenReplace As New AnnouncementsTokenReplace(announcement)
           
            'tokenReplace.Language = GetFormat(Me, PortalSettings.PortalId) '"ar-JO"
           
           
            If (counter Mod 2 = 0) Or (Not altItemTemplateAvailable) Then
                ReplaceAnnouncementField(announcement, Template.ItemTemplate)
                output.Append(tokenReplace.ReplaceAnnouncmentTokens(Template.ItemTemplate))
            Else
                ReplaceAnnouncementField(announcement, Template.ItemTemplate)
                output.Append(tokenReplace.ReplaceAnnouncmentTokens(Template.AltItemTemplate))
            End If
            If (dnnTokenReplace IsNot Nothing) AndAlso (counter < arrAnnouncements.Count - 1) Then
                ReplaceAnnouncementField(announcement, Template.ItemTemplate)
                output.Append(dnnTokenReplace.ReplaceEnvironmentTokens(Template.Separator))
            End If
            counter += 1

        Next
        If dnnTokenReplace IsNot Nothing Then
            output.Append(dnnTokenReplace.ReplaceEnvironmentTokens(Template.FooterTemplate))
        End If

        Me.litAnnouncements.Text = output.ToString
       
    End Sub
   
    Protected Sub ReplaceAnnouncementField(ByVal announcement As AnnouncementInfo, ByRef template As String)
        Dim strFormat As String = GetFormat(Me, PortalSettings.PortalId)
        template = template.Replace("[PUBLISHDATE]", announcement.CreatedDate.ToString("MMMM d, yyyy", New CultureInfo(strFormat, True).DateTimeFormat()))
    End Sub

 

the main code like the follows:

 

                ReplaceAnnouncementField(announcement, Template.ItemTemplate)
                output.Append(tokenReplace.ReplaceAnnouncmentTokens(Template.ItemTemplate))

 

Although I use C# as my main programming language ,  I can also code other .net language , so I think other people can also do what I do , so you can also read and write my vb vode

返回上一级菜单
 
下一条
HomeHome技术交流区(DNN新手,DNN...技术交流区(DNN新手,DNN...DNN Module相关DNN Module相关question about tokenreplace and also cache of dotnetnukequestion about tokenreplace and also cache of dotnetnuke


版权所有:武汉努客科技 备案许可证号:鄂ICP备09017480号   |  隐私声明  |  服务条款