Exemple #1
0
        public void OpenDocument()
        {
            //Step 1: Login to DokuFlex to get the ticket;
            var ticket = Session.GetTikect();

            //Step 2: get addional info
            var community = (UserGroup)null;
            var folder    = (FileFolder)null;
            var file      = (FileFolder)null;

            using (var form = new OpenFileForm(ticket, _fileExtensions))
            {
                if (form.ShowOpenFileDialog())
                {
                    community = form.Group;
                    folder    = form.Folder;
                    file      = form.File;
                }
                else
                {
                    return;
                }
            }

            TrackingListManager.Reload();

            var trackingItem = TrackingListManager.GetByFileId(file.id);

            if (trackingItem != null && File.Exists(trackingItem.Path))
            {
                if (trackingItem.ModifiedTime < file.modifiedTime)
                {
                    using (var form = new TransferProgressForm())
                    {
                        if (form.DownloadFile(ticket, trackingItem.FileId, trackingItem.Path))
                        {
                            TrackOff();
                            Globals.ThisAddIn.Application.Documents.Open(trackingItem.Path);
                            TrackOn();
                            trackingItem.ModifiedTime = file.modifiedTime;
                            TrackingListManager.Save();
                        }
                    }
                }
                else
                {
                    //Open the document.
                    TrackOff();
                    this.Application.Documents.Open(trackingItem.Path);
                    TrackOn();
                }
            }
            else
            {
                //Step 3: Create directory and file paths
                var currentDir  = String.Format("{0}\\{1}", DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.Documents), community.name);
                var currentPath = string.Format("{0}\\{1}", currentDir, file.name);

                try
                {
                    if (!Directory.Exists(currentDir))
                    {
                        try
                        {
                            Directory.CreateDirectory(currentDir);
                        }
                        catch (Exception)
                        {
                            //Silent exception
                        }
                    }
                }
                catch (Exception e)
                {
                    LogFactory.CreateLog().LogError(e);
                    MessageBox.Show(e.Message, this.Application.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                //Step 4: download the file
                using (var form = new TransferProgressForm())
                {
                    if (form.DownloadFile(ticket, file.id, currentPath))
                    {
                        TrackOff();
                        Globals.ThisAddIn.Application.Documents.Open(currentPath);
                        TrackOn();

                        trackingItem = new TrackingItem()
                        {
                            Name          = file.name,
                            LastWriteTime = DateTime.Now.ToFileTimeUtc(),
                            Path          = currentPath,
                            Type          = "F",
                            GroupId       = community.id,
                            FolderId      = folder.id,
                            FileId        = file.id,
                            ModifiedTime  = file.modifiedTime
                        };

                        TrackingListManager.Add(trackingItem);
                        TrackingListManager.Save();
                    }
                }
            }
        }
Exemple #2
0
        public void OpenRecentDocument(string ticket, IDocument document)
        {
            TrackingListManager.Reload();

            var trackingItem = TrackingListManager.GetByFileId(document.id);

            if (trackingItem != null)
            {
                if (trackingItem.ModifiedTime < document.modifiedTime)
                {
                    using (var form = new TransferProgressForm())
                    {
                        if (form.DownloadFile(ticket, trackingItem.FileId, trackingItem.Path))
                        {
                            TrackOff();
                            Globals.ThisAddIn.Application.Documents.Open(trackingItem.Path);
                            TrackOn();
                            trackingItem.ModifiedTime = document.modifiedTime;
                            TrackingListManager.Save();
                        }
                    }
                }
                else
                {
                    //Open the document.
                    TrackOff();
                    this.Application.Documents.Open(trackingItem.Path);
                    TrackOn();
                }
            }
            else
            {
                //Step 3: Create directory and file paths
                var currentDir  = String.Format("{0}\\{1}", DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.Documents), "Huerfanos");
                var currentPath = string.Format("{0}\\{1}", currentDir, document.name);

                try
                {
                    if (!Directory.Exists(currentDir))
                    {
                        try
                        {
                            Directory.CreateDirectory(currentDir);
                        }
                        catch (Exception)
                        {
                            //Silent exception
                        }
                    }
                }
                catch (Exception e)
                {
                    LogFactory.CreateLog().LogError(e);
                    MessageBox.Show(e.Message, this.Application.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                //Step 4: download the file
                using (var form = new TransferProgressForm())
                {
                    if (form.DownloadFile(ticket, document.id, currentPath))
                    {
                        TrackOff();
                        Globals.ThisAddIn.Application.Documents.Open(currentPath);
                        TrackOn();

                        trackingItem = new TrackingItem()
                        {
                            Name          = document.name,
                            LastWriteTime = DateTime.Now.ToFileTimeUtc(),
                            Path          = currentPath,
                            Type          = "F",
                            FileId        = document.id,
                            ModifiedTime  = document.modifiedTime
                        };

                        TrackingListManager.Add(trackingItem);
                        TrackingListManager.Save();
                    }
                }
            }
        }