{"id":18734624,"url":"https://github.com/brandonc/statemachine","last_synced_at":"2025-04-12T19:11:03.200Z","repository":{"id":136722280,"uuid":"1899149","full_name":"brandonc/statemachine","owner":"brandonc","description":"A simple, templated state machine class for .net","archived":false,"fork":false,"pushed_at":"2011-06-17T23:36:19.000Z","size":101,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T13:21:33.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-06-15T08:53:21.000Z","updated_at":"2020-08-31T14:36:26.000Z","dependencies_parsed_at":"2023-07-16T00:46:58.899Z","dependency_job_id":null,"html_url":"https://github.com/brandonc/statemachine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonc%2Fstatemachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonc%2Fstatemachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonc%2Fstatemachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonc%2Fstatemachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonc","download_url":"https://codeload.github.com/brandonc/statemachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618277,"owners_count":21134200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-07T15:14:21.635Z","updated_at":"2025-04-12T19:11:03.178Z","avatar_url":"https://github.com/brandonc.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# statemachine\n\n\u003e A simple, templated state machine class for c#\n\n## Example ##\n\n    public enum OrderState\n    {\n        Created,\n        Ordered,\n        Cancelled,\n        Preparing,\n        Shipped\n    };\n\n    public class Order\n    {\n        public StateMachine\u003cOrderState\u003e Status { get; set; }\n\n        public void Complete()\n        {\n            this.Status.State = OrderState.Ordered;\n        }\n\n        public void Cancel()\n        {\n            this.Status.State = OrderState.Cancelled;\n        }\n\n        public void Prepare()\n        {\n            this.Status.State = OrderState.Preparing;\n        }\n\n        public void Ship()\n        {\n            this.Status.State = OrderState.Shipped;\n        }\n\n        public Order()\n        {\n            // You could also subclass StateMachine\u003cT\u003e and encapsulate these details\n            Status = new StateMachine\u003cOrderState\u003e(OrderState.Created);\n            \n            // Only transitions defined here are valid. Alternatively, you could call\n            // ValidAny() to allow all state transitions\n            Status.Valid(OrderState.Created,   OrderState.Ordered);\n            Status.Valid(OrderState.Ordered,   new[] { OrderState.Cancelled, OrderState.Preparing });\n            Status.Valid(OrderState.Preparing, OrderState.Shipped);\n\n            // Enter transition events\n            Status.DoWhenAny((status) =\u003e\n            {\n                // Useful for writing a transition history log\n                Debug.WriteLine(\"[{0}] Order Status =\u003e {1}\", (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds, status);\n            });\n\n            // Or DoFollowingAny() for exit transitions\n        }\n    }\n\n## Dynamic Events ##\n\t\nIf you're using .net 4.0, you can use dynamic binding in the style of rails:\n\n\tStatus.Transitions.Enter_Shipped((Action)delegate()\n    {\n\t\tDebug.WriteLine(\"Order Shipped!\");\n    });\n\n\tStatus.Transitions.Exit_Ordered((Action)delegate()\n    {\n\t\tDebug.WriteLine(\"Order Processed!\");\n    });","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonc%2Fstatemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonc%2Fstatemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonc%2Fstatemachine/lists"}