コード例 #1
0
        public static Id MakeReplyId(Id parent, DateTime published)
        {
            if (!Uri.IsWellFormedUriString(parent.ToString(), UriKind.RelativeOrAbsolute))
            {
                throw new Exception("id is not a valid uri: " + parent);
            }

            string childPath = RandomChars(12);
            Id resultId = new Id(parent.Owner, published, parent.Collection, parent.EntryPath + "," + childPath);

            string uriString = resultId.ToString();
            if (!Uri.IsWellFormedUriString(resultId.ToString(), UriKind.RelativeOrAbsolute))
            {
                throw new Exception("id is not a valid uri: " + uriString);
            }

            return resultId;
        }
コード例 #2
0
        private static int IndexOfId(this IList<AppCollection> list, Id id) 
        {
            string idString = id.ToString();
            for (int index = 0; index < list.Count; index++)
            {
                if (String.Equals(idString, list[index].Id.ToString())) 
                {
                    return index;
                }
            }

            return -1;
        }
    public AtomEntry GetEntry(Id entryId)
    {
      ItemDataContext dc = new ItemDataContext();
      Item item = dc.Items.Where(i => i.Id == entryId.ToString()).SingleOrDefault();
      SyndicationItem si = new SyndicationItem()
      {
        Id = item.Id,
        LastUpdatedTime = item.LastUpdatedTime,
        PublishDate = item.PublishDate.Value
      };
      if (!string.IsNullOrEmpty(item.BaseUri)) si.BaseUri = new Uri(item.BaseUri);

      LoadAttributes(si.AttributeExtensions, item.Attributes);
      LoadElements(si.ElementExtensions, item.Elements);
      LoadPersons(si.Authors, item.Persons, PersonTypeAuthor);
      LoadPersons(si.Contributors, item.Persons, PersonTypeContributor);
      si.Content = GetContent(item.Content);
      si.Title = GetTextContent(item.Title);
      si.Summary = GetTextContent(item.Summary);
      si.Copyright = GetTextContent(item.Copyright);
      LoadLinks(si.Links, item.Links);
      LoadCategories(si.Categories, item.Categories);

      using (Stream s = new MemoryStream())
      {
        XmlWriter w = new XmlTextWriter(s, Encoding.UTF8);
        si.GetAtom10Formatter().WriteTo(w);
        w.Flush();
        AtomEntry entry = new AtomEntry();
        s.Position = 0;
        XmlReader r = new XmlTextReader(s);
        entry.Xml = XElement.Load(r);
        //entry.ReadXml(r);
        return entry;
      }
    }
 private AtomEntry GetEntryById(Id entryId)
 {
     return entriesList.Where(entry => entry.Id.ToString() == entryId.ToString()).SingleOrDefault();
 }
        private int IndexOfId(Id id)
        {
            string idString = id.ToString();

            for (int loopIndex = 0; loopIndex < entriesList.Count(); loopIndex++)
            {
                if (entriesList[loopIndex].Id.ToString() == idString)
                {
                    return loopIndex;
                }
            }

            return -1;
        }
 public string GetEntryEtag(Id entryId)
 {
     string key = entryId.ToString();
     if (eTags.ContainsKey(key))
     {
         // return the entry Id with a version apended
         return key + "::" + eTags[key];
     }
     else
     {
         return string.Empty;
     }
 }
 /// <summary>
 /// Approves an entry... 
 /// TODO: should we remove this whole method and just keep in service?
 /// It is more efficient here, but is it worth the cost of duplicate logic?
 /// </summary>
 /// <param name="entryId"></param>
 public void ApproveEntry(Id entryId)
 {
   string path = pathResolver.GetEntryPath(entryId);
   try
   {
     AtomEntry entry = AtomEntry.Load(path);
     if (!entry.Approved)
     {
       Uncompute(entry);
       entry.Control.Approved = true;
       entry.Edited = DateTimeOffset.UtcNow;
       entries.Put(path, entry);
     }
   }
   catch (FileNotFoundException)
   {
     throw new ResourceNotFoundException("entry", entryId.ToString());
   }
 }
    public void DeleteEntry(Id entryId)
    {
      string path = pathResolver.GetEntryPath(entryId);
      if (!System.IO.File.Exists(path))
        throw new ResourceNotFoundException("entry", entryId.ToString());
      System.IO.File.Delete(path);

      //delete annotations
      string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path),
        System.IO.Path.GetFileNameWithoutExtension(path));
      
      if (System.IO.Directory.Exists(dir))
      {
        try
        {

          foreach (string file in Directory.GetFiles(dir, "*" + PathResolver.DefaultEntryExt, SearchOption.AllDirectories))
            System.IO.File.Delete(file);
          foreach (string file in Directory.GetFiles(dir, "*" + PathResolver.DefaultMediaLinkEntryExt, SearchOption.AllDirectories))
            System.IO.File.Delete(file);

      //try and clean up old directories
          //don't delete directory because it causes application restart

          //System.IO.Directory.Delete(dir, true);
          //AtomSite.Utils.FileHelper.RemoveEmptyPaths(pathResolver.GetCollectionPath(entryId), true);
        }
        catch (Exception ex)
        {
          System.Diagnostics.Trace.TraceError(ex.Message);
        }
      }

      //clear parent from cache
      if (entryId.IsAnnotation)
      {
        string parent = pathResolver.GetEntryPath(entryId.GetParentId());
        entries.Clear(parent);
      }

    }
 public string GetEntryEtag(Id entryId)
 {
   string path = pathResolver.GetEntryPath(entryId);
   try
   {
     //contentLength = (int)(new FileInfo(path).Length);
     return FileHelper.ComputeMD5Sum(path);
   }
   catch (FileNotFoundException)
   {
     throw new ResourceNotFoundException("entry", entryId.ToString());
   }
 }
