Пример #1
0
        /// <summary>
        /// Creates a new JIRA server resource.
        /// </summary>
        public static JiraServer CreateNew()
        {
            ResourceProxy proxy = ResourceProxy.BeginNewResource(Type);

            proxy.AddLink(Core.Props.Parent, RootResource);
            proxy.EndUpdate();

            JiraServer retval = new JiraServer(proxy.Resource);

            retval.Name = Jiffa.GetRandomName();

            return(retval);
        }
Пример #2
0
        /// <summary>
        /// Extracts the attachments, including the names and their content.
        /// </summary>
        private void ReadArticle_PickAttachments(IResource res)
        {
            IResourceList resAttachments = res.GetLinksTo(null, "NewsAttachment");

            foreach (IResource resAttachment in resAttachments)
            {
                // Att name
                string sName = resAttachment.DisplayName;

                // Prevent duplicate names
                int nMaxTries = 0x20;
                int a;
                for (a = 0; (a < nMaxTries) && ((string.IsNullOrEmpty(sName)) || _attachments.ContainsKey(sName)); a++)
                {
                    sName = sName + Jiffa.GetRandomName();
                }
                if (a >= nMaxTries)
                {
                    throw new InvalidOperationException("Could not chose an unique name for an attachment.");
                }

                // Att content
                byte[] data = null;
                using (Stream datastream = resAttachment.GetBlobProp("Content"))
                {
                    if (datastream != null)
                    {
                        data = new byte[datastream.Length];
                        datastream.Read(data, 0, data.Length);
                    }
                }
                data = data ?? new byte[] {};

                // Store
                _attachments.Add(sName, data);
            }
        }