Skip to content

Commit 2ca4ea4

Browse files
author
Ali Ahmed Sahi
authored
Merge pull request #23 from aliahmedgroupdocs/master
GroupDocs_Annotation_SharePoint_WebPart added
2 parents 6c982cf + a062b5c commit 2ca4ea4

170 files changed

Lines changed: 53668 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace GroupDocs.Data.Json
4+
{
5+
public class DataJsonException : Exception
6+
{
7+
public DataJsonException(string message, Exception innerException)
8+
: base(message, innerException)
9+
{
10+
}
11+
}
12+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{352BBB7A-98AF-4B05-B8D7-74334EDCE61C}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>GroupDocs.Data.Json</RootNamespace>
12+
<AssemblyName>GroupDocs.Data.Json</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
16+
<RestorePackages>true</RestorePackages>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<SignAssembly>true</SignAssembly>
37+
</PropertyGroup>
38+
<PropertyGroup>
39+
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
40+
</PropertyGroup>
41+
<ItemGroup>
42+
<Reference Include="GroupDocs.Annotation, Version=3.2.1.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
43+
<HintPath>..\packages\groupdocs-annotation-dotnet.3.2.1\lib\GroupDocs.Annotation.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="Microsoft.CSharp" />
52+
<Reference Include="System.Configuration" />
53+
<Reference Include="System.Web" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Compile Include="DataJsonException.cs" />
57+
<Compile Include="Repositories\AnnotationCollaboratorRepository.cs" />
58+
<Compile Include="Repositories\AnnotationReplyRepository.cs" />
59+
<Compile Include="Repositories\AnnotationRepository.cs" />
60+
<Compile Include="JsonFile.cs" />
61+
<Compile Include="Repositories\DocumentInfoRepository.cs" />
62+
<Compile Include="Repositories\DocumentRepository.cs" />
63+
<Compile Include="Repositories\FileRepository.cs" />
64+
<Compile Include="Repositories\JsonRepository.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
<Compile Include="Repositories\UserRepository.cs" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<None Include="app.config" />
70+
<None Include="key.snk" />
71+
<None Include="packages.config">
72+
<SubType>Designer</SubType>
73+
</None>
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
77+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78+
Other similar extension points exist, see Microsoft.Common.targets.
79+
<Target Name="BeforeBuild">
80+
</Target>
81+
<Target Name="AfterBuild">
82+
</Target>
83+
-->
84+
</Project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.IO;
3+
using Newtonsoft.Json;
4+
5+
namespace GroupDocs.Data.Json
6+
{
7+
8+
public class JsonFile<T>
9+
where T : new()
10+
{
11+
#region Fields
12+
protected readonly object _syncRoot = new object();
13+
14+
private string _filePath;
15+
private T _data;
16+
#endregion Fields
17+
18+
public JsonFile(string filePath)
19+
{
20+
if (String.IsNullOrWhiteSpace(filePath))
21+
{
22+
throw new ArgumentNullException("filePath");
23+
}
24+
25+
_filePath = filePath;
26+
}
27+
28+
protected virtual void Serialize()
29+
{
30+
if (_data == null)
31+
{
32+
return;
33+
}
34+
35+
lock (_syncRoot)
36+
{
37+
if (_data != null)
38+
{
39+
try
40+
{
41+
using (var stream = File.OpenWrite(_filePath))
42+
using (var writer = new StreamWriter(stream))
43+
using (JsonWriter jwriter = new JsonTextWriter(writer) {Formatting = Formatting.Indented})
44+
{
45+
JsonSerializer serializer = new JsonSerializer();
46+
serializer.Serialize(jwriter, _data);
47+
}
48+
}
49+
catch (Exception e)
50+
{
51+
throw new Exception("Failed to serialize an object to file: '{0}'.", e);
52+
}
53+
}
54+
}
55+
}
56+
57+
protected virtual void Deserialize()
58+
{
59+
lock (_syncRoot)
60+
{
61+
try
62+
{
63+
if (!File.Exists(_filePath))
64+
{
65+
var fileStream = File.Create(_filePath);
66+
fileStream.Close();
67+
_data = new T();
68+
return;
69+
}
70+
71+
using (var stream = File.OpenRead(_filePath))
72+
using (var reader = new StreamReader(stream))
73+
using (JsonReader jreader = new JsonTextReader(reader))
74+
{
75+
JsonSerializer serializer = new JsonSerializer();
76+
_data = serializer.Deserialize<T>(jreader);
77+
}
78+
}
79+
catch (Exception e)
80+
{
81+
throw new Exception("Failed to deserialize an object from file: '{0}'.", e);
82+
}
83+
84+
if(_data == null)
85+
{
86+
_data = new T();
87+
}
88+
}
89+
}
90+
91+
protected T Data
92+
{
93+
get
94+
{
95+
lock (_syncRoot)
96+
{
97+
if (_data == null)
98+
{
99+
Deserialize();
100+
}
101+
102+
return _data;
103+
}
104+
}
105+
}
106+
}
107+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("GroupDocs.Data.Json")]
9+
[assembly: AssemblyDescription("GroupDocs.Annotation for .NET API WebForms Front-End")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("GroupDocs.Data.Json")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("fc3ec246-83d0-4a13-b5f7-0b49650bf1e6")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using GroupDocs.Annotation.Handler.Input;
5+
using GroupDocs.Annotation.Handler.Input.DataObjects;
6+
7+
namespace GroupDocs.Data.Json.Repositories
8+
{
9+
public class AnnotationCollaboratorRepository : JsonRepository<AnnotationCollaborator>, IAnnotationCollaboratorDataHandler
10+
{
11+
private const string _repoName = "GroupDocs.annotation.collaborators.json";
12+
13+
public AnnotationCollaboratorRepository(string repositoryFolder)
14+
: base(Path.Combine(repositoryFolder, _repoName))
15+
{
16+
}
17+
18+
public AnnotationCollaborator[] GetDocumentCollaborators(long documentId)
19+
{
20+
lock (_syncRoot)
21+
{
22+
try
23+
{
24+
return Data.Where(x => x.DocumentId == documentId).ToArray();
25+
}
26+
catch (Exception e)
27+
{
28+
throw new DataJsonException("Failed to get document collaborators.", e);
29+
}
30+
}
31+
}
32+
}
33+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using GroupDocs.Annotation.Handler.Input;
6+
using GroupDocs.Annotation.Handler.Input.DataObjects;
7+
8+
namespace GroupDocs.Data.Json.Repositories
9+
{
10+
public class AnnotationReplyRepository : JsonRepository<AnnotationReply>, IAnnotationReplyDataHandler
11+
{
12+
13+
private const string _repoName = "GroupDocs.annotation.replies.json";
14+
15+
public AnnotationReplyRepository(string repositoryFolder)
16+
: base(Path.Combine(repositoryFolder, _repoName))
17+
{
18+
}
19+
20+
21+
public AnnotationReply GetReply(string guid)
22+
{
23+
lock (_syncRoot)
24+
{
25+
try
26+
{
27+
return Data.FirstOrDefault(x => x.Guid == guid);
28+
}
29+
catch (Exception e)
30+
{
31+
throw new DataJsonException("Failed to get annotation reply by GUID.", e);
32+
}
33+
}
34+
}
35+
36+
public AnnotationReply[] GetReplies(long annotationId)
37+
{
38+
lock (_syncRoot)
39+
{
40+
try
41+
{
42+
return Data
43+
.Where(x => x.AnnotationId == annotationId)
44+
.OrderBy(r => r.RepliedOn)
45+
.ToArray();
46+
}
47+
catch (Exception e)
48+
{
49+
throw new DataJsonException("Failed to get annotation replies.", e);
50+
}
51+
}
52+
}
53+
54+
public bool DeleteReplyAndChildReplies(long replyId)
55+
{
56+
lock (_syncRoot)
57+
{
58+
try
59+
{
60+
var data = this.Data;
61+
bool returnValue = true;
62+
63+
AnnotationReply reply = data.FirstOrDefault(r => r.Id == replyId);
64+
List<AnnotationReply> childReplies = new List<AnnotationReply>();
65+
AnnotationReply[] repliesOfCurrentLevel = data.Where(r => r.ParentReplyId == replyId).ToArray();
66+
List<AnnotationReply> repliesOfNextLevel = new List<AnnotationReply>();
67+
68+
while (repliesOfCurrentLevel.Length > 0)
69+
{
70+
repliesOfNextLevel.Clear();
71+
childReplies.AddRange(repliesOfCurrentLevel);
72+
73+
for (int i = 0; i < repliesOfCurrentLevel.Length; i++)
74+
{
75+
decimal id = repliesOfCurrentLevel[i].Id;
76+
repliesOfNextLevel.AddRange(
77+
data.Where(r => r.ParentReplyId == id).ToArray());
78+
}
79+
80+
repliesOfCurrentLevel = repliesOfNextLevel.ToArray();
81+
}
82+
83+
childReplies.Reverse();
84+
childReplies.ForEach(x => returnValue &= base.Remove(x));
85+
86+
returnValue &= base.Remove(reply);
87+
return returnValue;
88+
}
89+
catch (Exception e)
90+
{
91+
throw new DataJsonException("Failed to delete annotation replies.", e);
92+
}
93+
}
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)