コード例 #10
0
    public AtomEntry GetEntry(Id entryId)
    {
      string path = pathResolver.GetEntryPath(entryId);
      if (!File.Exists(path)) throw new ResourceNotFoundException("entry", entryId.ToString());

      //TODO: why the cast needed?
      AtomEntry e = (AtomEntry)entries.Get(path);
      Compute(e); //determine computed data
      return e;
    }
コード例 #11
0
    protected void OnAnnotateEntry(Id entryId, AtomEntry entry, string slug)
    {
      LogService.Info("BlogService.OnAnnotateEntry");
      if (!new BlogAppCollection(AppService.GetCollection(entryId)).BloggingOn) return;
      //TODO: check if author url (referrer) is blocked

      //TODO: check if content src is blocked

      //TODO: check if spam

      if (entry.AnnotationType == null) entry.AnnotationType = "comment";

      AppCollection coll = AppService.GetCollection(entryId);
      AnnotationState state = AnnotateService.GetAnnotationState(coll, entryId);
      if (state != AnnotationState.On)
        throw new AnnotationNotAllowedException(entryId.ToString(), entry.AnnotationType, "the state is " + state);


      //default title to comment when not given
      if (entry.Title == null || string.IsNullOrEmpty(entry.Title.Text))
        entry.Title = new AtomText(Atom.AtomNs + "title") { Text = "Comment" };

      //approved?
      if (!AuthorizeService.IsAuthorized((User)System.Threading.Thread.CurrentPrincipal.Identity,
        entry.Id.ToScope(), AuthAction.ApproveAnnotation))
      {
        entry.Control = new AppControl() { Approved = false };
      }

      //clean input
      if (entry.Content.Type == "html" || entry.Content.Type == "xhtml")
      {
        if (AuthorizeService.IsAuthorized((User)System.Threading.Thread.CurrentPrincipal.Identity,
          entryId.ToScope(), AuthAction.ApproveAnnotation))
          CleanContentService.CleanContentTrusted(entry.Content);
        else
          CleanContentService.CleanContentFully(entry.Content);
      }
      else if (entry.Content.Type == "text")
      {
          entry.Content.Text = entry.Content.Text.Replace("<", "&lt;").Replace(">", "&gt;");
      }

      else if (entry.Content.Src == null)
          throw new AnnotationNotAllowedException(entryId.ToString(), entry.AnnotationType, "content must be text, html, or external.");

      AtomEntry parent = AtomEntryRepository.GetEntry(entryId);
      //check if there is already a content src annotation with this link
      int total;
      if (entry.IsExternal && AtomEntryRepository.GetEntries(
        new EntryCriteria()
        {
          EntryId = parent.Id,
          Annotations = true,
          Authorized = true,
          Deep = true
        }, 0, int.MaxValue, out total)
        .Where(a => a.Content.Src != null && a.Content.Src == entry.Content.Src).Count() > 0)
        throw new AnnotationNotAllowedException(parent.Id, entry.AnnotationType, "it already contains a link to the source.");

      //TODO: allow categories on annotations?
      entry.Categories = null;
    }
コード例 #12
0
 public static bool ContainsId(this IEnumerable<AtomEntry> entries, Id id)
 {
     return entries.Any(entry => entry.Id.ToString() == id.ToString());
 }
コード例 #13
0
    private void ChangeCollectionId(AppService appSvc, Id oldId, Id newId)
    {
      if (newId == null) return;

      //update old id's in service.config
      //update include ids
      foreach (XElement xid in appSvc.Xml.Descendants(Atom.SvcNs + "id"))
      {
        if (xid.Value.StartsWith(oldId.ToString()))
        {
          string id = newId.ToString() + xid.Value.Substring(oldId.ToString().Length);
          LogProgress("Changing old include id from {0} to {1}", xid, id);
          xid.SetValue(id);
        }
      }
      LogProgress("Changing old collection id from {0} to {1}", oldId, newId);
      appSvc.GetCollection(oldId).Id = newId;
    }