This commit is contained in:
Devis Lucato 2017-04-30 18:17:01 -07:00
Родитель 43db723eb1
Коммит da56943aae
50 изменённых файлов: 2164 добавлений и 24 удалений

14
.gitconfig Normal file
Просмотреть файл

@ -0,0 +1,14 @@
[core]
whitespace = trailing-space,space-before-tab
autocrlf = true
eol = lf
[apply]
whitespace = fix
[alias]
st = status
co = checkout
ci = commit
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
lg1 = log --pretty=oneline
lgx = log --stat
stashx = stash show --patience

428
.gitignore поставляемый
Просмотреть файл

@ -1,3 +1,426 @@
### Custom
_dev/
*.crt
*._gistcs
*.tgz
*.tar
*.exe
*.bck
### MacOS
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Vagrant
.vagrant/
### SublimeText
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# workspace files are user-specific
*.sublime-workspace
# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project
# sftp configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### JetBrains
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### VisualStudio
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
@ -250,3 +673,8 @@ paket-files/
# JetBrains Rider # JetBrains Rider
.idea/ .idea/
*.sln.iml *.sln.iml
# Overrides

16
.travis.yml Normal file
Просмотреть файл

@ -0,0 +1,16 @@
language: csharp
mono: none
dotnet: 1.0.1
dist: trusty
sudo: false
cache:
directories:
- "$HOME/.nuget/"
before_install:
- set -e
script:
- "./$CODEBASE/scripts/build"
notifications:
slack:
rooms:
- secure: uHniNf/kLZ0s2M3PdWQrzeNNB3v9zeHrCRaXSOzNgSNgV10OBm6ryLolGSPic/4jImCOPviiCu7M9lZ/IxdJn3zg0lY9o7q8JzyIOt5FYoVrdlxEoQebX4UdPLh3X/1YNSThdC+crgwHKc/6g8YRNluwd1jggdNdYpm021lOA0AItmtwl9bXn2Ba7Zlu6R7MezXxVo0hDELBwONra+lixpIGwprHEQfIX54lrBAaaEX9Pm3W9VSEfV+0YLnxI09PkF/vLquUdrm6axh9XG4UA2TxkCGB2nk11LSc+lvDxkcZmuQdEED7lAuuthB7TiQ5NViULtYl42S/uCfXGZHpmoiyp5t6vPftuZeEkq3c/Zlmi6qNX1PxzXML4v2VHHmLxOii47vUsfbntOWFmCMavztSdsnBTen3i6+IpPXMw2tJ4NVRFss8pnlELMlVGCEqRhVseNBDF1Ni0sCTyOzqGxnfjWmQqgITwGHDOrg6UU09qLtz43U+4OzItXUWwQdG14wP0ZpPkWI/LnfktPe8TwBU+eu4iF5bLjZUSldueInOgVzk6xUCox42NGsDQ96jNt+nU8YKofsKwHHHrTRf6mcORGc7kYvkJkeYkPEBfOnns7uZZaYCWaij7y9gtrV7E9r3wQBndNLS6/HD9OhUuGGnd627QvLqtfzhEmrZAwQ=

