text:
<file_sep># hello-github
test for git
hi
i'm Yi
nice to meet you

branch_name: refs/heads/master

repo_language: Markdown


text:
<file_sep>Public Class AddRevenueToCampaignSubPriorityGlobalChangeUIModel

    Private Sub AddRevenueToCampaignSubPriorityGlobalChangeUIModel_Loaded(ByVal sender As Object, ByVal e As Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs) Handles Me.Loaded
        _campaignid.Required = True
        _subpriorityid.Required = True
    End Sub

    Private Sub _campaignid_ValueChanged(ByVal sender As Object, ByVal e As Blackbaud.AppFx.UIModeling.Core.ValueChangedEventArgs) Handles _campaignid.ValueChanged
        _subpriorityid.ResetDataSource()
    End Sub
End Class<file_sep>Option Strict On
Option Explicit On
Option Infer On

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by BBUIModelLibrary
'     Version:  2.93.2034.0
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
''' <summary>
''' Represents the UI model for the 'Add any constituent attribute w/ start date' data form
''' </summary>

Partial Public Class [AddAnyConstituentAttributeWStartDateUIModel]
	Inherits Global.Blackbaud.AppFx.UIModeling.Core.CustomUIModel

#Region "Enums"

    ''' <summary>
    ''' Enumerated values for use with the BOOLEANVALUE property
    ''' </summary>
	<System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public Enum BOOLEANVALUES As Integer
        [No] = 0
        [Yes] = 1
    End Enum

#End Region

#Region "Extensibility methods"

    Partial Private Sub OnCreated()
    End Sub

