Exemplo n.º 1
0
        public MediaObjectInfo NewMediaObject(string name, string type, byte[] bits)
        {
            var service = new Service(this.BlogConnectionInfo.MetaWeblogURL);

            var input_struct_ = new Struct();

            input_struct_["name"] = new StringValue(name);
            input_struct_["type"] = new StringValue(type);
            input_struct_["bits"] = new Base64Data(bits);

            var method = new MethodCall("metaWeblog.newMediaObject");

            method.Parameters.Add(this.BlogConnectionInfo.BlogID);
            method.Parameters.Add(this.BlogConnectionInfo.Username);
            method.Parameters.Add(this.BlogConnectionInfo.Password);
            method.Parameters.Add(input_struct_);

            service.Cookies = this.BlogConnectionInfo.Cookies;

            var response = service.Execute(method);
            var param    = response.Parameters[0];
            var struct_  = (Struct)param;

            var mediaobject = new MediaObjectInfo
            {
                URL = struct_.Get("url", StringValue.NullString).String
            };

            return(mediaobject);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="bits"></param>
        /// <returns></returns>
        public async Task <MediaObjectInfo> NewMediaObject(string name, string type, byte[] bits)
        {
            var service = new Service(BlogConnectionInfo.MetaWeblogUrl);

            var inputStruct = new Struct();

            inputStruct["name"] = new StringValue(name);
            inputStruct["type"] = new StringValue(type);
            inputStruct["bits"] = new Base64Data(bits);

            var method = new MethodCall("metaWeblog.newMediaObject");

            method.Parameters.Add(BlogConnectionInfo.BlogId);
            method.Parameters.Add(BlogConnectionInfo.Username);
            method.Parameters.Add(BlogConnectionInfo.Password);
            method.Parameters.Add(inputStruct);

            var response = await service.Execute(method);

            var param   = response.Parameters[0];
            var _struct = (Struct)param;

            var mediaobject = new MediaObjectInfo {
                Url = _struct.Get("url", StringValue.NullString).String
            };

            return(mediaobject);
        }
        public void RoundTrip_Struct()
        {
            // In this test, we'll simply make sure that
            // an array can handle all the supported types

            var src = new X.Struct();

            src["a"] = (IntegerValue)0;
            src["b"] = (IntegerValue)18;
            src["c"] = (IntegerValue)(-18);
            src["d"] = (DoubleValue)1.0893;
            src["e"] = (DoubleValue)(-1.0893);
            src["f"] = (BooleanValue)true;
            src["g"] = (BooleanValue)false;
            src["h"] = (DateTimeValue)System.DateTime.Now;
            src["i"] = new Base64Data(new byte[] { 0, 1, 2, 3 });
            src["j"] = new Struct();
            src["k"] = new X.Array();

            var dest = RoundTrip(src);

            Assert.AreEqual(src.Count, dest.Count);
            foreach (var src_pair in src)
            {
                Assert.IsTrue(dest.ContainsKey(src_pair.Key));
                Assert.AreEqual(src[src_pair.Key], dest[src_pair.Key]);
            }
        }
Exemplo n.º 4
0
        public async Task <MediaObjectInfo> NewMediaObjectAsync(string name, string type, byte[] bits)
        {
            Service service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
            Struct  @struct = new Struct();

            @struct["name"] = new StringValue(name);
            @struct["type"] = new StringValue(type);
            @struct["bits"] = new Base64Data(bits);
            MethodCall methodCall = new MethodCall("metaWeblog.newMediaObject");

            methodCall.Parameters.Add(this.BlogConnectionInfo.BlogID);
            methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
            methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
            methodCall.Parameters.Add(@struct);
            service.Cookies = this.BlogConnectionInfo.Cookies;
            MethodResponse methodResponse = await service.ExecuteAsync(methodCall);

            Value  value   = methodResponse.Parameters[0];
            Struct struct2 = (Struct)value;

            return(new MediaObjectInfo
            {
                URL = struct2.Get <StringValue>("url", StringValue.NullString).String
            });
        }
        public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            var value = (string)reader.Value !;

            // ReSharper disable once HeapView.BoxingAllocation
            return(Base64Data.Decode(value));
        }
