Exemplo n.º 1
0
        public async Task <AuthResultModel> Authenticate(string token)
        {
            var             encodedVallue = Base64Utility.Encode(token.ToString());
            AuthResultModel result        = await base.Post <AuthResultModel>("auth", encodedVallue, null);

            return(result);
        }
Exemplo n.º 2
0
        public async Task <LogResultModel> Log(string token, object data)
        {
            var            encodedVallue = Base64Utility.Encode(token.ToString());
            LogResultModel result        = await base.Post <LogResultModel>("log", encodedVallue, data);

            return(result);
        }
Exemplo n.º 3
0
        public void TestBase64Utility()
        {
            string helloWorld             = "Hello World!";
            string helloWorldBase64String = Base64Utility.Serialize(helloWorld);

            Assert.AreEqual("Hello World!", Base64Utility.Deserialize(helloWorldBase64String));
        }
Exemplo n.º 4
0
        private T DecompressContent <T>(string compressedContent)
        {
            var decodedContent      = Base64Utility.Decode(compressedContent);
            var deserializedContent = JsonConvert.DeserializeObject <T>(decodedContent);

            return(deserializedContent);
        }
Exemplo n.º 5
0
        private string CompressContent(object content)
        {
            var serializedContent = JsonConvert.SerializeObject(content);
            var compressedContent = Base64Utility.Encode(serializedContent);

            return(compressedContent);
        }
Exemplo n.º 6
0
        public void Set(string key, object content)
        {
            var cacheKey          = Base64Utility.Encode(key);
            var compressedContent = CompressContent(content);

            _cache.Set(cacheKey, compressedContent, TimeSpan.FromMinutes(_config.Expiration));
        }
Exemplo n.º 7
0
        private XDocument CreatePayload(String serviceName, String label, String description,
                                        String location, String affinityGroup)
        {
            XDocument payload = null;

            try
            {
                String base64LabelName = Base64Utility.ConvertToBase64String(label);

                XElement xServiceName = new XElement(wa + "ServiceName", serviceName);

                XElement xLabel = new XElement(wa + "Label", base64LabelName);

                XElement xDescription = new XElement(wa + "Description", description);

                XElement xLocation = new XElement(wa + "Location", location);

                XElement xAffinityGroup = new XElement(wa + "AffinityGroup", affinityGroup);

                XElement createHostedService = new XElement(wa + "CreateHostedService");

                createHostedService.Add(xServiceName);
                createHostedService.Add(xLabel);
                createHostedService.Add(xDescription);

                // We should have one or the other of location and affinityGroup,
                // not both.
                if (string.IsNullOrWhiteSpace(location) == true &&
                    string.IsNullOrWhiteSpace(affinityGroup) == false)
                {
                    createHostedService.Add(xAffinityGroup);
                }
                else if (string.IsNullOrWhiteSpace(location) == false &&
                         string.IsNullOrWhiteSpace(affinityGroup) == true)
                {
                    createHostedService.Add(xLocation);
                }

                payload = new XDocument();

                payload.Add(createHostedService);

                payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in CreatePayload()  Error: {0}", ex.Message));

                payload = null;
            }

            return(payload);
        }
Exemplo n.º 8
0
        public bool TryGet <T>(string key, out T content)
        {
            var cacheKey = Base64Utility.Encode(key);

            if (!_cache.TryGetValue(cacheKey, out string compressedContent))
            {
                content = default(T);
                return(false);
            }

            content = DecompressContent <T>(compressedContent);
            return(true);
        }
Exemplo n.º 9
0
 public void SendOpsNotification(string name, string content, IList <string> toAddresses = null)
 {
     try
     {
         string subject = String.Format(this.NotificationTemplateConfig.SubjectWapper, name);
         string body    = String.Format(Base64Utility.Deserialize(this.NotificationTemplateConfig.BodyWapper), content);
         this.SendNotification(this.TemplateConfig.FromAddress, this.TemplateConfig.FromDisplayName, toAddresses != null ? toAddresses : this.TemplateConfig.ToAddresses, this.TemplateConfig.CCAddresses, this.TemplateConfig.BCCAddresses,
                               this.TemplateConfig.ReplyToAddresses, this.TemplateConfig.Headers != null ? this.TemplateConfig.Headers.Select(h => new Header {
             Name = h.Name, Value = h.Value
         }).ToList() : null, subject, body, true);
     }
     catch (Exception exception)
     {
         this.Logger.LogError(exception, exception.Message);
     }
 }
Exemplo n.º 10
0
        private XDocument CreatePayload(String deploymentName, String packageUrl,
                                        String configurationString, String label)
        {
            XDocument payload = null;

            try
            {
                String base64ConfigurationString = Base64Utility.ConvertToBase64String(configurationString);

                String base64Label = Base64Utility.ConvertToBase64String(label);

                XElement xName = new XElement(wa + "Name", deploymentName);

                XElement xPackageUrl = new XElement(wa + "PackageUrl", packageUrl);

                XElement xLabel = new XElement(wa + "Label", base64Label);

                XElement xConfiguration = new XElement(wa + "Configuration", base64ConfigurationString);

                XElement xStartDeployment = new XElement(wa + "StartDeployment", "true");

                XElement xTreatWarningsAsError = new XElement(wa + "TreatWarningsAsError", "false");

                XElement createDeployment = new XElement(wa + "CreateDeployment");

                createDeployment.Add(xName);
                createDeployment.Add(xPackageUrl);
                createDeployment.Add(xLabel);
                createDeployment.Add(xConfiguration);
                createDeployment.Add(xStartDeployment);
                createDeployment.Add(xTreatWarningsAsError);

                payload = new XDocument();

                payload.Add(createDeployment);

                payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in CreatePayload()  Error: {0}", ex.Message));

                payload = null;
            }

            return(payload);
        }
Exemplo n.º 11
0
        public void CanBase64UrlEncode()
        {
            // Example values from http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-08#appendix-A.1
            // Arrange
            string jwtHeader  = @"{""typ"":""JWT"",
 ""alg"":""HS256""}";
            string jwtPayload = @"{""iss"":""joe"",
 ""exp"":1300819380,
 ""http://example.com/is_root"":true}";

            // Act
            string encodedHeader  = Base64Utility.UTF8UrlEncode(jwtHeader);
            string encodedPayload = Base64Utility.UTF8UrlEncode(jwtPayload);

            // Assert
            Assert.AreEqual("eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9", encodedHeader);
            Assert.AreEqual("eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ", encodedPayload);
        }