Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void LoadTripsWithPlannedVisits()
.ToDictionary(
tripId => tripId,
tripId => plannedVisitsWithStartTimes
.Where(v => tripId == v.FieldTrip.Id && IsCandidateVisit(v))
.Where(v => IsCandidateVisit(v) && tripId == v.FieldTrip.Id)
.ToList());

var items = tripsWithPlannedVisits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.405.0")]
[assembly: AssemblyFileVersion("1.0.405.0")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.IO;
using System.Reflection;

namespace ExcelToCSVProcessor
{
public class EmbeddedResource
{
public static byte[] LoadEmbeddedResource(string path)
{
// ReSharper disable once PossibleNullReferenceException
var resourceName = $"{MethodBase.GetCurrentMethod().DeclaringType.Namespace}.{path.Replace('\\', '.')}";

using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream == null)
throw new ExpectedException($"Can't load '{resourceName}' as embedded resource.");

using (var reader = new BinaryReader(stream))
{
return reader.ReadBytes((int)stream.Length);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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>{E921CFC6-AE8A-48C7-8B14-4DD3F3EA2306}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ExcelToCSVProcessor</RootNamespace>
<AssemblyName>ExcelToCSVProcessor</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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="ExcelDataReader, Version=3.6.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDataReader.3.6.0\lib\net45\ExcelDataReader.dll</HintPath>
</Reference>
<Reference Include="ExcelDataReader.DataSet, Version=3.6.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDataReader.DataSet.3.6.0\lib\net35\ExcelDataReader.DataSet.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Interfaces.5.8.0\lib\net45\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Logging.Log4Net, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Logging.Log4Net.5.8.0\lib\net45\ServiceStack.Logging.Log4Net.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.5.8.0\lib\net45\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.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="EmbeddedResource.cs" />
<Compile Include="ExpectedException.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TableExtension.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<EmbeddedResource Include="log4net.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ExcelToCSVProcessor
{
public class ExpectedException : Exception
{
public ExpectedException(string message)
: base(message)
{
}
}
}
97 changes: 97 additions & 0 deletions TimeSeries/PublicApis/SdkExamples/ExcelToCSVProcessor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceStack.Logging.Log4Net;
using log4net;
using System.IO;
using System.Xml;
using System.Reflection;
using ExcelDataReader;
using ServiceStack;
using System.Data;

namespace ExcelToCSVProcessor
{
internal class Program
{
private static ILog Log = null;

static void Main(string[] args)
{
bool debug = false;
Environment.ExitCode = 1;

try
{
debug = args.Length == 1 && string.Compare(args[0], "DEBUG", true) == 0;

ConfigureLogging();

using (Stream stdin = Console.OpenStandardInput())
{
using (Stream stdout = Console.OpenStandardOutput())
{
using (MemoryStream memoryStream = new MemoryStream())
{
stdin.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

using (var reader = ExcelReaderFactory.CreateReader(memoryStream))
{
var spreadsheet = reader.AsDataSet();
var table = spreadsheet.Tables[0];

var worksheetColumn = new DataColumn() { DefaultValue = table.TableName };
table.Columns.Add(worksheetColumn);
worksheetColumn.SetOrdinal(0);
table.Rows[0][worksheetColumn] = "#SheetName#";

var csv = table.ToCSV();
var bytes = Encoding.UTF8.GetBytes(csv);

if (debug)
foreach (var row in table.ToCSVArray())
Log?.Info(row);

stdout.Write(bytes, 0, bytes.Length);
if (debug)
Log?.Info($"Total row count(DEBUG): {table.Rows.Count}, Columns: {table.ColumnsToCSV()}");
else
Log?.Info($"Total row count: {table.Rows.Count}, Columns: {table.ColumnsToCSV()}");
}
}
}
}

Environment.ExitCode = 0;
}
catch (Exception ex)
{
Log?.Fatal(ex);
Console.WriteLine(ex.ToString());
}
finally
{
LogManager.Flush(5000);
}
}

private static void ConfigureLogging()
{
using (var stream = new MemoryStream(EmbeddedResource.LoadEmbeddedResource("log4net.config")))
using (var reader = new StreamReader(stream))
{
var xml = new XmlDocument();
xml.LoadXml(reader.ReadToEnd());

log4net.Config.XmlConfigurator.Configure(xml.DocumentElement);

Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

ServiceStack.Logging.LogManager.LogFactory = new Log4NetFactory();
}
}
}
}
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;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ExcelToCSVProcessor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExcelToCSVProcessor")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e921cfc6-ae8a-48c7-8b14-4dd3f3ea2306")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading