Exemplo n.º 1
0
        public ShareFileItem createFile(FileInfo fileInfo, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try
            {
                FileRecord fileRecord = VmosoFileUtils.uploadFile(session, fileInfo.FullName, title, description, true);

                if (spaceKeys != null)
                {
                    SpaceApi          spaceApi    = new SpaceApi(session.GetApiClient());
                    ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                    ShareObjectResult shareResult = spaceApi.ShareObject(fileRecord.Key, shareInput);
                    if (shareResult.Hdr.Rc == 0)
                    {
                        FileApi        fileApi        = new FileApi(session.GetApiClient());
                        ViewFileResult viewFileResult = fileApi.ViewFile(fileRecord.Key);
                        if (viewFileResult.Hdr.Rc == 0)
                        {
                            fileRecord = viewFileResult.File;
                        }
                        else
                        {
                            throw new Exception("Vmoso error getting created link. Rc=" + viewFileResult.Hdr.Rc);
                        }
                    }
                    else
                    {
                        throw new Exception("Vmoso error sharing link. Rc=" + shareResult.Hdr.Rc);
                    }
                }

                ShareFileItem item = new ShareFileItem(fileRecord.Name, fileRecord.Description);
                item.Key      = fileRecord.Key;
                item.FileInfo = fileInfo;
                item.SetIcon(icon);
                item.Record = fileRecord;

                List <ShareSpace> itemSpaces = new List <ShareSpace>();
                foreach (DisplayRecord spaceDisplayRecord in fileRecord.Destinations)
                {
                    ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                    itemSpaces.Add(space);
                }

                item.Spaces = itemSpaces;
                return(item);
            } catch (Exception ex)
            {
                throw new Exception("Error creating file", ex);
            }
        }