#End Region

    Private WithEvents _idsetregisterid As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
    Private WithEvents _recordtypeid As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
    Private WithEvents _attributecategoryid As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
    Private WithEvents _stringvalue As Global.Blackbaud.AppFx.UIModeling.Core.StringField
    Private WithEvents _numbervalue As Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
    Private WithEvents _moneyvalue As Global.Blackbaud.AppFx.UIModeling.Core.MoneyField
    Private WithEvents _datevalue As Global.Blackbaud.AppFx.UIModeling.Core.DateField
    Private WithEvents _booleanvalue As Global.Blackbaud.AppFx.UIModeling.Core.ValueListField(Of Nullable(Of BOOLEANVALUES))
    Private WithEvents _codetablevalue As Global.Blackbaud.AppFx.UIModeling.Core.CodeTableField
    Private WithEvents _fuzzydatevalue As Global.Blackbaud.AppFx.UIModeling.Core.FuzzyDateField
    Private WithEvents _constituentidvalue As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
    Private WithEvents _hourminutevalue As Global.Blackbaud.AppFx.UIModeling.Core.HourMinuteField
    Private WithEvents _memovalue As Global.Blackbaud.AppFx.UIModeling.Core.StringField
    Private WithEvents _attributecategories As Global.Blackbaud.AppFx.UIModeling.Core.CollectionField(Of AddAnyConstituentAttributeWStartDateATTRIBUTECATEGORIESUIModel)
    Private WithEvents _startdate As Global.Blackbaud.AppFx.UIModeling.Core.DateField
    Private WithEvents _comment As Global.Blackbaud.AppFx.UIModeling.Core.StringField
    Private WithEvents _removeunqualified As Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
    Private WithEvents _overwriteexistingvalue As Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
    Private WithEvents _currencyid As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
    Private WithEvents _uivaluefield As Global.Blackbaud.AppFx.UIModeling.Core.StringField

	<System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public Sub New()
        MyBase.New()

        _idsetregisterid = New Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        _recordtypeid = New Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        _attributecategoryid = New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        _stringvalue = New Global.Blackbaud.AppFx.UIModeling.Core.StringField
        _numbervalue = New Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
        _moneyvalue = New Global.Blackbaud.AppFx.UIModeling.Core.MoneyField
        _datevalue = New Global.Blackbaud.AppFx.UIModeling.Core.DateField
        _booleanvalue = New Global.Blackbaud.AppFx.UIModeling.Core.ValueListField(Of Nullable(Of BOOLEANVALUES))
        _codetablevalue = New Global.Blackbaud.AppFx.UIModeling.Core.CodeTableField
        _fuzzydatevalue = New Global.Blackbaud.AppFx.UIModeling.Core.FuzzyDateField
        _constituentidvalue = New Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        _hourminutevalue = New Global.Blackbaud.AppFx.UIModeling.Core.HourMinuteField
        _memovalue = New Global.Blackbaud.AppFx.UIModeling.Core.StringField
        _attributecategories = New Global.Blackbaud.AppFx.UIModeling.Core.CollectionField(Of AddAnyConstituentAttributeWStartDateATTRIBUTECATEGORIESUIModel)
        _startdate = New Global.Blackbaud.AppFx.UIModeling.Core.DateField
        _comment = New Global.Blackbaud.AppFx.UIModeling.Core.StringField
        _removeunqualified = New Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
        _overwriteexistingvalue = New Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
        _currencyid = New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        _uivaluefield = New Global.Blackbaud.AppFx.UIModeling.Core.StringField

        '
        '_idsetregisterid
        '
        _idsetregisterid.Name = "IDSETREGISTERID"
        _idsetregisterid.Caption = "Selection"
        _idsetregisterid.SearchListID = New Guid("98d0070e-c4a7-495b-a438-2ac12da79068")
        _idsetregisterid.EnableQuickFind = True
        _idsetregisterid.SearchFieldOverrides.Add(New Global.Blackbaud.AppFx.UIModeling.Core.FieldOverride() With {.FieldId = "RECORDTYPEID", .Caption = "Record type", .ReadOnly = True, .DefaultValueText = "Fields!RECORDTYPEID"})
        _idsetregisterid.SystemSearchType = Global.Blackbaud.AppFx.UIModeling.Core.SystemSearchType.Selection
        Me.Fields.Add(_idsetregisterid)
        '
        '_recordtypeid
        '
        _recordtypeid.Name = "RECORDTYPEID"
        _recordtypeid.Caption = "RECORDTYPEID"
        _recordtypeid.Visible = False
        _recordtypeid.DBReadOnly = True
        Me.Fields.Add(_recordtypeid)
        '
        '_attributecategoryid
        '
        _attributecategoryid.Name = "ATTRIBUTECATEGORYID"
        _attributecategoryid.Caption = "Category"
        _attributecategoryid.Required = True
        _attributecategoryid.SimpleDataListID = New Guid("958132a3-762a-4844-b7a1-f3a3098da95a")
        _attributecategoryid.Parameters.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListParameter("RECORDTYPE", "Constituent"))
        Me.Fields.Add(_attributecategoryid)
        '
        '_stringvalue
        '
        _stringvalue.Name = "STRINGVALUE"
        _stringvalue.Caption = "Value"
        _stringvalue.MaxLength = 250
        Me.Fields.Add(_stringvalue)
        '
        '_numbervalue
        '
        _numbervalue.Name = "NUMBERVALUE"
        _numbervalue.Caption = "Value"
        Me.Fields.Add(_numbervalue)
        '
        '_moneyvalue
        '
        _moneyvalue.Name = "MONEYVALUE"
        _moneyvalue.Caption = "Value"
        _moneyvalue.CurrencyFieldId = "CURRENCYID"
        Me.Fields.Add(_moneyvalue)
        '
        '_datevalue
        '
        _datevalue.Name = "DATEVALUE"
        _datevalue.Caption = "Value"
        Me.Fields.Add(_datevalue)
        '
        '_booleanvalue
        '
        _booleanvalue.Name = "BOOLEANVALUE"
        _booleanvalue.Caption = "Value"
        _booleanvalue.DataSource.Add(New Global.Blackbaud.AppFx.UIModeling.Core.ValueListItem(Of Nullable(Of BOOLEANVALUES)) With {.Value = BOOLEANVALUES.[No], .Translation = "No"})
        _booleanvalue.DataSource.Add(New Global.Blackbaud.AppFx.UIModeling.Core.ValueListItem(Of Nullable(Of BOOLEANVALUES)) With {.Value = BOOLEANVALUES.[Yes], .Translation = "Yes"})
        Me.Fields.Add(_booleanvalue)
        '
        '_codetablevalue
        '
        _codetablevalue.Name = "CODETABLEVALUE"
        _codetablevalue.Caption = "Value"
        _codetablevalue.CodeTableName = "ADDRESSTYPECODE"
        Me.Fields.Add(_codetablevalue)
        '
        '_fuzzydatevalue
        '
        _fuzzydatevalue.Name = "FUZZYDATEVALUE"
        _fuzzydatevalue.Caption = "Value"
        Me.Fields.Add(_fuzzydatevalue)
        '
        '_constituentidvalue
        '
        _constituentidvalue.Name = "CONSTITUENTIDVALUE"
        _constituentidvalue.Caption = "Value"
        _constituentidvalue.SearchListID = New Guid("23c5c603-d7d8-4106-aecc-65392b563887")
        _constituentidvalue.EnableQuickFind = True
        _constituentidvalue.SearchListAddForms.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SearchListAddForm(New Guid("1986f0cf-efb6-48b3-afde-950b57562434"), "Individual"))
        _constituentidvalue.SearchListAddForms.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SearchListAddForm(New Guid("d846a816-46c7-470e-9ad0-973b2730e836"), "Household"))
        _constituentidvalue.SearchListAddForms.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SearchListAddForm(New Guid("f0f6426a-fccd-48bb-846b-eb3d1a4a0ed4"), "Group"))
        _constituentidvalue.SearchListAddForms.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SearchListAddForm(New Guid("ca3ed110-a5f0-4b5b-8eb7-0616e0a82e8e"), "Organization"))
        Me.Fields.Add(_constituentidvalue)
        '
        '_hourminutevalue
        '
        _hourminutevalue.Name = "HOURMINUTEVALUE"
        _hourminutevalue.Caption = "Value"
        Me.Fields.Add(_hourminutevalue)
        '
        '_memovalue
        '
        _memovalue.Name = "MEMOVALUE"
        _memovalue.Caption = "Value"
        Me.Fields.Add(_memovalue)
        '
        '_attributecategories
        '
        _attributecategories.Name = "ATTRIBUTECATEGORIES"
        _attributecategories.Caption = "ATTRIBUTECATEGORIES"
        _attributecategories.DBReadOnly = True
        _attributecategories.AvailableToClient = False
        Me.Fields.Add(_attributecategories)
        '
        '_startdate
        '
        _startdate.Name = "STARTDATE"
        _startdate.Caption = "Start Date"
        Me.Fields.Add(_startdate)
        '
        '_comment
        '
        _comment.Name = "COMMENT"
        _comment.Caption = "Comment"
        _comment.MaxLength = 255
        Me.Fields.Add(_comment)
        '
        '_removeunqualified
        '
        _removeunqualified.Name = "REMOVEUNQUALIFIED"
        _removeunqualified.Caption = "Remove value from unqualified records"
        Me.Fields.Add(_removeunqualified)
        '
        '_overwriteexistingvalue
        '
        _overwriteexistingvalue.Name = "OVERWRITEEXISTINGVALUE"
        _overwriteexistingvalue.Caption = "Overwrite existing value"
        _overwriteexistingvalue.Value = True
        Me.Fields.Add(_overwriteexistingvalue)
        '
        '_currencyid
        '
        _currencyid.Name = "CURRENCYID"
        _currencyid.Caption = "Currency"
        _currencyid.SimpleDataListID = New Guid("13612288-b37e-409d-ba52-6ab31637ddd6")
        Me.Fields.Add(_currencyid)
        '
        '_uivaluefield
        '
        _uivaluefield.Name = "UIVALUEFIELD"
        _uivaluefield.Caption = "Value"
        _uivaluefield.Visible = False
        _uivaluefield.DBReadOnly = True
        _uivaluefield.AvailableToClient = False
        Me.Fields.Add(_uivaluefield)

		OnCreated()

    End Sub

    ''' <summary>
    ''' Selection
    ''' </summary>
    <System.ComponentModel.Description("Selection")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [IDSETREGISTERID]() As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        Get
            Return _idsetregisterid
        End Get
    End Property

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [RECORDTYPEID]() As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        Get
            Return _recordtypeid
        End Get
    End Property

    ''' <summary>
    ''' Category
    ''' </summary>
    <System.ComponentModel.Description("Category")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [ATTRIBUTECATEGORYID]() As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        Get
            Return _attributecategoryid
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [STRINGVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.StringField
        Get
            Return _stringvalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [NUMBERVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
        Get
            Return _numbervalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [MONEYVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.MoneyField
        Get
            Return _moneyvalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [DATEVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.DateField
        Get
            Return _datevalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [BOOLEANVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.ValueListField(Of Nullable(Of BOOLEANVALUES))
        Get
            Return _booleanvalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CODETABLEVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.CodeTableField
        Get
            Return _codetablevalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [FUZZYDATEVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.FuzzyDateField
        Get
            Return _fuzzydatevalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CONSTITUENTIDVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        Get
            Return _constituentidvalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [HOURMINUTEVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.HourMinuteField
        Get
            Return _hourminutevalue
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [MEMOVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.StringField
        Get
            Return _memovalue
        End Get
    End Property

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [ATTRIBUTECATEGORIES]() As Global.Blackbaud.AppFx.UIModeling.Core.CollectionField(Of AddAnyConstituentAttributeWStartDateATTRIBUTECATEGORIESUIModel)
        Get
            Return _attributecategories
        End Get
    End Property

    ''' <summary>
    ''' Start Date
    ''' </summary>
    <System.ComponentModel.Description("Start Date")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [STARTDATE]() As Global.Blackbaud.AppFx.UIModeling.Core.DateField
        Get
            Return _startdate
        End Get
    End Property

    ''' <summary>
    ''' Comment
    ''' </summary>
    <System.ComponentModel.Description("Comment")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [COMMENT]() As Global.Blackbaud.AppFx.UIModeling.Core.StringField
        Get
            Return _comment
        End Get
    End Property

    ''' <summary>
    ''' Remove value from unqualified records
    ''' </summary>
    <System.ComponentModel.Description("Remove value from unqualified records")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [REMOVEUNQUALIFIED]() As Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
        Get
            Return _removeunqualified
        End Get
    End Property

    ''' <summary>
    ''' Overwrite existing value
    ''' </summary>
    <System.ComponentModel.Description("Overwrite existing value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [OVERWRITEEXISTINGVALUE]() As Global.Blackbaud.AppFx.UIModeling.Core.BooleanField
        Get
            Return _overwriteexistingvalue
        End Get
    End Property

    ''' <summary>
    ''' Currency
    ''' </summary>
    <System.ComponentModel.Description("Currency")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CURRENCYID]() As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        Get
            Return _currencyid
        End Get
    End Property

    ''' <summary>
    ''' Value
    ''' </summary>
    <System.ComponentModel.Description("Value")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [UIVALUEFIELD]() As Global.Blackbaud.AppFx.UIModeling.Core.StringField
        Get
            Return _uivaluefield
        End Get
    End Property

End Class
<file_sep>Option Strict On
Option Explicit On
Option Infer On

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by BBUIModelLibrary
'     Version:  2.93.2034.0
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
''' <summary>
''' Represents the UI model for the 'AddAnyConstituentAttributeWStartDateATTRIBUTECATEGORIES' data form
''' </summary>
Partial Public Class [AddAnyConstituentAttributeWStartDateATTRIBUTECATEGORIESUIModel]
	Inherits Global.Blackbaud.AppFx.UIModeling.Core.UIModel

#Region "Extensibility methods"

    Partial Private Sub OnCreated()
    End Sub

#End Region

    Private WithEvents _id As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
    Private WithEvents _datatypecode As Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
    Private WithEvents _constituentsearchlistcatalogid As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
    Private WithEvents _codetablename As Global.Blackbaud.AppFx.UIModeling.Core.StringField

	<System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public Sub New()
        MyBase.New()

        _id = New Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        _datatypecode = New Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
        _constituentsearchlistcatalogid = New Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        _codetablename = New Global.Blackbaud.AppFx.UIModeling.Core.StringField

        '
        '_id
        '
        _id.Name = "ID"
        _id.Caption = "ID"
        Me.Fields.Add(_id)
        '
        '_datatypecode
        '
        _datatypecode.Name = "DATATYPECODE"
        _datatypecode.Caption = "DATATYPECODE"
        Me.Fields.Add(_datatypecode)
        '
        '_constituentsearchlistcatalogid
        '
        _constituentsearchlistcatalogid.Name = "CONSTITUENTSEARCHLISTCATALOGID"
        _constituentsearchlistcatalogid.Caption = "CONSTITUENTSEARCHLISTCATALOGID"
        Me.Fields.Add(_constituentsearchlistcatalogid)
        '
        '_codetablename
        '
        _codetablename.Name = "CODETABLENAME"
        _codetablename.Caption = "CODETABLENAME"
        Me.Fields.Add(_codetablename)

		OnCreated()

    End Sub

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [ID]() As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        Get
            Return _id
        End Get
    End Property

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [DATATYPECODE]() As Global.Blackbaud.AppFx.UIModeling.Core.IntegerField
        Get
            Return _datatypecode
        End Get
    End Property

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CONSTITUENTSEARCHLISTCATALOGID]() As Global.Blackbaud.AppFx.UIModeling.Core.GuidField
        Get
            Return _constituentsearchlistcatalogid
        End Get
    End Property

    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CODETABLENAME]() As Global.Blackbaud.AppFx.UIModeling.Core.StringField
        Get
            Return _codetablename
        End Get
    End Property

End Class
<file_sep>Public Class AddAnyConstituentAttributeWStartDateUIModel

    Private Sub AddAnyConstituentAttributeWStartDateUIModel_Loaded(ByVal sender As Object, ByVal e As Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs) Handles Me.Loaded

    End Sub

End Class<file_sep>Option Strict On
Option Explicit On
Option Infer On

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by BBUIModelLibrary
'     Version:  2.93.2034.0
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
''' <summary>
''' Represents the UI model for the 'Add Revenue To Campaign Sub Priority Global Change' data form
''' </summary>

Partial Public Class [AddRevenueToCampaignSubPriorityGlobalChangeUIModel]
	Inherits Global.Blackbaud.AppFx.UIModeling.Core.CustomUIModel

#Region "Extensibility methods"

    Partial Private Sub OnCreated()
    End Sub

#End Region

    Private WithEvents _revenueappselectionid As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
    Private WithEvents _campaignid As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
    Private WithEvents _subpriorityid As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)

	<System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public Sub New()
        MyBase.New()

        _revenueappselectionid = New Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        _campaignid = New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        _subpriorityid = New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)

        'MyBase.UserInterfaceUrl = "browser/htmlforms/AddRevenueToCampaignSubPriorityGlobalChange.html"

        '
        '_revenueappselectionid
        '
        _revenueappselectionid.Name = "REVENUEAPPSELECTIONID"
        _revenueappselectionid.Caption = "Revenue Application Selection"
        _revenueappselectionid.Required = True
        _revenueappselectionid.SearchListID = New Guid("1f0e603c-1c55-4e1e-8218-bdb877b2cbe8")
        _revenueappselectionid.SystemSearchType = Global.Blackbaud.AppFx.UIModeling.Core.SystemSearchType.Selection
        Me.Fields.Add(_revenueappselectionid)
        '
        '_campaignid
        '
        _campaignid.Name = "CAMPAIGNID"
        _campaignid.Caption = "Campaign"
        _campaignid.SimpleDataListID = New Guid("2e7566f2-cc4c-44c5-aed1-4700b691cef6")
        Me.Fields.Add(_campaignid)
        '
        '_subpriorityid
        '
        _subpriorityid.Name = "SUBPRIORITYID"
        _subpriorityid.Caption = "Sub Priority"
        _subpriorityid.SimpleDataListID = New Guid("e3e9e22a-85f2-4a77-ba74-25b391252dab")
        _subpriorityid.Parameters.Add(New Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListParameter("CAMPAIGNID", "Fields!CAMPAIGNID"))
        Me.Fields.Add(_subpriorityid)

		OnCreated()

    End Sub

    ''' <summary>
    ''' Revenue Application Selection
    ''' </summary>
    <System.ComponentModel.Description("Revenue Application Selection")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [REVENUEAPPSELECTIONID]() As Global.Blackbaud.AppFx.UIModeling.Core.SearchListField(Of Guid)
        Get
            Return _revenueappselectionid
        End Get
    End Property

    ''' <summary>
    ''' Campaign
    ''' </summary>
    <System.ComponentModel.Description("Campaign")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [CAMPAIGNID]() As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        Get
            Return _campaignid
        End Get
    End Property

    ''' <summary>
    ''' Sub Priority
    ''' </summary>
    <System.ComponentModel.Description("Sub Priority")> _
    <System.CodeDom.Compiler.GeneratedCodeAttribute("BBUIModelLibrary", "2.93.2034.0")> _
    Public ReadOnly Property [SUBPRIORITYID]() As Global.Blackbaud.AppFx.UIModeling.Core.SimpleDataListField(Of Guid)
        Get
            Return _subpriorityid
        End Get
    End Property

End Class

repo_language: Visual Basic .NET

repo_name: CadeJenkins/GCSPECS


text:
<repo_name>Kafonin/PayCalculatorConsole<file_sep>/Source.cpp
#include <iostream>

int main() {

	float basePay = 12.50;
	float hoursWorked = 0.0;
	float overTime = 0.0;
	float totalPay = 0.0;
	float overTimePay = 0.0;

	std::cout << "Enter the hours worked for the week as a whole number: " << std::endl;
	std::cin >> hoursWorked;

	switch (hoursWorked > 0)
	{
	case 1:
		if (hoursWorked > 40)
		{
			overTime = hoursWorked - 40;
			overTimePay = overTime * (basePay * 1.5);
			std::cout << "You worked " << overTime << " overtime hours\n" << std::endl;
			totalPay = (basePay * 40) + (overTimePay);
			std::cout << "Your total pay this week is $" << totalPay << std::endl;
		}
	case 2:
		if (hoursWorked <= 40)
		{
			totalPay = (basePay * hoursWorked);
			std::cout << "Your total pay this week is $" << totalPay << std::endl;
		}

	}
}

repo_name: Kafonin/PayCalculatorConsole


text:
<repo_name>imonteroperez/puppet-integration<file_sep>/puppet/modules/itlm/manifests/consumes.pp
define itlm::consumes (
  $environment  = 'all',
  $destination  = undef,
  $service	    = [ 'all-provided' ],
  $action       = 'allow',
) {
}
<file_sep>/puppet/modules/role/manifests/app/webserver.pp
class role::app::webserver {
  include profile::server::base
  include profile::puppet::node
  include profile::app::webserver
}
<file_sep>/puppet/modules/profile/manifests/server/base.pp
class profile::server::base {
  class { 'ntp':
    servers => [
      'nist-time-server.eoni.com',
      'nist1-lv.ustiming.org',
      'ntp-nist.ldsbc.edu',
    ]
  }
  # Should configure DNS but won't or demo won't work at the moment

  itlm::consumes { 'dns::resolv':
    destination => [ 'profile::server::dnsserver' ],
    service      => [ 'dns::resolv' ],
  }
  itlm::provides { 'server::ssh':
    source  => [ 'Admins' ],
    ports   => [ '22/tcp' ],
  }
}
<file_sep>/app/services/RequirementModel.scala
package services

import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
import play.api.libs.ws.ning._
import play.api.libs.ws._

/**
 * Model for requirements
 */
object RequirementModel {

  /**
   * Pair including existing requirements and the new ones
   */
  type RequirementResponse = (Iterable[IssuedRequirement], Iterable[Requirement])

  val Protocols = Map(1 -> "icmp", 6 -> "tcp", 17 -> "udp")

  // Puppet-Intelliment Model
  case class Network(id: String, name: String, ipAddress: Option[String])
  case class ItlmService(id: String)
  case class ItlmRequirement(name: String, action: String, services: List[ItlmService])

  implicit val networkReads: Reads[Network] = (
    (JsPath \ "id").read[String] and
    (JsPath \ "name").read[String] and
    (JsPath \ "ip").readNullable[String])(Network.apply _)

  // Intelliment Model
  case class Issue(status: String, elementId: String, message: String)
  case class Endpoint(id: Option[String], name: String, ip: Option[String])
  case class Service(name: String, ports: List[String])

  object Service {

    /**
     * Transform a json from Intelliment API to Service case class
     */
    def build(service: JsObject): Service = {
      val name = service.\("name").as[String]
      val protocol = service.\("protocol").as[Int]
      val dstPorts = service.\("destinationPorts").asOpt[String]

      val srv = Protocols.get(protocol).getOrElse(protocol.toString())
      val srvPorts = if (dstPorts.isDefined) dstPorts.get + "/" + srv else srv

      Service(name, List(srvPorts))
    }

  }

  case class Status(kind: String, message: Option[String])
  case class IssuedRequirement(id: Option[String], status: Status, source: Endpoint, destination: Endpoint, services: List[Service], tags: List[String], action: String)
  case class ConfigurationEntry(confType: Option[String], services: List[Service])
  case class RequirementApi(id: String, source: Endpoint, destination: Endpoint, configuration: List[ConfigurationEntry], tags: List[String], action: String)
  case class Requirement(id: Option[String], source: Endpoint, destination: Endpoint, services: List[Service], tags: List[String], action: String)

  implicit val serviceFormat = Json.format[Service]

  implicit val issueReads: Reads[Issue] = (
    (JsPath \ "status").read[String] and
    (JsPath \ "element" \\ "id").read[String] and
    (JsPath \ "message").read[String])(Issue.apply _)

  implicit val endpointReads: Reads[Endpoint] = (
      (JsPath \ "id").readNullable[String] and
      (JsPath \ "name").read[String] and
      (JsPath \ "ip").readNullable[String])(Endpoint.apply _)

  implicit val requirementReads: Reads[Requirement] = (
    (JsPath \ "id").readNullable[String] and
    (JsPath \ "source").read[Endpoint] and
    (JsPath \ "destination").read[Endpoint] and
    (JsPath \ "services").readNullable[List[JsObject]].map {
      x => x.getOrElse(List.empty).map { s => Service.build(s) } } and
    (JsPath \ "tags").read[List[String]] and
    (JsPath \ "action").read[String])(Requirement.apply _)

  implicit val configurationReads: Reads[ConfigurationEntry] = (
      (JsPath \ "type").readNullable[String] and
      (JsPath \ "services").readNullable[List[JsObject]].map {
      x => x.getOrElse(List.empty).map { s => Service.build(s) } })(ConfigurationEntry.apply _)

  implicit val requirementApiReads: Reads[RequirementApi] = (
    (JsPath \ "id").read[String] and
    (JsPath \ "source").read[Endpoint] and
    (JsPath \ "destination").read[Endpoint] and
    (JsPath \ "configuration").read[List[ConfigurationEntry]] and
    (JsPath \ "tags").readNullable[List[String]].map {
      x => x.getOrElse(List.empty)} and
    (JsPath \ "action").read[String])(RequirementApi.apply _)

  implicit val requirementFormat = new Writes[Requirement] {
    def writes(req: Requirement) = Json.obj(
      "id" -> req.id,
      "sourceName" -> req.source.name,
      "sourceIp" -> req.source.ip,
      "destinationName" -> req.destination.name,
      "destinationIp" -> req.destination.ip,
      "services" -> req.services,
      "tags" -> req.tags,
      "action" -> req.action)
  }

  implicit val issuedRequirementFormat = new Writes[IssuedRequirement] {
    def writes(req: IssuedRequirement) = Json.obj(
      "id" -> req.id,
      "status" -> req.status.kind,
      "message" -> req.status.message,
      "sourceName" -> req.source.name,
      "sourceIp" -> req.source.ip,
      "destinationName" -> req.destination.name,
      "destinationIp" -> req.destination.ip,
      "services" -> req.services,
      "tags" -> req.tags,
      "action" -> req.action)
  }

}<file_sep>/app/controllers/AngularController.scala
package controllers

import javax.inject._
import play.api._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.ws.WS
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration._
import akka.actor.ActorSystem
import services.PuppetResource
import services.PuppetResourceModel.Provider
import services.PuppetResourceModel.Consumer
import services.RequirementService
import scala.collection.mutable.ListBuffer
import services.RequirementModel.Requirement
import services.RequirementModel.RequirementResponse
import services.RequirementModel.Endpoint
import services.RequirementModel.Service
import services.IntellimentApiClient

/**
 * This controller creates an `Action` to handle HTTP requests to the
 * application's home page.
 */
@Singleton
class AngularController @Inject() (puppetResource: PuppetResource,
    requirementService: RequirementService, api: IntellimentApiClient,
    conf: Configuration, actorSystem: ActorSystem)
    (implicit exec: ExecutionContext)
    extends Controller {

  val PuppetDbUrl = conf.underlying.getString("intelliment.puppetDbUrl")

  implicit val requirementResponseFormat = new Writes[RequirementResponse] {
    def writes(reqs: RequirementResponse) = Json.obj(
      "existingRequirements" -> reqs._1,
      "newRequirements" -> reqs._2)
  }

  /**
   * Return the index page
   */
  def index = Action {
    Ok(views.html.index("Intelliment - Puppet : Proof of Concept"))
  }

  /**
   * Return the scenario list
   */
  def getScenarios = Action.async {
    val scenarios = api.getScenarios
    scenarios map { scenario => Ok(Json.toJson(scenario)) }
  }

  /**
   * Return the PuppetDB - url
   */
  def getPuppetUrl = Action {
    Ok(PuppetDbUrl)
  }

  /**
   * Return the existing and new requirements
   */
  def requirements(id: String, url: String) = Action.async {
    val requirements = generateReqs(id, url)
    requirements map { resp => Ok(Json.toJson(resp)) }
  }

  def getServices(id: String) = Action.async {
    val services = api.getServices(id)
    services map { service => Ok(Json.toJson(service)) }
  }

  /**
   * Create the requirements
   */
  def apply(id: String, url: String) = Action.async { request =>
    val json = request.body.asJson.map { x => toRequirementList(x.as[List[JsValue]]) }
    val created = requirementService.applyRequirements(id, json.getOrElse(List.empty))

    val x = created.map( x => {
        generateReqs(id, url).map{ resp => Ok(Json.toJson(resp)) }
      }
    )

    x.flatMap { i => i }

  }

  /**
   * Remove the requirements
   */
  def remove(id: String, url: String) = Action.async { request =>
    val list = request.body.asJson.map{ x => x.as[List[String]] }
    val deleted = list.map(l => requirementService.removeRequirements(id, l))

    val result = deleted.map( s => generateReqs(id, url).map{ resp => Ok(Json.toJson(resp)) } )

    result match {
      case Some(x) => x
      case _ => Future { Ok("error") }
    }
  }

  private def generateReqs(id: String, url: String): Future[RequirementResponse] = {
    val resources = puppetResource.getPuppetResources(url)
    resources flatMap {
      res => requirementService.generateRequirements(id, res)
    }
  }

  private def toRequirementList(list: List[JsValue]): List[Requirement] = {
    for {
      el <- list
    } yield Requirement(
        None,
        Endpoint(None, el.\("sourceName").as[String], el.\("sourceIp").asOpt[String]),
        Endpoint(None, el.\("destinationName").as[String], el.\("destinationIp").asOpt[String]),
        el.\("services").as[List[Service]],
        el.\("tags").as[List[String]],
        el.\("action").as[String]
        )
  }

}
<file_sep>/app/services/PuppetResourceModel.scala
package services

import play.api.libs.json.Reads
import play.api.libs.json.JsPath
import play.api.libs.functional.syntax._

/**
 * Model for service response
 */
object PuppetResourceModel {

  case class Provider(node: String, ipAddress: String, service: String, ports: List[String], source: List[String], tags: List[String], action: String)
  case class Consumer(node: String, ipAddress: String, service: List[String], dest: List[String], tags: List[String], action: String)
  case class PuppetResources(providers: List[Provider], consumers: List[Consumer])

   // Model for json response and ipAddress
  case class Resource(title: String, tags: List[String], node: String, resourceType: String, parameters: Parameters)
  case class Parameters(ports: Option[List[String]], service: Option[List[String]], source: Option[List[String]], destination: Option[List[String]], action: Option[String])
  case class IpAddress(node: String, ipAddress: String)

  implicit val parameterReads: Reads[Parameters] = (
    (JsPath \ "ports").readNullable[List[String]] and
    (JsPath \ "service").readNullable[List[String]] and
    (JsPath \ "source").readNullable[List[String]] and
    (JsPath \ "destination").readNullable[List[String]] and
    (JsPath \ "action").readNullable[String])(Parameters.apply _)

  implicit val resourceReads: Reads[Resource] = (
    (JsPath \ "title").read[String] and
    (JsPath \ "tags").read[List[String]] and
    (JsPath \ "certname").read[String] and
    (JsPath \ "type").read[String] and
    (JsPath \ "parameters").read[Parameters])(Resource.apply _)

  implicit val ipAddressReads: Reads[IpAddress] = (
    (JsPath \ "certname").read[String] and
    (JsPath \ "value").read[String])(IpAddress.apply _)
}<file_sep>/app/services/RequirementService.scala
package services

import services.PuppetResourceModel._
import services.RequirementModel._
import javax.inject.Singleton
import javax.inject.Inject
import play.api.libs.ws.WSClient
import play.api.libs.ws.WSRequest
import scala.concurrent.Future
import play.api.libs.ws.WSResponse
import scala.concurrent.ExecutionContext
import play.api.libs.json._
import play.api.Configuration
import java.math.BigInteger
import java.net.InetAddress
import play.api.Logger

/**
 * Services to interact with Intelliment
 */
trait RequirementService {

  /**
   * Return a pair with existing requirements and new requirements
   */
  def generateRequirements(scenarioId: String, resources: PuppetResources): Future[RequirementResponse]

  /**
   * Creates the requirements in Intelliment
   */
  def applyRequirements(scenarioId: String, requirements: List[Requirement]): Future[String]

  /**
   * Creates the requirements in Intelliment
   */
  def removeRequirements(scenarioId: String, requirements: List[String]): Future[String]

}

@Singleton
class RestRequirementService @Inject() (api: IntellimentApiClient)
  (implicit exec: ExecutionContext)
  extends RequirementService {

  val logger: Logger = Logger(this.getClass())

  val IpCidr = ("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.)" +
                   "{3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" +
                   "(\\/(\\d|[1-2]\\d|3[0-2]))?$").r
  /**
   * Implementation with Intelliment API
   */
  override def generateRequirements(scenarioId: String, resources: PuppetResources): Future[RequirementResponse] = {

    logger.info(s"Generate requirements for scenario $scenarioId")

    val networks = api.getNetworks(scenarioId)
    val generated = for {
      nets <- networks
    } yield for {
      provider <- resources.providers
      consumer <- resources.consumers
      if(!provider.node.equals(consumer.node))
    } yield toRequirement(scenarioId, provider, consumer, nets)

    val generatedFlatten = generated.flatMap { l => Future.sequence(l) } map { _.flatten }

    // group in pairs of (requirement -> id (or empty string if new))
    val listOfPairs = for {
      gen <- generatedFlatten
      nets <- networks
    } yield for {
      req <- gen
    } yield existingAndNew(scenarioId, req, getInternetId(nets))

    val listOfFuture = listOfPairs.flatMap { x => Future.sequence(x) }
    /////

    Thread.sleep(5000)

    /////
    val issues = api.getIssues(scenarioId)
    val grouped = for {
      list <- listOfFuture
      issueMap <- issues
    } yield for {
      req <- list
    } yield (toIssuedReq(issueMap, req.existing), req.others)

    val existing = grouped.map(l => l.map(p => p._1)).map { i => i.flatten }
    val others = grouped.map(l => l.map(p => p._2)).map { i => i.flatten }

    for {
      e <- existing
      o <- others
    } yield (e.distinct, o.distinct)

  }

  /**
   * Return the internet id, it means the network without Ip address
   */
  private def getInternetId(networks: List[Network]): Option[String] = {
    val ids = for {
      net <- networks
      if net.ipAddress.isEmpty
    } yield net.id

    ids.headOption
  }

  private def toIssuedReq(issues: Map[String, List[Issue]],
      reqs: List[Requirement]): List[IssuedRequirement] = {

    for {
      req <- reqs
    } yield IssuedRequirement(
        req.id,
        statusFor(issues.getOrElse(req.id.get, List.empty)),
        req.source,
        req.destination,
        req.services,
        req.tags,
        req.action)
  }

  private def statusFor(issues: List[Issue]): Status = {
    val grouped = issues.groupBy { st => st.status }
    val errors = grouped.getOrElse("ERROR", List.empty)

    if (!errors.isEmpty) {
      val messages = errors.foldLeft("")((msg, st) => msg + st.message + ". ")
      Status("error", Some(messages))
    } else {
      Status("ok", Some("This requirement has no issues"))
    }
  }

  case class ExistingAndNew(existing: List[Requirement], others: List[Requirement])

  /**
   * Return the list of the requirements in Intelliment with the same source/destination
   */
  private def existingAndNew(scenarioId: String, requirement: Requirement, internetId: Option[String]): Future[ExistingAndNew] = {

    val source: Option[String] = requirement.source.ip match {
      case Some(ip) => Some("sourceIp=" + ip)
      case _ => if (internetId.isDefined) Some("sourceId=" + internetId.get) else None
    }

    val dest: Option[String] = requirement.destination.ip match {
      case Some(ip) => Some("destinationIp=" + ip)
      case _ => if (internetId.isDefined) Some("destinationId=" + internetId.get) else None
    }

    if (source.isDefined && dest.isDefined && !requirement.tags.isEmpty) {
      val sValue = source.get
      val dValue = dest.get
      val existing = api.getRequirements(scenarioId, Some(s"$sValue&$dValue"))

      /**
       * Check services, tags and actions
       */
      def sameParameters(req: Requirement, existing: List[Requirement]): Boolean = {
        val ports = req.services.flatMap { x => x.ports }
        val list = existing.filter { r => r.action.equals(req.action) && containsPorts(r, ports) }
        !list.isEmpty
      }

      def containsPorts(req: Requirement, ports: List[String]): Boolean = {
        !req.services.filter(s => !s.ports.intersect(ports).isEmpty).isEmpty
      }

//      existing map {
//        list => if (sameParameters(requirement, list)) ExistingAndNew(list, List.empty) else ExistingAndNew(list, List(requirement))
//      }

      existing map {
        list => ExistingAndNew(list, List(requirement))
      }

    } else {
      Future { ExistingAndNew(List.empty, List.empty) }
    }
  }

  /**
   * Implementation with Intelliment API
   */
  override def applyRequirements(scenarioId: String, requirements: List[Requirement]): Future[String] = {

    logger.info(s"Applying requirements for scenario $scenarioId")

    val requests = for {
      req <- requirements
    } yield api.createRequirement(scenarioId, req.source, req.destination, req.tags, req.services)

    val requestList = Future.sequence(requests)
    return requestList map {
      list =>
        if(list.contains("error"))
          "Error! Application of requirements are fail"
        else
          "Success! Requirements are successfully applied"
    }
  }

  /**
   * Implementation with Intelliment API
   */
  override def removeRequirements(scenarioId: String, requirements: List[String]): Future[String] = {

    logger.info(s"Removing requirements for scenario $scenarioId")
    logger.debug(s"Requirements to remove: $requirements")

    val requests = for {
      id <- requirements
    } yield api.removeRequirement(scenarioId, id)

    val requestList = Future.sequence(requests)
    return requestList map {
      list =>
        if(list.contains("error"))
          "Error! Application of requirements are fail"
        else
          "Success! Requirements are successfully applied"
    }
  }

  private def toRequirement(scenarioId: String, provider: Provider, consumer: Consumer, networks: List[Network]):
    Future[List[Requirement]] =  {

    def isApp(tag: String) = tag.startsWith("app:") && !tag.startsWith("app::")

    val pNode = provider.node
    val pIp = provider.ipAddress
    val pTags = provider.tags
    val pService = provider.service
    val pPorts = provider.ports
    val cNode = consumer.node
    val cIp = consumer.ipAddress
    val cTags = consumer.tags
    val cService = consumer.service
    val cDest = consumer.dest
    val tags = (provider.tags.filter { isApp } ++ consumer.tags.filter { isApp }).distinct
    val action = provider.action // FIXME: action should be the same for consumer and provider

    def reqWithServer = Future {
      List(
        Requirement(
            None,
            Endpoint(None, cNode, Some(cIp)),
            Endpoint(None,pNode, Some(pIp)),
            List(Service(pService, pPorts)),
            tags,
            action
            ))
    }

    def getIpBitsAndMask(ip: String): (String, Int) = {
      val array = ip.split('/')
      val mask = if (array.size > 1) array(1).toInt else 32

      def ipToBits(a: List[String]): String = a match {
        case Nil => ""
        case head :: Nil => toBits(head)
        case head :: xs => toBits(head) + ipToBits(xs)
      }

      def toBits(part: String): String = {
        val bin = Integer.toBinaryString(Integer.parseInt(part))
        val length = 8 - bin.length()
        "0" * length ++ bin
      }

      val parts = array(0).split("\\.").toList
      (ipToBits(parts), mask)
    }

    def isInSameNetwork(netIp: Option[String], subnetIp: String) = netIp match {
      case None => true
      case Some(networkIp) => {
        val networkIpMask = getIpBitsAndMask(networkIp)
        val netBits = networkIpMask._1
        val netMask = networkIpMask._2
        val subnetIpMask = getIpBitsAndMask(subnetIp)
        val subBits = subnetIpMask._1
        val subMask = subnetIpMask._2

        // a subnet is contained in a network if:
        // a) network mask is lower than subnet mask
        // AND
        // b) the prefix (from 0 to network mask) for network ip is equals to prefix for subnet ip
        (netMask < subMask) && (netBits.substring(0, netMask).equals(subBits.substring(0, netMask)))
      }
    }

    def requirementFromAll: Future[List[Requirement]] = {
      val req = for {
        net <- networks
        if !isInSameNetwork(net.ipAddress, pIp)
      } yield Requirement(
          None,
          Endpoint(Some(net.id), net.name, net.ipAddress),
          Endpoint(None,pNode, Some(pIp)),
          List(Service(pService, pPorts)),
          tags,
          action)

      Future { req }
    }

    def requirementFromNetwork(netName: String): Future[List[Requirement]] = {
      for {
        net <- api.getNetworkByName(scenarioId, netName)
      } yield net match {
        case None => List.empty
        case Some(n) => List(Requirement(
            None,
            Endpoint(Some(n.id), n.name, n.ipAddress),
            Endpoint(None, pNode, Some(pIp)),
            List(Service(pService, pPorts)),
            tags,
            action))
      }
    }

    // Create requirements according to the source type
    val reqs = for {
      source <- provider.source
    } yield source match {
      case "all" => requirementFromAll
      case "all-consumers" if cService.contains(pService) && pTags.intersect(cDest).size > 0 => reqWithServer
      case IpCidr(ip) => Future { List(
          Requirement(
              None,
              Endpoint(None, ip, Some(ip)),
              Endpoint(None,pNode, Some(pIp)),
              List(Service(pService, pPorts)),
              tags,
              action)) }
      case role if cService.contains(pService) && cTags.contains(role) => reqWithServer
      case name => requirementFromNetwork(name)
    }

    Future.sequence(reqs).map { _.flatten }
  }

}
<file_sep>/app/services/PuppetDBApiClient.scala
package services

import javax.inject.Inject
import scala.concurrent.ExecutionContext
import play.api.libs.ws.WSClient
import scala.concurrent.Future
import services.RequirementModel.Issue
import play.api.libs.ws.WSResponse
import play.api.libs.json.JsObject
import services.RequirementModel.Endpoint
import play.api.libs.json.JsString
import services.RequirementModel.Service
import services.RequirementModel.Network
import play.api.libs.json.Json
import play.api.libs.ws.WSRequest
import services.PuppetResourceModel.Resource
import services.PuppetResourceModel.IpAddress
import play.api.Logger

/**
 * Client for PuppetDB API calls
 */
trait PuppetDBApiClient {

  /**
   * Return the list of resources in a PuppetDB
   */
  def getResources(url: String) : Future[List[Resource]]

  /**
   * Return the IP addresses for nodes in a PuppetDB
   */
  def getIpAddresses(url: String) : Future[List[IpAddress]]

}

class WSPuppetDBApiClient @Inject() (ws: WSClient)
  (implicit exec: ExecutionContext)
  extends PuppetDBApiClient {

  val logger: Logger = Logger(this.getClass())

  /**
   * Request body to retrieve all intelliment resources
   */
  val ItlmResourcesQuery = Json.obj(
      "query" -> """["=", "tags", "itlm"]"""
      )

  /**
   * Request body to retrieve all ip addresses for resources with tag itlm
   */
  val ItlmIpAddressQuery = Json.obj(
      "query" -> """
      ["and", ["=","name","ipaddress"],
      ["in", "certname", ["extract", "certname", ["select_resources", ["=","tags","itlm"]]]]]}"""
      )

  override def getResources(url: String) : Future[List[Resource]] = {
    val resourcesUrl = s"$url/query/v4/resources";
    logger.info(s"GET $resourcesUrl")
    val response: Future[WSResponse] = ws.url(resourcesUrl).post(ItlmResourcesQuery)
    return response map { resources => resources.json.as[List[Resource]] }
  }

  override def getIpAddresses(url: String) : Future[List[IpAddress]] = {
    val factsUrl = s"$url/query/v4/facts";
    logger.info(s"GET $factsUrl")
    val response: Future[WSResponse] = ws.url(factsUrl).post(ItlmIpAddressQuery)
    return response map { ipAddresses => ipAddresses.json.as[List[IpAddress]] }
  }

}<file_sep>/puppet/modules/itlm/manifests/requirement.pp
define itlm::requirement (
  $environment	= 'all',
  $source_ip	  = undef,
  $source_class = undef,
  $dest_ip	    = undef,
  $dest_class	  = undef,
  $service	    = 'all-provided',
  $ports	      = 'all',
  $action	      = 'allow',
  $source_nat	  = undef,
  $dest_nat	    = undef,
  $ports_nat	  = undef,
) {
}
<file_sep>/app/controllers/DummyPuppetDBApiClient.scala
package controllers

import play.api.libs.json.Json
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import services.PuppetDBApiClient
import services.PuppetResourceModel._
import play.api.libs.json.Reads

class DummyPuppetDBApiClient (implicit exec: ExecutionContext) extends PuppetDBApiClient {

  override def getIpAddresses(url: String): Future[List[IpAddress]] = {
    getFutureJson[List[IpAddress]]("/facts.json")
  }

  override def getResources(url: String): Future[List[Resource]] = {
    getFutureJson[List[Resource]]("/resources.json")
  }

  def getFutureJson[T](file: String)(implicit fjs: Reads[T]): Future[T] = {
    val json = getClass.getResourceAsStream(file)
    val x = Json.parse(json).as[T]
    Future { x }
  }

}<file_sep>/puppet/modules/profile/manifests/puppet/node.pp
class profile::puppet::node {
  pe_ini_setting { 'use_cached_catalog':
    ensure  => present,
    path    => $settings::config,
    section => 'agent',
    setting => 'use_cached_catalog',
    value   => 'false',
  }
  pe_ini_setting { 'pluginsync':
    ensure  => present,
    path    => $settings::config,
    section => 'agent',
    setting => 'pluginsync',
    value   => 'false',
  }
}
<file_sep>/puppet/modules/role/manifests/puppet/master.pp
class role::puppet::master {
  include profile::puppet::master
}
<file_sep>/app/services/IntellimentApiClient.scala
package services

import javax.inject.Inject
import scala.concurrent.ExecutionContext
import scala.collection.breakOut
import play.api.libs.ws.WSClient
import play.api.Configuration
import scala.concurrent.Future
import services.RequirementModel.Issue
import play.api.libs.ws.WSResponse
import play.api.libs.json.JsObject
import services.RequirementModel.Endpoint
import play.api.libs.json.JsString
import services.RequirementModel._
import play.api.libs.json.Json
import play.api.libs.ws.WSRequest
import play.api.libs.json.Reads
import play.api.libs.json.Writes
import play.api.libs.json.JsPath
import play.api.Logger
import play.api.libs.json.JsValue
import play.api.libs.json.JsArray
import play.api.libs.json.JsBoolean
import play.api.libs.json.JsLookupResult
import scala.concurrent.Await
import scala.concurrent.duration.Duration

/**
 * Client for Intelliment API calls
 */
trait IntellimentApiClient {

  def getScenarios: Future[List[JsObject]]

  def getIssues(scenarioId: String): Future[Map[String, List[Issue]]]

  def getNetworks(scenarioId: String): Future[List[Network]]

  def getNetworkByName(scenarioId: String, name: String): Future[Option[Network]]

  def getRequirements(scenarioId: String, query: Option[String]): Future[List[Requirement]]

  def createRequirement(scenarioId: String, source: Endpoint, destination: Endpoint, tags: List[String], services: List[Service]): Future[String]

  def removeRequirement(scenarioId: String, id: String): Future[String]

  def getServices(scenarioId: String): Future[Map[String, String]]
}

class WSIntellimentApiClient @Inject() (ws: WSClient, conf: Configuration)
  (implicit exec: ExecutionContext)
  extends IntellimentApiClient {

  val logger: Logger = Logger(this.getClass())

  // Constants
  val IntellimentServer = conf.underlying.getString("intelliment.server")
  val ApiToken = conf.underlying.getString("intelliment.token")
  val BaseUri = s"$IntellimentServer/api/v1/policy-automation/scenarios"

  override def getScenarios: Future[List[JsObject]] = {
    val url = s"$BaseUri?limit=100"
    val response: Future[WSResponse] = get(url)
    response map { scenarios => scenarios.json.\("data").as[List[JsObject]] }
  }

  override def getIssues(scenarioId: String): Future[Map[String, List[Issue]]] = {
    val url = s"$BaseUri/$scenarioId/issues?limit=100"
    val response: Future[WSResponse] = get(url)
    val list = response map { issues => { issues.json.\("data").as[List[Issue]]} }

    list map { x => x.groupBy { issue => issue.elementId } }
  }

  override def getNetworks(scenarioId: String): Future[List[Network]] = {
    val url = s"$BaseUri/$scenarioId/objects?types=zone,internet&limit=100"
    val response: Future[WSResponse] = get(url)
    response map { _.json.\("data").as[List[Network]] }
  }

  override def getNetworkByName(scenarioId: String, name: String): Future[Option[Network]] = {
    val url = s"$BaseUri/$scenarioId/objects?types=zone,internet&limit=100"
    val response: Future[WSResponse] = get(s"$url&name=$name")
    response map { _.json.\("data").as[List[Network]] } map { _.headOption }
  }

  override def getRequirements(scenarioId: String, query: Option[String]): Future[List[Requirement]] = {
    val reqUrl = s"$BaseUri/$scenarioId/requirements?expand=source,destination,services"
    val url = query match {
      case None => reqUrl
      case Some(q) => reqUrl + "&" + q
    }

     val response: Future[WSResponse] = get(url)
     val reqs = response map { _.json.\("data").as[List[RequirementApi]] }
     reqs map { r => toReq(r) }
  }

  override def removeRequirement(scenarioId: String, id: String): Future[String] = {
    val url = s"$BaseUri/$scenarioId/requirements"
    val response: Future[WSResponse] = delete(url + "/" + id)
    response flatMap( x_ => Future { "success" })
  }

  override def createRequirement(scenarioId: String, source: Endpoint, destination: Endpoint, tags: List[String], services: List[Service]): Future[String] = {
    // FIXME: Changes this block to avoid await
    val futureServiceBinding = getServiceMap(scenarioId)
    val serviceBinding = Await.result(futureServiceBinding, Duration.Inf)

    val servicesJson = for {
      service <- services
      port <- service.ports
    } yield JsObject(Seq(
          "id" -> JsString(serviceBinding(port))
        ))

    val config: JsValue = JsArray(Seq(
      JsObject(Seq(
        "enabled" -> JsBoolean(true),
        "type" -> JsString("custom"),
        "services" -> Json.toJson(servicesJson)
      ))))

    val tagJson: JsValue = Json.toJson(tags)

    val request = for {
      srcOpt <- endpointJson(scenarioId, source)
      dstOpt <- endpointJson(scenarioId, destination)
    } yield for {
      src <- srcOpt
      dst <- dstOpt
    } yield JsObject(Seq(
      "description" -> JsString("Created from Puppet"),
      "source" -> src,
      "destination" -> dst,
      "configuration" -> config,
      "tags" -> tagJson,
      "action" -> JsString("allow")
      ))

    val reqUrl = s"$BaseUri/$scenarioId/requirements"
    request.flatMap {
      case Some(req) => {
        post(reqUrl, req) flatMap(response => response.status match {
          case 200 => Future { "success" }
          case 422 => update(reqUrl, req, response)
          case _ => Future { "error" }
        })
      }
      case None => Future { "error" }
    }

  }

  override def getServices(scenarioId: String): Future[Map[String, String]] = getServiceMap(scenarioId)

  private def endpointJson(scenarioId: String, endpoint: Endpoint): Future[Option[JsObject]] = endpoint match {
    case Endpoint(None, _, Some(ip)) =>
      Future {
        Some(JsObject(Seq("type" -> JsString("ip"), "value" -> JsString(ip))))
      }
    case Endpoint(None, name, None) => {
      getIdByName(scenarioId, name) map {
        case Some(n) => Some(JsObject(Seq("type" -> JsString("id"), "value" -> JsString(n))))
        case None => None
        }
      }
  }

  private def getIdByName(scenarioId: String, name: String): Future[Option[String]] = {
    val url = s"$BaseUri/$scenarioId/objects?name="
    val response: Future[WSResponse] = get(url + name)

    val objOpt = response map { _.json.\("data").as[List[JsObject]] } map { _.headOption }
    objOpt flatMap {
      case Some(obj) => Future { obj.\("id").asOpt[String] }
      case None => Future { None }
    }

  }

  private def getServiceMap(scenarioId: String): Future[Map[String, String]] = {
    val url = s"$BaseUri/$scenarioId/objects?limit=100&types=tcp_service,udp_service,icmp_service,service"

    val pagination = new Pagination(ws, ApiToken)
    val futureListPages = pagination.fetch(url)

    val x = for {
      listPages <- futureListPages
    } yield for {
      page <- listPages
    } yield toMap(page.data)

    x map { _.flatten.toMap }
  }

  private def toMap(services: List[JsObject]): Map[String, String] = {
    def name(srvType: String, param: JsLookupResult): String = {
      val value = param.as[String]
      if (value == null || value.equals("")) return srvType
      value + "/" + srvType
    }

    def categorize(srv: JsObject): String = {
      srv.\("type").as[String] match {
        case "tcp_service" => name("tcp", srv.\("destinationPorts"))
        case "udp_service" => name("udp", srv.\("destinationPorts"))
        case "icmp_service" => name("icmp", srv.\("typeCode"))
        case _ => name("ip", srv.\("protocol"))
      }
    }

    return Map(services map { s => (categorize(s), s.\("id").as[String])} : _*)
  }

  private def update(url: String, request: JsObject, response: WSResponse): Future[String] = {
      val msg = response.json.\("message").as[String]
      val Pattern = "Requirement already exists. Conflict with: (.*)".r

      def update(id: String) = {
        put(s"$url/$id", request + ("id", JsString(id))) map(r => r.status match {
          case 200 => "success"
          case _ => "error"
        })
      }

      msg match {
        case Pattern(id) => update(id)
        case _ => Future { "error" }
      }
  }

  private def toReq(reqs: List[RequirementApi]): List[Requirement] = {
    for {
      r <- reqs
    } yield toReq(r)
  }

  private def toReq(r: RequirementApi): Requirement = Requirement(
        Some(r.id),
        r.source,
        r.destination,
        r.configuration.map(_.services).flatten,
        r.tags,
        r.action)

  private def get(url: String): Future[WSResponse] = {
    logger.debug(s"GET $url")
    request(url).get()
  }

  private def delete(url: String): Future[WSResponse] = {
    logger.debug(s"DELETE $url")
    request(url).delete()
  }

  private def post(url: String, requestBody: JsObject): Future[WSResponse] = {
    logger.debug(s"POST $url")
    request(url).post(requestBody)
  }

  private def put(url: String, requestBody: JsObject): Future[WSResponse] = {
    logger.debug(s"PUT $url")
    request(url).put(requestBody)
  }

  private def request(url: String): WSRequest = {
    ws.url(url).withHeaders("Authorization" -> s"Bearer $ApiToken")
  }
}<file_sep>/puppet/modules/role/manifests/server/dnsserver.pp
class role::server::dnsserver {
  include profile::server::base
  include profile::puppet::node
  include profile::server::dnsserver
}
<file_sep>/puppet/modules/itlm/manifests/provides.pp
define itlm::provides (
  $ports        = undef,
  $source       = [ 'all-consumers' ],
  $action	      = 'allow',
) {
  # firewall { $title:
  # $proto =>
  # $dport =>
}
<file_sep>/app/services/PuppetResource.scala
package services

import play.api.libs.json._
import play.api.libs.json.Reads._
import javax.inject.Singleton
import javax.inject.Inject
import play.api.libs.ws.WSClient
import play.api.libs.ws.WSRequest
import scala.concurrent.Future
import play.api.libs.ws.WSResponse
import scala.concurrent.ExecutionContext
import scala.util.Success
import scala.util.Failure
import services.PuppetResourceModel.PuppetResources
import services.PuppetResourceModel.Provider
import services.PuppetResourceModel.Consumer
import services.PuppetResourceModel.Resource
import services.PuppetResourceModel.IpAddress

/**
 * This service provides the Intelliment Resources defined in Puppet
 */
trait PuppetResource {

  /**
   * Retrieve the resources from a PuppetDB
   */
  def getPuppetResources(puppetDbUrl: String): Future[PuppetResources]

}

/**
 * This implementation provides the resources from PuppetDB by using
 * a REST call
 */
@Singleton
class RestPuppetResource @Inject() (api: PuppetDBApiClient)(implicit exec: ExecutionContext) extends PuppetResource {

  override def getPuppetResources(puppetDbUrl: String): Future[PuppetResources] = {
    val futureResources = api.getResources(puppetDbUrl)
    val futureIpAddresses = api.getIpAddresses(puppetDbUrl)

    return for {
      f1 <- futureResources
      f2 <- futureIpAddresses
    } yield createPuppetResources(f1, f2)

  }

  def createPuppetResources(resources: List[Resource], ips: List[IpAddress]): PuppetResources = {
    def isProvider(res: Resource): Boolean = { res.resourceType.equalsIgnoreCase("itlm::provides") }
    def isConsumer(res: Resource): Boolean = { res.resourceType.equalsIgnoreCase("itlm::consumes") }
    val ipsGrouped = ips groupBy { ipAddress => ipAddress.node }

    def getProviders(res: List[Resource]) = {
      res withFilter isProvider map {
        p => toProvider(p, ipsGrouped(p.node))
      }
    }

    def getConsumers(res: List[Resource]) = {
      res withFilter isConsumer map {
        c => toConsumer(c, ipsGrouped(c.node))
      }
    }

    PuppetResources(getProviders(resources), getConsumers(resources))
  }

  private def toProvider(provider: Resource, ipAddress: List[IpAddress]) : Provider = {
    val node = provider.node
    val service = provider.title
    val ports = provider.parameters.ports.getOrElse(List("all ports"))
    val source = provider.parameters.source.getOrElse(List("all-consumers"))
    val action = provider.parameters.action.getOrElse("allow")
    val ip = if (ipAddress.isEmpty) "" else ipAddress.head.ipAddress

    Provider(node, ip, service, ports, source, provider.tags, action)
  }

  private def toConsumer(consumer: Resource, ipAddress: List[IpAddress]) : Consumer = {
    val node = consumer.node
    val service = consumer.parameters.service.getOrElse(List("undefined"))
    val dest = consumer.parameters.destination.getOrElse(List("undefined"))
    val action = consumer.parameters.action.getOrElse("allow")
    val ip = if (ipAddress.isEmpty) "" else ipAddress.head.ipAddress

    Consumer(node, ip, service, dest, consumer.tags, action)
  }

}<file_sep>/app/controllers/DummyIntellimentApiClient.scala
package controllers

import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import services.IntellimentApiClient
import services.RequirementModel.Issue
import services.RequirementModel.Network
import services.RequirementModel.Endpoint
import services.RequirementModel.Service
import scala.util.Random
import java.util.UUID
import services.RequirementModel.Requirement
import play.api.libs.json.Reads
import play.api.libs.json.Json
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
import play.api.libs.json.JsObject

class DummyIntellimentApiClient (implicit exec: ExecutionContext) extends IntellimentApiClient {

  def id = UUID.randomUUID().toString()
  val networks = List(
        Network(id, "Admins",	Some("10.3.42.0/24")),
        Network(id, "Users",	Some("10.2.42.0/24")),
        Network(id, "Internet", None)
    )

  def getScenarios: Future[List[JsObject]] = ???

  def getIssues(scenarioId: String): Future[Map[String, List[Issue]]] = Future { Map.empty }

  def getNetworks(scenarioId: String): Future[List[Network]] = Future { networks }

  def getNetworkByName(scenarioId: String, name: String): Future[Option[Network]] = {
    val network = networks.filter { net => net.name.equals(name) }.headOption
    Future { network }
  }

  def getRequirements(scenarioId: String, query: Option[String]): Future[List[Requirement]] =
    getFutureJson[List[Requirement]]("/requirements.json")

  def createRequirement(scenarioId: String, source: Endpoint,
      destination: Endpoint, tags: List[String], services: List[Service]): Future[String] = Future { "ok" }

  def removeRequirement(scenarioId: String, id: String): Future[String] = Future { "ok" }

  def getFutureJson[T](file: String)(implicit fjs: Reads[T]): Future[T] = {
    val json = getClass.getResourceAsStream(file)
    val x = Json.parse(json).as[T]
    Future { x }
  }

  def getServices(scenarioId: String): Future[Map[String, String]] = ???

}<file_sep>/app/Module.scala
import com.google.inject.AbstractModule
import java.time.Clock

import services.PuppetResource
import services.RestPuppetResource
import services.RequirementService
import services.RestRequirementService
import services.WSIntellimentApiClient
import services.IntellimentApiClient
import services.PuppetDBApiClient
import services.WSPuppetDBApiClient

/**
 * This class is a Guice module that tells Guice how to bind several
 * different types. This Guice module is created when the Play
 * application starts.

 * Play will automatically use any class called `Module` that is in
 * the root package. You can create modules in other locations by
 * adding `play.modules.enabled` settings to the `application.conf`
 * configuration file.
 */
class Module extends AbstractModule {

  override def configure() = {
    bind(classOf[PuppetDBApiClient]).to(classOf[WSPuppetDBApiClient])
    bind(classOf[IntellimentApiClient]).to(classOf[WSIntellimentApiClient])
    bind(classOf[PuppetResource]).to(classOf[RestPuppetResource])
    bind(classOf[RequirementService]).to(classOf[RestRequirementService])
  }

}
<file_sep>/puppet/modules/role/manifests/app/database.pp
class role::app::database {
  include profile::server::base
  include profile::puppet::node
  include profile::app::database
}
<file_sep>/app/services/Pagination.scala
package services

import scala.concurrent.Future
import javax.inject.Inject
import play.api.libs.ws.WSClient
import scala.concurrent.ExecutionContext
import play.api.Logger
import play.api.libs.ws.WSResponse
import play.api.libs.json.JsObject
import play.api.libs.ws.WSRequest

class Pagination (ws: WSClient, token: String)
  (implicit exec: ExecutionContext) {

  case class Page(data: List[JsObject], next: Option[String])

  val logger: Logger = Logger(this.getClass())

  def fetchPage(url: String): Future[Page] = {
    val response: Future[WSResponse] = get(url)
    val futureData = response map { _.json.\("data").as[List[JsObject]] }
    val futureNext = response map { _.json.\("pagination").\("next").asOpt[String] }
    for {
      data <- futureData
      next <- futureNext
    } yield Page(data, next)
  }

  def fetch(urlPage: String): Future[List[Page]] = fetchAll(urlPage, List.empty)

  def fetchAll(urlPage: String, collected: List[Page]): Future[List[Page]] = {
    val a = for {
      page <- fetchPage(urlPage)
    } yield {
        page.next.fold {
           // No next page, return all collected up to this moment
          Future.successful(page :: collected)
        }{ nextPage =>
           // one more page to visit
          fetchAll(nextPage, page :: collected)
        }
    }
    // Future[Future[List[Page]]] => Future[List[Page]]]
    a.flatMap { x => x }
  }

  private def get(url: String): Future[WSResponse] = {
    logger.info(s"GET $url")
    ws.url(url).withHeaders("Authorization" -> s"Bearer $token").get()
  }

}<file_sep>/puppet/modules/profile/manifests/app/database.pp
class profile::app::database {
  tag 'app:banking-app'
  class { '::mysql::server':
    root_password    => '<PASSWORD>',
    override_options => {
      'mysqld'       => { 'bind-address' => '0.0.0.0' }
    },
  }
  include ::mysql::server::account_security
  mysql_database { 'appdb':
    ensure  => present,
    charset => 'utf8',
  }
  mysql_user { 'app_user@localhost':
    ensure => present,
  }
  mysql_grant { 'app_user@localhost/appdb.*':
    ensure     => present,
    options    => ['GRANT'],
    privileges => ['ALL'],
    table      => 'appdb.*',
    user       => 'app_user@localhost',
  }
  itlm::provides { 'app::database':
    source  => [ 'all-consumers' ],
    ports   => [ '3306/tcp' ],
  }
}
<file_sep>/README.md
# Puppet Integration

Proof of Concept of Puppet integration with Intelliment Security Policy Automation. This integration shows how to define network visibility requirements as code using Puppet, near the definition for each application component.

![Puppet integration](images/integration.png)

### Who can use this integration?

*DevOps* that:

+ Do an advanced configuration management with Puppet
+ Use of applications component profiles and roles
+ Want to automate all aspects of IT management

*Benefits*:

+ Define network visibility requirements with each component of your applications
+ Provision - decomission automatically with each application or component change
+ No need for manual operation to get network visibility
+ Graphical visualization of network visibility changes

## Introduction

This repository contains the following components:

* Puppet module: itlm puppet module found [here](https://github.com/intelliment/puppet-integration/tree/master/puppet/modules/itlm/manifests)
* A web application written in Scala + Play + Angular : A single application that check resources in the PuppetDB and matches with a scenario in order to create requirements according to the _provides_ and _consumes_ stereotypes. This UI also shows inconsistences in case of new requirements violates existing requirements in the scenario.

## How it works

The application built in Scala checks the Puppet nodes reports on PuppetDB to detect changes on visibility requirements. Requirements can be checked against:

+ _Intelliment validators_: to detect issues with the model.
+ _Meta-policies_: pre-defined allows/denies based on standard or custom policies.

Exceptions can start an approval workflow (external sources).

Deployment can be done directly from Intelliment Deployer or delegate to another platform.

![Solution overview](images/solution.png)

## How to run

TBD

## Demo

Following you can see a short video with a demo showing how to define network visibilities using roles and profiles in Puppet and deploying them in a heterogeneous network infrastructure.

[![Intelliment and Puppet integration](https://img.youtube.com/vi/YR4ikbydS9U/0.jpg)](https://youtu.be/YR4ikbydS9U)

If you want more info, please contact us at <EMAIL>
<file_sep>/public/javascripts/app.js
// Define the `puppetModuleApp` module
var puppetModuleApp = angular.module('puppetModuleApp', []);

// Define the `RequirementController` controller
puppetModuleApp.controller('RequirementController', function ($scope, $http) {

  $scope.existingRequirements = [];
  $scope.newRequirements = [];

  $scope.puppetDbUrl = "";
  $scope.message = "";
  $scope.loading = false;
  $scope.applying = false;
  $scope.removing = false;
  $scope.existingAll = false;
  $scope.newAll = false;

  $scope.scenarios = [];
  $scope.scenario = "";

  // Initializes the structures
  $scope.init = function () {
	  $http({
          method: 'GET',
          url: '/puppet-url'
      }).success(function(data){
    	  $scope.puppetDbUrl = data;
      }).error(function(){
          alert("Error getting scenarios");
      });
	  $http({
          method: 'GET',
          url: '/scenarios'
      }).success(function(data){
    	  $scope.scenarios = data;
      }).error(function(){
          alert("Error getting scenarios");
      });
  }

  $scope.init();

  // Services
  $scope.isSelectAllExisting = function() {
	  angular.forEach($scope.existingRequirements, function (item) {
	    item.selected = $scope.existingAll;
	  });
	}

  $scope.isSelectAllNew = function() {
	  angular.forEach($scope.newRequirements, function (item) {
	    item.selected = $scope.newAll;
	  });
	}

  $scope.getRequirements = function() {

	  if($scope.scenario === "") {
		  alert("Choose a scenario!!")
		  return;
	  }

	  $scope.loading = true;
	  $http({
          method: 'GET',
          url: '/requirements?id=' + $scope.scenario.id + '&url=' + $scope.puppetDbUrl
      }).success(function(data){
    	  $scope.existingRequirements = data.existingRequirements;
    	  $scope.newRequirements = data.newRequirements;
      }).error(function(){
    	  alert("Error getting requirements");
      }).finally(function(){
    	  $scope.loading = false;
      });
  }

  $scope.applyRequirements = function() {

	  if($scope.scenario === "") {
		  alert("Choose a scenario!!")
		  return;
	  }

	  $scope.applying = true;

	  var reqs = $scope.newRequirements.filter(function (el) { return el.selected });

	  $http({
          method: 'POST',
          url: '/apply?id=' + $scope.scenario.id + '&url=' + $scope.puppetDbUrl,
          data: reqs
      }).success(function(data){
    	  $scope.existingRequirements = data.existingRequirements;
    	  $scope.newRequirements = data.newRequirements;
      }).error(function(){
    	  alert("Error applying requirements");
      }).finally(function(){
    	  $scope.applying = false;
      });
  }

  $scope.removeRequirements = function() {

	  if($scope.scenario === "") {
		  alert("Choose a scenario!!")
		  return;
	  }

	  $scope.removing = true;

	  var reqs = $scope.existingRequirements.filter(function (el) { return el.selected });
	  var ids = reqs.map(function (el) { return el.id });

	  $http({
          method: 'POST',
          url: '/remove?id=' + $scope.scenario.id + '&url=' + $scope.puppetDbUrl,
          data: ids
      }).success(function(data){
    	  $scope.existingRequirements = data.existingRequirements;
    	  $scope.newRequirements = data.newRequirements;
      }).error(function(){
    	  alert("Error removing requirements");
      }).finally(function(){
    	  $scope.removing = false;
      });
  }

});

// Filters
puppetModuleApp.filter('printServices', function () {
	// print the services in a pretty format
	function prettyPrint(json) {
		var services = "any";
		if (json && json.length > 0) {
			services = $.map(json, function(v){
				return v.name + " -> " + v.ports;
			}).join(', ');
		}

		return services;
    }

	return prettyPrint;
});

puppetModuleApp.filter('printApplications', function () {

	function prettyPrint(json) {
		var apps = "";

		if (json && json.length > 0) {
			apps = $.map(json, function(v){
				return v;
			}).join(', ');
		}

		return apps;
    }

	return prettyPrint;
});

puppetModuleApp.filter('actionClass', function () {

	function prettyPrint(action) {
		var clazz = "text-success";
		if (action === "deny") {
			clazz = "text-danger"
		}

		return clazz;
    }

	return prettyPrint;
});
<file_sep>/puppet/modules/profile/manifests/server/dnsserver.pp
class profile::server::dnsserver {
  tag 'app:dns'
  include ::dns

  itlm::provides { 'dns::resolv':
    source  => [ 'all-consumers' ],
    ports   => [ '53/udp' ],
  }
}
<file_sep>/puppet/modules/profile/manifests/app/webserver.pp
class profile::app::webserver {
  tag 'app:banking-app'
  class {'apache':
    default_mods  => false,
    mpm_module    => 'prefork',
    default_vhost => true,
  }
  itlm::consumes { 'app::database':
    destination  => [ 'profile::app::database' ],
    service      => [ 'app::database' ],
  }
  itlm::provides { 'app::web':
    source => [ 'HQ_DMZ' , 'Users' ],
    ports  => [ '80/tcp' ],
    # ports  => [ '443/tcp' ],
  }
}

languages: Markdown Puppet JavaScript Scala

repo_name: imonteroperez/puppet-integration


text:
<file_sep># 章回目录
----

* [【第001回】 甄士隐梦幻识通灵　贾雨村风尘怀闺秀](ch_cgb/001.md)
* [【第002回】 贾夫人仙逝扬州城　冷子兴演说荣国府](ch_cgb/002.md)
* [【第003回】 贾雨村夤缘复旧职　林黛玉抛父进京都](ch_cgb/003.md)
* [【第004回】 薄命女偏逢薄命郎　葫芦僧乱判葫芦案](ch_cgb/004.md)
* [【第005回】 贾宝玉神游太虚境　警幻仙曲演红楼梦](ch_cgb/005.md)
* [【第006回】 贾宝玉初试云雨情　刘姥姥一进荣国府](ch_cgb/006.md)
* [【第007回】 送宫花贾琏戏熙凤　宴宁府宝玉会秦钟](ch_cgb/007.md)
* [【第008回】 贾宝玉奇缘识金锁　薛宝钗巧合认通灵](ch_cgb/008.md)
* [【第009回】 恋风流情友入家塾　起嫌疑顽童闹学堂](ch_cgb/009.md)
* [【第010回】 金寡妇贪利权受辱　张太医论病细穷源](ch_cgb/010.md)
* [【第011回】 庆寿辰宁府排家宴　见熙凤贾瑞起淫心](ch_cgb/011.md)
* [【第012回】 王熙凤毒设相思局　贾天祥正照风月鉴](ch_cgb/012.md)
* [【第013回】 秦可卿死封龙禁尉　王熙凤协理宁国府](ch_cgb/013.md)
* [【第014回】 林如海捐馆扬州城　贾宝玉路谒北静王](ch_cgb/014.md)
* [【第015回】 王凤姐弄权铁槛寺　秦鲸卿得趣馒头庵](ch_cgb/015.md)
* [【第016回】 贾元春才选凤藻宫　秦鲸卿夭逝黄泉路](ch_cgb/016.md)
* [【第017回】 大观园试才题对额　荣国府归省庆元宵](ch_cgb/017.md)
* [【第018回】 隔珠帘父女勉忠勤　搦湘管姊弟裁题咏](ch_cgb/018.md)
* [【第019回】 情切切良宵花解语　意绵绵静日玉生香](ch_cgb/019.md)
* [【第020回】 王熙凤正言弹妒意　林黛玉俏语谑娇音](ch_cgb/020.md)
* [【第021回】 贤袭人娇嗔箴宝玉　俏平儿软语救贾琏](ch_cgb/021.md)
* [【第022回】 听曲文宝玉悟禅机　制灯迷贾政悲谶语](ch_cgb/022.md)
* [【第023回】 西厢记妙词通戏语　牡丹亭艳曲警芳心](ch_cgb/023.md)
* [【第024回】 醉金刚轻财尚义侠　痴女儿遗帕惹相思](ch_cgb/024.md)
* [【第025回】 魇魔法姊弟逢五鬼　红楼梦通灵遇双真](ch_cgb/025.md)
* [【第026回】 蜂腰桥设言传心事　潇湘馆春困发幽情](ch_cgb/026.md)
* [【第027回】 滴翠亭杨妃戏彩蝶　埋香冢飞燕泣残红](ch_cgb/027.md)
* [【第028回】 蒋玉菡情赠茜香罗　薛宝钗羞笼红麝串](ch_cgb/028.md)
* [【第029回】 享福人福深还祷福　痴情女情重愈斟情](ch_cgb/029.md)
* [【第030回】 宝钗借扇机带双敲　龄官划蔷痴及局外](ch_cgb/030.md)
* [【第031回】 撕扇子作千金一笑　因麒麟伏白首双星](ch_cgb/031.md)
* [【第032回】 诉肺腑心迷活宝玉　含耻辱情烈死金钏](ch_cgb/032.md)
* [【第033回】 手足耽耽小动唇舌　不肖种种大承笞挞](ch_cgb/033.md)
* [【第034回】 情中情因情感妹妹　错里错以错劝哥哥](ch_cgb/034.md)
* [【第035回】 白玉钏亲尝莲叶羹　黄金莺巧结梅花络](ch_cgb/035.md)
* [【第036回】 绣鸳鸯梦兆绛芸轩　识分定情悟梨香院](ch_cgb/036.md)
* [【第037回】 秋爽斋偶结海棠社　蘅芜苑夜拟菊花题](ch_cgb/037.md)
* [【第038回】 林潇湘魁夺菊花诗　薛蘅芜讽和螃蟹咏](ch_cgb/038.md)
* [【第039回】 村姥姥是信口开合　情哥哥偏寻根究底](ch_cgb/039.md)
* [【第040回】 史太君两宴大观园　金鸳鸯三宣牙牌令](ch_cgb/040.md)
* [【第041回】 栊翠庵茶品梅花雪　怡红院劫遇母蝗虫](ch_cgb/041.md)
* [【第042回】 蘅芜君兰言解疑癖　潇湘子雅谑补余香](ch_cgb/042.md)
* [【第043回】 闲取乐偶攒金庆寿　不了情暂撮土为香](ch_cgb/043.md)
* [【第044回】 变生不测凤姐泼醋　喜出望外平儿理妆](ch_cgb/044.md)
* [【第045回】 金兰契互剖金兰语　风雨夕闷制风雨词](ch_cgb/045.md)
* [【第046回】 尴尬人难免尴尬事　鸳鸯女誓绝鸳鸯偶](ch_cgb/046.md)
* [【第047回】 呆霸王调情遭苦打　冷郎君惧祸走他乡](ch_cgb/047.md)
* [【第048回】 滥情人情误思游艺　慕雅女雅集苦吟诗](ch_cgb/048.md)
* [【第049回】 琉璃世界白雪红梅　脂粉香娃割腥啖膻](ch_cgb/049.md)
* [【第050回】 芦雪庵争联即景诗　暖香坞雅制春灯谜](ch_cgb/050.md)
* [【第051回】 薛小妹新编怀古诗　胡庸医乱用虎狼药](ch_cgb/051.md)
* [【第052回】 俏平儿情掩虾须镯　勇晴雯病补雀金裘](ch_cgb/052.md)
* [【第053回】 宁国府除夕祭宗祠　荣国府元宵开夜宴](ch_cgb/053.md)
* [【第054回】 史太君破陈腐旧套　王熙凤效戏彩斑衣](ch_cgb/054.md)
* [【第055回】 辱亲女愚妾争闲气　欺幼主刁奴蓄险心](ch_cgb/055.md)
* [【第056回】 敏探春兴利除宿弊　时宝钗小惠全大体](ch_cgb/056.md)
* [【第057回】 慧紫鹃情辞试忙玉　慈姨妈爱语慰痴颦](ch_cgb/057.md)
* [【第058回】 杏子阴假凤泣虚凰　茜纱窗真情揆痴理](ch_cgb/058.md)
* [【第059回】 柳叶渚边嗔莺咤燕　绛云轩里召将飞符](ch_cgb/059.md)
* [【第060回】 茉莉粉替去蔷薇硝　玫瑰露引来茯苓霜](ch_cgb/060.md)
* [【第061回】 投鼠忌器宝玉瞒赃　判冤决狱平儿行权](ch_cgb/061.md)
* [【第062回】 憨湘云醉眠芍药茵　呆香菱情解石榴裙](ch_cgb/062.md)
* [【第063回】 寿怡红群芳开夜宴　死金丹独艳理亲丧](ch_cgb/063.md)
* [【第064回】 幽淑女悲题五美吟　浪荡子情遗九龙佩](ch_cgb/064.md)
* [【第065回】 贾二舍偷娶尤二姨　尤三姐思嫁柳二郎](ch_cgb/065.md)
* [【第066回】 情小妹耻情归地府　冷二郎一冷入空门](ch_cgb/066.md)
* [【第067回】 见土仪颦卿思故里　闻秘事凤姐讯家童](ch_cgb/067.md)
* [【第068回】 苦尤娘赚入大观园　酸凤姐大闹宁国府](ch_cgb/068.md)
* [【第069回】 弄小巧用借剑杀人　觉大限吞生金自逝](ch_cgb/069.md)
* [【第070回】 林黛玉重建桃花社　史湘云偶填柳絮词](ch_cgb/070.md)
* [【第071回】 嫌隙人有心生嫌隙　鸳鸯女无意遇鸳鸯](ch_cgb/071.md)
* [【第072回】 王熙凤恃强羞说病　来旺妇倚势霸成亲](ch_cgb/072.md)
* [【第073回】 痴丫头误拾绣春囊　懦小姐不问累金凤](ch_cgb/073.md)
* [【第074回】 惑奸谗抄检大观园　矢孤介杜绝宁国府](ch_cgb/074.md)
* [【第075回】 开夜宴异兆发悲音　赏中秋新词得佳谶](ch_cgb/075.md)
* [【第076回】 凸碧堂品笛感凄清　凹晶馆联诗悲寂寞](ch_cgb/076.md)
* [【第077回】 俏丫鬟抱屈夭风流　美优伶斩情归水月](ch_cgb/077.md)
* [【第078回】 老学士闲征诡画词　痴公子杜撰芙蓉诔](ch_cgb/078.md)
* [【第079回】 薛文龙悔娶河东狮　贾迎春误嫁中山狼](ch_cgb/079.md)
* [【第080回】 美香菱屈受贪夫棒　王道士胡诌妒妇方](ch_cgb/080.md)
* [【第081回】 占旺相四美钓游鱼　奉严词两番入家塾](ch_cgb/081.md)
* [【第082回】 老学究讲义警顽心　病潇湘痴魂惊恶梦](ch_cgb/082.md)
* [【第083回】 省宫闱贾元妃染恙　闹闺阃薛宝钗吞声](ch_cgb/083.md)
* [【第084回】 试文字宝玉始提亲　探惊风贾环重结怨](ch_cgb/084.md)
* [【第085回】 贾存周报升郎中任　薛文起复惹放流刑](ch_cgb/085.md)
* [【第086回】 受私贿老官翻案牍　寄闲情淑女解琴书](ch_cgb/086.md)
* [【第087回】 感深秋抚琴悲往事　坐禅寂走火入邪魔](ch_cgb/087.md)
* [【第088回】 博庭欢宝玉赞孤儿　正家法贾珍鞭悍仆](ch_cgb/088.md)
* [【第089回】 人亡物在公子填词　蛇影杯弓颦卿绝粒](ch_cgb/089.md)
* [【第090回】 失绵衣贫女耐嗷嘈　送果品小郎惊叵测](ch_cgb/090.md)
* [【第091回】 纵淫心宝蟾工设计　布疑阵宝玉妄谈禅](ch_cgb/091.md)
* [【第092回】 评女传巧姐慕贤良　玩母珠贾政参聚散](ch_cgb/092.md)
* [【第093回】 甄家仆投靠贾家门　水月庵掀翻风月案](ch_cgb/093.md)
* [【第094回】 宴海棠贾母赏花妖　失宝玉通灵知奇祸](ch_cgb/094.md)
* [【第095回】 因讹成实元妃薨逝　以假混真宝玉疯颠](ch_cgb/095.md)
* [【第096回】 瞒消息凤姐设奇谋　泄机关颦儿迷本性](ch_cgb/096.md)
* [【第097回】 林黛玉焚稿断痴情　薛宝钗出闺成大礼](ch_cgb/097.md)
* [【第098回】 苦绛珠魂归离恨天　病神瑛泪洒相思地](ch_cgb/098.md)
* [【第099回】 守官箴恶奴同破例　阅邸报老舅自担惊](ch_cgb/099.md)
* [【第100回】 破好事香菱结深恨　悲远嫁宝玉感离情](ch_cgb/100.md)
* [【第101回】 大观园月夜感幽魂　散花寺神签惊异兆](ch_cgb/101.md)
* [【第102回】 宁国府骨肉病灾襟　大观园符水驱妖孽](ch_cgb/102.md)
* [【第103回】 施毒计金桂自焚身　昧真禅雨村空遇旧](ch_cgb/103.md)
* [【第104回】 醉金刚小鳅生大浪　痴公子余痛触前情](ch_cgb/104.md)
* [【第105回】 锦衣军查抄宁国府　骢马使弹劾平安州](ch_cgb/105.md)
* [【第106回】 王熙凤致祸抱羞惭　贾太君祷天消祸患](ch_cgb/106.md)
* [【第107回】 散余资贾母明大义　复世职政老沐天恩](ch_cgb/107.md)
* [【第108回】 强欢笑蘅芜庆生辰　死缠绵潇湘闻鬼哭](ch_cgb/108.md)
* [【第109回】 候芳魂五儿承错爱　还孽债迎女返真元](ch_cgb/109.md)
* [【第110回】 史太君寿终归地府　王凤姐力诎失人心](ch_cgb/110.md)
* [【第111回】 鸳鸯女殉主登太虚　狗彘奴欺天招伙盗](ch_cgb/111.md)
* [【第112回】 活冤孽妙尼遭大劫　死雠仇赵妾赴冥曹](ch_cgb/112.md)
* [【第113回】 忏宿冤凤姐托村妪　释旧憾情婢感痴郎](ch_cgb/113.md)
* [【第114回】 王熙凤历幻返金陵　甄应嘉蒙恩还玉阙](ch_cgb/114.md)
* [【第115回】 惑偏私惜春矢素志　证同类宝玉失相知](ch_cgb/115.md)
* [【第116回】 得通灵幻境悟仙缘　送慈柩故乡全孝道](ch_cgb/116.md)
* [【第117回】 阻超凡佳人双护玉　欣聚党恶子独承家](ch_cgb/117.md)
* [【第118回】 记微嫌舅兄欺弱女　惊谜语妻妾谏痴人](ch_cgb/118.md)
* [【第119回】 中乡魁宝玉却尘缘　沐皇恩贾家延世泽](ch_cgb/119.md)
* [【第120回】 甄士隐详说太虚情　贾雨村归结红楼梦](ch_cgb/120.md)

<file_sep># 章回目录
----

* [【第01回】甄士隐梦幻识通灵 贾雨村风尘怀闺秀](ch/001.md)
* [【第02回】贾夫人仙逝扬州城 冷子兴演说荣国府](ch/002.md)
* [【第03回】金陵城起复贾雨村 荣国府收养林黛玉](ch/003.md)
* [【第04回】薄命女偏逢薄命郎 葫芦僧乱判葫芦案](ch/004.md)
* [【第05回】游幻境指迷十二钗 饮仙醪曲演红楼梦](ch/005.md)
* [【第06回】贾宝玉初试云雨情 刘姥姥一进荣国府](ch/006.md)
* [【第07回】送宫花周瑞叹英莲 谈肄业秦钟结宝玉](ch/007.md)
* [【第08回】比通灵金莺微露意 探宝钗黛玉半含酸](ch/008.md)
* [【第09回】恋风流情友入家塾 起嫌疑顽童闹学堂](ch/009.md)
* [【第10回】金寡妇贪利权受辱 张太医论病细穷源](ch/010.md)
* [【第11回】庆寿辰宁府排家宴 见熙凤贾瑞起淫心](ch/011.md)
* [【第12回】王熙凤毒设相思局 贾天祥正照风月鉴](ch/012.md)
* [【第13回】秦可卿死封龙禁尉 王熙凤协理宁国府](ch/013.md)
* [【第14回】林如海捐馆扬州城 贾宝玉路谒北静王](ch/014.md)
* [【第15回】王熙凤弄权铁槛寺 秦鲸卿得趣馒头庵](ch/015.md)
* [【第16回】贾元春才选凤藻宫 秦鲸卿夭逝黄泉路](ch/016.md)
* [【第17回】大观园试才题对额 荣国府归省庆元宵](ch/017.md)
* [【第18回】皇恩重元妃省父母 天伦乐宝玉呈才藻](ch/018.md)
* [【第19回】情切切良宵花解语 意绵绵静日玉生香](ch/019.md)
* [【第20回】王熙凤正言弹妒意 林黛玉悄语谑娇音](ch/020.md)
* [【第21回】贤袭人娇嗔箴宝玉 俏平儿软语救贾琏](ch/021.md)
* [【第22回】听曲文宝玉悟禅机 制灯谜贾政悲谶语](ch/022.md)
* [【第23回】西厢记妙词通戏语 牡丹亭艳曲警芳心](ch/023.md)
* [【第24回】醉金刚轻财尚义侠 痴女儿遗帕惹相思](ch/024.md)
* [【第25回】魇魔法叔嫂逢五鬼 通灵玉蒙蔽遇双真](ch/025.md)
* [【第26回】蜂腰桥设言传蜜意 潇湘馆春困发幽情](ch/026.md)
* [【第27回】滴翠亭杨妃戏彩蝶 埋香冢飞燕泣残红](ch/027.md)
* [【第28回】蒋玉菡情赠茜香罗 薛宝钗羞笼红麝串](ch/028.md)
* [【第29回】享福人福深还祷福 痴情女情重愈斟情](ch/029.md)
* [【第30回】宝钗借扇机带双敲 龄官划蔷痴及局外](ch/030.md)
* [【第31回】撕扇子作千金一笑 因麒麟伏白首双星](ch/031.md)
* [【第32回】诉肺腑心迷活宝玉 含耻辱情烈死金钏](ch/032.md)
* [【第33回】手足耽耽小动唇舌 不肖种种大承笞挞](ch/033.md)
* [【第34回】情中情因情感妹妹 错里错以错劝哥哥](ch/034.md)
* [【第35回】白玉钏亲尝莲叶羹 黄金莺巧结梅花络](ch/035.md)
* [【第36回】绣鸳鸯梦兆绛芸轩 识分定情语梨香院](ch/036.md)
* [【第37回】秋爽斋偶结海棠社 蘅芜苑夜拟菊花题](ch/037.md)
* [【第38回】林潇湘魁夺菊花诗 薛蘅芜讽和螃蟹咏](ch/038.md)
* [【第39回】村姥姥是信口开河 情哥哥偏寻根究底](ch/039.md)
* [【第40回】史太君两宴大观园 金鸳鸯三宣牙牌令](ch/040.md)
* [【第41回】栊翠庵茶品梅花雪 怡红院劫遇母蝗虫](ch/041.md)
* [【第42回】蘅芜君兰言解疑癖 潇湘子雅谑补余香](ch/042.md)
* [【第43回】闲取乐偶攒金庆寿 不了情暂撮土为香](ch/043.md)
* [【第44回】变生不测凤姐泼醋 喜出望外平儿理妆](ch/044.md)
* [【第45回】金兰契互剖金兰语 风雨夕闷制风雨词](ch/045.md)
* [【第46回】尴尬人难免尴尬事 鸳鸯女誓绝鸳鸯偶](ch/046.md)
* [【第47回】呆霸王调情遭苦打 冷郎君惧祸走他乡](ch/047.md)
* [【第48回】滥情人情误思游艺 慕雅女雅集苦吟诗](ch/048.md)
* [【第49回】琉璃世界白雪红梅 脂粉香娃割腥啖膻](ch/049.md)
* [【第50回】芦雪庵争联即景诗 暖香坞雅制春灯谜](ch/050.md)
* [【第51回】薛小妹新编怀古诗 胡庸医乱用虎狼药](ch/051.md)
* [【第52回】俏平儿情掩虾须镯 勇晴雯病补雀金裘](ch/052.md)
* [【第53回】宁国府除夕祭宗祠 荣国府元宵开夜宴](ch/053.md)
* [【第54回】史太君破陈腐旧套 王熙凤效戏彩斑衣](ch/054.md)
* [【第55回】辱亲女愚妾争闲气 欺幼主刁奴蓄险心](ch/055.md)
* [【第56回】敏探春兴利除宿弊 识宝钗小惠全大体](ch/056.md)
* [【第57回】慧紫鹃情辞试莽玉 慈姨妈爱语慰痴颦](ch/057.md)
* [【第58回】杏子阴假凤泣虚凰 茜纱窗真情揆痴理](ch/058.md)
* [【第59回】柳叶渚边嗔莺咤燕 绛芸轩里召将飞符](ch/059.md)
* [【第60回】茉莉粉替去蔷薇硝 玫瑰露引出茯苓霜](ch/060.md)
* [【第61回】投鼠忌器宝玉瞒赃 判冤决狱平儿行权](ch/061.md)
* [【第62回】憨湘云醉眠芍药裀 呆香菱情解石榴裙](ch/062.md)
* [【第63回】寿怡红群芳开夜宴 死金丹独艳理亲丧](ch/063.md)
* [【第64回】幽淑女悲题五美吟 浪荡子情遗九龙珮](ch/064.md)
* [【第65回】贾二舍偷娶尤二姨 尤三姐思嫁柳二郎](ch/065.md)
* [【第66回】情小妹耻情归地冷 冷二郎一冷入空门](ch/066.md)
* [【第67回】见土仪颦卿思故里 闻秘事凤姐讯家童](ch/067.md)
* [【第68回】苦尤娘赚入大观园 酸凤姐大闹宁国府](ch/068.md)
* [【第69回】弄小巧用借剑杀人 觉大限吞生金自逝](ch/069.md)
* [【第70回】林黛玉重建桃花社 史湘云偶填柳絮词](ch/070.md)
* [【第71回】嫌隙人有心生嫌隙 鸳鸯女无意遇鸳鸯](ch/071.md)
* [【第72回】王熙凤恃强羞说病 来旺妇倚势霸成亲](ch/072.md)
* [【第73回】痴丫头误拾绣春囊 懦小姐不问累金凤](ch/073.md)
* [【第74回】惑奸谗抄检大观园 矢孤介杜绝宁国府](ch/074.md)
* [【第75回】开夜宴异兆发悲音 赏中秋新词得佳谶](ch/075.md)
* [【第76回】凸碧堂品笛感凄清 凹晶馆联诗悲寂寞](ch/076.md)
* [【第77回】俏丫环抱屈夭风流 美优伶斩情归水月](ch/077.md)
* [【第78回】老学士闲征姽嫿词 痴公子杜撰芙蓉诔](ch/078.md)
* [【第79回】薛文龙悔娶河东狮 贾迎春误嫁中山狼](ch/079.md)
* [【第80回】美香菱屈受贪夫棒 王道士胡诌妒妇方](ch/080.md)

<file_sep># 前言
----

本站免费提供两种版本的红楼梦在线阅读,分别是脂评本和程高本。
脂评本的校对参考为岳麓书社出版的《脂砚斋批评本红楼梦》, 程高本则参考人民文学出版社较为普及的《红楼梦》。
其中,脂评本正在编辑中,程高本已经初步编辑完毕。

由于相关工作人员的时间有限, 因此在初期使用了一些编程技术手段对文本进行处理, 细节上会不如人工校对的精致, 我们会在后期逐渐采用人工全面审核。
书中如有纰漏之处, 欢迎读者反馈, 我们会第一时间进行修改。
欢迎各位红迷加入我们, 一起维护和完善这个红楼梦在线阅读网站, 为红楼梦的普及贡献一份力量!

### 贡献者列表
- Eacon（站长）
    - 微信：tyingk
    - 邮箱: <EMAIL>
    - 博客：blog.tangyingkang.com
- 白朮
    - QQ: 251259647
- 小武
    - QQ: 121110874

    <file_sep># Summary

* [前言](README.md)
* [脂评本](zpb.md)
    * [戚蓼生序](prologue.md)
    * [甲戌本凡例](notes.md)
    * [章回目录](catalogue.md)
    * [【第01回】甄士隐梦幻识通灵 贾雨村风尘怀闺秀](ch/001.md)
    * [【第02回】贾夫人仙逝扬州城 冷子兴演说荣国府](ch/002.md)
    * [【第03回】金陵城起复贾雨村 荣国府收养林黛玉](ch/003.md)
    * [【第04回】薄命女偏逢薄命郎 葫芦僧乱判葫芦案](ch/004.md)
    * [【第05回】游幻境指迷十二钗 饮仙醪曲演红楼梦](ch/005.md)
    * [【第06回】贾宝玉初试云雨情 刘姥姥一进荣国府](ch/006.md)
    * [【第07回】送宫花周瑞叹英莲 谈肄业秦钟结宝玉](ch/007.md)
    * [【第08回】比通灵金莺微露意 探宝钗黛玉半含酸](ch/008.md)
    * [【第09回】恋风流情友入家塾 起嫌疑顽童闹学堂](ch/009.md)
    * [【第10回】金寡妇贪利权受辱 张太医论病细穷源](ch/010.md)
    * [【第11回】庆寿辰宁府排家宴 见熙凤贾瑞起淫心](ch/011.md)
    * [【第12回】王熙凤毒设相思局 贾天祥正照风月鉴](ch/012.md)
    * [【第13回】秦可卿死封龙禁尉 王熙凤协理宁国府](ch/013.md)
    * [【第14回】林如海捐馆扬州城 贾宝玉路谒北静王](ch/014.md)
    * [【第15回】王熙凤弄权铁槛寺 秦鲸卿得趣馒头庵](ch/015.md)
    * [【第16回】贾元春才选凤藻宫 秦鲸卿夭逝黄泉路](ch/016.md)
    * [【第17回】大观园试才题对额 荣国府归省庆元宵](ch/017.md)
    * [【第18回】皇恩重元妃省父母 天伦乐宝玉呈才藻](ch/018.md)
    * [【第19回】情切切良宵花解语 意绵绵静日玉生香](ch/019.md)
    * [【第20回】王熙凤正言弹妒意 林黛玉悄语谑娇音](ch/020.md)
    * [【第21回】贤袭人娇嗔箴宝玉 俏平儿软语救贾琏](ch/021.md)
    * [【第22回】听曲文宝玉悟禅机 制灯谜贾政悲谶语](ch/022.md)
    * [【第23回】西厢记妙词通戏语 牡丹亭艳曲警芳心](ch/023.md)
    * [【第24回】醉金刚轻财尚义侠 痴女儿遗帕惹相思](ch/024.md)
    * [【第25回】魇魔法叔嫂逢五鬼 通灵玉蒙蔽遇双真](ch/025.md)
    * [【第26回】蜂腰桥设言传蜜意 潇湘馆春困发幽情](ch/026.md)
    * [【第27回】滴翠亭杨妃戏彩蝶 埋香冢飞燕泣残红](ch/027.md)
    * [【第28回】蒋玉菡情赠茜香罗 薛宝钗羞笼红麝串](ch/028.md)
    * [【第29回】享福人福深还祷福 痴情女情重愈斟情](ch/029.md)
    * [【第30回】宝钗借扇机带双敲 龄官划蔷痴及局外](ch/030.md)
    * [【第31回】撕扇子作千金一笑 因麒麟伏白首双星](ch/031.md)
    * [【第32回】诉肺腑心迷活宝玉 含耻辱情烈死金钏](ch/032.md)
    * [【第33回】手足耽耽小动唇舌 不肖种种大承笞挞](ch/033.md)
    * [【第34回】情中情因情感妹妹 错里错以错劝哥哥](ch/034.md)
    * [【第35回】白玉钏亲尝莲叶羹 黄金莺巧结梅花络](ch/035.md)
    * [【第36回】绣鸳鸯梦兆绛芸轩 识分定情语梨香院](ch/036.md)
    * [【第37回】秋爽斋偶结海棠社 蘅芜苑夜拟菊花题](ch/037.md)
    * [【第38回】林潇湘魁夺菊花诗 薛蘅芜讽和螃蟹咏](ch/038.md)
    * [【第39回】村姥姥是信口开河 情哥哥偏寻根究底](ch/039.md)
    * [【第40回】史太君两宴大观园 金鸳鸯三宣牙牌令](ch/040.md)
    * [【第41回】栊翠庵茶品梅花雪 怡红院劫遇母蝗虫](ch/041.md)
    * [【第42回】蘅芜君兰言解疑癖 潇湘子雅谑补余香](ch/042.md)
    * [【第43回】闲取乐偶攒金庆寿 不了情暂撮土为香](ch/043.md)
    * [【第44回】变生不测凤姐泼醋 喜出望外平儿理妆](ch/044.md)
    * [【第45回】金兰契互剖金兰语 风雨夕闷制风雨词](ch/045.md)
    * [【第46回】尴尬人难免尴尬事 鸳鸯女誓绝鸳鸯偶](ch/046.md)
    * [【第47回】呆霸王调情遭苦打 冷郎君惧祸走他乡](ch/047.md)
    * [【第48回】滥情人情误思游艺 慕雅女雅集苦吟诗](ch/048.md)
    * [【第49回】琉璃世界白雪红梅 脂粉香娃割腥啖膻](ch/049.md)
    * [【第50回】芦雪庵争联即景诗 暖香坞雅制春灯谜](ch/050.md)
    * [【第51回】薛小妹新编怀古诗 胡庸医乱用虎狼药](ch/051.md)
    * [【第52回】俏平儿情掩虾须镯 勇晴雯病补雀金裘](ch/052.md)
    * [【第53回】宁国府除夕祭宗祠 荣国府元宵开夜宴](ch/053.md)
    * [【第54回】史太君破陈腐旧套 王熙凤效戏彩斑衣](ch/054.md)
    * [【第55回】辱亲女愚妾争闲气 欺幼主刁奴蓄险心](ch/055.md)
    * [【第56回】敏探春兴利除宿弊 识宝钗小惠全大体](ch/056.md)
    * [【第57回】慧紫鹃情辞试莽玉 慈姨妈爱语慰痴颦](ch/057.md)
    * [【第58回】杏子阴假凤泣虚凰 茜纱窗真情揆痴理](ch/058.md)
    * [【第59回】柳叶渚边嗔莺咤燕 绛芸轩里召将飞符](ch/059.md)
    * [【第60回】茉莉粉替去蔷薇硝 玫瑰露引出茯苓霜](ch/060.md)
    * [【第61回】投鼠忌器宝玉瞒赃 判冤决狱平儿行权](ch/061.md)
    * [【第62回】憨湘云醉眠芍药裀 呆香菱情解石榴裙](ch/062.md)
    * [【第63回】寿怡红群芳开夜宴 死金丹独艳理亲丧](ch/063.md)
    * [【第64回】幽淑女悲题五美吟 浪荡子情遗九龙珮](ch/064.md)
    * [【第65回】贾二舍偷娶尤二姨 尤三姐思嫁柳二郎](ch/065.md)
    * [【第66回】情小妹耻情归地冷 冷二郎一冷入空门](ch/066.md)
    * [【第67回】见土仪颦卿思故里 闻秘事凤姐讯家童](ch/067.md)
    * [【第68回】苦尤娘赚入大观园 酸凤姐大闹宁国府](ch/068.md)
    * [【第69回】弄小巧用借剑杀人 觉大限吞生金自逝](ch/069.md)
    * [【第70回】林黛玉重建桃花社 史湘云偶填柳絮词](ch/070.md)
    * [【第71回】嫌隙人有心生嫌隙 鸳鸯女无意遇鸳鸯](ch/071.md)
    * [【第72回】王熙凤恃强羞说病 来旺妇倚势霸成亲](ch/072.md)
    * [【第73回】痴丫头误拾绣春囊 懦小姐不问累金凤](ch/073.md)
    * [【第74回】惑奸谗抄检大观园 矢孤介杜绝宁国府](ch/074.md)
    * [【第75回】开夜宴异兆发悲音 赏中秋新词得佳谶](ch/075.md)
    * [【第76回】凸碧堂品笛感凄清 凹晶馆联诗悲寂寞](ch/076.md)
    * [【第77回】俏丫环抱屈夭风流 美优伶斩情归水月](ch/077.md)
    * [【第78回】老学士闲征姽嫿词 痴公子杜撰芙蓉诔](ch/078.md)
    * [【第79回】薛文龙悔娶河东狮 贾迎春误嫁中山狼](ch/079.md)
    * [【第80回】美香菱屈受贪夫棒 王道士胡诌妒妇方](ch/080.md)
* [程高本](cgb.md)
    * [章回目录](catalogue_cgb.md)
    * [【第001回】 甄士隐梦幻识通灵　贾雨村风尘怀闺秀](ch_cgb/001.md)
    * [【第002回】 贾夫人仙逝扬州城　冷子兴演说荣国府](ch_cgb/002.md)
    * [【第003回】 贾雨村夤缘复旧职　林黛玉抛父进京都](ch_cgb/003.md)
    * [【第004回】 薄命女偏逢薄命郎　葫芦僧乱判葫芦案](ch_cgb/004.md)
    * [【第005回】 贾宝玉神游太虚境　警幻仙曲演红楼梦](ch_cgb/005.md)
    * [【第006回】 贾宝玉初试云雨情　刘姥姥一进荣国府](ch_cgb/006.md)
    * [【第007回】 送宫花贾琏戏熙凤　宴宁府宝玉会秦钟](ch_cgb/007.md)
    * [【第008回】 贾宝玉奇缘识金锁　薛宝钗巧合认通灵](ch_cgb/008.md)
    * [【第009回】 恋风流情友入家塾　起嫌疑顽童闹学堂](ch_cgb/009.md)
    * [【第010回】 金寡妇贪利权受辱　张太医论病细穷源](ch_cgb/010.md)
    * [【第011回】 庆寿辰宁府排家宴　见熙凤贾瑞起淫心](ch_cgb/011.md)
    * [【第012回】 王熙凤毒设相思局　贾天祥正照风月鉴](ch_cgb/012.md)
    * [【第013回】 秦可卿死封龙禁尉　王熙凤协理宁国府](ch_cgb/013.md)
    * [【第014回】 林如海捐馆扬州城　贾宝玉路谒北静王](ch_cgb/014.md)
    * [【第015回】 王凤姐弄权铁槛寺　秦鲸卿得趣馒头庵](ch_cgb/015.md)
    * [【第016回】 贾元春才选凤藻宫　秦鲸卿夭逝黄泉路](ch_cgb/016.md)
    * [【第017回】 大观园试才题对额　荣国府归省庆元宵](ch_cgb/017.md)
    * [【第018回】 隔珠帘父女勉忠勤　搦湘管姊弟裁题咏](ch_cgb/018.md)
    * [【第019回】 情切切良宵花解语　意绵绵静日玉生香](ch_cgb/019.md)
    * [【第020回】 王熙凤正言弹妒意　林黛玉俏语谑娇音](ch_cgb/020.md)
    * [【第021回】 贤袭人娇嗔箴宝玉　俏平儿软语救贾琏](ch_cgb/021.md)
    * [【第022回】 听曲文宝玉悟禅机　制灯迷贾政悲谶语](ch_cgb/022.md)
    * [【第023回】 西厢记妙词通戏语　牡丹亭艳曲警芳心](ch_cgb/023.md)
    * [【第024回】 醉金刚轻财尚义侠　痴女儿遗帕惹相思](ch_cgb/024.md)
    * [【第025回】 魇魔法姊弟逢五鬼　红楼梦通灵遇双真](ch_cgb/025.md)
    * [【第026回】 蜂腰桥设言传心事　潇湘馆春困发幽情](ch_cgb/026.md)
    * [【第027回】 滴翠亭杨妃戏彩蝶　埋香冢飞燕泣残红](ch_cgb/027.md)
    * [【第028回】 蒋玉菡情赠茜香罗　薛宝钗羞笼红麝串](ch_cgb/028.md)
    * [【第029回】 享福人福深还祷福　痴情女情重愈斟情](ch_cgb/029.md)
    * [【第030回】 宝钗借扇机带双敲　龄官划蔷痴及局外](ch_cgb/030.md)
    * [【第031回】 撕扇子作千金一笑　因麒麟伏白首双星](ch_cgb/031.md)
    * [【第032回】 诉肺腑心迷活宝玉　含耻辱情烈死金钏](ch_cgb/032.md)
    * [【第033回】 手足耽耽小动唇舌　不肖种种大承笞挞](ch_cgb/033.md)
    * [【第034回】 情中情因情感妹妹　错里错以错劝哥哥](ch_cgb/034.md)
    * [【第035回】 白玉钏亲尝莲叶羹　黄金莺巧结梅花络](ch_cgb/035.md)
    * [【第036回】 绣鸳鸯梦兆绛芸轩　识分定情悟梨香院](ch_cgb/036.md)
    * [【第037回】 秋爽斋偶结海棠社　蘅芜苑夜拟菊花题](ch_cgb/037.md)
    * [【第038回】 林潇湘魁夺菊花诗　薛蘅芜讽和螃蟹咏](ch_cgb/038.md)
    * [【第039回】 村姥姥是信口开合　情哥哥偏寻根究底](ch_cgb/039.md)
    * [【第040回】 史太君两宴大观园　金鸳鸯三宣牙牌令](ch_cgb/040.md)
    * [【第041回】 栊翠庵茶品梅花雪　怡红院劫遇母蝗虫](ch_cgb/041.md)
    * [【第042回】 蘅芜君兰言解疑癖　潇湘子雅谑补余香](ch_cgb/042.md)
    * [【第043回】 闲取乐偶攒金庆寿　不了情暂撮土为香](ch_cgb/043.md)
    * [【第044回】 变生不测凤姐泼醋　喜出望外平儿理妆](ch_cgb/044.md)
    * [【第045回】 金兰契互剖金兰语　风雨夕闷制风雨词](ch_cgb/045.md)
    * [【第046回】 尴尬人难免尴尬事　鸳鸯女誓绝鸳鸯偶](ch_cgb/046.md)
    * [【第047回】 呆霸王调情遭苦打　冷郎君惧祸走他乡](ch_cgb/047.md)
    * [【第048回】 滥情人情误思游艺　慕雅女雅集苦吟诗](ch_cgb/048.md)
    * [【第049回】 琉璃世界白雪红梅　脂粉香娃割腥啖膻](ch_cgb/049.md)
    * [【第050回】 芦雪庵争联即景诗　暖香坞雅制春灯谜](ch_cgb/050.md)
    * [【第051回】 薛小妹新编怀古诗　胡庸医乱用虎狼药](ch_cgb/051.md)
    * [【第052回】 俏平儿情掩虾须镯　勇晴雯病补雀金裘](ch_cgb/052.md)
    * [【第053回】 宁国府除夕祭宗祠　荣国府元宵开夜宴](ch_cgb/053.md)
    * [【第054回】 史太君破陈腐旧套　王熙凤效戏彩斑衣](ch_cgb/054.md)
    * [【第055回】 辱亲女愚妾争闲气　欺幼主刁奴蓄险心](ch_cgb/055.md)
    * [【第056回】 敏探春兴利除宿弊　时宝钗小惠全大体](ch_cgb/056.md)
    * [【第057回】 慧紫鹃情辞试忙玉　慈姨妈爱语慰痴颦](ch_cgb/057.md)
    * [【第058回】 杏子阴假凤泣虚凰　茜纱窗真情揆痴理](ch_cgb/058.md)
    * [【第059回】 柳叶渚边嗔莺咤燕　绛云轩里召将飞符](ch_cgb/059.md)
    * [【第060回】 茉莉粉替去蔷薇硝　玫瑰露引来茯苓霜](ch_cgb/060.md)
    * [【第061回】 投鼠忌器宝玉瞒赃　判冤决狱平儿行权](ch_cgb/061.md)
    * [【第062回】 憨湘云醉眠芍药茵　呆香菱情解石榴裙](ch_cgb/062.md)
    * [【第063回】 寿怡红群芳开夜宴　死金丹独艳理亲丧](ch_cgb/063.md)
    * [【第064回】 幽淑女悲题五美吟　浪荡子情遗九龙佩](ch_cgb/064.md)
    * [【第065回】 贾二舍偷娶尤二姨　尤三姐思嫁柳二郎](ch_cgb/065.md)
    * [【第066回】 情小妹耻情归地府　冷二郎一冷入空门](ch_cgb/066.md)
    * [【第067回】 见土仪颦卿思故里　闻秘事凤姐讯家童](ch_cgb/067.md)
    * [【第068回】 苦尤娘赚入大观园　酸凤姐大闹宁国府](ch_cgb/068.md)
    * [【第069回】 弄小巧用借剑杀人　觉大限吞生金自逝](ch_cgb/069.md)
    * [【第070回】 林黛玉重建桃花社　史湘云偶填柳絮词](ch_cgb/070.md)
    * [【第071回】 嫌隙人有心生嫌隙　鸳鸯女无意遇鸳鸯](ch_cgb/071.md)
    * [【第072回】 王熙凤恃强羞说病　来旺妇倚势霸成亲](ch_cgb/072.md)
    * [【第073回】 痴丫头误拾绣春囊　懦小姐不问累金凤](ch_cgb/073.md)
    * [【第074回】 惑奸谗抄检大观园　矢孤介杜绝宁国府](ch_cgb/074.md)
    * [【第075回】 开夜宴异兆发悲音　赏中秋新词得佳谶](ch_cgb/075.md)
    * [【第076回】 凸碧堂品笛感凄清　凹晶馆联诗悲寂寞](ch_cgb/076.md)
    * [【第077回】 俏丫鬟抱屈夭风流　美优伶斩情归水月](ch_cgb/077.md)
    * [【第078回】 老学士闲征诡画词　痴公子杜撰芙蓉诔](ch_cgb/078.md)
    * [【第079回】 薛文龙悔娶河东狮　贾迎春误嫁中山狼](ch_cgb/079.md)
    * [【第080回】 美香菱屈受贪夫棒　王道士胡诌妒妇方](ch_cgb/080.md)
    * [【第081回】 占旺相四美钓游鱼　奉严词两番入家塾](ch_cgb/081.md)
    * [【第082回】 老学究讲义警顽心　病潇湘痴魂惊恶梦](ch_cgb/082.md)
    * [【第083回】 省宫闱贾元妃染恙　闹闺阃薛宝钗吞声](ch_cgb/083.md)
    * [【第084回】 试文字宝玉始提亲　探惊风贾环重结怨](ch_cgb/084.md)
    * [【第085回】 贾存周报升郎中任　薛文起复惹放流刑](ch_cgb/085.md)
    * [【第086回】 受私贿老官翻案牍　寄闲情淑女解琴书](ch_cgb/086.md)
    * [【第087回】 感深秋抚琴悲往事　坐禅寂走火入邪魔](ch_cgb/087.md)
    * [【第088回】 博庭欢宝玉赞孤儿　正家法贾珍鞭悍仆](ch_cgb/088.md)
    * [【第089回】 人亡物在公子填词　蛇影杯弓颦卿绝粒](ch_cgb/089.md)
    * [【第090回】 失绵衣贫女耐嗷嘈　送果品小郎惊叵测](ch_cgb/090.md)
    * [【第091回】 纵淫心宝蟾工设计　布疑阵宝玉妄谈禅](ch_cgb/091.md)
    * [【第092回】 评女传巧姐慕贤良　玩母珠贾政参聚散](ch_cgb/092.md)
    * [【第093回】 甄家仆投靠贾家门　水月庵掀翻风月案](ch_cgb/093.md)
    * [【第094回】 宴海棠贾母赏花妖　失宝玉通灵知奇祸](ch_cgb/094.md)
    * [【第095回】 因讹成实元妃薨逝　以假混真宝玉疯颠](ch_cgb/095.md)
    * [【第096回】 瞒消息凤姐设奇谋　泄机关颦儿迷本性](ch_cgb/096.md)
    * [【第097回】 林黛玉焚稿断痴情　薛宝钗出闺成大礼](ch_cgb/097.md)
    * [【第098回】 苦绛珠魂归离恨天　病神瑛泪洒相思地](ch_cgb/098.md)
    * [【第099回】 守官箴恶奴同破例　阅邸报老舅自担惊](ch_cgb/099.md)
    * [【第100回】 破好事香菱结深恨　悲远嫁宝玉感离情](ch_cgb/100.md)
    * [【第101回】 大观园月夜感幽魂　散花寺神签惊异兆](ch_cgb/101.md)
    * [【第102回】 宁国府骨肉病灾襟　大观园符水驱妖孽](ch_cgb/102.md)
    * [【第103回】 施毒计金桂自焚身　昧真禅雨村空遇旧](ch_cgb/103.md)
    * [【第104回】 醉金刚小鳅生大浪　痴公子余痛触前情](ch_cgb/104.md)
    * [【第105回】 锦衣军查抄宁国府　骢马使弹劾平安州](ch_cgb/105.md)
    * [【第106回】 王熙凤致祸抱羞惭　贾太君祷天消祸患](ch_cgb/106.md)
    * [【第107回】 散余资贾母明大义　复世职政老沐天恩](ch_cgb/107.md)
    * [【第108回】 强欢笑蘅芜庆生辰　死缠绵潇湘闻鬼哭](ch_cgb/108.md)
    * [【第109回】 候芳魂五儿承错爱　还孽债迎女返真元](ch_cgb/109.md)
    * [【第110回】 史太君寿终归地府　王凤姐力诎失人心](ch_cgb/110.md)
    * [【第111回】 鸳鸯女殉主登太虚　狗彘奴欺天招伙盗](ch_cgb/111.md)
    * [【第112回】 活冤孽妙尼遭大劫　死雠仇赵妾赴冥曹](ch_cgb/112.md)
    * [【第113回】 忏宿冤凤姐托村妪　释旧憾情婢感痴郎](ch_cgb/113.md)
    * [【第114回】 王熙凤历幻返金陵　甄应嘉蒙恩还玉阙](ch_cgb/114.md)
    * [【第115回】 惑偏私惜春矢素志　证同类宝玉失相知](ch_cgb/115.md)
    * [【第116回】 得通灵幻境悟仙缘　送慈柩故乡全孝道](ch_cgb/116.md)
    * [【第117回】 阻超凡佳人双护玉　欣聚党恶子独承家](ch_cgb/117.md)
    * [【第118回】 记微嫌舅兄欺弱女　惊谜语妻妾谏痴人](ch_cgb/118.md)
    * [【第119回】 中乡魁宝玉却尘缘　沐皇恩贾家延世泽](ch_cgb/119.md)
    * [【第120回】 甄士隐详说太虚情　贾雨村归结红楼梦](ch_cgb/120.md)

repo_name: buobao/HLM-txt


text:
<file_sep>#include <stdio.h>
#define SIZE 10

int main(void)
{
    //initialize a
    int a[SIZE]={2,6,4,8,10,12,89,68,45,37};
    int pass;//pass counter
    size_t i;//comparison counter
    int hold;//temporary location used to swap array elements
    int continue_flag=1;//whether to continue the sorting or not
    puts("Data items in original order");

    for(i=0; i<SIZE; i++){
        printf("%4d", a[i]);
    }

    for(pass=1; pass<SIZE&&continue_flag==1; pass++){
        continue_flag=0;
        for(i=0; i<SIZE-pass; i++){
            if(a[i]>a[i+1]){
                hold=a[i];
                a[i]=a[i+1];
                a[i+1]=hold;
                continue_flag=1;
            }
        }
    }

    puts("\nData items in ascending order");

    for(i=0; i<SIZE; i++){
        printf("%4d", a[i]);
    }
    puts("");
    return 0;
}

repo_language: C