{"id":47724278,"url":"https://github.com/tofupilot/csharp","last_synced_at":"2026-04-07T01:00:32.882Z","repository":{"id":348282892,"uuid":"1197241668","full_name":"tofupilot/csharp","owner":"tofupilot","description":"Upload hardware test data to TofuPilot from C#.","archived":false,"fork":false,"pushed_at":"2026-04-02T11:36:34.000Z","size":248,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-03T22:33:55.562Z","etag":null,"topics":["csharp","dotnet","functional","hardware","testing","tofupilot"],"latest_commit_sha":null,"homepage":"https://tofupilot.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tofupilot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-31T12:38:35.000Z","updated_at":"2026-04-02T11:36:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tofupilot/csharp","commit_stats":null,"previous_names":["tofupilot/csharp-client"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tofupilot/csharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofupilot%2Fcsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofupilot%2Fcsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofupilot%2Fcsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofupilot%2Fcsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tofupilot","download_url":"https://codeload.github.com/tofupilot/csharp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofupilot%2Fcsharp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31418286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","functional","hardware","testing","tofupilot"],"created_at":"2026-04-02T20:05:06.309Z","updated_at":"2026-04-04T23:00:36.661Z","avatar_url":"https://github.com/tofupilot.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TofuPilot C# Client\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![.NET](https://img.shields.io/badge/.NET-8.0-512BD4)](https://dotnet.microsoft.com/)\n[![Tests](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/upview/3c4792a8e7e8e8d0b37e141e95cc885e/raw/csharp-client-tests.json)](https://github.com/tofupilot/csharp)\n\nThe official C# client for [TofuPilot](https://tofupilot.com). Integrate your hardware test runs into one app with just a few lines of C#.\n\n## Installation\n\nAdd a project reference:\n\n```bash\ndotnet add reference path/to/TofuPilot.csproj\n```\n\n## Quick Start\n\n```csharp\nusing TofuPilot;\nusing TofuPilot.Models.Requests;\n\nvar client = new TofuPilot(apiKey: Environment.GetEnvironmentVariable(\"TOFUPILOT_API_KEY\")!);\n\nvar run = await client.Runs.CreateAsync(new RunCreateRequest\n{\n    ProcedureId = \"your-procedure-id\",\n    SerialNumber = \"SN001\",\n    PartNumber = \"PN001\",\n    Outcome = RunCreateOutcome.Pass,\n    StartedAt = DateTime.UtcNow.AddMinutes(-5),\n    EndedAt = DateTime.UtcNow,\n});\n\nConsole.WriteLine($\"Run created: {run.Id}\");\n```\n\nAll async methods support `CancellationToken`:\n\n```csharp\nusing var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));\nvar run = await client.Runs.CreateAsync(request, cts.Token);\n```\n\n## Authentication\n\nSet your API key as an environment variable:\n\n```bash\nexport TOFUPILOT_API_KEY=\"your-api-key\"\n```\n\nOr pass it directly:\n\n```csharp\nvar client = new TofuPilot(apiKey: \"your-api-key\");\n```\n\nTo point to a different server (e.g. self-hosted):\n\n```csharp\nvar client = new TofuPilot(\n    apiKey: \"your-api-key\",\n    serverUrl: \"https://your-instance.com/api\"\n);\n```\n\n### Custom certificates\n\n```csharp\nusing System.Security.Cryptography.X509Certificates;\nusing TofuPilot.Utils;\n\nvar handler = new HttpClientHandler();\nhandler.ClientCertificates.Add(new X509Certificate2(\"client.pfx\", \"password\"));\n\nvar client = new TofuPilot(\n    apiKey: \"your-api-key\",\n    client: new TofuPilotHttpClient(handler)\n);\n```\n\n## Available Resources\n\n| Resource | Operations |\n|----------|-----------|\n| `client.Runs` | List, Create, Get, Delete, Update |\n| `client.Units` | List, Create, Get, Delete, Update, AddChild, RemoveChild |\n| `client.Parts` | List, Create, Get, Delete, Update |\n| `client.Parts.Revisions` | Create, Get, Delete, Update |\n| `client.Procedures` | List, Create, Get, Delete, Update |\n| `client.Procedures.Versions` | Create, Get, Delete |\n| `client.Batches` | List, Create, Get, Delete, Update |\n| `client.Stations` | List, Create, Get, GetCurrent, Remove, Update |\n| `client.Attachments` | Initialize, Finalize, Delete |\n| `client.User` | List |\n\n## Usage Examples\n\n### Create a run with measurements\n\n```csharp\nvar run = await client.Runs.CreateAsync(new RunCreateRequest\n{\n    ProcedureId = procedureId,\n    SerialNumber = \"SN-001\",\n    PartNumber = \"PCB-V1\",\n    Outcome = RunCreateOutcome.Pass,\n    StartedAt = DateTime.UtcNow.AddMinutes(-5),\n    EndedAt = DateTime.UtcNow,\n    Phases = new List\u003cRunCreatePhases\u003e\n    {\n        new()\n        {\n            Name = \"Voltage Test\",\n            Outcome = RunCreatePhasesOutcome.Pass,\n            StartedAt = DateTime.UtcNow.AddMinutes(-5),\n            EndedAt = DateTime.UtcNow,\n            Measurements = new List\u003cRunCreateMeasurements\u003e\n            {\n                new()\n                {\n                    Name = \"Output Voltage\",\n                    Outcome = RunCreateMeasurementsOutcome.Pass,\n                    MeasuredValue = 3.3,\n                    Units = new RunCreateUnits { Value = \"V\" },\n                    Validators = new List\u003cRunCreateValidators\u003e\n                    {\n                        new() { Operator = \"\u003e=\", ExpectedValue = RunCreateExpectedValue.CreateNumber(3.0) },\n                        new() { Operator = \"\u003c=\", ExpectedValue = RunCreateExpectedValue.CreateNumber(3.6) },\n                    },\n                },\n            },\n        },\n    },\n});\n```\n\n### List and filter runs\n\n```csharp\nvar result = await client.Runs.ListAsync(\n    partNumbers: new List\u003cstring\u003e { \"PCB-V1\" },\n    outcomes: new List\u003cRunListQueryParamOutcome\u003e { RunListQueryParamOutcome.Pass },\n    limit: 10\n);\n\nforeach (var run in result.Data)\n    Console.WriteLine($\"{run.Id} — {run.Unit.SerialNumber}\");\n```\n\n### Manage units and sub-units\n\n```csharp\n// Create part and revision\nawait client.Parts.CreateAsync(new PartCreateRequest { Number = \"PCB-V1\", Name = \"Main Board\" });\nawait client.Parts.Revisions.CreateAsync(\"PCB-V1\", new PartCreateRevisionRequestBody { Number = \"REV-A\" });\n\n// Create units\nawait client.Units.CreateAsync(new UnitCreateRequest\n{\n    SerialNumber = \"PARENT-001\",\n    PartNumber = \"PCB-V1\",\n    RevisionNumber = \"REV-A\",\n});\nawait client.Units.CreateAsync(new UnitCreateRequest\n{\n    SerialNumber = \"CHILD-001\",\n    PartNumber = \"PCB-V1\",\n    RevisionNumber = \"REV-A\",\n});\n\n// Link parent-child\nawait client.Units.AddChildAsync(\"PARENT-001\", new UnitAddChildRequestBody\n{\n    ChildSerialNumber = \"CHILD-001\",\n});\n```\n\n### Upload and download attachments\n\n```csharp\n// Upload a file (one line)\nvar attachmentId = await client.Attachments.UploadAsync(\"report.pdf\");\n\n// Link to a run\nawait client.Runs.UpdateAsync(runId, new RunUpdateRequestBody\n{\n    Attachments = new List\u003cstring\u003e { attachmentId },\n});\n\n// Download an attachment\nawait client.Attachments.DownloadAsync(downloadUrl, \"local-copy.pdf\");\n```\n\n## Error Handling\n\nAPI errors throw typed exceptions:\n\n```csharp\nusing TofuPilot.Models.Errors;\n\ntry\n{\n    await client.Runs.GetAsync(\"nonexistent-id\");\n}\ncatch (NotFoundException ex)\n{\n    Console.WriteLine($\"Not found: {ex.Message}\");\n}\ncatch (BadRequestException ex)\n{\n    Console.WriteLine($\"Bad request: {ex.Message}\");\n}\ncatch (ApiException ex)\n{\n    Console.WriteLine($\"API error {ex.StatusCode}: {ex.Body}\");\n}\n```\n\n| Exception | Status Code |\n|-----------|------------|\n| `BadRequestException` | 400 |\n| `UnauthorizedException` | 401 |\n| `ForbiddenException` | 403 |\n| `NotFoundException` | 404 |\n| `ConflictException` | 409 |\n| `UnprocessableContentException` | 422 |\n| `InternalServerErrorException` | 500 |\n| `ApiException` | Any other |\n\n## Running Tests\n\n```bash\ncd clients/csharp/tests\n# Create .env.local with your API key and URL:\n# TOFUPILOT_URL=http://localhost:3000\n# TOFUPILOT_API_KEY_USER=your-api-key\ndotnet test\n```\n\n## Documentation\n\n- [Getting Started](https://tofupilot.com/docs/dashboard)\n- [API Reference](https://tofupilot.com/docs/dashboard/api/v2)\n- [Changelog](https://tofupilot.com/changelog)\n\n## Acknowledgments\n\nThis package builds on the original C# client created by [@Hylaean](https://github.com/Hylaean) (versions 1.x).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftofupilot%2Fcsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftofupilot%2Fcsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftofupilot%2Fcsharp/lists"}