コード例 #1
0
        public CreateLinkResult CreateLink(string symbolicName, string userName)
        {
            using (var context = new RelayContext())
            {
                var password            = _passwordHash.GeneratePassword(_configuration.LinkPasswordLength);
                var passwordInformation = _passwordHash.CreatePasswordInformation(password);

                var link = new DbLink
                {
                    Id           = Guid.NewGuid(),
                    Password     = passwordInformation.Hash,
                    Salt         = passwordInformation.Salt,
                    Iterations   = passwordInformation.Iterations,
                    SymbolicName = symbolicName,
                    UserName     = userName,
                    CreationDate = DateTime.UtcNow
                };

                context.Links.Add(link);
                context.SaveChanges();

                var result = new CreateLinkResult
                {
                    Id       = link.Id,
                    Password = Convert.ToBase64String(password)
                };

                return(result);
            }
        }
コード例 #2
0
        public ShareLinkItem createBookmark(Uri link, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try
            {
                LinkApi linkApi = new LinkApi(session.GetApiClient());

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

                CreateLinkInput  createLinkInput  = new CreateLinkInput(linkRecord);
                CreateLinkResult createLinkResult = linkApi.CreateLink(createLinkInput);
                if (createLinkResult.Hdr.Rc == 0)
                {
                    LinkV2Record createdLink = createLinkResult.Link;

                    if (spaceKeys != null)
                    {
                        SpaceApi          spaceApi    = new SpaceApi(session.GetApiClient());
                        ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                        ShareObjectResult shareResult = spaceApi.ShareObject(createdLink.Key, shareInput);
                        if (shareResult.Hdr.Rc == 0)
                        {
                            GetLinkResult getLinkResult = linkApi.GetLink(createdLink.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=" + createLinkResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Vmoso error creating link", ex);
            }
        }