Esempio n. 1
0
        internal static void CreateReportStorage()
        {
            var settingsStorage = new FoundationSyncStorage();

            if (settingsStorage.SyncSettings() == null)
            {
                return;
            }
            if (!settingsStorage.SyncSettings().LoggingEx)
            {
                return;
            }
            try
            {
                var adminWebApplication = SPAdministrationWebApplication.Local;

                using (SPSite site = adminWebApplication.Sites[0])
                {
                    var web = site.OpenWeb(site.RootWeb.ID);

                    var library = (from SPList list in web.Lists
                                   where list.RootFolder.Name.Equals(reportLibrary)
                                   select list).FirstOrDefault();

                    if (library == null)
                    {
                        var listTemplates    = web.ListTemplates["Document Library"];
                        var documentTemplate = (from SPDocTemplate dt in web.DocTemplates
                                                where dt.Type == 100
                                                select dt).FirstOrDefault();
                        var listGuid = web.Lists.Add(reportLibrary,
                                                     "Reporting on FoundationSync activity.", listTemplates,
                                                     documentTemplate);

                        library = (SPDocumentLibrary)web.Lists[listGuid];
                        library.OnQuickLaunch        = true;
                        library.EnableFolderCreation = false;
                        library.Update();
                        settingsStorage.SyncSettings().LoggingExLibrary = (SPDocumentLibrary)library;
                    }
                    else
                    {
                        settingsStorage.SyncSettings().LoggingExLibrary = (SPDocumentLibrary)library;
                    }
                }
            }
            catch (Exception e)
            {
                FoudationSync.LogMessage(402, FoudationSync.LogCategories.FoundationSync, TraceSeverity.Unexpected,
                                         "Unable to create Report Storage in Central Administration for" +
                                         " FoundationSyncSetting object. " + e.StackTrace, null);
            }
        }
Esempio n. 2
0
        internal static void SaveReport()
        {
            var settingsStorage = new FoundationSyncStorage();

            if (settingsStorage.SyncSettings() == null)
            {
                return;
            }
            if (!settingsStorage.SyncSettings().LoggingEx)
            {
                return;
            }
            if (settingsStorage.SyncSettings().LoggingExLibrary == null)
            {
                return;
            }

            var dt = DateTime.Now.ToString("MMdyyyy-HHmm");

            var fileName = string.Format("{0}-FoundationSync.log", dt);

            try
            {
                var adminWebApplication = SPAdministrationWebApplication.Local;

                using (SPSite site = adminWebApplication.Sites[0])
                {
                    var web = site.OpenWeb(site.RootWeb.ID);

                    var library = (from SPList list in web.Lists
                                   where list.RootFolder.Name.Equals(reportLibrary)
                                   select list).FirstOrDefault();

                    var folder     = library.RootFolder;
                    var tempBytes  = Encoding.UTF8.GetBytes("Abc123");
                    var tempStream = new MemoryStream(tempBytes);

                    folder.Files.Add(fileName, tempStream, true);
                    folder.Update();

                    var url    = string.Format("{0}/{1}", folder.Url, fileName);
                    var file   = web.GetFile(url);
                    var stream = file.OpenBinaryStream();

                    stream.Position = 0;

                    var separatorMessage = Encoding.UTF8.GetBytes("\r\n-------------------\r\n");

                    var userFoundBytes = _usersFoundMemoryStream.GetBuffer();
                    if (userFoundBytes.Length == 0)
                    {
                        var logMessage = Encoding.UTF8.GetBytes("No User or Groups Found.\r\n");
                        stream.Write(logMessage, 0, logMessage.Length);
                    }
                    {
                        stream.Write(userFoundBytes, 0, userFoundBytes.Length);
                    }

                    stream.Write(separatorMessage, 0, separatorMessage.Length);

                    var userUpdatedBytes = _usersUpdatedMemoryStream.GetBuffer();

                    if (userUpdatedBytes.Length == 0)
                    {
                        var logMessage = Encoding.UTF8.GetBytes("No User or Groups Updated.\r\n");
                        stream.Write(logMessage, 0, logMessage.Length);
                    }
                    else
                    {
                        stream.Write(userUpdatedBytes, 0, userUpdatedBytes.Length);
                    }

                    stream.Write(separatorMessage, 0, separatorMessage.Length);

                    var userDeletedBytes = _usersDeletedMemoryStream.GetBuffer();

                    if (userDeletedBytes.Length == 0)
                    {
                        var logMessage = Encoding.UTF8.GetBytes("No Users Deleted.\r\n");
                        stream.Write(logMessage, 0, logMessage.Length);
                    }
                    else
                    {
                        stream.Write(userDeletedBytes, 0, userDeletedBytes.Length);
                        stream.Flush();
                    }

                    _userPropertiesMemoryStream.Clear();
                    _usersDeletedMemoryStream.Clear();
                    _usersFoundMemoryStream.Clear();
                    _usersUpdatedMemoryStream.Clear();

                    file.SaveBinary(stream);
                    file.Update();
                }
            }
            catch (Exception)
            {
                //ToDo: Log to ULS
            }
        }