├── .gitignore
├── LICENSE
├── README.md
├── images
├── net-iron-c.png
├── net-iron-core.png
├── net-iron-mq.png
├── net-iron-w.png
└── products.png
└── src
├── Demo.IronSharp
├── App.config
├── Demo.IronSharp.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Tests
│ ├── IntegrationTests.cs
│ └── LongRunningIntegrationTests.cs
└── packages.config
├── IronSharp.Core
├── Abstract
│ ├── IIdCollection.cs
│ ├── IInspectable.cs
│ ├── IIronSharpConfig.cs
│ ├── IMsg.cs
│ ├── IPagingFilter.cs
│ ├── IRequestHelpersContainer.cs
│ ├── IRestClientRequest.cs
│ ├── ITokenContainer.cs
│ └── IValueSerializer.cs
├── Attributes
│ └── QueueNameAttribute.cs
├── Config
│ ├── HttpClientOptions.cs
│ ├── IronClientConfig.cs
│ ├── IronDotConfigManager.cs
│ ├── IronSharpConfig.cs
│ └── KeystoneClientConfig.cs
├── Constants
│ ├── AuthHeaderLocation.cs
│ └── IronProduct.cs
├── Content
│ ├── iron.json
│ └── web.config.transform
├── DateTimeHelpers.cs
├── DefaultValueSerializer.cs
├── Exceptions
│ ├── IronSharpException.cs
│ ├── MaximumRetryAttemptsExceededException.cs
│ └── RestResponseException.cs
├── ExponentialBackoff.cs
├── Extensions
│ ├── ExtensionsForDictionary.cs
│ ├── ExtensionsForIInspectable.cs
│ ├── ExtensionsForIMsg.cs
│ └── ExtensionsForString.cs
├── IronSharp.Core.csproj
├── IronSharp.Core.csproj.DotSettings
├── IronSharp.Core.nuspec
├── JSON.cs
├── JsonContent.cs
├── MqRestClient.cs
├── Properties
│ └── AssemblyInfo.cs
├── RestClient.cs
├── Types
│ ├── HttpRequestMessageBuilder.cs
│ ├── IronTokenContainer.cs
│ ├── Keystone.cs
│ ├── KeystoneContainer.cs
│ ├── PagingFilter.cs
│ ├── ResponseMsg.cs
│ ├── RestClientRequest.cs
│ └── RestResponse.cs
└── packages.config
├── IronSharp.Extras.ProtoBufSerializers
├── ExtensionsForISharpConfig.cs
├── IronSharp.Extras.ProtoBufSerializers.csproj
├── ModelSerializerContext.cs
├── Properties
│ └── AssemblyInfo.cs
├── ProtoBufConfig.cs
├── ProtoBufValueSerializer.cs
└── packages.config
├── IronSharp.Extras.ServiceStackSerializers
├── ExtensionsForISharpConfig.cs
├── IronSharp.Extras.ServiceStackSerializers.2013.10.55.845.nupkg
├── IronSharp.Extras.ServiceStackSerializers.csproj
├── IronSharp.Extras.ServiceStackSerializers.nuspec
├── Properties
│ └── AssemblyInfo.cs
├── ServiceStackJsonSerializer.cs
├── ServiceStackTypeSerializer.cs
├── ServiceStackXmlSerializer.cs
└── packages.config
├── IronSharp.IronCache
├── CacheClient.cs
├── CacheIncrementResult.cs
├── CacheInfo.cs
├── CacheItem.cs
├── CacheItemOptions.cs
├── Client.cs
├── IronCacheCloudHosts.cs
├── IronCacheRestClient.cs
├── IronSharp.IronCache.csproj
├── IronSharp.IronCache.nuspec
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── IronSharp.IronMQ
├── Alert.cs
├── AlertCollection.cs
├── AlertDirection.cs
├── AlertType.cs
├── Client.cs
├── IronMqCloudHosts.cs
├── IronMqRestClient.cs
├── IronSharp.IronMQ.csproj
├── IronSharp.IronMQ.nuspec
├── MessageCollection.cs
├── MessageContainer.cs
├── MessageIdCollection.cs
├── MessageIdContainer.cs
├── MessageOptions.cs
├── MqPagingFilter.cs
├── Properties
│ └── AssemblyInfo.cs
├── PushInfo.cs
├── PushStatus.cs
├── PushType.cs
├── QueueClient.cs
├── QueueContainer.cs
├── QueueDeadletterInfo.cs
├── QueueInfo.cs
├── QueueMessage.cs
├── QueueMessageContext.cs
├── QueuesInfo.cs
├── ReservedMessageIdCollection.cs
├── Subscriber.cs
├── SubscriberCollection.cs
└── packages.config
├── IronSharp.IronWorker
├── Client.cs
├── Code
│ ├── CodeClient.cs
│ ├── CodeInfo.cs
│ ├── CodeInfoCollection.cs
│ ├── RevisionCollection.cs
│ └── WorkerOptions.cs
├── IronSharp.IronWorker.csproj
├── IronSharp.IronWorker.csproj.DotSettings
├── IronSharp.IronWorker.nuspec
├── IronWorkCloudHosts.cs
├── IronWorkerRestClient.cs
├── PriorityOption.cs
├── Properties
│ └── AssemblyInfo.cs
├── Schedules
│ ├── ScheduleBuilder.cs
│ ├── ScheduleClient.cs
│ ├── ScheduleIdCollection.cs
│ ├── ScheduleInfo.cs
│ ├── ScheduleInfoCollection.cs
│ ├── ScheduleOptions.cs
│ ├── ScheduleOptionsBuilder.cs
│ ├── SchedulePayload.cs
│ ├── SchedulePayloadCollection.cs
│ └── TimeUnit.cs
├── TaskPriority.cs
├── TaskStates.cs
├── Tasks
│ ├── TaskClient.cs
│ ├── TaskId.cs
│ ├── TaskIdCollection.cs
│ ├── TaskInfo.cs
│ ├── TaskInfoCollection.cs
│ ├── TaskListFilter.cs
│ ├── TaskOptions.cs
│ ├── TaskPayload.cs
│ ├── TaskPayloadCollection.cs
│ ├── TaskProgress.cs
│ └── TaskWebhookResponse.cs
└── packages.config
├── IronSharp.sln
├── IronSharp.sln.DotSettings
└── SolutionInfo.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.log
36 | *.vspscc
37 | *.vssscc
38 | .builds
39 |
40 | # Visual C++ cache files
41 | ipch/
42 | *.aps
43 | *.ncb
44 | *.opensdf
45 | *.sdf
46 |
47 | # Visual Studio profiler
48 | *.psess
49 | *.vsp
50 | *.vspx
51 |
52 | # Guidance Automation Toolkit
53 | *.gpState
54 |
55 | # ReSharper is a .NET coding add-in
56 | _ReSharper*
57 |
58 | # NCrunch
59 | *.ncrunch*
60 | .*crunch*.local.xml
61 |
62 | # Installshield output folder
63 | [Ee]xpress
64 |
65 | # DocProject is a documentation generator add-in
66 | DocProject/buildhelp/
67 | DocProject/Help/*.HxT
68 | DocProject/Help/*.HxC
69 | DocProject/Help/*.hhc
70 | DocProject/Help/*.hhk
71 | DocProject/Help/*.hhp
72 | DocProject/Help/Html2
73 | DocProject/Help/html
74 |
75 | # Click-Once directory
76 | publish
77 |
78 | # Publish Web Output
79 | *.Publish.xml
80 |
81 | # NuGet Packages Directory
82 | packages
83 | *.nupkg
84 |
85 | # Windows Azure Build Output
86 | csx
87 | *.build.csdef
88 |
89 | # Windows Store app package directory
90 | AppPackages/
91 |
92 | # Others
93 | [Bb]in
94 | [Oo]bj
95 | sql
96 | TestResults
97 | [Tt]est[Rr]esult*
98 | *.Cache
99 | ClientBin
100 | [Ss]tyle[Cc]op.*
101 | ~$*
102 | *.dbmdl
103 | Generated_Code #added for RIA/Silverlight projects
104 |
105 | # Backup & report files from converting an old project file to a newer
106 | # Visual Studio version. Backup files are not needed, because we have git ;-)
107 | _UpgradeReport_Files/
108 | Backup*/
109 | UpgradeLog*.XML
110 |
111 | src/*/lib/*.dll
112 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Jeremy Bell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/images/net-iron-c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iron-io/iron_dotnet/b5dfcaeefa2f549413c9136b2bc39ef8e1f331af/images/net-iron-c.png
--------------------------------------------------------------------------------
/images/net-iron-core.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iron-io/iron_dotnet/b5dfcaeefa2f549413c9136b2bc39ef8e1f331af/images/net-iron-core.png
--------------------------------------------------------------------------------
/images/net-iron-mq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iron-io/iron_dotnet/b5dfcaeefa2f549413c9136b2bc39ef8e1f331af/images/net-iron-mq.png
--------------------------------------------------------------------------------
/images/net-iron-w.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iron-io/iron_dotnet/b5dfcaeefa2f549413c9136b2bc39ef8e1f331af/images/net-iron-w.png
--------------------------------------------------------------------------------
/images/products.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iron-io/iron_dotnet/b5dfcaeefa2f549413c9136b2bc39ef8e1f331af/images/products.png
--------------------------------------------------------------------------------
/src/Demo.IronSharp/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Demo.IronSharp/Demo.IronSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {4EFB32B2-4CD3-4604-9ADC-458A4FC4C50B}
8 | Exe
9 | Properties
10 | Demo.IronSharpConsole
11 | Demo.IronSharpConsole
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | False
37 | ..\packages\Common.Logging.2.1.2\lib\net40\Common.Logging.dll
38 |
39 |
40 | ..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll
41 |
42 |
43 | False
44 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | {1a6cc922-40a5-440a-868d-757fcdb08622}
62 | IronSharp.Core
63 |
64 |
65 | {2603e861-09ab-482e-bf28-41d8b0b1b20b}
66 | IronSharp.IronCache
67 |
68 |
69 | {d891a220-aa6f-4d0c-b012-b25875787ba0}
70 | IronSharp.IronMQ
71 |
72 |
73 | {4fa5bf5d-c543-404e-89ec-c3bff90acf6b}
74 | IronSharp.IronWorker
75 |
76 |
77 |
78 |
85 |
--------------------------------------------------------------------------------
/src/Demo.IronSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("Demo.IronSharp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Demo.IronSharp")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("668efe21-f96d-4736-8de1-d34d47b7a416")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/src/Demo.IronSharp/Tests/IntegrationTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text.RegularExpressions;
5 | using IronSharp.Core;
6 | using IronSharp.IronMQ;
7 | using NUnit.Framework;
8 |
9 | namespace Demo.IronSharpConsole.Tests
10 | {
11 | [TestFixture]
12 | class IntegrationTests
13 | {
14 | private IronMqRestClient ironMq;
15 |
16 | private QueueClient queue;
17 |
18 | [SetUp]
19 | public void Init()
20 | {
21 | // Put your ".iron.json" file to home directory, eg. C:\Users\YourUsername
22 | ironMq = Client.New();
23 | queue = ironMq.Queue(GetQueueName());
24 | queue.Clear();
25 |
26 | // Or config the client here:
27 | // ironMq = Client.New(new IronClientConfig
28 | // {
29 | // ProjectId = "xxxxxxxxxxxxxxxxxxxxxxxx",
30 | // Token = "yyyyyyyyyyyyyyyyyyyy",
31 | // Host = "host-of-ironmq.com",
32 | // ApiVersion = 3,
33 | // Port = 80,
34 | // Scheme = Uri.UriSchemeHttp
35 | // });
36 | }
37 |
38 | [TearDown]
39 | public void After()
40 | {
41 | queue.Delete();
42 | }
43 |
44 | [Test]
45 | public void PostMessage()
46 | {
47 | string messageId = queue.Post("some data");
48 | Assert.IsTrue(Regex.IsMatch(messageId, "^[a-f0-9]{19}$"));
49 | }
50 |
51 | [Test]
52 | public void ReserveMessage()
53 | {
54 | queue.Post("one");
55 |
56 | var msg = queue.Reserve();
57 | Assert.AreEqual(19, msg.Id.Length);
58 | Assert.IsTrue(Regex.IsMatch(msg.ReservationId, "^[a-f0-9]{32}$"));
59 | }
60 |
61 | [Test]
62 | public void ReserveMessages()
63 | {
64 | for (int i = 0; i < 2; i++)
65 | queue.Post(i.ToString());
66 |
67 | var messagesContainer = queue.Reserve(3);
68 | foreach (var message in messagesContainer.Messages)
69 | {
70 | Assert.AreEqual(19, message.Id.Length);
71 | Assert.IsTrue(Regex.IsMatch(message.ReservationId, "^[a-f0-9]{32}$"));
72 | }
73 | }
74 |
75 | [Test]
76 | public void ClearQueue()
77 | {
78 | queue.Post("one");
79 | var cleared = queue.Clear();
80 | Assert.IsTrue(cleared);
81 | Assert.AreEqual(queue.Info().Size, 0);
82 | }
83 |
84 | [Test]
85 | public void DeleteReservedMessage()
86 | {
87 | PostTwoMessages();
88 | var message = queue.Reserve();
89 | var deleted = message.Delete();
90 | Assert.IsTrue(deleted);
91 | Assert.AreEqual(queue.Info().Size, 1);
92 | }
93 |
94 | [Test]
95 | public void DeleteReservedMessageViaQueue()
96 | {
97 | PostTwoMessages();
98 | var message = queue.Reserve();
99 | var deleted = queue.DeleteMessage(message.Id, message.ReservationId);
100 | Assert.IsTrue(deleted);
101 | Assert.AreEqual(queue.Info().Size, 1);
102 | }
103 |
104 | [Test]
105 | public void DeleteNotReservedMessage()
106 | {
107 | queue.Post("one");
108 | var messageId = queue.Post("two");
109 | var deleted = queue.Delete(messageId);
110 | Assert.IsTrue(deleted);
111 | Assert.AreEqual(1, queue.Info().Size);
112 | }
113 |
114 | [Test]
115 | public void DeleteNotReservedMessageViaQueue()
116 | {
117 | var messageId = queue.Post("one");
118 | queue.Post("two");
119 | var deleted = queue.DeleteMessage(messageId);
120 | Assert.IsTrue(deleted);
121 | Assert.AreEqual(1, queue.Info().Size);
122 | }
123 |
124 | [Test]
125 | public void UpdateQueue()
126 | {
127 | var expectedTimeout = 66;
128 | var expectedExpiration = 3333;
129 | queue.Update(new QueueInfo { MessageTimeout = expectedTimeout, MessageExpiration = expectedExpiration });
130 |
131 | var actualQueueInfo = queue.Info();
132 | Assert.AreEqual(expectedTimeout, actualQueueInfo.MessageTimeout);
133 | Assert.AreEqual(expectedExpiration, actualQueueInfo.MessageExpiration);
134 | }
135 |
136 | [Test]
137 | public void DeleteQueue()
138 | {
139 | var q = ironMq.Queue(GetQueueName());
140 | q.Post("one");
141 | var deleted = q.Delete();
142 | Assert.IsTrue(deleted);
143 | Assert.IsNull(q.Info());
144 | }
145 |
146 | [Test]
147 | public void GetMessageById()
148 | {
149 | var expectedBody = "testGetById";
150 | var messageId = queue.Post(expectedBody);
151 | Assert.AreEqual(expectedBody,queue.Get(messageId).Body);
152 | }
153 |
154 | [Test]
155 | public void PeekMessage()
156 | {
157 | var firstMessageId = queue.Post("one");
158 | queue.Post("two");
159 | var peekedMessage = queue.PeekNext();
160 | Assert.AreEqual(firstMessageId, peekedMessage.Id);
161 | }
162 |
163 | [Test]
164 | public void ReleaseMessage()
165 | {
166 | queue.Post("one");
167 | var msg = queue.Reserve();
168 | var released = msg.Release();
169 | Assert.IsTrue(released);
170 | Assert.AreEqual(msg.Id,queue.Reserve().Id);
171 | }
172 |
173 | [Test]
174 | public void DeleteMessages()
175 | {
176 | PostTwoMessages();
177 | var messages = queue.Reserve(2);
178 | queue.Delete(messages);
179 | Assert.AreEqual(0, queue.Info().Size);
180 | }
181 |
182 | [Test]
183 | public void CreatePushQueue()
184 | {
185 | var q = ironMq.Queue(GetQueueName());
186 | var pushInfo = GenerateSubscribers(1);
187 | q.Update(new QueueInfo { PushType = PushType.Multicast, PushInfo = pushInfo});
188 |
189 | Assert.AreEqual(PushType.Multicast, q.Info().PushType);
190 | }
191 |
192 | [Test]
193 | public void AddSubscribers()
194 | {
195 | var q = ironMq.Queue(GetQueueName());
196 | var pushInfo = GenerateSubscribers(2);
197 | q.Update(new QueueInfo { PushType = PushType.Multicast, PushInfo = pushInfo });
198 | var actualPushInfo = q.Info().PushInfo;
199 |
200 | Assert.AreEqual(pushInfo.Subscribers.Count, actualPushInfo.Subscribers.Count);
201 | Assert.AreEqual(pushInfo.Subscribers[0].Url, actualPushInfo.Subscribers[0].Url);
202 | Assert.AreEqual(pushInfo.Subscribers[1].Url, actualPushInfo.Subscribers[1].Url);
203 | }
204 |
205 | private void PostTwoMessages()
206 | {
207 | queue.Post("one");
208 | queue.Post("two");
209 | }
210 |
211 | private String GetQueueName()
212 | {
213 | return String.Format("queue{0}", DateTime.Now.Ticks);
214 | }
215 |
216 | private PushInfo GenerateSubscribers(int count)
217 | {
218 | var subscribes = new List();
219 | for(int i=0;i
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IIdCollection.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace IronSharp.Core
4 | {
5 | public interface IIdCollection
6 | {
7 | IEnumerable GetIds();
8 | }
9 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IInspectable.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public interface IInspectable
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IIronSharpConfig.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public interface IIronSharpConfig
4 | {
5 | IronSharpConfig SharpConfig { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IMsg.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public interface IMsg
4 | {
5 | ///
6 | /// Gets the information message
7 | ///
8 | string Message { get; }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IPagingFilter.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public interface IPagingFilter
4 | {
5 | ///
6 | /// The 0-based page to view. The default is 0.
7 | ///
8 | int Page { get; set; }
9 |
10 | ///
11 | /// The number of queues to return per page. The default is 30, the maximum is 100.
12 | ///
13 | int PerPage { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IRequestHelpersContainer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.Specialized;
4 | using System.Linq;
5 | using System.Net.Http.Headers;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace IronSharp.Core.Abstract
10 | {
11 | interface IRequestHelpersContainer
12 | {
13 | Uri BuildUri(IronClientConfig config, string path, NameValueCollection query);
14 |
15 | void SetOathQueryParameterIfRequired(IRestClientRequest request, string token);
16 |
17 | void SetOauthHeaderIfRequired(IronClientConfig config, IRestClientRequest request, HttpRequestHeaders headers);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IRestClientRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Specialized;
2 | using System.Net.Http;
3 |
4 | namespace IronSharp.Core
5 | {
6 | public interface IRestClientRequest
7 | {
8 | HttpContent Content { get; set; }
9 |
10 | string EndPoint { get; set; }
11 |
12 | NameValueCollection Query { get; set; }
13 |
14 | HttpMethod Method { get; set; }
15 |
16 | string Accept { get; set; }
17 |
18 | AuthTokenLocation AuthTokenLocation { get; set; }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/ITokenContainer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace IronSharp.Core
8 | {
9 | public interface ITokenContainer
10 | {
11 | String getToken();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Abstract/IValueSerializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IronSharp.Core
4 | {
5 | public interface IValueSerializer
6 | {
7 | string Generate(object value);
8 |
9 | object Parse(string value, Type type);
10 |
11 | T Parse(string value);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Attributes/QueueNameAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IronSharp.Core.Attributes
4 | {
5 | [AttributeUsage(AttributeTargets.Class, Inherited = true)]
6 | public sealed class QueueNameAttribute : Attribute
7 | {
8 | public QueueNameAttribute(string name)
9 | {
10 | Name = name;
11 | }
12 |
13 | public string Name { get; private set; }
14 |
15 | public static string GetName()
16 | {
17 | Type type = typeof(T);
18 | object[] customAttributes = type.GetCustomAttributes(typeof(QueueNameAttribute), true);
19 | return customAttributes.Length > 0 ? ((QueueNameAttribute) customAttributes[0]).Name : type.FullName;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Config/HttpClientOptions.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public static class HttpClientOptions
4 | {
5 | static HttpClientOptions()
6 | {
7 | EnableRetry = true;
8 | RetryLimit = 4;
9 | }
10 |
11 | public static bool EnableRetry { get; set; }
12 |
13 | public static int RetryLimit { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Config/IronClientConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Newtonsoft.Json;
4 |
5 | namespace IronSharp.Core
6 | {
7 | public class IronClientConfig : IIronSharpConfig, IInspectable
8 | {
9 | private IronSharpConfig _sharpConfig;
10 |
11 | [JsonProperty("host")]
12 | public string Host { get; set; }
13 |
14 | [JsonProperty("project_id")]
15 | public string ProjectId { get; set; }
16 |
17 | [JsonProperty("token")]
18 | public string Token { get; set; }
19 |
20 | [JsonProperty("api_version")]
21 | public int ApiVersion { get; set; }
22 |
23 | [JsonProperty("port")]
24 | public int? Port { get; set; }
25 |
26 | [JsonProperty("scheme")]
27 | public String Scheme { get; set; }
28 |
29 | [JsonProperty("keystone")]
30 | public KeystoneClientConfig Keystone { get; set; }
31 |
32 | [JsonProperty("sharp_config")]
33 | public IronSharpConfig SharpConfig
34 | {
35 | get { return LazyInitializer.EnsureInitialized(ref _sharpConfig, CreateDefaultIronSharpConfig); }
36 | set { _sharpConfig = value; }
37 | }
38 |
39 | public bool KeystoneKeysExist()
40 | {
41 | return Keystone.Tenant != null && Keystone.Server != null &&
42 | Keystone.Username != null && Keystone.Password != null;
43 | }
44 |
45 | private static IronSharpConfig CreateDefaultIronSharpConfig()
46 | {
47 | return new IronSharpConfig
48 | {
49 | BackoffFactor = 25
50 | };
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Config/IronDotConfigManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Reflection;
5 | using System.Web.Hosting;
6 | using Common.Logging;
7 | using Newtonsoft.Json;
8 |
9 | namespace IronSharp.Core
10 | {
11 | ///
12 | /// http://dev.iron.io/cache/reference/configuration/
13 | ///
14 | public static class IronDotConfigManager
15 | {
16 | public static string GetEnvironmentKey(IronProduct product, string key)
17 | {
18 | if (key == null) throw new ArgumentNullException("key");
19 |
20 | string productName = GetProductName(product);
21 |
22 | return string.Format("{0}_{1}", productName, key).ToUpper();
23 | }
24 |
25 | public static T GetEnvironmentValue(IronProduct product, string key, EnvironmentVariableTarget target = EnvironmentVariableTarget.Process)
26 | {
27 | return GetEnvironmentValue(product, key, default(T), target);
28 | }
29 |
30 | public static T GetEnvironmentValue(IronProduct product, string key, T defaultValue, EnvironmentVariableTarget target = EnvironmentVariableTarget.Process)
31 | {
32 | return Environment.GetEnvironmentVariable(GetEnvironmentKey(product, key), target).As(defaultValue);
33 | }
34 |
35 | public static IronClientConfig Load(IronProduct product = IronProduct.AllProducts, IronClientConfig overrideConfig = null, string env = null)
36 | {
37 | string homeIronDotJson = Path.Combine(GetHomeDirectory(), ".iron.json");
38 | string appIronDotJson = Path.Combine(GetAppDirectory(), "iron.json");
39 |
40 | IronClientConfig home = ParseJsonFile(product, homeIronDotJson, env);
41 | IronClientConfig app = ParseJsonFile(product, appIronDotJson, env);
42 |
43 | ApplyOverrides(home, app);
44 | ApplyOverrides(home, overrideConfig);
45 |
46 | return home;
47 | }
48 |
49 | public static IronClientConfig LoadFromEnvironment(IronProduct product, EnvironmentVariableTarget target = EnvironmentVariableTarget.Process)
50 | {
51 | var baseConfig = new IronClientConfig
52 | {
53 | ProjectId = GetEnvironmentValue(IronProduct.AllProducts, "projectid", target),
54 | Token = GetEnvironmentValue(IronProduct.AllProducts, "token", target)
55 | };
56 |
57 | var productConfig = new IronClientConfig
58 | {
59 | ProjectId = GetEnvironmentValue(product, "projectid", target),
60 | Token = GetEnvironmentValue(product, "token", target),
61 | Host = GetEnvironmentValue(product, "host", target)
62 | };
63 |
64 | ApplyOverrides(baseConfig, productConfig);
65 |
66 | return baseConfig;
67 | }
68 |
69 | public static IronClientConfig ParseJsonFile(IronProduct product, string filePath, string env = null)
70 | {
71 | JsonDotConfigModel config = LoadJson(filePath, env);
72 |
73 | var settings = new IronClientConfig
74 | {
75 | ProjectId = config.ProjectId,
76 | Token = config.Token,
77 | Host = config.Host,
78 | Keystone = config.Keystone
79 | };
80 |
81 | ApplyOverrides(settings, GetProductOverride(product, config));
82 |
83 | return settings;
84 | }
85 |
86 | public static void SetEnvironmentValue(IronProduct product, string key, string value, EnvironmentVariableTarget target = EnvironmentVariableTarget.Process)
87 | {
88 | Environment.SetEnvironmentVariable(GetEnvironmentKey(product, key), value, target);
89 | }
90 |
91 | public static void DeleteEnvironmentValue(IronProduct product, string key, EnvironmentVariableTarget target = EnvironmentVariableTarget.Process)
92 | {
93 | SetEnvironmentValue(product, key, null, target);
94 | }
95 |
96 | private static void ApplyOverrides(IronClientConfig targetConfig, IronClientConfig overrideConfig)
97 | {
98 | if (overrideConfig == null)
99 | {
100 | return;
101 | }
102 |
103 | targetConfig.ProjectId = string.IsNullOrEmpty(overrideConfig.ProjectId) ? targetConfig.ProjectId : overrideConfig.ProjectId;
104 | targetConfig.Token = string.IsNullOrEmpty(overrideConfig.Token) ? targetConfig.Token : overrideConfig.Token;
105 | targetConfig.Host = string.IsNullOrEmpty(overrideConfig.Host) ? targetConfig.Host : overrideConfig.Host;
106 | targetConfig.Scheme = string.IsNullOrEmpty(overrideConfig.Scheme) ? targetConfig.Scheme : overrideConfig.Scheme;
107 | targetConfig.ApiVersion = overrideConfig.ApiVersion == default(int) ? targetConfig.ApiVersion : overrideConfig.ApiVersion;
108 | targetConfig.Port = overrideConfig.Port.HasValue ? overrideConfig.Port : targetConfig.Port;
109 | targetConfig.Keystone = overrideConfig.Keystone == null ? targetConfig.Keystone : overrideConfig.Keystone;
110 | }
111 |
112 | private static string _appDirectory;
113 |
114 | public static void SetAppDirectory(string path)
115 | {
116 | _appDirectory = path;
117 | }
118 |
119 | private static string GetAppDirectory()
120 | {
121 | if (string.IsNullOrEmpty(_appDirectory))
122 | {
123 | _appDirectory = HostingEnvironment.IsHosted ?
124 | HostingEnvironment.MapPath("~/") :
125 | Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
126 | }
127 | return _appDirectory;
128 | }
129 |
130 | private static string GetHomeDirectory()
131 | {
132 | return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
133 | }
134 |
135 | private static string GetProductName(IronProduct product)
136 | {
137 | string productName;
138 |
139 | switch (product)
140 | {
141 | case IronProduct.AllProducts:
142 | productName = "iron";
143 | break;
144 | case IronProduct.IronMQ:
145 | productName = "iron_mq";
146 | break;
147 | case IronProduct.IronWorker:
148 | productName = "iron_worker";
149 | break;
150 | case IronProduct.IronCache:
151 | productName = "iron_cache";
152 | break;
153 | default:
154 | throw new ArgumentOutOfRangeException("product");
155 | }
156 | return productName;
157 | }
158 |
159 | private static IronClientConfig GetProductOverride(IronProduct product, JsonDotConfigModel config)
160 | {
161 | IronClientConfig productOverride = null;
162 |
163 | switch (product)
164 | {
165 | case IronProduct.IronCache:
166 | productOverride = config.IronCache;
167 | break;
168 | case IronProduct.IronMQ:
169 | productOverride = config.IronMQ;
170 | break;
171 | case IronProduct.IronWorker:
172 | productOverride = config.IronWoker;
173 | break;
174 | }
175 | return productOverride;
176 | }
177 |
178 | private static JsonDotConfigModel LoadJson(string filePath, string env = null)
179 | {
180 | try
181 | {
182 | if (File.Exists(filePath))
183 | {
184 | string content = File.ReadAllText(filePath);
185 |
186 | if (!string.IsNullOrEmpty(env))
187 | {
188 | var envType = JsonConvert.DeserializeObject>(content, new JsonSerializerSettings
189 | {
190 | Error = (sender, args) =>
191 | {
192 | args.ErrorContext.Handled = true;
193 | }
194 | });
195 | JsonDotConfigModel envSpecific;
196 | if (envType.TryGetValue(env, out envSpecific))
197 | {
198 | return envSpecific;
199 | }
200 | }
201 | return JsonConvert.DeserializeObject(content);
202 | }
203 | }
204 | catch (IOException ex)
205 | {
206 | LogManager.GetCurrentClassLogger().Error(ex);
207 | }
208 | return new JsonDotConfigModel();
209 | }
210 |
211 | private class JsonDotConfigModel : IronClientConfig
212 | {
213 | [JsonProperty("iron_cache")]
214 | public IronClientConfig IronCache { get; set; }
215 |
216 | [JsonProperty("iron_mq")]
217 | public IronClientConfig IronMQ { get; set; }
218 |
219 | [JsonProperty("iron_worker")]
220 | public IronClientConfig IronWoker { get; set; }
221 | }
222 | }
223 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Config/IronSharpConfig.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using Newtonsoft.Json;
3 |
4 | namespace IronSharp.Core
5 | {
6 | public class IronSharpConfig : IInspectable
7 | {
8 | private IValueSerializer _valueSerializer;
9 |
10 | [JsonProperty("back_off_factor")]
11 | public double BackoffFactor { get; set; }
12 |
13 | [JsonIgnore]
14 | public IValueSerializer ValueSerializer
15 | {
16 | get { return LazyInitializer.EnsureInitialized(ref _valueSerializer, () => new DefaultValueSerializer()); }
17 | set { _valueSerializer = value; }
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Config/KeystoneClientConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Newtonsoft.Json;
4 |
5 | namespace IronSharp.Core
6 | {
7 | public class KeystoneClientConfig
8 | {
9 | [JsonProperty("tenant")]
10 | public String Tenant { get; set; }
11 |
12 | [JsonProperty("server")]
13 | public String Server { get; set; }
14 |
15 | [JsonProperty("username")]
16 | public String Username { get; set; }
17 |
18 | [JsonProperty("password")]
19 | public String Password { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Constants/AuthHeaderLocation.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public enum AuthTokenLocation
4 | {
5 | None = 0,
6 | Header = 1,
7 | Querystring = 2
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/Constants/IronProduct.cs:
--------------------------------------------------------------------------------
1 | namespace IronSharp.Core
2 | {
3 | public enum IronProduct
4 | {
5 | AllProducts = 0,
6 | IronMQ,
7 | IronWorker,
8 | IronCache
9 | }
10 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Content/iron.json:
--------------------------------------------------------------------------------
1 | {"token":"XXXXXXXXXXXXXXXXXXXXXXXXXX","project_id":"0000000000000000000000000000"}
--------------------------------------------------------------------------------
/src/IronSharp.Core/Content/web.config.transform:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/IronSharp.Core/DateTimeHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IronSharp.Core
4 | {
5 | public static class DateTimeHelpers
6 | {
7 | public static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1);
8 |
9 | public static int SecondsSinceEpoch(DateTime value)
10 | {
11 | return (value - UnixEpoch).Seconds;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/DefaultValueSerializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Newtonsoft.Json;
3 |
4 | namespace IronSharp.Core
5 | {
6 | public class DefaultValueSerializer : IValueSerializer
7 | {
8 | private readonly JsonSerializerSettings _settings;
9 |
10 | public DefaultValueSerializer() : this(null)
11 | {
12 | }
13 |
14 | public DefaultValueSerializer(JsonSerializerSettings settings)
15 | {
16 | _settings = settings;
17 | }
18 |
19 | public string Generate(object value)
20 | {
21 | return JSON.Generate(value, _settings);
22 | }
23 |
24 | public object Parse(string value, Type type)
25 | {
26 | return JSON.Parse(value, type);
27 | }
28 |
29 | public T Parse(string value)
30 | {
31 | return JSON.Parse(value, _settings);
32 | }
33 | }
34 |
35 | public static class ExtensionsForDefaultSerializer
36 | {
37 | public static void UseDefaultSerializer(this IIronSharpConfig config)
38 | {
39 | config.SharpConfig.ValueSerializer = null;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Exceptions/IronSharpException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IronSharp.Core
4 | {
5 | public class IronSharpException : ApplicationException
6 | {
7 | public IronSharpException(string message) : base(message)
8 | {
9 | }
10 |
11 | public IronSharpException(string message, Exception innerException) : base(message, innerException)
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Exceptions/MaximumRetryAttemptsExceededException.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 |
3 | namespace IronSharp.Core
4 | {
5 | public class MaximumRetryAttemptsExceededException : IronSharpException
6 | {
7 | private readonly HttpRequestMessage _request;
8 |
9 | public MaximumRetryAttemptsExceededException(HttpRequestMessage request, int maxAttempts)
10 | : base(string.Format("The maximum number of retry attempts ({0}) has been exceeded.", maxAttempts))
11 | {
12 | _request = request;
13 | }
14 |
15 | public HttpRequestMessage Request
16 | {
17 | get { return _request; }
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Exceptions/RestResponseException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Net.Http;
4 |
5 | namespace IronSharp.Core
6 | {
7 | public class RestResponseException : IronSharpException
8 | {
9 | public RestResponseException(string message, HttpResponseMessage response)
10 | : base(message + AppendDebugInfo(response))
11 | {
12 | Response = response;
13 | }
14 |
15 | public RestResponseException(string message, HttpResponseMessage response, Exception innerException)
16 | : base(message + AppendDebugInfo(response), innerException)
17 | {
18 | Response = response;
19 | }
20 |
21 | public HttpRequestMessage RequestMessage
22 | {
23 | get { return Response.RequestMessage; }
24 | }
25 |
26 | public HttpResponseMessage Response { get; set; }
27 |
28 | private static string AppendDebugInfo(HttpResponseMessage response)
29 | {
30 | if (response == null || response.RequestMessage == null)
31 | {
32 | return null;
33 | }
34 |
35 | using (var sw = new StringWriter())
36 | {
37 | HttpRequestMessage request = response.RequestMessage;
38 |
39 | sw.WriteLine();
40 |
41 | sw.WriteLine("RequestUri: {0} {1}", request.Method, request.RequestUri);
42 |
43 | if (request.Content != null)
44 | {
45 | try
46 | {
47 | sw.WriteLine(request.Content.ReadAsStringAsync().Result);
48 | }
49 | catch (Exception e)
50 | {
51 | sw.WriteLine("Unable to read response content. " + e.Message);
52 | }
53 | }
54 |
55 | return sw.ToString();
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/ExponentialBackoff.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace IronSharp.Core
5 | {
6 | internal static class ExponentialBackoff
7 | {
8 | public static void Sleep(double backoffFactor, int attempt)
9 | {
10 | Thread.Sleep(TimeSpan.FromMilliseconds(Math.Pow(backoffFactor, attempt)));
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/IronSharp.Core/Extensions/ExtensionsForDictionary.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Diagnostics.Contracts;
6 |
7 | namespace IronSharp.Core
8 | {
9 | public static class ExtensionsForDictionary
10 | {
11 | public static void AddValues(this IDictionary dictionary, object value)
12 | {
13 | if (value == null)
14 | {
15 | return;
16 | }
17 | foreach (PropertyDescriptor item in TypeDescriptor.GetProperties(value))
18 | {
19 | dictionary.Add(item.Name, item.GetValue(value));
20 | }
21 | }
22 |
23 | public static TValue Get(this IDictionary dictionary, object key)
24 | {
25 | Contract.Requires(dictionary != null);
26 | if (!dictionary.Contains(key))
27 | {
28 | return default(TValue);
29 | }
30 | return (TValue) dictionary[key];
31 | }
32 |
33 | public static TValue Get(this IDictionary dictionary, string key, TValue defaultValue = default(TValue))
34 | {
35 | Contract.Requires(dictionary != null);
36 | object value;
37 | if (dictionary.TryGetValue(key, out value))
38 | {
39 | try
40 | {
41 | return (TValue) value;
42 | }
43 | catch (InvalidCastException)
44 | {
45 | return Convert.ToString(value).As();
46 | }
47 | }
48 | return defaultValue;
49 | }
50 |
51 | public static TValue GetOrAdd(this IDictionary dictionary, object key, Func