67
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1,67 @@
Contribution license Agreement
==============================
If you want/plan to contribute, we ask you to sign a
[CLA](https://cla.microsoft.com/) (Contribution license Agreement). A friendly
bot will remind you about it when you submit a pull-request.
Development
===========
... notes about code style ...
... how to run tests locally ...
... requirements, e.g. Azure sub, IoT Hub setup etc. ...
... useful scripts included in the project ...
Development setup
=================
## .NET setup
1. Install [.NET Core](https://dotnet.github.io/)
2. MacOS/Linux: Install [Mono 5.x](http://www.mono-project.com/download/alpha/)
3. Some IDE options:
* [Visual Studio](https://www.visualstudio.com/)
* [IntelliJ Rider](https://www.jetbrains.com/rider)
* [Visual Studio Code](https://code.visualstudio.com/)
* [Visual Studio for Mac](https://www.visualstudio.com/vs/visual-studio-mac)
Note: .NET Core support is work in progress, all .NET development is
currently via .NET Framework on Windows and Mono on Linux/MacOS.
We provide also a [Java version here](https://github.com/Azure/device-simulation-java).
## IoT Hub setup
At some point you will probably want to setup your Azure IoT Hub, for
development and integration tests.
The project includes some Bash scripts to help you with this setup:
* Create new IoT Hub: `./scripts/iothub/create-hub.sh`
* List existing hubs: `./scripts/iothub/list-hubs.sh`
* Show IoT Hub details (e.g. keys): `./scripts/iothub/show-hub.sh`
and in case you had multiple Azure subscriptions:
* Show subscriptions list: `./scripts/iothub/list-subscriptions.sh`
* Change current subscription: `./scripts/iothub/select-subscription.sh`
## Git setup
The project includes a Git hook, to automate some checks before accepting a
code change. You can run the tests manually, or let the CI platform to run
the tests. We use the following Git hook to automatically run all the tests
before sending code changes to GitHub and speed up the development workflow.
To setup the included hooks, open a Windows/Linux/MacOS console and execute:
```
cd PROJECT-FOLDER
cd scripts/git
setup
```
If at any point you want to remove the hook, simply delete the file installed
under `.git/hooks`. You can also bypass the pre-commit hook using the
`--no-verify` option.

42
LICENSE
Просмотреть файл

@ -1,21 +1,21 @@
MIT License MIT License
Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE SOFTWARE

Просмотреть файл

@ -1,3 +1,48 @@
# Contributing [![Build][build-badge]][build-url]
[![Issues][issues-badge]][issues-url]
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. [![Gitter][gitter-badge]][gitter-url]
IoT Device Simulation
=====================
... project description ...
Overview
========
... quick demonstrative examples ...
How to use it
=============
... steps to use this project ...
... deployment notes ...
Configuration
=============
... how to customize the service, settings, etc. ...
Special notes
=============
... technical details ...
Edge cases
==========
... things to take into consideration ...
... known limitations ...
Other documents
===============
* [Contributing and development setup](CONTRIBUTING.md)
[build-badge]: https://img.shields.io/travis/Azure/device-simulation-dotnet.svg
[build-url]: https://travis-ci.org/Azure/device-simulation-dotnet
[issues-badge]: https://img.shields.io/github/issues/azure/device-simulation-dotnet.svg
[issues-url]: https://github.com/azure/device-simulation-dotnet/issues
[gitter-badge]: https://img.shields.io/gitter/room/azure/iot-pcs.js.svg
[gitter-url]: https://gitter.im/azure/iot-pcs

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Services.Test")]
[assembly: AssemblyProduct("Services.Test")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft. All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("CDB4D7B6-84D6-48F8-983F-81843B288699")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CDB4D7B6-84D6-48F8-983F-81843B288699}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Services.Test</RootNamespace>
<AssemblyName>Services.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SomeTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

15
Services.Test/SomeTest.cs Executable file
Просмотреть файл

@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit;
namespace Services.Test
{
public class SomeTest
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
}

10
Services.Test/packages.config Executable file
Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
<package id="xunit.runner.console" version="2.2.0" targetFramework="net462" developmentDependency="true" />
</packages>

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Microsoft.Azure.IoTSolutions.DeviceSimulation.Services")]
[assembly: AssemblyProduct("Microsoft.Azure.IoTSolutions.DeviceSimulation.Services")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft. All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("8ACBC846-B16C-4857-94F1-0BB297FE1CD3")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

89
Services/Services.csproj Executable file
Просмотреть файл

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.IoTSolutions.DeviceSimulation.Services</RootNamespace>
<AssemblyName>Microsoft.Azure.IoTSolutions.DeviceSimulation.Services</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>anycpu</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>Default</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>Default</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.Amqp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.Azure.Amqp.2.0.3\lib\net45\Microsoft.Azure.Amqp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Devices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.Azure.Devices.1.2.4\lib\net451\Microsoft.Azure.Devices.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Devices.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.Azure.Devices.Shared.1.0.10\lib\net45\Microsoft.Azure.Devices.Shared.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c">
<HintPath>..\packages\PCLCrypto.2.0.147\lib\net45\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="PInvoke.BCrypt, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a">
<HintPath>..\packages\PInvoke.BCrypt.0.3.2\lib\net40\PInvoke.BCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Kernel32, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a">
<HintPath>..\packages\PInvoke.Kernel32.0.3.2\lib\net40\PInvoke.Kernel32.dll</HintPath>
</Reference>
<Reference Include="PInvoke.NCrypt, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a">
<HintPath>..\packages\PInvoke.NCrypt.0.3.2\lib\net40\PInvoke.NCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a">
<HintPath>..\packages\PInvoke.Windows.Core.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.Windows.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Validation, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7">
<HintPath>..\packages\Validation.2.2.8\lib\dotnet\Validation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

15
Services/packages.config Normal file
Просмотреть файл

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.Azure.Amqp" version="2.0.3" targetFramework="net462" />
<package id="Microsoft.Azure.Devices" version="1.2.4" targetFramework="net462" />
<package id="Microsoft.Azure.Devices.Shared" version="1.0.10" targetFramework="net462" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net462" />
<package id="PCLCrypto" version="2.0.147" targetFramework="net462" />
<package id="PInvoke.BCrypt" version="0.3.2" targetFramework="net462" />
<package id="PInvoke.Kernel32" version="0.3.2" targetFramework="net462" />
<package id="PInvoke.NCrypt" version="0.3.2" targetFramework="net462" />
<package id="PInvoke.Windows.Core" version="0.3.2" targetFramework="net462" />
<package id="Validation" version="2.2.8" targetFramework="net462" />
</packages>

Просмотреть файл

@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit;
namespace WebService.Test.Controllers
{
public class SomeControllerTest
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("WebService.Test")]
[assembly: AssemblyProduct("WebService.Test")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft. All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("15CBDB1E-2AA0-438B-B502-A6483AB594B4")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{15CBDB1E-2AA0-438B-B502-A6483AB594B4}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebService.Test</RootNamespace>
<AssemblyName>WebService.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controllers\SomeControllerTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

10
WebService.Test/packages.config Executable file
Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
<package id="xunit.runner.console" version="2.2.0" targetFramework="net462" developmentDependency="true" />
</packages>

26
WebService/Program.cs Executable file
Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime;
using Microsoft.Owin.Hosting;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService
{
public class Program
{
static readonly IConfig config = new Config();
static void Main(string[] args)
{
// TODO: remove workaround and support all versions
var options = new StartOptions("http://*:" + config.Port + "/" + v1.Version.Name);
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Server listening at http://*:" + config.Port);
Console.WriteLine("Health check: http://127.0.0.1:" + config.Port + "/v1/status");
Console.WriteLine("Press [Enter] to quit...");
Console.ReadLine();
}
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService")]
[assembly: AssemblyProduct("Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft. All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("2834a1fa-8d60-4ba4-9155-e318608b1c4f")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,46 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
using Akka.Configuration;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime
{
public interface IConfig
{
int Port { get; }
}
public class Config : IConfig
{
private const string Namespace = "com.microsoft.azure.iotsolutions.";
private const string Application = "device-simulation.";
public Config()
{
// Load HOCON and apply env vars substitutions
var config = ConfigurationFactory.ParseString(GetHoconConfiguration());
this.Port = config.GetInt(Namespace + Application + "webservice-port");
}
public int Port { get; }
private static string GetHoconConfiguration()
{
var hocon = File.ReadAllText("application.conf");
// Append environment variables to allow Hocon substitutions on them
var filter = new Regex(@"^[a-zA-Z0-9_/.,:;#(){}^=+~| !@$%&*'[\\\]-]*$");
hocon += "\n";
foreach (DictionaryEntry x in Environment.GetEnvironmentVariables())
{
if (filter.IsMatch(x.Value.ToString())) hocon += x.Key + " : \"" + x.Value + "\"\n";
}
return hocon;
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime
{
public static class Uptime
{
public static DateTime Start { get; } = DateTime.UtcNow;
public static TimeSpan Duration => DateTime.UtcNow.Subtract(Start);
}
}

23
WebService/Startup.cs Executable file
Просмотреть файл

@ -0,0 +1,23 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Web.Http;
using Owin;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
}
}
}

102
WebService/WebService.csproj Executable file
Просмотреть файл

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2834A1FA-8D60-4BA4-9155-E318608B1C4F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService</RootNamespace>
<AssemblyName>Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Akka.Hocon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Akka.Hocon.0.3.0\lib\net45\Akka.Hocon.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.3.1.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Hosting, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Hosting.3.1.0\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Runtime\Uptime.cs" />
<Compile Include="v1\Controllers\StatusController.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Runtime\Config.cs" />
<Compile Include="Startup.cs" />
<Compile Include="v1\Models\StatusModel.cs" />
<Compile Include="v1\Version.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="application.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Services\Services.csproj">
<Project>{8acbc846-b16c-4857-94f1-0bb297fe1cd3}</Project>
<Name>Services</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

18
WebService/app.config Executable file
Просмотреть файл

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Просмотреть файл

@ -0,0 +1,12 @@
com.microsoft.azure.iotsolutions {
device-simulation {
webservice-port: 8080
webservice-hostname: "0.0.0.0"
iothub.connstring: ${PCS_IOTHUB_CONN_STRING}
}
}
akka {
# Options: OFF, ERROR, WARNING, INFO, DEBUG
loglevel: INFO
}

Просмотреть файл

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Akka.Hocon" version="0.3.0" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net462" />
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net462" />
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net462" />
<package id="Microsoft.Owin.Hosting" version="3.1.0" targetFramework="net462" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net462" />
<package id="Owin" version="1.0" targetFramework="net462" />
</packages>

Просмотреть файл

@ -0,0 +1,21 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Web.Http;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1.Models;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1.Controllers
{
[RoutePrefix(Version.Name)]
public class StatusController : ApiController
{
public StatusModel Get()
{
return new StatusModel
{
Message = "OK",
CurrentTime = DateTime.UtcNow
};
}
}
}

Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.Runtime;
using Newtonsoft.Json;
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1.Models
{
public class StatusModel
{
public string Message { get; set; }
public DateTime CurrentTime { get; set; }
public DateTime StartTime => Uptime.Start;
public TimeSpan UpTime => Uptime.Duration;
[JsonProperty(PropertyName = "$metadata")]
public Dictionary<string, string> Metadata => new Dictionary<string, string>
{
{ "$type", "Status;" + Version.Name },
{ "$uri", "/" + Version.Name + "/status" }
};
}
}

10
WebService/v1/Version.cs Normal file
Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1
{
public static class Version
{
public const string Name = "v1";
public const string Date = "201704";
}
}

65
device-simulation.sln Executable file
Просмотреть файл

@ -0,0 +1,65 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services.Test", "Services.Test\Services.Test.csproj", "{CDB4D7B6-84D6-48F8-983F-81843B288699}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebService", "WebService\WebService.csproj", "{2834A1FA-8D60-4BA4-9155-E318608B1C4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebService.Test", "WebService.Test\WebService.Test.csproj", "{15CBDB1E-2AA0-438B-B502-A6483AB594B4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution", "solution", "{3FC36D0A-780E-49C1-9AE0-F8B4B07CC802}"
ProjectSection(SolutionItems) = preProject
.gitconfig = .gitconfig
.gitignore = .gitignore
.travis.yml = .travis.yml
CONTRIBUTING.md = CONTRIBUTING.md
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{62C8C8A3-CD4F-4A9B-9BB5-F5C6D7BE94CC}"
ProjectSection(SolutionItems) = preProject
scripts\.functions.sh = scripts\.functions.sh
scripts\build = scripts\build
scripts\build.cmd = scripts\build.cmd
scripts\run = scripts\run
scripts\run.cmd = scripts\run.cmd
scripts\run.vbs = scripts\run.vbs
scripts\compile = scripts\compile
scripts\compile.cmd = scripts\compile.cmd
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8ACBC846-B16C-4857-94F1-0BB297FE1CD3}.Release|Any CPU.Build.0 = Release|Any CPU
{CDB4D7B6-84D6-48F8-983F-81843B288699}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDB4D7B6-84D6-48F8-983F-81843B288699}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDB4D7B6-84D6-48F8-983F-81843B288699}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDB4D7B6-84D6-48F8-983F-81843B288699}.Release|Any CPU.Build.0 = Release|Any CPU
{2834A1FA-8D60-4BA4-9155-E318608B1C4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2834A1FA-8D60-4BA4-9155-E318608B1C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2834A1FA-8D60-4BA4-9155-E318608B1C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2834A1FA-8D60-4BA4-9155-E318608B1C4F}.Release|Any CPU.Build.0 = Release|Any CPU
{15CBDB1E-2AA0-438B-B502-A6483AB594B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15CBDB1E-2AA0-438B-B502-A6483AB594B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15CBDB1E-2AA0-438B-B502-A6483AB594B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15CBDB1E-2AA0-438B-B502-A6483AB594B4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{62C8C8A3-CD4F-4A9B-9BB5-F5C6D7BE94CC} = {3FC36D0A-780E-49C1-9AE0-F8B4B07CC802}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,21 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">Field, Property, Event, Method</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_FIXED_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_FOR_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_FOREACH_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_LOCK_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_USINGS_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_WHILE_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/STICK_COMMENT/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

12
scripts/.functions.sh Executable file
Просмотреть файл

@ -0,0 +1,12 @@
COL_NO="\033[0m" # no color
COL_ERR="\033[1;31m" # light red
COL_H1="\033[1;33m" # yellow
COL_H2="\033[1;36m" # light cyan
header() {
echo -e "${COL_H1}\n### $1 ${COL_NO}"
}
error() {
echo -e "${COL_ERR}$1 ${COL_NO}"
}

50
scripts/build Executable file
Просмотреть файл

@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Debug|Release
CONFIGURATION=Release
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
source "$APP_HOME/scripts/.functions.sh"
cd $APP_HOME
check_dependencies() {
TEST=$(which mono)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'mono' command not found. Install Mono 5.x first (http://www.mono-project.com/docs/about-mono/releases/5.0.0)."
exit 1
fi
TEST=$(which nuget)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'nuget' command not found. Install Mono 5.x first (http://www.mono-project.com/docs/about-mono/releases/5.0.0)."
exit 1
fi
TEST=$(which dotnet)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'dotnet' command not found. Install .NET Core first (https://dotnet.github.io)."
exit 1
fi
}
failed() {
echo "Build failed"
exit 1
}
compile() {
nuget restore
msbuild /m /p:Configuration=$CONFIGURATION
}
run_tests() {
PROJECTS=$(dotnet sln list | grep 'csproj$' | grep '\.Test'| sed s#/.*##)
for PROJ in $PROJECTS; do
mono ./packages/xunit.runner.console.2.2.0/tools/xunit.console.exe $PROJ/bin/Release/$PROJ.dll
done
}
check_dependencies
compile
run_tests

37
scripts/build.cmd Normal file
Просмотреть файл

@ -0,0 +1,37 @@
@ECHO off
setlocal enableextensions enabledelayedexpansion
:: Debug|Release
SET CONFIGURATION=Release
:: strlen("\scripts\") => 9
SET APP_HOME=%~dp0
SET APP_HOME=%APP_HOME:~0,-9%
cd %APP_HOME%
call nuget restore
IF NOT ERRORLEVEL 0 GOTO FAIL
call msbuild /m /p:Configuration=%CONFIGURATION%;Platform="Any CPU"
IF NOT ERRORLEVEL 0 GOTO FAIL
SET PATTERN=bin\%CONFIGURATION%
for /r %%i in (*.Test.dll) do (
echo.%%i | findstr /C:%PATTERN% >nul
IF !ERRORLEVEL! EQU 0 (
echo === %%i
.\packages\xunit.runner.console.2.2.0\tools\xunit.console.exe %%i -verbose -nologo -noshadow -parallel all
IF ERRORLEVEL 1 GOTO FAIL
)
)
:: - - - - - - - - - - - - - -
goto :END
:FAIL
echo Command failed
endlocal
exit /B 1
:END
endlocal

40
scripts/compile Executable file
Просмотреть файл

@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
source "$APP_HOME/scripts/.functions.sh"
cd $APP_HOME
check_dependencies() {
TEST=$(which mono)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'mono' command not found. Install Mono 5.x first (http://www.mono-project.com/docs/about-mono/releases/5.0.0)."
exit 1
fi
TEST=$(which nuget)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'nuget' command not found. Install Mono 5.x first (http://www.mono-project.com/docs/about-mono/releases/5.0.0)."
exit 1
fi
TEST=$(which dotnet)
if [[ -z "$TEST" ]]; then
echo "ERROR: 'dotnet' command not found. Install .NET Core first (https://dotnet.github.io)."
exit 1
fi
}
failed() {
echo "Build failed"
exit 1
}
compile() {
nuget restore
msbuild /m /p:Configuration=Debug
msbuild /m /p:Configuration=Release
}
check_dependencies
compile

27
scripts/compile.cmd Normal file
Просмотреть файл

@ -0,0 +1,27 @@
@ECHO off
setlocal enableextensions enabledelayedexpansion
:: strlen("\scripts\") => 9
SET APP_HOME=%~dp0
SET APP_HOME=%APP_HOME:~0,-9%
cd %APP_HOME%
call nuget restore
IF NOT ERRORLEVEL 0 GOTO FAIL
call msbuild /m /p:Configuration=Debug;Platform="Any CPU"
IF NOT ERRORLEVEL 0 GOTO FAIL
call msbuild /m /p:Configuration=Release;Platform="Any CPU"
IF NOT ERRORLEVEL 0 GOTO FAIL
:: - - - - - - - - - - - - - -
goto :END
:FAIL
echo Command failed
endlocal
exit /B 1
:END
endlocal

Просмотреть файл

@ -0,0 +1,7 @@
header() {
echo -e "\n### $1"
}
error() {
echo -e "$1"
}

Просмотреть файл

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
# Path relative to .git/hooks/
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
source "$APP_HOME/scripts/git/pre-commit.sh"

111
scripts/git/pre-commit.sh Executable file
Просмотреть файл

@ -0,0 +1,111 @@
#!/usr/bin/env bash
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
source "$APP_HOME/scripts/git/.functions.sh"
cd $APP_HOME
echo "Current folder: `pwd`"
if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
check_filenames() {
header "Checking filenames..."
# Redirect output to stderr.
exec 1>&2
# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
set +e
if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then
error "Attempt to add a non-ASCII file name. This can cause problems on other platforms."
exit 1
fi
set -e
}
check_whitespaces() {
header "Checking white spaces and line separators..."
git diff-index --check --cached $against --
}
check_do_not_commit() {
PATTERN1="DONOT"
PATTERN1="${PATTERN1}COMMIT"
PATTERN2="DO NOT"
PATTERN2="${PATTERN2} COMMIT"
PATTERN3="DONT"
PATTERN3="${PATTERN3}COMMIT"
PATTERN4="DONT"
PATTERN4="${PATTERN4} COMMIT"
PATTERN5="DON'T"
PATTERN5="${PATTERN5} COMMIT"
header "Checking diff for comments containing '${PATTERN1}'..."
set +e
PATT="^\+.*${PATTERN1}.*$"
diffstr=`git diff --cached $against | grep -ie "$PATT"`
if [[ -n "$diffstr" ]]; then
error "You have left '${PATTERN1}' in your changes, you can't commit until it has been removed."
exit 1
fi
PATT="^\+.*${PATTERN2}.*$"
diffstr=`git diff --cached $against | grep -ie "$PATT"`
if [[ -n "$diffstr" ]]; then
error "You have left '${PATTERN2}' in your changes, you can't commit until it has been removed."
exit 1
fi
PATT="^\+.*${PATTERN3}.*$"
diffstr=`git diff --cached $against | grep -ie "$PATT"`
if [[ -n "$diffstr" ]]; then
error "You have left '${PATTERN3}' in your changes, you can't commit until it has been removed."
exit 1
fi
PATT="^\+.*${PATTERN4}.*$"
diffstr=`git diff --cached $against | grep -ie "$PATT"`
if [[ -n "$diffstr" ]]; then
error "You have left '${PATTERN4}' in your changes, you can't commit until it has been removed."
exit 1
fi
PATT="^\+.*${PATTERN5}.*$"
diffstr=`git diff --cached $against | grep -ie "$PATT"`
if [[ -n "$diffstr" ]]; then
error "You have left '${PATTERN5}' in your changes, you can't commit until it has been removed."
exit 1
fi
set -e
}
verify_build() {
header "Verifying build..."
cd $APP_HOME/scripts
./build
if [ $? -ne 0 ]; then
error "Some tests failed."
exit 1
fi
}
check_filenames
check_whitespaces
check_do_not_commit
verify_build

19
scripts/git/setup Executable file
Просмотреть файл

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
failed() {
echo "Git hooks setup failed"
exit 1
}
cd $APP_HOME/.git || failed
mkdir -p hooks || failed
cd hooks || failed
echo "Adding pre-commit hook..."
rm -f pre-commit
cp -p $APP_HOME/scripts/git/pre-commit-runner.sh ./pre-commit || failed
echo "Done."

28
scripts/git/setup.cmd Normal file
Просмотреть файл

@ -0,0 +1,28 @@
@ECHO off
setlocal
:: strlen("\scripts\git\") => 13
SET APP_HOME=%~dp0
SET APP_HOME=%APP_HOME:~0,-13%
cd %APP_HOME%
echo Adding pre-commit hook...
mkdir .git\hooks\ 2> nul
del /F .git\hooks\pre-commit 2> nul
copy scripts\git\pre-commit-runner.sh .git\hooks\pre-commit
IF NOT ERRORLEVEL 0 GOTO FAIL
echo Done.
:: - - - - - - - - - - - - - -
goto :END
:FAIL
echo Command failed
endlocal
exit /B 1
:END
endlocal

Просмотреть файл

@ -0,0 +1,130 @@
COL_NO="\033[0m" # no color
COL_ERR="\033[1;31m" # light red
COL_H1="\033[1;33m" # yellow
COL_H2="\033[1;36m" # light cyan
header() {
echo -e "${COL_H1}\n### $1 ${COL_NO}\n"
}
announce() {
echo -e "${COL_H2}\n> $1 ${COL_NO}"
}
error() {
echo -e "${COL_ERR}$1 ${COL_NO}"
}
error_and_exit() {
echo -e "${COL_ERR}$1 ${COL_NO}"
exit -1
}
user_exit() {
echo -e "${COL_H2}\nStopped${COL_NO}"
exit -2
}
check_dependencies() {
TEST=$(which jq)
if [[ -z "$TEST" ]]; then
error "ERROR: 'jq' command not found. Install 'jq' first."
error "with debian/ubuntu: apt-get install jq"
error "with homebrew: brew install jq"
exit -1
fi
TEST=$(which az)
if [[ -z "$TEST" ]]; then
error "ERROR: 'az' command not found. Install Azure CLI first."
error "how to: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli"
error "with bash: curl -L https://aka.ms/InstallAzureCli | bash"
exit -1
fi
TEST=$(which azure)
if [[ -z "$TEST" ]]; then
error "ERROR: 'azure' command not found. Install Azure cross-platform CLI first."
error "with npm: npm install -g azure-cli"
error "with homebrew: brew install azure-cli"
exit -1
fi
}
login() {
TEST=$(az account list-locations 2>&1)
if [[ "$?" != "0" ]]; then
header "Azure authentication required"
announce "After the authentication, this machine will be allowed to execute Azure commands on your behalf."
announce "At any moment, you can use 'az logout' to close the authenticated session."
echo
az login
fi
}
show_hub_details() {
header "Azure IoT Hub details"
DATA=$(az iot hub show --name "$2")
echo "Name: $(echo $DATA | jq .name)"
echo "Location: $(echo $DATA | jq .location)"
echo "SKU: $(echo $DATA | jq .sku.name)"
echo "Units: $(echo $DATA | jq .sku.capacity)"
echo "D2C Events endpoint: $(echo $DATA | jq .properties.eventHubEndpoints.events.endpoint)"
echo "D2C Partitions: $(echo $DATA | jq .properties.eventHubEndpoints.events.partitionCount)"
echo "D2C Events retention: $(echo $DATA | jq .properties.eventHubEndpoints.events.retentionTimeInDays) days"
echo "C2D Hostname: $(echo $DATA | jq .properties.hostName)"
echo "C2D Messages retention: $(echo $DATA | jq .properties.cloudToDevice.defaultTtlAsIso8601)"
header "Quota"
DATA=$(az iot hub show-quota-metrics --name "$2")
echo "Messages: $(echo $DATA | jq '.[0].currentValue')/$(echo $DATA | jq '.[0].maxValue')"
echo "Devices: $(echo $DATA | jq '.[1].currentValue')/$(echo $DATA | jq '.[1].maxValue')"
header "Azure IoT Hub keys"
azure iothub key list "$1" "$2"
}
do_select_subscription() {
header "Select subscription"
azure account list
echo
TEMP=""
while [[ -z "$TEMP" ]]; do
echo -n "Enter subscription ID: "
read TEMP
done
azure account set "$TEMP" || error_and_exit "Unable to select the requested subscription."
}
select_subscription() {
header "Azure subscription"
echo -e "Reading account...\n"
TEST0=$(az account list)
TEST1=$(echo $TEST0 | grep isDefault|grep true)
if [[ -z "$TEST1" ]]; then
echo "No subscription selected"
do_select_subscription
else
echo "Current subscription:"
echo $TEST0 | jq '.[] | select(.isDefault == true)' | jq '{name: .name, id: .id, user: .user.name}' | jq .
echo -e "\nDo you want to change to a different subscription?"
PS3=">> "
select YNC in No Yes; do
case $YNC in
Yes ) do_select_subscription; break;;
No ) break;;
esac
done
fi
}

247
scripts/iothub/create-hub.sh Executable file
Просмотреть файл

@ -0,0 +1,247 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
source "$DIR/.functions.sh"
if [[ "$1" == "-a" || "$1" == "--all-options" ]]; then
ADVANCED=true
else
ADVANCED=false
fi
SUBSCRIPTION=""
HUB_NAME=""
RESOURCE_GROUP=""
NEW_RESOURCE_GROUP="false"
LOCATION=""
SKU=""
MAXUNITS=""
UNITS=""
D2C_PARTITIONS=""
D2C_TTL=""
C2D_ATTEMPTS=""
C2D_TTL=""
C2D_FEEDBACK_LOCK=""
C2D_FEEDBACK_TTL=""
C2D_FEEDBACK_ATTEMPTS=""
ask_hub_name() {
header "New Azure IoT Hub"
HUB_NAME=""
while [[ -z "$HUB_NAME" ]]; do
echo -n "Enter IoT Hub name: "
read HUB_NAME
done
}
select_resource_group() {
header "Resource group"
echo "Existing resource groups"
azure group list
echo
announce "You can re-use an existing group or enter a new name to create a new resource group."
echo
RESOURCE_GROUP=""
while [[ -z "$RESOURCE_GROUP" ]]; do
echo -n "Enter resource group name: "
read RESOURCE_GROUP
done
NEW_RESOURCE_GROUP="false"
TEST=$(azure group list | grep -i "$RESOURCE_GROUP")
if [[ -z "$TEST" ]]; then
NEW_RESOURCE_GROUP="true"
fi
}
select_location() {
header "Azure region"
# TODO: az account list-locations + filter for IoT Hub
echo -e "Select the location where to create the hub:"
PS3=">> "
select LOCATION in eastus westus westus2 westcentralus northeurope westeurope eastasia southeastasia japaneast japanwest australiaeast australiasoutheast; do
break;
done
}
select_sku_and_units() {
header "Pricing and Scale Tier"
echo "F1: 8k messages/unit/day (free)"
echo "S1: 400k messages/unit/day"
echo "S2: 6M messages/unit/day"
echo "S3: 300M messages/unit/day"
echo -e "\nSelect pricing and scale:"
PS3=">> "
select SKU in F1 S1 S2 S3; do
case $SKU in
F1 ) MAXUNITS=1; break;;
S1 ) MAXUNITS=200; break;;
S2 ) MAXUNITS=200; break;;
S3 ) MAXUNITS=10; break;;
esac
done
UNITS="1"
if [[ "$SKU" != "F1" ]]; then
echo -n -e "\nHow many units? (1..${MAXUNITS}) [${UNITS}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then UNITS="$TEMP"; fi
fi
}
ask_d2c_partitions() {
D2C_PARTITIONS="2" # 2..128 (2 for F1)
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
if [[ "$SKU" != "F1" ]]; then
echo -n "How many partitions? (1..128) [${D2C_PARTITIONS}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then D2C_PARTITIONS="$TEMP"; fi
fi
}
ask_d2c_retention() {
D2C_TTL="1" # 1..7 days
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How many days before device-to-cloud messages expire? (1..7) [${D2C_TTL}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then D2C_TTL="$TEMP"; fi
}
ask_c2d_attempts() {
C2D_ATTEMPTS="10" # 1..100 count
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How many attempts to deliver a cloud-to-device message? (1..100) [${C2D_ATTEMPTS}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then C2D_ATTEMPTS="$TEMP"; fi
}
ask_c2d_ttl() {
# PnYnMnDTnHnMnS
C2D_TTL="PT1H" # 1 min .. 2 days
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How long before cloud-to-device messages expire? (ISO8601: 1 min .. 2 days) [${C2D_TTL}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then C2D_TTL="$TEMP"; fi
}
ask_c2d_feedback_lock() {
# PnYnMnDTnHnMnS
C2D_FEEDBACK_LOCK="PT1M" # 5 secs .. 5 mins
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How long before cloud-to-device feedback messages lock expire? (ISO8601: 5 secs .. 5 mins) [${C2D_FEEDBACK_LOCK}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then C2D_FEEDBACK_LOCK="$TEMP"; fi
}
ask_c2d_feedback_ttl() {
# PnYnMnDTnHnMnS
C2D_FEEDBACK_TTL="PT1M" # 1 min .. 2days
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How long before cloud-to-device feedback messages expire? (ISO8601: 1 min .. 2days) [${C2D_FEEDBACK_TTL}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then C2D_FEEDBACK_TTL="$TEMP"; fi
}
ask_c2d_feedback_attempts() {
C2D_FEEDBACK_ATTEMPTS="1" # 1..100 count
if [[ "$ADVANCED" == "false" ]]; then return 0; fi
echo -n "How many attempts to deliver a cloud-to-device feedback message? (1..100) [${C2D_FEEDBACK_ATTEMPTS}]: "
read TEMP
if [[ ! -z "$TEMP" ]]; then C2D_FEEDBACK_ATTEMPTS="$TEMP"; fi
}
advanced() {
if [[ "$ADVANCED" == "true" ]]; then
header "Other settings";
else
announce "Using default settings. Use '--all-options' to manually set all the hub options."
fi
ask_d2c_partitions
ask_d2c_retention
ask_c2d_attempts
ask_c2d_ttl
ask_c2d_feedback_lock
ask_c2d_feedback_ttl
ask_c2d_feedback_attempts
}
create_hub() {
header "Create '$HUB_NAME' in '$LOCATION'"
if [[ $NEW_RESOURCE_GROUP == "true" ]]; then
azure group create "$RESOURCE_GROUP" "$LOCATION" || error_and_exit "Unable to create resource group."
fi
azure iothub create "$RESOURCE_GROUP" "$HUB_NAME" "$LOCATION" "$SKU" "$UNITS" \
--enable-dm \
--d2c-partitions "$D2C_PARTITIONS" \
--d2c-retention-time-in-days "$D2C_TTL" \
--c2d-max-delivery-count "$C2D_ATTEMPTS" \
--c2d-ttl "$C2D_TTL" \
--feedback-lock-duration "$C2D_FEEDBACK_LOCK" \
--feedback-ttl "$C2D_FEEDBACK_TTL" \
--feedback-max-delivery-count "$C2D_FEEDBACK_ATTEMPTS" \
|| error_and_exit "Unable to create IoT Hub"
}
confirm() {
header "Summary"
echo "Azure IoT Hub name: ${HUB_NAME}"
echo "Resource group name: ${RESOURCE_GROUP} (new: ${NEW_RESOURCE_GROUP})"
echo "Azure region: ${LOCATION}"
echo "Pricing and Scaling SKU ${SKU}"
echo "Capacity units: ${UNITS}"
echo "D2C events partitions: ${D2C_PARTITIONS}"
echo "D2C events TTL: ${D2C_TTL} days"
echo "C2D messages TTL: ${C2D_TTL}"
echo "C2D message delivery attempts: ${C2D_ATTEMPTS}"
echo "C2D feedback TTL: ${C2D_FEEDBACK_TTL}"
echo "C2D feedback delivery attempts: ${C2D_FEEDBACK_ATTEMPTS}"
echo "C2D feedback lock TTL: ${C2D_FEEDBACK_LOCK}"
echo
echo "Proceed?"
PS3=">> "
select SKU in Yes No; do
case $SKU in
No ) user_exit;;
Yes ) break;;
esac
done
}
main() {
check_dependencies
login
ask_hub_name
select_subscription
select_resource_group
select_location
select_sku_and_units
advanced
confirm
create_hub
show_hub_details "$RESOURCE_GROUP" "$HUB_NAME"
announce "Tip: to show the hub details, run: ./show-hub.sh $RESOURCE_GROUP $HUB_NAME"
}
main

15
scripts/iothub/list-hubs.sh Executable file
Просмотреть файл

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
source "$DIR/.functions.sh"
main() {
check_dependencies
login
header "Azure IoT Hubs in the current subscription"
az iot hub list | jq '.[] | {name: .name, resourcegroup: .resourcegroup, location: .location, subscription: .subscriptionid}' | jq .
}
main

Просмотреть файл

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
source "$DIR/.functions.sh"
main() {
check_dependencies
login
header "Azure subscriptions"
azure account list
#az account list | jq '.[] | {name: .name, id: .id, current: .isDefault}' | jq .
}
main

Просмотреть файл

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
source "$DIR/.functions.sh"
SUBSCRIPTION_ID="$1"
check_input() {
if [[ -z "$SUBSCRIPTION_ID" ]]; then
announce "Usage: ./select-subscription.sh SUBSCRIPTION_ID"
echo "Use './list-subscriptions.sh' to see the list of subscriptions."
fi
}
main() {
check_input
check_dependencies
login
if [[ ! -z "$SUBSCRIPTION_ID" ]]; then
header "Changing current subscription"
#az account set --subscription "$SUBSCRIPTION_ID"
azure account set "$SUBSCRIPTION_ID"
else
select_subscription
fi
}
main

25
scripts/iothub/show-hub.sh Executable file
Просмотреть файл

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
source "$DIR/.functions.sh"
RESOURCE_GROUP="$1"
HUB_NAME="$2"
check_input() {
if [[ -z "$RESOURCE_GROUP" || -z "$HUB_NAME" ]]; then
announce "Usage: ./show-hub.sh RESOURCE_GROUP HUB_NAME"
echo "Use './list-hubs.sh' to see the list of hubs."
exit -1
fi
}
main() {
check_input
check_dependencies
login
show_hub_details "$RESOURCE_GROUP" "$HUB_NAME"
}
main

17
scripts/run Executable file
Просмотреть файл

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Debug|Release
CONFIGURATION=Release
set -e
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
cd $APP_HOME
echo "Building..."
nuget restore
msbuild /m /p:Configuration=$CONFIGURATION /verbosity:quiet
echo "Starting web service..."
cd $APP_HOME/WebService/bin/$CONFIGURATION/
mono Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.exe

31
scripts/run.cmd Normal file
Просмотреть файл

@ -0,0 +1,31 @@
@ECHO off
setlocal
:: Debug|Release
SET CONFIGURATION=Release
:: strlen("\scripts\") => 9
SET APP_HOME=%~dp0
SET APP_HOME=%APP_HOME:~0,-9%
cd %APP_HOME%
call nuget restore
IF NOT ERRORLEVEL 0 GOTO FAIL
call msbuild /m /p:Configuration=%CONFIGURATION%;Platform="Any CPU"
IF NOT ERRORLEVEL 0 GOTO FAIL
copy .\scripts\run.vbs .\WebService\bin\%CONFIGURATION%
cd WebService\bin\%CONFIGURATION%
call cscript run.vbs "Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.exe"
:: - - - - - - - - - - - - - -
goto :END
:FAIL
echo Command failed
endlocal
exit /B 1
:END
endlocal

2
scripts/run.vbs Normal file
Просмотреть файл

@ -0,0 +1,2 @@
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute WScript.Arguments(0), "", "", "runas", 1