Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
MyUncleSam committed Aug 7, 2017
0 parents commit 5916bc0
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 0 deletions.
Binary file added .vs/TeamviewerExporter/v15/.suo
Binary file not shown.
22 changes: 22 additions & 0 deletions TeamviewerExporter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamviewerExporter", "TeamviewerExporter\TeamviewerExporter.csproj", "{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions TeamviewerExporter/Devices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TeamviewerExporter
{
public class Device
{
public string remotecontrol_id { get; set; }
public string device_id { get; set; }
public string alias { get; set; }
public string groupid { get; set; }
public string online_state { get; set; }
public bool assigned_to { get; set; }
public string supported_features { get; set; }
public string description { get; set; }

public string remotecontrol_id_clean { get; set; }
public string groupname { get; set; }
}

public class Devices
{
public List<Device> devices { get; set; }
}
}
47 changes: 47 additions & 0 deletions TeamviewerExporter/ExportToRdm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CsvHelper.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TeamviewerExporter
{
public class ExportToRdm
{
public ExportToRdm()
{
ConnectionType = "TeamViewer";
//OpenEmbedded = false;
//UserName = Environment.UserName;

if(!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportDefaultPassword))
{
TeamViewer_Password = Properties.Settings.Default.ImportDefaultPassword;
}
}

public string Host { get; set; }
public string Name { get; set; }
public string ConnectionType { get; set; }
public string Group { get; set; }
public string Description { get; set; }
//public bool OpenEmbedded { get; set; }
//public string UserName { get; set; }
//public string Domain { get; set; }
public string TeamViewer_Password { get; set; }
public string TeamViewer_ID { get; set; }
}

public sealed class MapClass : CsvClassMap<ExportToRdm>
{
/// <summary>
/// this mapping class is needed to overwrite header names to the needed ones from remotedesktopmanager
/// </summary>
public MapClass()
{
base.AutoMap();
Map(m => m.TeamViewer_ID).Name(@"TeamViewer\ID");
Map(m => m.TeamViewer_Password).Name(@"TeamViewer\Password");
}
}
}
19 changes: 19 additions & 0 deletions TeamviewerExporter/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TeamviewerExporter
{
public class Group
{
public string id { get; set; }
public string name { get; set; }
public string permissions { get; set; }
}

public class Groups
{
public List<Group> groups { get; set; }
}
}
119 changes: 119 additions & 0 deletions TeamviewerExporter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using CsvHelper;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TeamviewerExporter
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Connecting to teamviewer web api ...");
RestClient client = new RestClient(Properties.Settings.Default.BaseUrl);

Console.WriteLine("Getting device list...");
RestRequest requestDevices = new RestRequest(Properties.Settings.Default.DevicesUrlPart, Method.GET);
requestDevices.AddHeader("Authorization", string.Format("Bearer {0}", Properties.Settings.Default.AuthorizationToken));
IRestResponse<TeamviewerExporter.Devices> responseDevices = client.Execute<TeamviewerExporter.Devices>(requestDevices);

Console.WriteLine("Getting groups list...");
RestRequest requestGroups = new RestRequest(Properties.Settings.Default.GroupsUrlPart, Method.GET);
requestGroups.AddHeader("Authorization", string.Format("Bearer {0}", Properties.Settings.Default.AuthorizationToken));
IRestResponse<Groups> responseGroups = client.Execute<Groups>(requestGroups);

Console.WriteLine(string.Format("Got {0} entries and {1} groups.", responseDevices.Data.devices.Count, responseGroups.Data.groups.Count));

Console.WriteLine("Adding information to original entries...");

for (int i = 0; i < responseDevices.Data.devices.Count; i++)
{
// set cleaned teamviewer id
if(char.IsLetter(responseDevices.Data.devices[i].remotecontrol_id[0]))
{
responseDevices.Data.devices[i].remotecontrol_id_clean = responseDevices.Data.devices[i].remotecontrol_id.Substring(1);
}
else
{
responseDevices.Data.devices[i].remotecontrol_id_clean = responseDevices.Data.devices[i].remotecontrol_id;
}

// write group name
Group inGroup = responseGroups.Data.groups.FirstOrDefault(w => w.id == responseDevices.Data.devices[i].groupid);
if(inGroup != null)
{
responseDevices.Data.devices[i].groupname = inGroup.name;
}
}

Console.WriteLine("Writing json object to csv file 'original.csv'");
//TextWriter tw = File.CreateText("original.csv");

TextWriter tw = new StreamWriter("original.csv", false, Encoding.UTF8);

CsvWriter csv = new CsvWriter(tw);
csv.WriteRecords(responseDevices.Data.devices);
csv.Dispose();

Console.WriteLine("Wrote original csv file - starting to write RDM import csv.");

List<ExportToRdm> erdm = new List<ExportToRdm>();
foreach (TeamviewerExporter.Device dev in responseDevices.Data.devices)
{
ExportToRdm toAdd = new ExportToRdm();
toAdd.Description = dev.description;
toAdd.Name = dev.alias;
toAdd.TeamViewer_ID = dev.remotecontrol_id_clean;
toAdd.Host = toAdd.TeamViewer_ID;

if(dev.groupname != null)
{
toAdd.Group = dev.groupname;
}

erdm.Add(toAdd);
}

Console.WriteLine("Writing RDM compatible import file 'rdm.csv'");
//xtWriter rtw = File.CreateText("rdm.csv");
TextWriter rtw = new StreamWriter("rdm.csv", false, Encoding.UTF8);
CsvWriter rcsv = new CsvWriter(rtw);
rcsv.Configuration.RegisterClassMap(typeof(MapClass)); // add custom mapping for headlines
rcsv.WriteRecords(erdm); // write complete object to disc as csv
rcsv.Dispose();

Console.WriteLine("Successfully wrote 'rdm.csv' - application finished successfully");
}
catch(Exception ex)
{
Console.WriteLine();
Console.WriteLine(string.Format("SOMETHING HAPPENED{0}{1}", Environment.NewLine, ex.ToString()));
}
finally
{
Console.WriteLine("Press any enter to exit :-)");
Console.ReadLine();
}
}
}

public class EncodingStringWriter : StringWriter
{
private readonly Encoding _encoding;

public EncodingStringWriter(StringBuilder builder, Encoding encoding) : base(builder)
{
_encoding = encoding;
}

public override Encoding Encoding
{
get { return _encoding; }
}
}
}
36 changes: 36 additions & 0 deletions TeamviewerExporter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("TeamviewerExporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TeamviewerExporter")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("d08a2a84-18da-4c00-ba0a-aa73188e0e3b")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
71 changes: 71 additions & 0 deletions TeamviewerExporter/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions TeamviewerExporter/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="TeamviewerExporter.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="AuthorizationToken" Type="System.String" Scope="Application">
<Value Profile="(Default)">1863152-yCthX3KSfWLFJKuT9xMP</Value>
</Setting>
<Setting Name="BaseUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://webapi.teamviewer.com</Value>
</Setting>
<Setting Name="DevicesUrlPart" Type="System.String" Scope="Application">
<Value Profile="(Default)">/api/v1/devices</Value>
</Setting>
<Setting Name="ImportDefaultPassword" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="GroupsUrlPart" Type="System.String" Scope="Application">
<Value Profile="(Default)">/api/v1/groups</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 5916bc0

Please sign in to comment.