GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Exceptionless.JavaScript/src/EventBuilder.ts at master · csantero/Exceptionless.JavaScript Expand file tree/ Copy pathEventBuilder.tsMore file actions 233 lines (191 loc) · 6.62 KB / Copy pathEventBuilder.tsFile metadata and controls233 lines (191 loc) · 6.62 KB 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 import { ExceptionlessClient } from './ExceptionlessClient'; import { IEvent } from './models/IEvent'; import { IUserInfo } from './models/IUserInfo'; import { IManualStackingInfo } from './models/IManualStackingInfo'; import { ContextData } from './plugins/ContextData'; import { EventPluginContext } from './plugins/EventPluginContext'; import { Utils } from './Utils'; export class EventBuilder { public target: IEvent; public client: ExceptionlessClient; public pluginContextData: ContextData; private _validIdentifierErrorMessage: string = 'must contain between 8 and 100 alphanumeric or \'-\' characters.'; // optimization for minifier. constructor(event: IEvent, client: ExceptionlessClient, pluginContextData?: ContextData) { this.target = event; this.client = client; this.pluginContextData = pluginContextData || new ContextData(); } public setType(type: string): EventBuilder { if (!!type) { this.target.type = type; } return this; } public setSource(source: string): EventBuilder { if (!!source) { this.target.source = source; } return this; } public setReferenceId(referenceId: string): EventBuilder { if (!this.isValidIdentifier(referenceId)) { throw new Error(`ReferenceId ${this._validIdentifierErrorMessage}`); } this.target.reference_id = referenceId; return this; } /** * Allows you to reference a parent event by its ReferenceId property. This allows you to have parent and child relationships. * @param name Reference name * @param id The reference id that points to a specific event * @returns {EventBuilder} */ public setEventReference(name: string, id: string): EventBuilder { if (!name) { throw new Error('Invalid name'); } if (!id || !this.isValidIdentifier(id)) { throw new Error(`Id ${this._validIdentifierErrorMessage}`); } this.setProperty('@ref:' + name, id); return this; } public setMessage(message: string): EventBuilder { if (!!message) { this.target.message = message; } return this; } public setGeo(latitude: number, longitude: number): EventBuilder { if (latitude < -90.0 || latitude > 90.0) { throw new Error('Must be a valid latitude value between -90.0 and 90.0.'); } if (longitude < -180.0 || longitude > 180.0) { throw new Error('Must be a valid longitude value between -180.0 and 180.0.'); } this.target.geo = `${latitude},${longitude}`; return this; } public setUserIdentity(userInfo: IUserInfo): EventBuilder; public setUserIdentity(identity: string): EventBuilder; public setUserIdentity(identity: string, name: string): EventBuilder; public setUserIdentity(userInfoOrIdentity: IUserInfo | string, name?: string): EventBuilder { let userInfo = typeof userInfoOrIdentity !== 'string' ? userInfoOrIdentity : { identity: userInfoOrIdentity, name: name }; if (!userInfo || (!userInfo.identity && !userInfo.name)) { return this; } this.setProperty('@user', userInfo); return this; } /** * Sets the user's description of the event. * * @param emailAddress The email address * @param description The user's description of the event. * @returns {EventBuilder} */ public setUserDescription(emailAddress: string, description: string): EventBuilder { if (emailAddress && description) { this.setProperty('@user_description', { email_address: emailAddress, description: description }); } return this; } /** * Changes default stacking behavior by setting manual * stacking information. * @param signatureData A dictionary of strings to use for stacking. * @param title An optional title for the stacking information. * @returns {EventBuilder} */ public setManualStackingInfo(signatureData: any, title?: string) { if (signatureData) { let stack = <IManualStackingInfo>{ signature_data: signatureData }; if (title) { stack.title = title; } this.setProperty('@stack', stack); } return this; } /** * Changes default stacking behavior by setting the stacking key. * @param manualStackingKey The manual stacking key. * @param title An optional title for the stacking information. * @returns {EventBuilder} */ public setManualStackingKey(manualStackingKey: string, title?: string): EventBuilder { if (manualStackingKey) { let data = { 'ManualStackingKey': manualStackingKey }; this.setManualStackingInfo(data, title); } return this; } public setValue(value: number): EventBuilder { if (!!value) { this.target.value = value; } return this; } public addTags(...tags: string[]): EventBuilder { this.target.tags = Utils.addRange<string>(this.target.tags, ...tags); return this; } /** * Adds the object to extended data. Uses @excludedPropertyNames * to exclude data from being included in the event. * @param name The data object to add. * @param value The name of the object to add. * @param maxDepth The max depth of the object to include. * @param excludedPropertyNames Any property names that should be excluded. */ public setProperty(name: string, value: any, maxDepth?: number, excludedPropertyNames?: string[]): EventBuilder { if (!name || (value === undefined || value == null)) { return this; } if (!this.target.data) { this.target.data = {}; } let result = JSON.parse(Utils.stringify(value, this.client.config.dataExclusions.concat(excludedPropertyNames || []), maxDepth)); if (!Utils.isEmpty(result)) { this.target.data[name] = result; } return this; } public markAsCritical(critical: boolean): EventBuilder { if (critical) { this.addTags('Critical'); } return this; } public addRequestInfo(request: Object): EventBuilder { if (!!request) { this.pluginContextData['@request'] = request; } return this; } public submit(callback?: (context: EventPluginContext) => void): void { this.client.submitEvent(this.target, this.pluginContextData, callback); } private isValidIdentifier(value: string): boolean { if (!value) { return true; } if (value.length < 8 || value.length > 100) { return false; } for (let index = 0; index < value.length; index++) { let code = value.charCodeAt(index); let isDigit = (code >= 48) && (code <= 57); let isLetter = ((code >= 65) && (code <= 90)) || ((code >= 97) && (code <= 122)); let isMinus = code === 45; if (!(isDigit || isLetter) && !isMinus) { return false; } } return true; } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |