From aecdb643aa303c47b680a17de319cd0e601b8200 Mon Sep 17 00:00:00 2001 From: Manoj Malik Date: Fri, 6 May 2022 14:22:05 +0530 Subject: [PATCH] Improved logging and added the logic to sign the build in the CI (#12) * Basic setup of COM server and presence provider * Added the basic implementations of all the interfaces and more than basic of some interfaces Made a separate file for the AutomationBase class Fixed the logic for registering the type library by fixing the path given Added a new tlb extracted from Skype for Business Added a global exception handler Completed the implementation of IMClientContact class Completed the implementation of IMClientSelf class Added several dependent classes such as IMClientContactInformationDictionary, IMClientContactSettingDictionary Added the basic implementation of IContactEndpoint, IContactManager, IContactSubscription, IGroup, IGroupCollection, ILocaleString interfaces * Review fixes * Added the logic of showing the presence icon fetching status from Mattermost when Outlook starts Added required attributes like ComVisible and ComSourceInterfaces on top of all the classes Added some required Nuget packages like System.Text.Json etc and modified .gitignore to avoid the packages Added the logic to return different values from GetContactInformation depending on the type of value requested Made a HTTP client and added the necessary headers Made the self object by hard-coding the email id of the current user Added the logic of fetching the Mattermost server url from the registry and making a request for fetching status of a user Made a Constants class for storing the mapping between the Mattermost status and the Outlook availability Added a basic implementation of the IAsyncOperation interface and the Lookup method in the IMClientContactManager class * Added EOF in all the files * Removed useless imports from all the files * Removed useless directives and deleted useless file * Added polling strategy to trigger presence updates for all the contacts Fixed the presence text not showing in Outlook using ContactInformationType.ucPresenceActivityId Made a map in constants mapping availabilities with values of activity id Changed the logic in CanStart method of IMClientContact and the value of UnifiedCommunicationType property to observe the changes Solved the issue in triggering the presence change by returning the uri from ContactInformationType.ucPresenceInstantMessageAddresses in the GetContactInformation method Made a class IMClientContactInformationChangedEventData which implements ContactInformationChangedEventData Added the logic for handling groups in IMClientContactManager class Modified the call to OnLookup callback function Added a timer which runs in an interval of 10 seconds to trigger OnContactInformationChangedEvent for every contact in the list * Review fixes * Created a websocket client to connect to Mattermost websocket and added proper handling Moved all the Mattermost client related logic in a separate client class Added the logic to connect to Mattermost websocket and added an event handler in the ContactSubscription class to trigger presence change events for subscribed contacts Added the logic to use the status got from websocket event and not call the API Added the logic to not use the previous status for a contact but fetch the latest status when pages are changed in Outlook Changed the logic inside the ContactManager.Lookup function and added comments Optimized the way subscribed contacts are stored in the ContactSubscription class * Review fixes * Review fixes * Removed useless logs and added some comments Little refactoring * Added authentication with every request to the Mattermost server and the logic to read values from config file Uncommented and modified the logic to register the type library Modified the client to read the values from a config.json file and create one if doesn't exist Added the logic to send the secret with every request to the Mattermost server Changed the websocket reconnection timeout to 30 seconds * Implemented the status cache and added a setup project Created a store class to store the statuses for all the Mattermost users Added the logic to always return the availability from the store and always update the store based on websocket event Added the logic to initialize the store when the app starts Removed the hard coded self url from the ClientBase class Added and configured a setup project to create a setup for the app * Renamed the setup project as BuildSetup and modified .gitignore * Final refactoring Fixed the logic of creating entries in the registry so that Outlook can look for the app * Added empty ci.yml file in Github workflows * Added basic test setup for the CI script * Added CI script to create build and release in Github Modified the Author, Manufacturer and TargetFramework of the setup project Made the websocket reconnection timeout configurable via config.json Replaced all occurences of "" with string.Empty * Modified the CI workflow to run for tags only * Modified the name of the final zip file to contain the github tag * Fixed the filename of the zip created after the build in CI * Fixed the assembly name for the CSExeCOMServer * Added documentation * Added logging through a log file * WIP: Added the logic of creating entries in the registry while installing the app * Added logging through Event logs and completed the logic of creating registry entries while installing Removed logging in a file logic from the app.config Added logic to create a new event log and source while installing the setup project Added the newly created event source as the trace listener Improved logging of errors by adding message with the stack trace * Added the logic to specify a size for the event log * Improved logging in the app to figure out the cause of the error * Added the logic to sign the build with a certificate in the CI yml script * Added the logic to create a shortcut in the Start Menu after installation --- .github/workflows/release.yml | 10 + .../MattermostPresenceProvider.vdproj | 194 +++++++++++------- PresenceProvider/Mattermost/Client.cs | 9 +- PresenceProvider/Mattermost/Store.cs | 14 +- .../OtherInterfaces/IMClientContact.cs | 6 +- .../OtherInterfaces/IMClientContactManager.cs | 3 +- .../OutLookPresenceProvider.csproj | 1 + PresenceProvider/PresenceProvider.cs | 3 +- PresenceProvider/Utils.cs | 19 ++ 9 files changed, 166 insertions(+), 93 deletions(-) create mode 100644 PresenceProvider/Utils.cs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bca0be2..ea8e8ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,16 @@ jobs: - name: Build the solution run: devenv.com .\CSExeCOMServer.sln /Build Release + - name: Sign the build with a code signing certificate + run: | + $bytes = [Convert]::FromBase64String("${{ secrets.CODE_SIGNING_CERT }}") + [IO.File]::WriteAllBytes("cert.pfx", $bytes) + $SignToolPath = $env:WindowsSdkVerBinPath + "x64\signtool.exe" + if ($SignToolPath | Test-Path) { + & $SignToolPath sign /f .\cert.pfx /fd SHA256 /d "Mattermost Presence Provider" .\MattermostPresenceProvider\Setup.msi + & $SignToolPath sign /f .\cert.pfx /fd SHA256 /d "Mattermost Presence Provider" .\MattermostPresenceProvider\setup.exe + } + - name: Remove files and create a zip of the build run: | if (Test-Path .\MattermostPresenceProvider\MattermostPresenceProvider.vdproj) { Remove-Item .\MattermostPresenceProvider\MattermostPresenceProvider.vdproj } diff --git a/MattermostPresenceProvider/MattermostPresenceProvider.vdproj b/MattermostPresenceProvider/MattermostPresenceProvider.vdproj index 9cc8b04..3130122 100644 --- a/MattermostPresenceProvider/MattermostPresenceProvider.vdproj +++ b/MattermostPresenceProvider/MattermostPresenceProvider.vdproj @@ -40,12 +40,6 @@ "Entry" { "MsmKey" = "8:_5016D0532C492C9109DBCF9B3F381932" - "OwnerKey" = "8:_BB298BCD6074BDA64F4E08F9C6420161" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_5016D0532C492C9109DBCF9B3F381932" "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" "MsmSig" = "8:_UNDEFINED" } @@ -118,7 +112,7 @@ "Entry" { "MsmKey" = "8:_703C65C22BA13A0205A8461A7B5D043A" - "OwnerKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -135,6 +129,18 @@ } "Entry" { + "MsmKey" = "8:_74010AB752D49741378EB5A2CBBCC706" + "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_74010AB752D49741378EB5A2CBBCC706" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_8CE012C46979C0EA85B3685F146EC69C" "OwnerKey" = "8:_DB6720EAA3D5DA372A5924D4BD109058" "MsmSig" = "8:_UNDEFINED" @@ -159,7 +165,7 @@ } "Entry" { - "MsmKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" + "MsmKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" "MsmSig" = "8:_UNDEFINED" } @@ -172,13 +178,7 @@ "Entry" { "MsmKey" = "8:_BB298BCD6074BDA64F4E08F9C6420161" - "OwnerKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_BB298BCD6074BDA64F4E08F9C6420161" - "OwnerKey" = "8:_703C65C22BA13A0205A8461A7B5D043A" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -232,12 +232,6 @@ "Entry" { "MsmKey" = "8:_D2E4A208303334FEFE606F11ECD1F24D" - "OwnerKey" = "8:_ECC9F316C1DB31CE1C777158EBE5F947" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_D2E4A208303334FEFE606F11ECD1F24D" "OwnerKey" = "8:_DB6720EAA3D5DA372A5924D4BD109058" "MsmSig" = "8:_UNDEFINED" } @@ -261,12 +255,6 @@ } "Entry" { - "MsmKey" = "8:_D783AF66B9AA37D4923CADFFF325A26F" - "OwnerKey" = "8:_ECC9F316C1DB31CE1C777158EBE5F947" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_DB6720EAA3D5DA372A5924D4BD109058" "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" "MsmSig" = "8:_UNDEFINED" @@ -274,19 +262,7 @@ "Entry" { "MsmKey" = "8:_DB6720EAA3D5DA372A5924D4BD109058" - "OwnerKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_ECC9F316C1DB31CE1C777158EBE5F947" - "OwnerKey" = "8:_703C65C22BA13A0205A8461A7B5D043A" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_ECC9F316C1DB31CE1C777158EBE5F947" - "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -309,32 +285,20 @@ } "Entry" { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_D783AF66B9AA37D4923CADFFF325A26F" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_A55DCD399F53EFE7F4213EAE234896AF" + "MsmKey" = "8:_FAF12FB42146BB7C863FC2FDFF25A6DB" + "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" "MsmSig" = "8:_UNDEFINED" } "Entry" { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_6A126CFA9192A6860B444FDB4530F3AA" + "MsmKey" = "8:_FAF12FB42146BB7C863FC2FDFF25A6DB" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" "MsmSig" = "8:_UNDEFINED" } "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" + "OwnerKey" = "8:_D783AF66B9AA37D4923CADFFF325A26F" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -427,6 +391,24 @@ "OwnerKey" = "8:_13083496CDBF4520855C2C5A99DDA1F7" "MsmSig" = "8:_UNDEFINED" } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_A14E42BAB1A6CDDC6020263A578C099A" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_FAF12FB42146BB7C863FC2FDFF25A6DB" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_74010AB752D49741378EB5A2CBBCC706" + "MsmSig" = "8:_UNDEFINED" + } } "Configurations" { @@ -770,6 +752,37 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_74010AB752D49741378EB5A2CBBCC706" + { + "AssemblyRegister" = "3:1" + "AssemblyIsInGAC" = "11:FALSE" + "AssemblyAsmDisplayName" = "8:System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" + "ScatterAssemblies" + { + "_74010AB752D49741378EB5A2CBBCC706" + { + "Name" = "8:System.Net.Http.dll" + "Attributes" = "3:512" + } + } + "SourcePath" = "8:System.Net.Http.dll" + "TargetName" = "8:" + "Tag" = "8:" + "Folder" = "8:_7B0911FFC0404DA390170CCE6287BC92" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Vital" = "11:TRUE" + "ReadOnly" = "11:FALSE" + "Hidden" = "11:FALSE" + "System" = "11:FALSE" + "Permanent" = "11:FALSE" + "SharedLegacy" = "11:FALSE" + "PackageAs" = "3:1" + "Register" = "3:1" + "Exclude" = "11:FALSE" + "IsDependency" = "11:TRUE" + "IsolateTo" = "8:" + } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_8CE012C46979C0EA85B3685F146EC69C" { "AssemblyRegister" = "3:1" @@ -801,14 +814,14 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_A55DCD399F53EFE7F4213EAE234896AF" + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_A14E42BAB1A6CDDC6020263A578C099A" { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" "AssemblyAsmDisplayName" = "8:OutlookPresenceProvider, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" "ScatterAssemblies" { - "_A55DCD399F53EFE7F4213EAE234896AF" + "_A14E42BAB1A6CDDC6020263A578C099A" { "Name" = "8:OutlookPresenceProvider.dll" "Attributes" = "3:512" @@ -836,7 +849,7 @@ { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:System.Reactive, Version=4.3.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:System.Reactive, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL" "ScatterAssemblies" { "_BB298BCD6074BDA64F4E08F9C6420161" @@ -991,7 +1004,7 @@ { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:System.Text.Json, Version=6.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:System.Text.Json, Version=6.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" "ScatterAssemblies" { "_DB6720EAA3D5DA372A5924D4BD109058" @@ -1018,20 +1031,20 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_ECC9F316C1DB31CE1C777158EBE5F947" + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_ED01F8F93AD7AE95FE108EE94E3344DB" { "AssemblyRegister" = "3:1" - "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" + "AssemblyIsInGAC" = "11:TRUE" + "AssemblyAsmDisplayName" = "8:System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" "ScatterAssemblies" { - "_ECC9F316C1DB31CE1C777158EBE5F947" + "_ED01F8F93AD7AE95FE108EE94E3344DB" { - "Name" = "8:System.Threading.Channels.dll" + "Name" = "8:System.Net.Http.dll" "Attributes" = "3:512" } } - "SourcePath" = "8:System.Threading.Channels.dll" + "SourcePath" = "8:System.Net.Http.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7B0911FFC0404DA390170CCE6287BC92" @@ -1049,20 +1062,20 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_ED01F8F93AD7AE95FE108EE94E3344DB" + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_F87122926F8ED8FAB9B523E5BEAD40A9" { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:TRUE" - "AssemblyAsmDisplayName" = "8:System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" "ScatterAssemblies" { - "_ED01F8F93AD7AE95FE108EE94E3344DB" + "_F87122926F8ED8FAB9B523E5BEAD40A9" { - "Name" = "8:System.Net.Http.dll" + "Name" = "8:System.IO.Compression.dll" "Attributes" = "3:512" } } - "SourcePath" = "8:System.Net.Http.dll" + "SourcePath" = "8:System.IO.Compression.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7B0911FFC0404DA390170CCE6287BC92" @@ -1080,20 +1093,20 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_F87122926F8ED8FAB9B523E5BEAD40A9" + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_FAF12FB42146BB7C863FC2FDFF25A6DB" { "AssemblyRegister" = "3:1" - "AssemblyIsInGAC" = "11:TRUE" - "AssemblyAsmDisplayName" = "8:System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" + "AssemblyIsInGAC" = "11:FALSE" + "AssemblyAsmDisplayName" = "8:OutOfProcessCOMBase, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" "ScatterAssemblies" { - "_F87122926F8ED8FAB9B523E5BEAD40A9" + "_FAF12FB42146BB7C863FC2FDFF25A6DB" { - "Name" = "8:System.IO.Compression.dll" + "Name" = "8:OutOfProcessCOMBase.dll" "Attributes" = "3:512" } } - "SourcePath" = "8:System.IO.Compression.dll" + "SourcePath" = "8:OutOfProcessCOMBase.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7B0911FFC0404DA390170CCE6287BC92" @@ -1137,6 +1150,17 @@ "Property" = "8:ProgramMenuFolder" "Folders" { + "{9EF0B969-E518-4E46-987F-47570745A589}:_E9B1894F2FF24CE581FD67DD51BBB7CD" + { + "Name" = "8:Mattermost Presence Provider" + "AlwaysCreate" = "11:FALSE" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Property" = "8:_07838E619505405088C244A97DE5C1E8" + "Folders" + { + } + } } } "{3C67513D-01DD-4637-8A68-80971EB9504F}:_7B0911FFC0404DA390170CCE6287BC92" @@ -1434,6 +1458,20 @@ } "Shortcut" { + "{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_326D122991C9406A8AA97B7501969A0B" + { + "Name" = "8:Mattermost Presence Provider" + "Arguments" = "8:" + "Description" = "8:" + "ShowCmd" = "3:1" + "IconIndex" = "3:0" + "Transitive" = "11:FALSE" + "Target" = "8:_13083496CDBF4520855C2C5A99DDA1F7" + "Folder" = "8:_E9B1894F2FF24CE581FD67DD51BBB7CD" + "WorkingFolder" = "8:_7B0911FFC0404DA390170CCE6287BC92" + "Icon" = "8:" + "Feature" = "8:" + } } "UserInterface" { diff --git a/PresenceProvider/Mattermost/Client.cs b/PresenceProvider/Mattermost/Client.cs index 20052aa..60b9d66 100644 --- a/PresenceProvider/Mattermost/Client.cs +++ b/PresenceProvider/Mattermost/Client.cs @@ -88,8 +88,7 @@ private void InitializeStore() } } catch (Exception ex) { - Trace.TraceError(ex.Message); - Trace.TraceError(ex.StackTrace); + Utils.LogException(ex); } } @@ -107,7 +106,7 @@ private void InitializeWebsocketClientInNewThread() } catch (Exception ex) { - Trace.TraceError("ERROR: " + ex.ToString()); + Utils.LogException(ex); } } @@ -133,7 +132,7 @@ private void InitializeWebsocketClient() Trace.TraceInformation("Disconnection happened, type: " + info.Type); if (info.Type == DisconnectionType.Error || info.Type == DisconnectionType.ByServer) { - throw new Exception("Error in connecting to websocket server."); + Trace.TraceError($"Error in connecting to the websocket server: {info.Type}"); } }); @@ -163,7 +162,7 @@ private string GetValueFromConfig(string key) return configNode[key].GetValue(); } catch (Exception ex) { - Trace.TraceError(ex.Message); + Utils.LogException(ex); return string.Empty; } } diff --git a/PresenceProvider/Mattermost/Store.cs b/PresenceProvider/Mattermost/Store.cs index 2850f33..cf2977d 100644 --- a/PresenceProvider/Mattermost/Store.cs +++ b/PresenceProvider/Mattermost/Store.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Diagnostics; +using System.Collections.Generic; using UCCollaborationLib; namespace OutlookPresenceProvider.Mattermost @@ -18,7 +20,15 @@ public void Add(string email, string status) public ContactAvailability GetAvailability(string email) { - return Constants.StatusAvailabilityMap(_store[email]); + try + { + Trace.TraceInformation($"Returning availability of user: {email} from the store."); + return Constants.StatusAvailabilityMap(_store[email]); + } catch (Exception ex) + { + Utils.LogException(ex); + return ContactAvailability.ucAvailabilityOffline; + } } public bool Remove(string email) diff --git a/PresenceProvider/OtherInterfaces/IMClientContact.cs b/PresenceProvider/OtherInterfaces/IMClientContact.cs index d267189..3a53909 100644 --- a/PresenceProvider/OtherInterfaces/IMClientContact.cs +++ b/PresenceProvider/OtherInterfaces/IMClientContact.cs @@ -107,8 +107,7 @@ public object GetContactInformation(ContactInformationType _contactInformationTy } } catch (Exception ex) { - Trace.TraceError(ex.Message); - Trace.TraceError(ex.StackTrace); + Utils.LogException(ex); return null; } } @@ -176,8 +175,7 @@ public void RaiseOnContactInformationChangedEvent(ContactInformationChangedEvent handler(this, _eventData); } catch (Exception ex) { - Trace.TraceError(ex.Message); - Trace.TraceError(ex.StackTrace); + Utils.LogException(ex); } } } diff --git a/PresenceProvider/OtherInterfaces/IMClientContactManager.cs b/PresenceProvider/OtherInterfaces/IMClientContactManager.cs index 647eb88..2bf68e4 100644 --- a/PresenceProvider/OtherInterfaces/IMClientContactManager.cs +++ b/PresenceProvider/OtherInterfaces/IMClientContactManager.cs @@ -84,8 +84,7 @@ public AsynchronousOperation Lookup(string _lookupString, object _contactsAndGro callback.OnLookup(this, null, asyncOperation); } catch (Exception ex) { - Trace.TraceError(ex.Message); - Trace.TraceError(ex.StackTrace); + Utils.LogException(ex); } return asyncOperation; } diff --git a/PresenceProvider/OutLookPresenceProvider.csproj b/PresenceProvider/OutLookPresenceProvider.csproj index 3099300..35c9c1f 100644 --- a/PresenceProvider/OutLookPresenceProvider.csproj +++ b/PresenceProvider/OutLookPresenceProvider.csproj @@ -113,6 +113,7 @@ + diff --git a/PresenceProvider/PresenceProvider.cs b/PresenceProvider/PresenceProvider.cs index e12f040..1e30beb 100644 --- a/PresenceProvider/PresenceProvider.cs +++ b/PresenceProvider/PresenceProvider.cs @@ -34,8 +34,7 @@ public static void Register(Type t) } catch (Exception ex) { - Trace.TraceError(ex.Message); // Log the error - Trace.TraceError(ex.StackTrace); + Utils.LogException(ex); throw ex; // Re-throw the exception } } diff --git a/PresenceProvider/Utils.cs b/PresenceProvider/Utils.cs new file mode 100644 index 0000000..a0ffd6e --- /dev/null +++ b/PresenceProvider/Utils.cs @@ -0,0 +1,19 @@ +using System; +using System.Diagnostics; + +namespace OutlookPresenceProvider +{ + public class Utils + { + public static void LogException(Exception ex) + { + if (ex == null) + { + return; + } + + Trace.TraceError(ex.Message); + Trace.TraceError(ex.StackTrace); + } + } +}