-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscribe.go
75 lines (66 loc) · 1.92 KB
/
subscribe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package wsman
import (
"encoding/xml"
"io"
"strings"
"github.com/runner-mei/wsman/envelope"
)
func Subscribe(ep *Endpoint, ns, name string, selectorSet map[string]string,
deliveryMode string,
endToAddress string,
endToIdentifier string,
recvAddress string,
recvIdentifier string,
queryList map[string][]envelope.QueryFilter,
sendBookmarks bool) (io.Reader, *xml.Decoder, error) {
input := &envelope.Subscribe{
Namespace: ns,
MessageId: Uuid(),
Name: name,
SelectorSet: selectorSet,
DeliveryMode: deliveryMode,
EndToAddress: endToAddress,
EndToIdentifier: endToIdentifier,
RecvAddress: recvAddress,
RecvIdentifier: recvIdentifier,
QueryList: queryList,
SendBookmarks: sendBookmarks}
reader, err := ep.Deliver(strings.NewReader(input.Xml()))
if nil != err {
return nil, nil, err
}
//defer closeReader(reader)
decoder := xml.NewDecoder(reader)
if err = ReadEnvelopeResponse(decoder, "SubscribeResponse"); nil != err {
closeReader(reader)
return nil, nil, err
}
return reader, decoder, nil
}
func SubscribeByPull(ep *Endpoint, ns, name string, selectorSet map[string]string,
queryList map[string][]envelope.QueryFilter,
sendBookmarks bool) (*Enumerator, error) {
reader, decoder, e := Subscribe(ep, ns, name, selectorSet, envelope.DELIVERYMODE_WSMAN_PULL, "", "", "", "", queryList, sendBookmarks)
if nil != e {
return nil, e
}
defer closeReader(reader)
ok, e := locateElement(decoder, "EnumerationContext")
if nil != e {
return nil, e
}
if !ok {
return nil, ElementNotExists("Envelope/Body/SubscribeResponse/EnumerationContext")
}
context, e := readXmlText(decoder)
if nil != e {
return nil, e
}
return &Enumerator{Namespace: ns,
Endpoint: ep,
Name: name,
SelectorSet: selectorSet,
OptionSet: map[string]string{"ContentFormat": "RenderedText", "SubscriptionName": "hw_subscription"},
Context: context,
is_pull: true}, nil
}