Exemplo n.º 2
0
        public ShareLinkItem updateBookmark(String key, Uri link, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try
            {
                LinkApi     linkApi     = new LinkApi(session.GetApiClient());
                DocumentApi documentApi = new DocumentApi(session.GetApiClient());

                GetLinkResult getLinkResult = linkApi.GetLink(key);
                if (getLinkResult.Hdr.Rc == 0)
                {
                    LinkV2Record existingLink = getLinkResult.Link;
                    existingLink.Link  = link.ToString();
                    existingLink.Title = title;
                    existingLink.Text  = description;
                    existingLink.Type  = "link";

                    //UpdateLinkInput updateLinkInput = new UpdateLinkInput(existingLink);
                    //UpdateLinkResult updateLinkResult = linkApi.UpdateLink(key, updateLinkInput);

                    UpdateDocumentInput  updateDocumentInput  = new UpdateDocumentInput(existingLink);
                    UpdateDocumentResult updateDocumentResult = documentApi.UpdateDocument(key, updateDocumentInput);

                    if (updateDocumentResult.Hdr.Rc == 0)
                    {
                        DocumentV2Record updatedDocument = updateDocumentResult.Document;

                        SpaceApi spaceApi = new SpaceApi(session.GetApiClient());

                        // Remove spaces
                        foreach (DisplayRecord destination in updatedDocument.Destinations)
                        {
                            if (!spaceKeys.Contains(destination.Key))
                            {
                                List <String> itemKeysToRemove = new List <String>()
                                {
                                    updatedDocument.Key
                                };
                                RemoveObjectsInput  removeObjectsInput  = new RemoveObjectsInput(destination.Key, itemKeysToRemove);
                                RemoveObjectsResult removeObjectsResult = spaceApi.RemoveObjects(destination.Key, removeObjectsInput);
                                if (removeObjectsResult.Hdr.Rc != 0)
                                {
                                    throw new Exception("Vmoso error removing bookmark from space. Rc=" + removeObjectsResult.Hdr.Rc);
                                }
                            }
                            else
                            {
                                spaceKeys.Remove(destination.Key);
                            }
                        }

                        if (spaceKeys.Count > 0)
                        {
                            ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                            ShareObjectResult shareResult = spaceApi.ShareObject(updatedDocument.Key, shareInput);
                            if (shareResult.Hdr.Rc != 0)
                            {
                                throw new Exception("Vmoso error sharing bookmark. Rc=" + shareResult.Hdr.Rc);
                            }
                        }

                        getLinkResult = linkApi.GetLink(updatedDocument.Key);
                        if (getLinkResult.Hdr.Rc == 0)
                        {
                            LinkV2Record  updatedLink = getLinkResult.Link;
                            ShareLinkItem item        = new ShareLinkItem(updatedLink.Title, updatedLink.Text);
                            item.Key    = updatedLink.Key;
                            item.Link   = new Uri(updatedLink.Link);
                            item.Record = updatedLink;
                            item.SetIcon(icon);

                            List <ShareSpace> itemSpaces = new List <ShareSpace>();
                            foreach (DisplayRecord spaceDisplayRecord in updatedLink.Destinations)
                            {
                                ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                                itemSpaces.Add(space);
                            }

                            item.Spaces = itemSpaces;
                            return(item);
                        }
                        else
                        {
                            throw new Exception("Vmoso error getting updated link. Rc=" + getLinkResult.Hdr.Rc);
                        }
                    }
                    else
                    {
                        throw new Exception("Vmoso error updating link. Rc=" + updateDocumentResult.Hdr.Rc);
                    }
                }
                else
                {
                    throw new Exception("Vmoso error getting link to update. Rc=" + getLinkResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Vmoso error getting link to update", ex);
            }
        }
Exemplo n.º 3
0
        public ShareLinkItem createBookmarkAsDocument(Uri link, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try {
                DocumentApi documentApi = new DocumentApi(session.GetApiClient());

                LinkV2Record linkRecord = new LinkV2Record();
                linkRecord.Link  = link.ToString();
                linkRecord.Title = title;
                linkRecord.Text  = description;
                linkRecord.Type  = "link";

                CreateDocumentInput  createDocumentInput  = new CreateDocumentInput(linkRecord);
                CreateDocumentResult createDocumentResult = documentApi.CreateDocument(createDocumentInput);
                if (createDocumentResult.Hdr.Rc == 0)
                {
                    DocumentV2Record createdDocument = createDocumentResult.Document;
                    LinkV2Record     createdLink     = null;

                    if (spaceKeys != null)
                    {
                        SpaceApi          spaceApi    = new SpaceApi(session.GetApiClient());
                        ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                        ShareObjectResult shareResult = spaceApi.ShareObject(createdDocument.Key, shareInput);
                        if (shareResult.Hdr.Rc == 0)
                        {
                            LinkApi       linkApi       = new LinkApi(session.GetApiClient());
                            GetLinkResult getLinkResult = linkApi.GetLink(createdDocument.Key);
                            if (getLinkResult.Hdr.Rc == 0)
                            {
                                createdLink = getLinkResult.Link;
                            }
                            else
                            {
                                throw new Exception("Vmoso error getting created link. Rc=" + getLinkResult.Hdr.Rc);
                            }
                        }
                        else
                        {
                            throw new Exception("Vmoso error sharing link. Rc=" + shareResult.Hdr.Rc);
                        }
                    }

                    ShareLinkItem item = new ShareLinkItem(createdLink.Title, createdLink.Text);
                    item.Key    = createdLink.Key;
                    item.Link   = new Uri(createdLink.Link);
                    item.Record = createdLink;
                    item.SetIcon(icon);

                    List <ShareSpace> itemSpaces = new List <ShareSpace>();
                    foreach (DisplayRecord spaceDisplayRecord in createdLink.Destinations)
                    {
                        ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                        itemSpaces.Add(space);
                    }

                    item.Spaces = itemSpaces;
                    return(item);
                }
                else
                {
                    throw new Exception("Vmoso error creating link. Rc=" + createDocumentResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Vmoso error creating link", ex);
            }
        }
Exemplo n.º 4
0
        public ShareFileItem updateFile(String key, FileInfo fileInfo, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try
            {
                FileApi fileApi = new FileApi(session.GetApiClient());

                ViewFileResult viewFileResult = fileApi.ViewFile(key);

                if (viewFileResult.Hdr.Rc == 0)
                {
                    FileRecord existingFile = viewFileResult.File;
                    existingFile.Name        = title;
                    existingFile.Description = description;

                    UpdateFileInput  updateFileInput  = new UpdateFileInput(existingFile, null);
                    UpdateFileResult updateFileResult = fileApi.UpdateFile(key, updateFileInput);

                    if (updateFileResult.Hdr.Rc == 0)
                    {
                        FileRecord updatedFile = updateFileResult.Updated;

                        SpaceApi spaceApi = new SpaceApi(session.GetApiClient());

                        // Remove spaces
                        foreach (DisplayRecord destination in updatedFile.Destinations)
                        {
                            if (!spaceKeys.Contains(destination.Key))
                            {
                                List <String> itemKeysToRemove = new List <String>()
                                {
                                    updatedFile.Key
                                };
                                RemoveObjectsInput  removeObjectsInput  = new RemoveObjectsInput(destination.Key, itemKeysToRemove);
                                RemoveObjectsResult removeObjectsResult = spaceApi.RemoveObjects(destination.Key, removeObjectsInput);
                                if (removeObjectsResult.Hdr.Rc != 0)
                                {
                                    throw new Exception("Vmoso error removing file from space. Rc=" + removeObjectsResult.Hdr.Rc);
                                }
                            }
                            else
                            {
                                spaceKeys.Remove(destination.Key);
                            }
                        }

                        if (spaceKeys.Count > 0)
                        {
                            ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                            ShareObjectResult shareResult = spaceApi.ShareObject(updatedFile.Key, shareInput);
                            if (shareResult.Hdr.Rc != 0)
                            {
                                throw new Exception("Vmoso error sharing file. Rc=" + shareResult.Hdr.Rc);
                            }
                        }

                        viewFileResult = fileApi.ViewFile(updatedFile.Key);
                        if (viewFileResult.Hdr.Rc == 0)
                        {
                            updatedFile = viewFileResult.File;
                            ShareFileItem item = new ShareFileItem(updatedFile.Name, updatedFile.Description);
                            item.Key      = updatedFile.Key;
                            item.FileInfo = fileInfo;
                            item.Record   = updatedFile;
                            item.SetIcon(icon);

                            List <ShareSpace> itemSpaces = new List <ShareSpace>();
                            foreach (DisplayRecord spaceDisplayRecord in updatedFile.Destinations)
                            {
                                ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                                itemSpaces.Add(space);
                            }

                            item.Spaces = itemSpaces;
                            return(item);
                        }
                        else
                        {
                            throw new Exception("Vmoso error getting updated file. Rc=" + viewFileResult.Hdr.Rc);
                        }
                    }
                    else
                    {
                        throw new Exception("Vmoso error updating file. Rc=" + updateFileResult.Hdr.Rc);
                    }
                }
                else
                {
                    throw new Exception("Vmoso error getting file to update. Rc=" + viewFileResult.Hdr.Rc);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Vmoso updating file", ex);
            }
        }