Ejemplo n.º 1
0
        private static async Task CheckOutCheckIn(ServiceConnection serviceConnection)
        {
            string fileCabinetId = "00000000-0000-0000-0000-000000000000";
            int    documentId    = 1;

            FileInfo fileInfo = null;

            //Check out
            using (var result = await serviceConnection.EasyCheckOutToFileSystemAsync(fileCabinetId, documentId)
                                .ConfigureAwait(false))
            {
                var tempPath = Path.Combine(Path.GetTempPath(), result.EncodedFileName);

                using (var file = System.IO.File.Create(tempPath))
                    using (var stream = result.Response.Content)
                        await stream.CopyToAsync(file).ConfigureAwait(false);

                fileInfo = new FileInfo(tempPath);
            }

            //Do your stuff you want to do with the file
            await Task.Delay(2000).ConfigureAwait(false);

            //Check in
            CheckInActionParameters checkInActionParameters = new CheckInActionParameters()
            {
                Comments        = "comments...",
                DocumentVersion = new DocumentVersion()
                {
                    Major = 1,
                    Minor = 2
                }
            };
            DeserializedHttpResponse <Platform.ServerClient.Document> document = await serviceConnection.EasyCheckInFromFileSystemAsync(fileInfo, checkInActionParameters).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        private static void EditSection(Organization organization)
        {
            Console.WriteLine("UpdateIndexFields");

            string queryDialogId = "00000000-0000-0000-0000-000000000000";
            string fileCabinetId = "00000000-0000-0000-0000-000000000000";
            int    documentId    = 1;

            FileCabinet fileCabinet = organization.GetFileCabinetsFromFilecabinetsRelation().FileCabinet
                                      .FirstOrDefault(fc => fc.Id == fileCabinetId);

            if (fileCabinet == null)
            {
                Console.WriteLine("FileCabinet is null!");
            }
            else
            {
                Platform.ServerClient.Document document = null;

                DialogExpression dialogExpression = new DialogExpression()
                {
                    Operation = DialogExpressionOperation.And,
                    Condition = new List <DialogExpressionCondition>()
                    {
                        DialogExpressionCondition.Create("DWDOCID", documentId.ToString())
                    },
                    Count     = 100,
                    SortOrder = new List <SortedField>()
                    {
                        SortedField.Create("DWDOCID", SortDirection.Desc)
                    }
                };

                DialogInfos dialogInfos = fileCabinet.GetDialogInfosFromDialogsRelation();

                if (dialogInfos == null)
                {
                    Console.WriteLine("DialogInfos is null!");
                }
                else
                {
                    DialogInfo dialog = dialogInfos.Dialog.FirstOrDefault(d => d.Id == queryDialogId);

                    if (dialog == null)
                    {
                        Console.WriteLine("Dialog is null!");
                    }
                    else
                    {
                        DocumentsQueryResult documentsQueryResult =
                            dialog.GetDialogFromSelfRelation().GetDocumentsResult(dialogExpression);

                        Console.WriteLine("Query Result");
                        document = documentsQueryResult.Items.FirstOrDefault();

                        document = document?.GetDocumentFromSelfRelation();
                    }
                }

                if (document == null)
                {
                    Console.WriteLine("Document is null!");
                }
                else
                {
                    document = document.GetDocumentFromSelfRelation();

                    var section = document.Sections.FirstOrDefault();

                    if (section == null)
                    {
                        Console.WriteLine("Section is null!");
                    }
                    else
                    {
                        section = section.GetSectionFromSelfRelation();

                        DeserializedHttpResponse <Stream> deserializedHttpResponse = section.PostToFileDownloadRelationForStreamAsync(new FileDownload()
                        {
                            TargetFileType = FileDownloadType.Auto // FileDownloadType.PDF / FileDownloadType.ZIP
                        }).Result;

                        HttpContentHeaders httpContentHeaders = deserializedHttpResponse.ContentHeaders;

                        string ContentType   = httpContentHeaders.ContentType.MediaType;
                        string DirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                        string FileName      = Path.Combine(DirectoryPath, deserializedHttpResponse.GetFileName());
                        long?  ContentLength = httpContentHeaders.ContentLength;
                        Stream stream        = deserializedHttpResponse.Content;

                        Directory.CreateDirectory(DirectoryPath);

                        using (FileStream fileStream = File.Create(FileName))
                        {
                            if (stream.CanSeek)
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                            }
                            stream.CopyTo(fileStream);
                        }

                        //edit your file here

                        section.EasyReplaceFile(new FileInfo(FileName));

                        Directory.Delete(DirectoryPath, true);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void DownloadSection(Organization organization)
        {
            Console.WriteLine("DownloadSection");

            string queryDialogId = "00000000-0000-0000-0000-000000000000";
            string fileCabinetId = "00000000-0000-0000-0000-000000000000";
            int    documentId    = 1;

            FileCabinet fileCabinet = organization.GetFileCabinetsFromFilecabinetsRelation().FileCabinet
                                      .FirstOrDefault(fc => fc.Id == fileCabinetId);

            if (fileCabinet == null)
            {
                Console.WriteLine("FileCabinet is null!");
            }
            else
            {
                Platform.ServerClient.Document document = null;

                DialogExpression dialogExpression = new DialogExpression()
                {
                    Operation = DialogExpressionOperation.And,
                    Condition = new List <DialogExpressionCondition>()
                    {
                        DialogExpressionCondition.Create("DWDOCID", documentId.ToString())
                    },
                    Count     = 100,
                    SortOrder = new List <SortedField>()
                    {
                        SortedField.Create("DWDOCID", SortDirection.Desc)
                    }
                };

                DialogInfos dialogInfos = fileCabinet.GetDialogInfosFromDialogsRelation();

                if (dialogInfos == null)
                {
                    Console.WriteLine("DialogInfos is null!");
                }
                else
                {
                    DialogInfo dialog = dialogInfos.Dialog.FirstOrDefault(d => d.Id == queryDialogId);

                    if (dialog == null)
                    {
                        Console.WriteLine("Dialog is null!");
                    }
                    else
                    {
                        DocumentsQueryResult documentsQueryResult =
                            dialog.GetDialogFromSelfRelation().GetDocumentsResult(dialogExpression);

                        Console.WriteLine("Query Result");
                        document = documentsQueryResult.Items.FirstOrDefault();

                        document = document?.GetDocumentFromSelfRelation();
                    }
                }

                if (document == null)
                {
                    Console.WriteLine("Document is null!");
                }
                else
                {
                    document = document.GetDocumentFromSelfRelation();

                    if (document.Sections.Count < 1)
                    {
                        Console.WriteLine("Document has not enough sections!");
                    }
                    else
                    {
                        Section section = document.Sections[1];

                        section = section.GetSectionFromSelfRelation();

                        DeserializedHttpResponse <Stream> deserializedHttpResponse = section.PostToFileDownloadRelationForStreamAsync(new FileDownload()
                        {
                            TargetFileType = FileDownloadType.Auto
                        }).Result;

                        HttpContentHeaders httpContentHeaders = deserializedHttpResponse.ContentHeaders;

                        string ContentType   = httpContentHeaders.ContentType.MediaType;
                        string FileName      = deserializedHttpResponse.GetFileName();
                        long?  ContentLength = httpContentHeaders.ContentLength;
                        Stream stream        = deserializedHttpResponse.Content;

                        using (FileStream fileStream = File.Create(Path.Combine(@"C:\Temp\", FileName)))
                        {
                            if (stream.CanSeek)
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                            }
                            stream.CopyTo(fileStream);
                        }
                    }
                }
            }
        }