/// <summary> /// Create a new subscription to this hub for the supplied repository information and shared secret. /// </summary> /// <param name="repositoryXml"></param> /// <remarks></remarks> /// <returns>The client repository information retrieved from the server.</returns> public async Task <ClientRepositoryXml> CreateSubscription(ClientRepositoryXml repositoryXml) { var request = new ClientRepositoryUploadRequest(repositoryXml); //we have to use distinct credentials for this so we have to swap the credentials on the connection. var channel = await GetCurrentChannel().ConfigureAwait(false); bool retry; do { retry = false; //so we'll exit by default try { await channel.ExecuteRequest(request, 1).ConfigureAwait(false); } catch (WebChannelAuthorizationException ex) { //request better credentials.. Logger.Write(LogMessageSeverity.Warning, ex, true, LogCategory, "Requesting updated credentials for the server connection due to " + ex.GetType(), "We're going to assume the user can provide current credentials.\r\nDetails: {0}", ex.Message); retry = CachedCredentialsManager.UpdateCredentials(channel, m_ClientRepositoryId, true); if (retry == false) { throw; } } } while (retry); return(request.ResponseRepository); }
static void Main(string[] args) { ItemRepositoryXml itemRepo = new ItemRepositoryXml("./MyCoffeeItems.xml"); ClientRepositoryXml clientRepo = new ClientRepositoryXml("./MyClients.xml"); DomainClient client = clientRepo.FindByName("Петров"); DomainCart cart = new DomainCart(0, client); cart.Add(itemRepo.FindByName("Капучино"), 2); cart.Add(itemRepo.FindByName("Латте"), 1); cart.Bill.Issue(); return; }
/// <summary> /// convert a client repository set of information from its field form to XML /// </summary> /// <returns></returns> public static ClientRepositoryXml ToClientRepositoryXml(Guid id, string hostName, string computerKey, string statusName, DateTimeOffset addedDt, long currentSessionsVersion, string publicKey, DateTimeOffset lastContactDt) { ClientRepositoryXml newObject = new ClientRepositoryXml(); newObject.id = id.ToString(); newObject.addedDt = ToDateTimeOffsetXml(addedDt); newObject.computerKey = computerKey; newObject.currentSessionsVersion = currentSessionsVersion; newObject.hostName = hostName; newObject.lastContactDt = ToDateTimeOffsetXml(lastContactDt); newObject.publicKey = publicKey; newObject.status = ToClientRepositoryStatusXml(statusName); return(newObject); }
/// <summary> /// Implemented by inheritors to perform the request on the provided web client. /// </summary> /// <param name="connection"></param> protected override async Task OnProcessRequest(IWebChannelConnection connection) { byte[] requestedRepositoryRawData = await connection.UploadData(GenerateResourceUri(), HttpMethod.Put, XmlContentType, ConvertXmlToByteArray(InputRepository)).ConfigureAwait(false); //now we deserialize the response which is the new state of the document. //now, this is supposed to be a sessions list... using (var inputStream = new MemoryStream(requestedRepositoryRawData)) { XmlSerializerNamespaces xmlNsEmpty = new XmlSerializerNamespaces(); xmlNsEmpty.Add("", "http://www.gibraltarsoftware.com/Gibraltar/Repository.xsd"); //gets rid of the default namespaces we'd otherwise generate var xmlReader = XmlReader.Create(inputStream); XmlSerializer xmlSerializer = new XmlSerializer(typeof(ClientRepositoryXml), "http://www.gibraltarsoftware.com/Gibraltar/Repository.xsd"); ClientRepositoryXml repositoryXml = (ClientRepositoryXml)xmlSerializer.Deserialize(xmlReader); ResponseRepository = repositoryXml; } }
/// <summary> /// Create a new sessions version request /// </summary> public ClientRepositoryUploadRequest(ClientRepositoryXml repositoryXml) : base(true, true) { InputRepository = repositoryXml; }