internal static ContentServiceClient CreateClient() { var binding = new BasicHttpBinding(); binding.CloseTimeout = TimeSpan.FromMinutes(1); binding.OpenTimeout = TimeSpan.FromMinutes(1); binding.ReceiveTimeout = TimeSpan.FromMinutes(10); binding.SendTimeout = TimeSpan.FromMinutes(1); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; binding.MaxBufferSize = 65536; binding.MaxBufferPoolSize = 524288; binding.MaxReceivedMessageSize = 65536; binding.MessageEncoding = WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount = 16384 }; binding.Security = new BasicHttpSecurity() { Mode = BasicHttpSecurityMode.None, Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.None, ProxyCredentialType = HttpProxyCredentialType.None, Realm = string.Empty } }; var serviceURL = System.Configuration.ConfigurationManager.AppSettings["NeuCMSServiceURL"] as string; var endPoint = new EndpointAddress(serviceURL); var client = new ContentServiceClient(binding, endPoint); return client; }
public Stream dowlande(string authToken, string pathe, Node node) { //Create the DocumentManagement service client DocumentManagementClient docManClient = new DocumentManagementClient(); CWS.DocumentManagement.OTAuthentication otAuth = new CWS.DocumentManagement.OTAuthentication(); otAuth.AuthenticationToken = authToken; ContentServiceClient contentServiceClient = new ContentServiceClient(); CWS.ContentService.OTAuthentication otAuthConServices = new CWS.ContentService.OTAuthentication(); otAuthConServices.AuthenticationToken = authToken; //string fileName=null; string contextID = null; try { contextID = docManClient.GetVersionContentsContext(ref otAuth, node.ID, 0); } catch (FaultException e) { MessageBox.Show(e.Message); } finally { docManClient.Close(); } Stream downloadStream = null; try { downloadStream = contentServiceClient.DownloadContent(ref otAuthConServices, contextID); } catch (FaultException e) { MessageBox.Show(e.Message); } finally { contentServiceClient.Close(); } /*FileStream fileStream = null; * try * { * string path = Path.GetDirectoryName(Application.ExecutablePath).Replace(@"bin\Debug", string.Empty); * fileName = Path.Combine(path.Replace(@"bin\Debug", string.Empty), @"GED_image\" + node.Name + ".tif"); * if (File.Exists(fileName)) * { * File.Delete(fileName); * } * fileStream = new FileStream(fileName, FileMode.Create); * byte[] buffer = new byte[BUFFER_SIZE]; * long fileSize = 0; * for (int read = downloadStream.Read(buffer, 0, buffer.Length); read > 0; read = downloadStream.Read(buffer, 0, buffer.Length)) * { * fileStream.Write(buffer, 0, read); * fileSize += read; * } * } * catch (Exception e) * { * //MessageBox.Show(e.Message); * } * finally * { * if (fileStream != null) * { * fileStream.Close(); * } * downloadStream.Close(); * }*/ return(downloadStream); }
private long UploadFile(long parentId, string path,DoWorkEventArgs e) { if (_worker.CancellationPending){ e.Cancel = true; return -1; } ContentServiceClient contentService=new ContentServiceClient(); DocumentManagementClient docMan = new DocumentManagementClient(); FileInfo info = new FileInfo(path); _worker.ReportProgress(_counter, new {CurrentFile=info.Name}); FileAtts fileAtts = new FileAtts { CreatedDate = info.CreationTime, FileName = info.Name, FileSize = info.Length, ModifiedDate = info.LastWriteTime }; var stream = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read); ProgressStream pStream = new ProgressStream(stream); pStream.ProgressChanged += pStream_ProgressChanged; try { bool isVersionAdded = false; var res = docMan.GetNodeByName(ref _otAuthentication, parentId, info.Name); string contextId; if (res == null) { contextId=docMan.CreateDocumentContext(ref _otAuthentication, parentId, info.Name, null, false, null); } else { contextId = docMan.AddVersionContext(ref _otAuthentication, res.ID, null); isVersionAdded = true; } var id = contentService.UploadContent(ref _otAuthentication, contextId, fileAtts, pStream); ++_counter; _worker.ReportProgress(_counter,new {Message=isVersionAdded ? string.Format("{{{0}}} - Version {1} added.", id, info.Name) : string.Format("{{{0}}} - Document {1} added.", id, info.Name)}); } catch (Exception ex) { _worker.ReportProgress(_counter, new {Message=ex.ToString()}); } finally { contentService.Close(); docMan.Close(); stream.Close(); } return -1; }