Exemplo n.º 6
0
        public void ShouldNotExistById()
        {
            int        id   = leftRepository.GetAll().Count + 1;
            Base64Data data = leftRepository.GetById(id);

            Assert.IsNull(data);
        }
 public override object?ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string s)
     {
         // ReSharper disable once HeapView.BoxingAllocation
         return(Base64Data.Decode(s));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Exemplo n.º 8
0
        //Non-Test Methods

        private Base64Data CreateBase64Data(int id, string value)
        {
            Base64Data newBase64Data = new Base64Data();

            newBase64Data.Id = id;
            //newBase64Data.Base64Value = System.Text.Encoding.UTF8.GetBytes(value);
            newBase64Data.Base64Value = value;
            return(newBase64Data);
        }
Exemplo n.º 9
0
        public void DecodeBase64()
        {
            string base64 = Base64Data?.Trim();

            if (!string.IsNullOrWhiteSpace(base64))
            {
                Data = Convert.FromBase64String(base64);
            }
        }
Exemplo n.º 10
0
        public IHttpActionResult Left(int id, HttpRequestMessage value)
        {
            var        base64Text = value.Content.ReadAsStringAsync().Result;
            Base64Data product    = new Base64Data();

            product.Id          = id;
            product.Base64Value = base64Text;
            repositoryLeft.Add(product);
            return(Ok("Data saved"));
        }
Exemplo n.º 11
0
        private void Save(Base64Data product)
        {
            Base64Data existentProduct = GetById(product.Id);

            if (existentProduct != null)
            {
                Database.GetInstance().LeftData.Remove(existentProduct);
            }
            Database.GetInstance().LeftData.Add(product);
        }
        public void RoundTrip_Base64()
        {
            var src  = new Base64Data(new byte[] { 1, 2, 3, 4, 5 });
            var dest = RoundTrip(src);

            for (int i = 0; i < src.Bytes.Length; i++)
            {
                Assert.AreEqual(src.Bytes[i], dest.Bytes[i]);
            }
        }
Exemplo n.º 13
0
        public void ShouldEditData()
        {
            int count = leftRepository.GetAll().Count;

            leftRepository.Add(CreateBase64Data(count + 1, "Test"));
            Base64Data originalData = leftRepository.GetById(count + 1);

            leftRepository.Edit(CreateBase64Data(count + 1, "Test1"));
            Base64Data editedData = leftRepository.GetById(count + 1);

            Assert.AreEqual(originalData.Id, editedData.Id);
            Assert.AreNotEqual(originalData.Base64Value, editedData.Base64Value);
        }
Exemplo n.º 14
0
        public TmxLayer(XElement xLayer, int width, int height)
        {
            Name = (string)xLayer.Attribute("name");
            Opacity = (double?)xLayer.Attribute("opacity") ?? 1.0;
            Visible = (bool?)xLayer.Attribute("visible") ?? true;

            var xData = xLayer.Element("data");
            var encoding = (string)xData.Attribute("encoding");

            Tiles = new List<TmxLayerTile>();
            if (encoding == "base64")
            {
                var decodedStream = new Base64Data(xData);
                var stream = decodedStream.Data;

                using (var br = new BinaryReader(stream))
                    for (int j = 0; j < height; j++)
                        for (int i = 0; i < width; i++)
                            Tiles.Add(new TmxLayerTile(br.ReadUInt32(), i, j));
            }
            else if (encoding == "csv")
            {
                var csvData = (string)xData.Value;
                int k = 0;
                foreach (var s in csvData.Split(','))
                {
                    var gid = uint.Parse(s.Trim());
                    var x = k % width;
                    var y = k / width;
                    Tiles.Add(new TmxLayerTile(gid, x, y));
                    k++;
                }
            }
            else if (encoding == null)
            {
                int k = 0;
                foreach (var e in xData.Elements("tile"))
                {
                    var gid = (uint)e.Attribute("gid");
                    var x = k % width;
                    var y = k / width;
                    Tiles.Add(new TmxLayerTile(gid, x, y));
                    k++;
                }
            }
            else throw new Exception("TmxLayer: Unknown encoding.");

            Properties = new PropertyDict(xLayer.Element("properties"));
        }
Exemplo n.º 15
0
        private object GetSignatureObject(byte[] signature, SignatureFormat signatureFormat)
        {
            if (signatureFormat == SignatureFormat.PAdES)
            {
                Base64Data b64Data = new Base64Data();
                b64Data.MimeType = "application/pdf";
                b64Data.Value    = signature;

                return(b64Data);
            }
            else
            {
                return(signature);
            }
        }
        private InputDocuments GetInputDocuments(byte[] documentData, String mimeType)
        {
            InputDocuments inputDocuments = new InputDocuments();

            DocumentType document = new DocumentType();

            if (null == mimeType || mimeType.Equals("text/xml"))
            {
                document.Item = documentData;
            }
            else
            {
                Base64Data base64Data = new Base64Data();
                base64Data.MimeType = mimeType;
                base64Data.Value    = documentData;
                document.Item       = base64Data;
            }

            inputDocuments.Items = new object[] { document };
            return(inputDocuments);
        }
Exemplo n.º 17
0
        private object GetDocument(byte[] signature, SignatureFormat signatureFormat)
        {
            if (signatureFormat == SignatureFormat.XAdES)
            {
                return(signature);
            }

            Base64Data b64Data = new Base64Data();

            if (signatureFormat == SignatureFormat.PAdES)
            {
                b64Data.MimeType = "application/pdf";
            }
            else
            {
                b64Data.MimeType = "application/octet-stream";
            }

            b64Data.Value = signature;

            return(b64Data);
        }
Exemplo n.º 18
0
 private void Base64DataPaste_Click(object sender, RoutedEventArgs e)
 {
     Base64Data.Focus();
     Base64Data.Text = Clipboard.GetText(TextDataFormat.Text);
 }
Exemplo n.º 19
0
 public void Edit(Base64Data product)
 {
     Save(product);
 }
Exemplo n.º 20
0
 public void Add(Base64Data product)
 {
     Save(product);
 }
Exemplo n.º 21
0
        public Base64Data GetById(int id)
        {
            Base64Data entity = Database.GetInstance().LeftData.Where(s => s.Id == id).FirstOrDefault();

            return(entity);
        }
Exemplo n.º 22
0
        public JsonResponse Compare(int id)
        {
            JsonResponse    response        = new JsonResponse();
            LeftRepository  leftRepository  = new LeftRepository();
            RightRepository rightRepository = new RightRepository();
            Base64Data      leftData        = leftRepository.GetById(id);
            Base64Data      rightData       = rightRepository.GetById(id);

            if (leftData != null)
            {
                response.Left = leftData.Base64Value;
            }
            if (rightData != null)
            {
                response.Right = rightData.Base64Value;
            }
            response.Id = id;

            //Validate if right or left data is present
            if (leftData == null && rightData == null)
            {
                response.Result = "Id " + id + " does not exists in Left and Right side";
            }
            else if (leftData == null)
            {
                response.Result = "Id " + id + " does not exists in Left side";
            }
            else if (rightData == null)
            {
                response.Result = "Id " + id + " does not exists in Right side";
            }
            //Validate if right and left data are of equal size
            else if (!leftData.Base64Value.Length.Equals(rightData.Base64Value.Length))
            {
                response.Result = "Not of Equal Size";
            }
            else if (leftData.Base64Value.Equals(rightData.Base64Value))
            {
                response.Result = "Equals";
            }
            else
            {
                //Check the actual differences between the strings
                string diffMessage = string.Empty;
                bool   diffFound   = false;
                for (int i = 0; i < leftData.Base64Value.Length; i++)
                {
                    if (!leftData.Base64Value[i].Equals(rightData.Base64Value[i]) && diffFound == false)
                    {
                        diffMessage = "Difference in position " + i;
                        diffFound   = true;
                        if (i == leftData.Base64Value.Length - 1)
                        {
                            diffFound = false;
                            response.Differences.Add(diffMessage);
                        }
                    }
                    else if (leftData.Base64Value[i].Equals(rightData.Base64Value[i]) && diffFound)
                    {
                        diffMessage = diffMessage + " to " + (i - 1);
                        diffFound   = false;
                        response.Differences.Add(diffMessage);
                    }
                }
                response.Result = "Number of differences found: " + response.Differences.Count + ".";
            }

            return(response);
        }
        private InputDocuments GetInputDocuments(byte[] documentData, String mimeType)
        {
            InputDocuments inputDocuments = new InputDocuments();

            DocumentType document = new DocumentType();
            if (null == mimeType || mimeType.Equals("text/xml"))
            {
                document.Item = documentData;
            }
            else
            {
                Base64Data base64Data = new Base64Data();
                base64Data.MimeType = mimeType;
                base64Data.Value = documentData;
                document.Item = base64Data;
            }

            inputDocuments.Items = new object[] { document };
            return inputDocuments;
        }