-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRicohEmbeddedSoapService.cs
More file actions
117 lines (105 loc) · 4.54 KB
/
RicohEmbeddedSoapService.cs
File metadata and controls
117 lines (105 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
namespace Ricoh
{
public abstract class RicohEmbeddedSoapService: IDisposable
{
protected const ushort DEFAULT_TIMELIMIT = 30;
private string _hostname = "127.0.0.1";
private string _username = "admin";
private ushort _timeLimit = DEFAULT_TIMELIMIT;
/// <summary>The session id that identifies us to the copier.</summary>
public virtual string SessionId { get; protected set; }
/// <summary>The hostname or ip address of the copier to connect to.</summary>
public virtual string Hostname
{
get { return(_hostname); }
protected set { _hostname = value; }
}
/// <summary>The username for authentication. Default: "admin".</summary>
public virtual string Username
{
get { return(_username); }
protected set { _username = value; }
}
/// <summary>The password for authentiation.</summary>
public virtual string Password { get; set; }
/// <summary>The time limit for our sessionId in ??minutes / seconds??. Default: 30</summary>
public virtual ushort TimeLimit
{
get { return(_timeLimit); }
set { _timeLimit = value; }
}
/// <summary>Indicates if connected to the directory.</summary>
public virtual bool IsConnected
{
get { return (! String.IsNullOrEmpty(SessionId)); }
}
/// <param name="hostname">The hostname or ip address of the copier to connect to.</param>
/// <param name="username">The username for authentication. Default: "admin".</param>
/// <param name="password">The password for authentiation.</param>
protected RicohEmbeddedSoapService(string hostname, string username = "admin", string password = null)
{
Hostname = hostname;
Username = username;
Password = password;
}
/// <summary>
/// GetValue's the authentication string / scheme used by the ricoh service.
/// </summary>
/// <param name="scheme">The name of the service.</param>
/// <param name="username">The name of the user to authentication. If not specified, then the preconfigured username is used.</param>
/// <param name="password">The password to authenticate with. If not specified, then the preconfigured password is used.</param>
/// <returns>The unique authentication string required by the ricoh service.</returns>
protected virtual string GetAuthenticationScheme(string scheme = "BASIC", string username = null, string password = null)
{
return (String.Format("SCHEME={0};UID:UserName={1};PWD:Password={2};PES:Encoding=",
(scheme ?? "BASIC").ToBase64(),
(username ?? Username).ToBase64(),
(password ?? Password).ToBase64()));
}
/// <summary>
/// GetValue's the endpoint address for the connection.
/// </summary>
/// <returns>The configured endpoint address.</returns>
protected abstract EndpointAddress GetEndpointAddress();
/// <summary>
/// GetValue's the endpoint behavior for service proxy.
/// </summary>
/// <returns>The configured endpoint behavoir.</returns>
protected virtual IEnumerable<IEndpointBehavior> GetEndpointBehaviors()
{
return (new [] { new RicohEmbeddedEndpointBehavior() });
}
/// <summary>
/// GetValue's the endpoint binding.
/// </summary>
/// <returns>The configured binding.</returns>
protected virtual Binding GetBinding()
{
return (new BasicHttpBinding() {
MaxReceivedMessageSize = Int32.MaxValue
});
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <filterpriority>2</filterpriority>
public abstract void Dispose();
/// <summary>
/// Checks to see if the response is recognized as a valid OK response.
/// </summary>
/// <param name="response">The response to check.</param>
/// <param name="acceptableValues">The optional array of acceptable values that pass the truth test.</param>
/// <returns>True if the response is OK, false if otherwise.</returns>
protected virtual bool IsOK(string response, IEnumerable<string> acceptableValues = null)
{
if (acceptableValues == null) acceptableValues = new string[] { RicohResponseStatus.OK };
return(String.IsNullOrEmpty(response) || acceptableValues.Contains(response, StringComparer.CurrentCultureIgnoreCase));
}
}
}