Exemplo n.º 1
0
        /// <summary>
        /// Removes or replaces the header of a given project item.
        /// </summary>
        /// <param name="item">The project item.</param>
        /// <param name="headers">A dictionary of headers using the file extension as key and the header as value or null if headers should only be removed.</param>
        /// <param name="calledbyUser">Specifies whether the command was called by the user (as opposed to automatically by a linked command or by ItemAdded)</param>
        public void RemoveOrReplaceHeader(ProjectItem item, IDictionary <string, string[]> headers, bool calledbyUser = true)
        {
            try
            {
                Document document;
                bool     wasOpen;

                CreateDocumentResult result = TryCreateDocument(item, out document, out wasOpen, headers);
                string message;

                switch (result)
                {
                case CreateDocumentResult.DocumentCreated:
                    if (!document.ValidateHeader())
                    {
                        message = string.Format(Resources.Warning_InvalidLicenseHeader, Path.GetExtension(item.Name)).Replace(@"\n", "\n");
                        if (MessageBox.Show(message, Resources.Warning, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No)
                            == MessageBoxResult.No)
                        {
                            break;
                        }
                    }
                    try
                    {
                        document.ReplaceHeaderIfNecessary();
                    }
                    catch (ParseException)
                    {
                        message = string.Format(Resources.Error_InvalidLicenseHeader, item.Name).Replace(@"\n", "\n");
                        MessageBox.Show(message, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    break;

                case CreateDocumentResult.LanguageNotFound:
                    message = string.Format(Resources.Error_LanguageNotFound, Path.GetExtension(item.Name)).Replace(@"\n", "\n");
                    if (calledbyUser && MessageBox.Show(message, Resources.Error, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No)
                        == MessageBoxResult.Yes)
                    {
                        _licenseHeaderExtension.ShowLanguagesPage();
                    }
                    break;

                case CreateDocumentResult.EmptyHeader:
                    break;

                case CreateDocumentResult.NoHeaderFound:
                    if (calledbyUser)
                    {
                        message = string.Format(Resources.Error_NoHeaderFound).Replace(@"\n", "\n");
                        MessageBox.Show(message, Resources.NameOfThisExtension, MessageBoxButton.OK, MessageBoxImage.Question);
                    }
                    break;
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message + " " + item.Name, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Exemplo n.º 2
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);
            }
        }