Skip to content

Commit

Permalink
prep for view file, added comments, unified code style
Browse files Browse the repository at this point in the history
  • Loading branch information
petrsvihlik committed Oct 24, 2020
1 parent 44b4294 commit 96c41b1
Show file tree
Hide file tree
Showing 39 changed files with 430 additions and 316 deletions.
1 change: 1 addition & 0 deletions WOPI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VisualStudioVersion = 16.0.29319.158
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{785E1533-48CE-4B5E-8C59-D6F1FDA8C45C}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
appveyor.yml = appveyor.yml
coverage.ps1 = coverage.ps1
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Abstractions/WopiClaimTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public class WopiClaimTypes
{
public const string UserPermissions = nameof(UserPermissions);
public const string USER_PERMISSIONS = nameof(USER_PERMISSIONS);
}
}
58 changes: 29 additions & 29 deletions WopiHost.Cobalt/CobaltHostLockingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CobaltHostLockingStore(ClaimsPrincipal principal)

public override WhoAmIRequest.OutputType HandleWhoAmI(WhoAmIRequest.InputType input)
{
WhoAmIRequest.OutputType result = new WhoAmIRequest.OutputType
var result = new WhoAmIRequest.OutputType
{
UserEmailAddress = _principal?.FindFirst(ClaimTypes.Email).Value,
UserIsAnonymous = string.IsNullOrEmpty(_principal?.FindFirst(ClaimTypes.NameIdentifier).Value),
Expand All @@ -29,14 +29,14 @@ public override WhoAmIRequest.OutputType HandleWhoAmI(WhoAmIRequest.InputType in

public override ServerTimeRequest.OutputType HandleServerTime(ServerTimeRequest.InputType input)
{
ServerTimeRequest.OutputType result = new ServerTimeRequest.OutputType { ServerTime = DateTime.UtcNow };
var result = new ServerTimeRequest.OutputType { ServerTime = DateTime.UtcNow };

return result;
}

public override LockAndCheckOutStatusRequest.OutputType HandleLockAndCheckOutStatus(LockAndCheckOutStatusRequest.InputType input)
{
LockAndCheckOutStatusRequest.OutputType result = new LockAndCheckOutStatusRequest.OutputType
var result = new LockAndCheckOutStatusRequest.OutputType
{
LockType = 1U,
CheckOutType = 0U
Expand All @@ -47,84 +47,84 @@ public override LockAndCheckOutStatusRequest.OutputType HandleLockAndCheckOutSta

public override GetExclusiveLockRequest.OutputType HandleGetExclusiveLock(GetExclusiveLockRequest.InputType input)
{
GetExclusiveLockRequest.OutputType result = new GetExclusiveLockRequest.OutputType();
var result = new GetExclusiveLockRequest.OutputType();

return result;
}

public override RefreshExclusiveLockRequest.OutputType HandleRefreshExclusiveLock(RefreshExclusiveLockRequest.InputType input)
{
RefreshExclusiveLockRequest.OutputType result = new RefreshExclusiveLockRequest.OutputType();
var result = new RefreshExclusiveLockRequest.OutputType();

return result;
}

public override CheckExclusiveLockAvailabilityRequest.OutputType HandleCheckExclusiveLockAvailability(CheckExclusiveLockAvailabilityRequest.InputType input)
{
CheckExclusiveLockAvailabilityRequest.OutputType result = new CheckExclusiveLockAvailabilityRequest.OutputType();
var result = new CheckExclusiveLockAvailabilityRequest.OutputType();

return result;
}

public override ConvertExclusiveLockToSchemaLockRequest.OutputType HandleConvertExclusiveLockToSchemaLock(ConvertExclusiveLockToSchemaLockRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
ConvertExclusiveLockToSchemaLockRequest.OutputType result = new ConvertExclusiveLockToSchemaLockRequest.OutputType();
var result = new ConvertExclusiveLockToSchemaLockRequest.OutputType();

return result;
}

public override ConvertExclusiveLockWithCoauthTransitionRequest.OutputType HandleConvertExclusiveLockWithCoauthTransition(ConvertExclusiveLockWithCoauthTransitionRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
ConvertExclusiveLockWithCoauthTransitionRequest.OutputType result = new ConvertExclusiveLockWithCoauthTransitionRequest.OutputType();
var result = new ConvertExclusiveLockWithCoauthTransitionRequest.OutputType();

return result;
}

public override GetSchemaLockRequest.OutputType HandleGetSchemaLock(GetSchemaLockRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
GetSchemaLockRequest.OutputType result = new GetSchemaLockRequest.OutputType();
var result = new GetSchemaLockRequest.OutputType();

return result;
}

public override ReleaseExclusiveLockRequest.OutputType HandleReleaseExclusiveLock(ReleaseExclusiveLockRequest.InputType input)
{
ReleaseExclusiveLockRequest.OutputType result = new ReleaseExclusiveLockRequest.OutputType();
var result = new ReleaseExclusiveLockRequest.OutputType();

return result;
}

public override ReleaseSchemaLockRequest.OutputType HandleReleaseSchemaLock(ReleaseSchemaLockRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
ReleaseSchemaLockRequest.OutputType result = new ReleaseSchemaLockRequest.OutputType();
var result = new ReleaseSchemaLockRequest.OutputType();

return result;
}

public override RefreshSchemaLockRequest.OutputType HandleRefreshSchemaLock(RefreshSchemaLockRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
RefreshSchemaLockRequest.OutputType result = new RefreshSchemaLockRequest.OutputType { Lock = LockType.SchemaLock };
var result = new RefreshSchemaLockRequest.OutputType { Lock = LockType.SchemaLock };

return result;
}

public override ConvertSchemaLockToExclusiveLockRequest.OutputType HandleConvertSchemaLockToExclusiveLock(ConvertSchemaLockToExclusiveLockRequest.InputType input)
{
ConvertSchemaLockToExclusiveLockRequest.OutputType result = new ConvertSchemaLockToExclusiveLockRequest.OutputType();
var result = new ConvertSchemaLockToExclusiveLockRequest.OutputType();

return result;
}

public override CheckSchemaLockAvailabilityRequest.OutputType HandleCheckSchemaLockAvailability(CheckSchemaLockAvailabilityRequest.InputType input)
{
CheckSchemaLockAvailabilityRequest.OutputType result = new CheckSchemaLockAvailabilityRequest.OutputType();
var result = new CheckSchemaLockAvailabilityRequest.OutputType();

return result;
}

public override JoinCoauthoringRequest.OutputType HandleJoinCoauthoring(JoinCoauthoringRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
JoinCoauthoringRequest.OutputType result = new JoinCoauthoringRequest.OutputType
var result = new JoinCoauthoringRequest.OutputType
{
Lock = LockType.SchemaLock,
CoauthStatus = CoauthStatusType.Alone,
Expand All @@ -135,14 +135,14 @@ public override JoinCoauthoringRequest.OutputType HandleJoinCoauthoring(JoinCoau

public override ExitCoauthoringRequest.OutputType HandleExitCoauthoring(ExitCoauthoringRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
ExitCoauthoringRequest.OutputType result = new ExitCoauthoringRequest.OutputType();
var result = new ExitCoauthoringRequest.OutputType();

return result;
}

public override RefreshCoauthoringSessionRequest.OutputType HandleRefreshCoauthoring(RefreshCoauthoringSessionRequest.InputType input, int protocolMajorVersion, int protocolMinorVersion)
{
RefreshCoauthoringSessionRequest.OutputType result = new RefreshCoauthoringSessionRequest.OutputType
var result = new RefreshCoauthoringSessionRequest.OutputType
{
Lock = LockType.SchemaLock,
CoauthStatus = CoauthStatusType.Alone
Expand All @@ -153,28 +153,28 @@ public override RefreshCoauthoringSessionRequest.OutputType HandleRefreshCoautho

public override ConvertCoauthLockToExclusiveLockRequest.OutputType HandleConvertCoauthLockToExclusiveLock(ConvertCoauthLockToExclusiveLockRequest.InputType input)
{
ConvertCoauthLockToExclusiveLockRequest.OutputType result = new ConvertCoauthLockToExclusiveLockRequest.OutputType();
var result = new ConvertCoauthLockToExclusiveLockRequest.OutputType();

return result;
}

public override CheckCoauthLockAvailabilityRequest.OutputType HandleCheckCoauthLockAvailability(CheckCoauthLockAvailabilityRequest.InputType input)
{
CheckCoauthLockAvailabilityRequest.OutputType result = new CheckCoauthLockAvailabilityRequest.OutputType();
var result = new CheckCoauthLockAvailabilityRequest.OutputType();

return result;
}

public override MarkCoauthTransitionCompleteRequest.OutputType HandleMarkCoauthTransitionComplete(MarkCoauthTransitionCompleteRequest.InputType input)
{
MarkCoauthTransitionCompleteRequest.OutputType result = new MarkCoauthTransitionCompleteRequest.OutputType();
var result = new MarkCoauthTransitionCompleteRequest.OutputType();

return result;
}

public override GetCoauthoringStatusRequest.OutputType HandleGetCoauthoringStatus(GetCoauthoringStatusRequest.InputType input)
{
GetCoauthoringStatusRequest.OutputType result = new GetCoauthoringStatusRequest.OutputType
var result = new GetCoauthoringStatusRequest.OutputType
{
CoauthStatus = CoauthStatusType.Alone
};
Expand All @@ -189,35 +189,35 @@ public override Dictionary<string, EditorsTableEntry> QueryEditorsTable()

public override JoinEditingSessionRequest.OutputType HandleJoinEditingSession(JoinEditingSessionRequest.InputType input)
{
JoinEditingSessionRequest.OutputType result = new JoinEditingSessionRequest.OutputType();
var result = new JoinEditingSessionRequest.OutputType();

return result;
}

public override RefreshEditingSessionRequest.OutputType HandleRefreshEditingSession(RefreshEditingSessionRequest.InputType input)
{
RefreshEditingSessionRequest.OutputType result = new RefreshEditingSessionRequest.OutputType();
var result = new RefreshEditingSessionRequest.OutputType();

return result;
}

public override LeaveEditingSessionRequest.OutputType HandleLeaveEditingSession(LeaveEditingSessionRequest.InputType input)
{
LeaveEditingSessionRequest.OutputType result = new LeaveEditingSessionRequest.OutputType();
var result = new LeaveEditingSessionRequest.OutputType();

return result;
}

public override UpdateEditorMetadataRequest.OutputType HandleUpdateEditorMetadata(UpdateEditorMetadataRequest.InputType input)
{
UpdateEditorMetadataRequest.OutputType result = new UpdateEditorMetadataRequest.OutputType();
var result = new UpdateEditorMetadataRequest.OutputType();

return result;
}

public override RemoveEditorMetadataRequest.OutputType HandleRemoveEditorMetadata(RemoveEditorMetadataRequest.InputType input)
{
RemoveEditorMetadataRequest.OutputType result = new RemoveEditorMetadataRequest.OutputType();
var result = new RemoveEditorMetadataRequest.OutputType();

return result;
}
Expand All @@ -229,21 +229,21 @@ public override ulong GetEditorsTableWaterline()

public override AmIAloneRequest.OutputType HandleAmIAlone(AmIAloneRequest.InputType input)
{
AmIAloneRequest.OutputType result = new AmIAloneRequest.OutputType { AmIAlone = true };
var result = new AmIAloneRequest.OutputType { AmIAlone = true };

return result;
}

public override DocMetaInfoRequest.OutputType HandleDocMetaInfo(DocMetaInfoRequest.InputType input)
{
DocMetaInfoRequest.OutputType result = new DocMetaInfoRequest.OutputType();
var result = new DocMetaInfoRequest.OutputType();

return result;
}

public override VersionsRequest.OutputType HandleVersions(VersionsRequest.InputType input)
{
VersionsRequest.OutputType result = new VersionsRequest.OutputType { Enabled = false };
var result = new VersionsRequest.OutputType { Enabled = false };

return result;
}
Expand Down
18 changes: 9 additions & 9 deletions WopiHost.Cobalt/CobaltSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CobaltProcessor : ICobaltProcessor
private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
{
var disposal = new DisposalEscrow(file.Owner);
CobaltFilePartitionConfig content = new CobaltFilePartitionConfig
var content = new CobaltFilePartitionConfig
{
IsNewFile = true,
HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".Content"),
Expand All @@ -23,7 +23,7 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
PartitionId = FilePartitionId.Content
};

CobaltFilePartitionConfig coauth = new CobaltFilePartitionConfig
var coauth = new CobaltFilePartitionConfig
{
IsNewFile = true,
HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".CoauthMetadata"),
Expand All @@ -33,7 +33,7 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
PartitionId = FilePartitionId.CoauthMetadata
};

CobaltFilePartitionConfig wacupdate = new CobaltFilePartitionConfig
var wacupdate = new CobaltFilePartitionConfig
{
IsNewFile = true,
HostBlobStore = new TemporaryHostBlobStore(new TemporaryHostBlobStore.Config(), disposal, file.Identifier + @".WordWacUpdate"),
Expand All @@ -43,7 +43,7 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
PartitionId = FilePartitionId.WordWacUpdate
};

Dictionary<FilePartitionId, CobaltFilePartitionConfig> partitionConfigs = new Dictionary<FilePartitionId, CobaltFilePartitionConfig> { { FilePartitionId.Content, content }, { FilePartitionId.WordWacUpdate, wacupdate }, { FilePartitionId.CoauthMetadata, coauth } };
var partitionConfigs = new Dictionary<FilePartitionId, CobaltFilePartitionConfig> { { FilePartitionId.Content, content }, { FilePartitionId.WordWacUpdate, wacupdate }, { FilePartitionId.CoauthMetadata, coauth } };


var tempCobaltFile = new CobaltFile(disposal, partitionConfigs, new CobaltHostLockingStore(principal), null);
Expand All @@ -53,7 +53,7 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
using (var stream = file.GetReadStream())
{
var srcAtom = new AtomFromStream(stream);
tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, srcAtom, out Metrics o1);
tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).SetStream(RootId.Default.Value, srcAtom, out var o1);
tempCobaltFile.GetCobaltFilePartition(FilePartitionId.Content).GetStream(RootId.Default.Value).Flush();
}
}
Expand All @@ -65,7 +65,7 @@ private CobaltFile GetCobaltFile(IWopiFile file, ClaimsPrincipal principal)
public Stream GetFileStream(IWopiFile file, ClaimsPrincipal principal)
{
//TODO: use in filescontroller
using (MemoryStream ms = new MemoryStream())
using (var ms = new MemoryStream())
{
new GenericFda(GetCobaltFile(file, principal).CobaltEndpoint).GetContentStream().CopyTo(ms);
return ms;
Expand All @@ -76,11 +76,11 @@ public Stream GetFileStream(IWopiFile file, ClaimsPrincipal principal)
public Action<Stream> ProcessCobalt(IWopiFile file, ClaimsPrincipal principal, byte[] newContent)
{
// Refactoring tip: there are more ways of initializing Atom
AtomFromByteArray atomRequest = new AtomFromByteArray(newContent);
RequestBatch requestBatch = new RequestBatch();
var atomRequest = new AtomFromByteArray(newContent);
var requestBatch = new RequestBatch();


requestBatch.DeserializeInputFromProtocol(atomRequest, out object ctx, out ProtocolVersion protocolVersion);
requestBatch.DeserializeInputFromProtocol(atomRequest, out var ctx, out var protocolVersion);
var cobaltFile = GetCobaltFile(file, principal);
cobaltFile.CobaltEndpoint.ExecuteRequestBatch(requestBatch);

Expand Down
6 changes: 3 additions & 3 deletions WopiHost.Core/Controllers/ContainersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public CheckContainerInfo GetCheckContainerInfo(string id)
[Produces("application/json")]
public Container EnumerateChildren(string id)
{
Container container = new Container();
var container = new Container();
var files = new List<ChildFile>();
var containers = new List<ChildContainer>();

foreach (IWopiFile wopiFile in StorageProvider.GetWopiFiles(id))
foreach (var wopiFile in StorageProvider.GetWopiFiles(id))
{
files.Add(new ChildFile
{
Expand All @@ -64,7 +64,7 @@ public Container EnumerateChildren(string id)
});
}

foreach (IWopiFolder wopiContainer in StorageProvider.GetWopiContainers(id))
foreach (var wopiContainer in StorageProvider.GetWopiContainers(id))
{
containers.Add(new ChildContainer
{
Expand Down
2 changes: 1 addition & 1 deletion WopiHost.Core/Controllers/EcosystemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public EcosystemController(IWopiStorageProvider fileProvider, IWopiSecurityHandl
public RootContainerInfo GetRootContainer()
{
var root = StorageProvider.GetWopiContainer(@".\");
RootContainerInfo rc = new RootContainerInfo
var rc = new RootContainerInfo
{
ContainerPointer = new ChildContainer
{
Expand Down
Loading

0 comments on commit 96c41b1

Please sign in to comment.