Пример #1
0
        public override void Save(Stream stream)
        {
            if (stream == null)
            {
                _document = string.IsNullOrEmpty(_document.Key)
                    ? _client.Post(_document)
                    : _client.Put(_document);
                return;
            }

            var parms = new SDataParameters
            {
                Files = { new AttachedFile(null, _document.FileName, stream) }
            };

            if (string.IsNullOrEmpty(_document.Key))
            {
                parms.Method = HttpMethod.Post;
                parms.Path   = "libraryDocuments";
            }
            else
            {
                parms.Method = HttpMethod.Put;
                parms.Path   = "libraryDocuments(" + SDataUri.FormatConstant(_document.Key) + ")";
                parms.ETag   = _document.ETag;
            }

            if (_formMode)
            {
                foreach (var prop in typeof(LibraryDocument).GetProperties())
                {
                    var name = _client.NamingScheme.GetName(prop);
                    if (!name.StartsWith("$", StringComparison.Ordinal) && !new[] { "createDate", "createUser", "modifyDate", "modifyUser" }.Contains(name, StringComparer.Ordinal))
                    {
                        var value = prop.GetValue(_document, null);
                        if (value != null)
                        {
                            parms.Form[name] = value.ToString();
                        }
                    }
                }

                parms.Path += "/file";
                var results = _client.Execute(parms);
                if (!string.IsNullOrEmpty(results.Location))
                {
                    var selector = new SDataUri(results.Location).GetPathSegment(4).Selector;
                    _document.Key  = selector.Substring(1, selector.Length - 2);
                    _document.ETag = results.ETag;
                }
            }
            else
            {
                parms.Content = _document;
                _document     = _client.Execute <LibraryDocument>(parms).Content;
            }
        }
 public void Save(Stream stream)
 {
     _directory = string.IsNullOrEmpty(_directory.Key)
         ? _client.Post(_directory)
         : _client.Put(_directory);
 }