public void PostTelemetryRecord(string tenantId, string subscriptionId, Dictionary <string, string> processedItems) { TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.ExecutionId = Guid.Parse(app.Default.ExecutionId); telemetryrecord.SubscriptionId = new Guid(subscriptionId); telemetryrecord.TenantId = tenantId; telemetryrecord.ProcessedResources = processedItems; string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://asmtoarmtoolapi.azurewebsites.net/api/telemetry"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); }
public void SendRecord(TelemetryRecord record) { CheckStarted(); if (sendThrows) { throw new ApplicationException(nameof(SendErrorTelemetry)); } AddRecord(record); }
public IActionResult GetOrCreateUser([FromQuery] string email) { try { _serviceProvider.GetUserService().GetOrCreateUser(email); var user = _serviceProvider.GetUserService().GetUser(email); var result = new UserModel { Id = user.Id, Mail = user.Mail, Licence = new LicenceModel() }; LicenceKey licence; if (!user.LicenceKeyId.HasValue) { if (_serviceProvider.GetLicenceService().GetFirstUnusedLicenceKey() == null) { var licenceId = _serviceProvider.GetLicenceService().GenerateLicence(); _serviceProvider.GetUserService().AssignLicence(user.Id, licenceId); _serviceProvider.GetLicenceService().SetUsed(licenceId); user = _serviceProvider.GetUserService().GetUser(email); } } if (user.LicenceKeyId.HasValue) { licence = _serviceProvider.GetLicenceService().GetLicenceKey(user.LicenceKeyId.Value); result.Licence = new LicenceModel { Id = licence.Id, IsUsed = licence.IsUsed, Key = licence.Key }; } TelemetryRecord telemetry = _serviceProvider.GetTelemetryService().GetTelemetryRecordFor(user.Id); if (telemetry != null) { result.Telemetry = new TelemetryModel { Email = user.Mail, NetFxVersion = telemetry.NetFxVersion, OsVersion = telemetry.OsVersion }; } return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void PostTelemetryRecord(string tenantId, string subscriptionId, Dictionary <string, string> processedItems, string offercategories) { TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.ExecutionId = Guid.Parse(app.Default.ExecutionId); telemetryrecord.SubscriptionId = new Guid(subscriptionId); telemetryrecord.TenantId = tenantId; telemetryrecord.OfferCategories = offercategories; telemetryrecord.SourceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); telemetryrecord.ProcessedResources = processedItems; string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.migaz.tools/v1/telemetry/ARMtoARM"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); } catch (Exception exception) { DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void PostTelemetryRecord(AsmToArmGenerator templateGenerator) { TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.ExecutionId = templateGenerator.ExecutionGuid; telemetryrecord.SubscriptionId = templateGenerator.SourceSubscription.SubscriptionId; telemetryrecord.TenantId = templateGenerator.SourceSubscription.AzureAdTenantId; telemetryrecord.OfferCategories = templateGenerator.SourceSubscription.offercategories; telemetryrecord.SourceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); telemetryrecord.ProcessedResources = this.GetProcessedItems(templateGenerator); string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://asmtoarmtoolapi.azurewebsites.net/api/telemetry"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); } catch (Exception exception) { DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ActualiseCache() { _localCache.Clear(); var reader = _dataAccess.ExecuteReader("SELECT id, osver, netfxver, userId FROM telemetries;"); if (reader.HasRows) { reader.Read(); var tr = new TelemetryRecord(reader.GetInt64(0), reader.GetString(1), reader.GetString(2), reader.GetInt64(3)); if (!_localCache.Contains(tr)) { _localCache.Add(tr); } while (reader.Read()) { tr = new TelemetryRecord(reader.GetInt64(0), reader.GetString(1), reader.GetString(2), reader.GetInt64(3)); if (!_localCache.Contains(tr)) { _localCache.Add(tr); } } } reader.Close(); }
public void PostTelemetryRecord(Guid appSessionGuid, string migrationSourceType, AzureSubscription sourceSubscription, AzureGenerator templateGenerator) { if (templateGenerator == null) { throw new ArgumentException("Template Generator cannot be null."); } TelemetryRecord telemetryrecord = new TelemetryRecord(); telemetryrecord.AppSessionGuid = appSessionGuid; telemetryrecord.Id = templateGenerator.ExecutionGuid; telemetryrecord.MigrationSourceType = migrationSourceType; #if DEBUG telemetryrecord.ConfigurationMode = "Debug"; #else telemetryrecord.ConfigurationMode = "Release"; #endif if (sourceSubscription != null) { telemetryrecord.SourceEnvironment = sourceSubscription.AzureEnvironment.ToString(); telemetryrecord.SourceSubscriptionGuid = sourceSubscription.SubscriptionId; telemetryrecord.SourceTenantGuid = sourceSubscription.AzureAdTenantId; telemetryrecord.OfferCategories = String.Empty; // templateGenerator.SourceSubscription.offercategories; } if (templateGenerator.TargetSubscription != null) { telemetryrecord.TargetEnvironment = templateGenerator.TargetSubscription.AzureEnvironment.ToString(); telemetryrecord.TargetSubscriptionGuid = templateGenerator.TargetSubscription.SubscriptionId; telemetryrecord.TargetTenantGuid = templateGenerator.TargetSubscription.AzureAdTenantId; } telemetryrecord.SourceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); telemetryrecord.ProcessedResources = this.GetProcessedItems(templateGenerator); string jsontext = JsonConvert.SerializeObject(telemetryrecord, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(jsontext); try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://migaz.azurewebsites.net/api/v2"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result = new StreamReader(response.GetResponseStream()).ReadToEnd(); //TelemetryRecord mytelemetry = (TelemetryRecord)JsonConvert.DeserializeObject(jsontext, typeof(TelemetryRecord)); } catch (Exception exception) { // DialogResult dialogresult = MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void PublishTelemetry(string area, string feature, TelemetryRecord record) => PublishTelemetry(area, feature, record?.GetAssignedProperties());
protected void ProcessIncomingPacket(byte[] rgb, int cb) { byte bCommandType = rgb[0]; switch ((COMMAND_TYPE)bCommandType) { case COMMAND_TYPE.DIRECT_NO_REPLY_REQUIRED: // This is the NXT spontaneously transmitting a message { byte bCommand = rgb[1]; // the 'direct' command switch ((DIRECT_COMMAND)bCommand) { case DIRECT_COMMAND.MESSAGE_WRITE: // byte mailbox = rgb[2]; // the mailbox/queue to which the data was sent, should be iTelemetryMailbox. REVIEW: generalize for multiple telemetry streams byte cbPayload = rgb[3]; // the cbDevBroadcastDeviceInterface of the packet that came from the NXT // TelemetryRecord msg = new TelemetryRecord(rgb.Slice(4, cbPayload)); lock (this.telemetryRecords) { this.telemetryRecords.Add(msg); } this.TelemetryRecordAvailableEvent.Set(); // break; default: // Other direct commands ignored Program.Trace("unknown direct command: {0}", bCommand); break; } } break; case COMMAND_TYPE.REPLY: // This is the NXT replying to one of our messages { byte bCommand = rgb[1]; NxtMessage msgReplyTarget = GetNextReplyTarget(bCommand); if (null != msgReplyTarget) { msgReplyTarget.ProcessReply(rgb, this); } else { Program.Trace("reply with no matching request"); } } break; default: // It's a command type we don't know how to process. Just skip the message and hope for the best. Program.Trace("unknown command type: {0}", bCommandType); break; } }
// The data stream transmitted from the NXT consists of a sequence of records. Each record is a sequence of // bytes, the first of which consists of: // • a 7-bit byte count (in the lower 7 bits) indicating the length of the record in bytes (exclusive of this first byte), and // • a 1-bit flag (the high bit) indicating whether the record is // o a payload record (high bit is zero), containing app-defined data to be accumulated by the receiver, or // o a meta record (high bit is one), containing dynamic communication from the NXT to the receiver // // A meta record of zero length is degenerate and contains no actual communication. A meta record of length // greater than zero has semantics which depend upon the second byte cmd of the record (the byte immediately // following the byte-count/flag byte) according to the following: // // • cmd==0: Polling Interval // o If length is exactly 3 // Two bytes following cmd are taken as a little-endian unsigned integer. // Said integer is interpreted as the polling interval in milliseconds that the receiver should // use between polling requests (see below) by which new data in the data stream is retrieved. // A value of zero indicates that the receiver should poll as fast as reasonably possible. // The default value of the polling interval is 30. // o If length is exactly 1 // Polling is disabled // The receiver will not again poll the NXT until the Initialization Sequence is next executed. // // • cmd==1: Backchannel Mailbox // o If length is exactly 2 // The byte following cmd is interpreted as the zero-origin mailbox number by which the receiver // can dynamically communicate with the NXT using the Message Write Direct Command. // Until and unless the NXT so informs the Samantha of this mailbox number, no receiver-to-NXT communication is possible. // The format and semantics of the receiver -to-NXT communications is defined below in Backchannel Communication // // • cmd==2: Zero Telemetry Data // o If length is exactly 1 // Stored telemetry data is discarded // Persistent storage space is prepared for subsequent accumulation of payload records // • E.g.: Flash memory is zeroed // Note that in general this can take a significantly long time for the Samantha to execute. // • However, if no telemetry data is currently stored (i.e: no payload records have been observed since the // previous zeroing) this operation is relatively quick // // Any ill-formed meta records (e.g.: cmd==0 and length not 1 or 3, or cmd containing a value other than those // listed above) are ignored by the receiver. void ProcessIncomingPolledRecord(bool fMetaRecord, byte[] rgbRecord) { if (fMetaRecord) { // Process a meta record: adjust the polling parameters, etc // if (rgbRecord.Length > 0) { // First byte of record is the telemetry meta command switch (rgbRecord[0]) { case (byte)TELEMETRY_META_COMMAND.POLLING_INTERVAL: switch (rgbRecord.Length) { case 1: // disable polling Program.TheForm.NXTWantsTelemetryPolling = false; break; case 3: // enable polling at certain rate // int msPoll = (int)rgbRecord[1] + ((int)rgbRecord[2] << 8); Program.TheForm.TelemetryPollingInterval = msPoll; Program.TheForm.NXTWantsTelemetryPolling = true; break; } break; case (byte)TELEMETRY_META_COMMAND.BACKCHANNEL_MAILBOX: // // NYI. Backchannel has no current use // break; case (byte)TELEMETRY_META_COMMAND.ZERO_TELEMETRY_DATA: // // NYI. Probably not semantically interesting for non-Samantha-telemetry-accumulation situations // break; } } } else { // Process an ordinary telemetry data record TelemetryRecord record = new TelemetryRecord(rgbRecord); lock (this.TelemetryRecords) { this.TelemetryRecords.Add(record); this.TelemetryRecordAvailableEvent.Set(); } } }
public IActionResult GetOrCreateUser([FromQuery] string email, [FromQuery] string admKey) { try { if (_adminCode.AdminCode != admKey) { return(Unauthorized("Your admin code is not correct")); } _serviceProvider.GetUserService().GetOrCreateUser(email); var user = _serviceProvider.GetUserService().GetUser(email); var result = new UserModel { Id = user.Id, Mail = user.Mail, Licence = new LicenceModel() }; LicenceKey licence; if (!user.LicenceKeyId.HasValue) { var licenceId = _serviceProvider.GetLicenceService().GetFirstUnusedLicenceKey()?.Id; if (!licenceId.HasValue) { licenceId = _serviceProvider.GetLicenceService().GenerateLicence(); } _serviceProvider.GetUserService().AssignLicence(user.Id, licenceId.Value); _serviceProvider.GetLicenceService().SetUsed(licenceId.Value); user = _serviceProvider.GetUserService().GetUser(email); } licence = _serviceProvider.GetLicenceService().GetLicenceKey(user.LicenceKeyId.Value); result.Licence = new LicenceModel { Id = licence.Id, IsUsed = licence.IsUsed, Key = licence.Key }; TelemetryRecord telemetry = _serviceProvider.GetTelemetryService().GetTelemetryRecordFor(user.Id); if (telemetry != null) { result.Telemetry = new TelemetryModel { Email = user.Mail, NetFxVersion = telemetry.NetFxVersion, OsVersion = telemetry.OsVersion }; } var resultReader = _dataProvider.ExecuteReader($"SELECT * FROM telemetryIps WHERE telemetryId = {user.Id}"); var ips = new List <TelemetryIpModel>(); if (resultReader.HasRows) { resultReader.Read(); ips.Add(new TelemetryIpModel { Ip = resultReader.GetString(2) }); while (resultReader.Read()) { ips.Add(new TelemetryIpModel { Ip = resultReader.GetString(2) }); } resultReader.Close(); } result.Telemetry.TelemetryIps = ips; return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void SendRecord(TelemetryRecord record) { }
private void AddRecord(TelemetryRecord record) { RecordsSent.Add(record); sendCallback(record); }