Пример #1
0
        /// <summary>
        /// Imports the specified XML reader.
        /// </summary>
        /// <param name="xmlNode">The XML node.</param>
        /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param>
        /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param>
        /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param>
        /// <param name="mergeOptions">The merge options.</param>
        public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions)
        {
            //Create Store Groups
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                if (node.Name == "Attributes")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "Attribute")
                        {
                            if (!this.Attributes.ContainsKey(childNode.Attributes["Key"].Value))
                            {
                                IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value);
                            }
                            else
                            {
                                this.Attributes[childNode.Attributes["Key"].Value].Update(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value);
                            }
                        }
                    }
                }
                else if (node.Name == "Attribute")
                {
                    if (!this.Attributes.ContainsKey(node.Attributes["Key"].Value))
                    {
                        IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value);
                    }
                    else
                    {
                        this.Attributes[node.Attributes["Key"].Value].Update(node.Attributes["Key"].Value, node.Attributes["Value"].Value);
                    }
                }
                if (node.Name == "Permissions")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "Managers")
                        {
                            foreach (XmlNode childChildNode in childNode.ChildNodes)
                            {
                                if (childChildNode.Name == "Manager")
                                {
                                    this.GrantAccessAsManager(childChildNode.Attributes["SqlUserOrRole"].Value);
                                }
                            }
                        }
                        else if (childNode.Name == "Users")
                        {
                            foreach (XmlNode childChildNode in childNode.ChildNodes)
                            {
                                if (childChildNode.Name == "User")
                                {
                                    this.GrantAccessAsUser(childChildNode.Attributes["SqlUserOrRole"].Value);
                                }
                            }
                        }
                        else if (childNode.Name == "Readers")
                        {
                            foreach (XmlNode childChildNode in childNode.ChildNodes)
                            {
                                if (childChildNode.Name == "Reader")
                                {
                                    this.GrantAccessAsReader(childChildNode.Attributes["SqlUserOrRole"].Value);
                                }
                            }
                        }
                    }
                }
                if (node.Name == "StoreGroups")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "StoreGroup")
                        {
                            GroupType groupType = GroupType.Basic;
                            if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString())
                            {
                                groupType = GroupType.LDapQuery;
                            }
                            IAzManStoreGroup storeGroup = null;
                            string           sid        = null;
                            if (this.StoreGroups.ContainsKey(childNode.Attributes["Name"].Value))
                            {
                                storeGroup = this.StoreGroups[childNode.Attributes["Name"].Value];
                                sid        = storeGroup.SID.StringValue;
                                //Change Store Group SID
                                MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid);
                            }
                            else
                            {
                                sid        = SqlAzManSID.NewSqlAzManSid().StringValue;
                                storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childNode.Attributes["LDAPQuery"].Value, groupType);
                                //Change Store Group SID
                                MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid);
                            }

                            //newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeAuthorizations);
                        }
                    }
                }
                else if (node.Name == "StoreGroup")
                {
                    GroupType groupType = GroupType.Basic;
                    if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString())
                    {
                        groupType = GroupType.LDapQuery;
                    }

                    IAzManStoreGroup storeGroup = null;
                    string           sid        = null;
                    if (this.StoreGroups.ContainsKey(node.Attributes["Name"].Value))
                    {
                        storeGroup = this.StoreGroups[node.Attributes["Name"].Value];
                        sid        = storeGroup.SID.StringValue;
                        //Change Store Group SID
                        MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid);
                    }
                    else
                    {
                        sid        = SqlAzManSID.NewSqlAzManSid().StringValue;
                        storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), node.Attributes["Name"].Value, node.Attributes["Description"].Value, node.Attributes["LDAPQuery"].Value, groupType);
                        //Change Store Group SID
                        MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid);
                    }
                    //newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeAuthorizations);
                }
            }
            //Create Applications & Store Group Members
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                System.Windows.Forms.Application.DoEvents();
                if (node.Name == "Applications")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "Application")
                        {
                            IAzManApplication newApplication =
                                this.Applications.ContainsKey(childNode.Attributes["Name"].Value) ?
                                this.Applications[childNode.Attributes["Name"].Value] :
                                this.CreateApplication(childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value);
                            newApplication.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions);
                        }
                    }
                }
                else if (node.Name == "Application")
                {
                    IAzManApplication newApplication =
                        this.Applications.ContainsKey(node.Attributes["Name"].Value) ?
                        this.Applications[node.Attributes["Name"].Value] :
                        this.CreateApplication(node.Attributes["Name"].Value, node.Attributes["Description"].Value);
                    newApplication.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions);
                }
                else if (node.Name == "StoreGroups")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "StoreGroup")
                        {
                            GroupType groupType = GroupType.Basic;
                            if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString())
                            {
                                groupType = GroupType.LDapQuery;
                            }
                            if (groupType == GroupType.Basic)
                            {
                                IAzManStoreGroup newStoreGroup = this.StoreGroups[childNode.Attributes["Name"].Value];
                                newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions);
                            }
                        }
                    }
                }
                else if (node.Name == "StoreGroup")
                {
                    GroupType groupType = GroupType.Basic;
                    if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString())
                    {
                        groupType = GroupType.LDapQuery;
                    }
                    if (groupType == GroupType.Basic)
                    {
                        IAzManStoreGroup newStoreGroup = this.StoreGroups[node.Attributes["Name"].Value];
                        newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions);
                    }
                }
            }
            this.applications = null; //Force refresh
        }
Пример #2
0
        static void Main(string[] args)
        {
            #region Variables and messages
            var noMessage   = $"I'll open the directory for you now. Please copy over all the pdf documents you want to merge.\r\n";
            var noteMessage = $"NOTE: The merge order is determined alphabetically from the file names (e.g., FileA.pdf will come before FileB.pdf).\r\n";
            var yesMessage  = $"\r\nOk great, I'll open it now. Please copy over the your pdf documents you want to merge. \r\n";
            var goMessage   = $"Press [Enter] once you have finished copying the necessary files.\r\n";

            //Determining user's desktop filepath
            var rootPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            //Building working directory file path
            var workingPath = $"{rootPath}\\PDF_Merge";
            #endregion

            #region Checking for correct directory structure
            WriteLine("Hey, what's your name?", ConsoleColor.Cyan);
            var name = Console.ReadLine();
            WriteLine($"\r\nHey {name}, do you have a folder on your desktop entitled PDF_Merge?", ConsoleColor.Cyan);

            var readLine = Console.ReadLine();
            if (readLine != null)
            {
                var response1 = readLine.ToLower();

                if (response1.Contains("n".ToLower()))
                {
                    WriteLine("\r\nNot a problem. I'll create the directory now...\r\n", ConsoleColor.Cyan);
                    System.Threading.Thread.Sleep(2000);
                    try
                    {
                        //Creating and initializing working directory
                        workingPath = $"{rootPath}\\PDF_Merge";
                        Directory.CreateDirectory(workingPath);

                        System.Threading.Thread.Sleep(1000);

                        WriteLine(noMessage, ConsoleColor.Cyan);
                        WriteLine(noteMessage, ConsoleColor.Yellow);
                        System.Threading.Thread.Sleep(2000);

                        Process.Start(workingPath);
                    }
                    catch (Exception e)
                    {
                        WriteLine($"\r\nOops...something went wrong: {e.Message}", ConsoleColor.Red);
                    }
                }
                else
                {
                    WriteLine(yesMessage, ConsoleColor.Cyan);
                    WriteLine(noteMessage, ConsoleColor.Yellow);
                    System.Threading.Thread.Sleep(2000);

                    Process.Start(workingPath);

                    System.Threading.Thread.Sleep(2000);
                }
            }

            System.Threading.Thread.Sleep(2000);
            WriteLine(goMessage, ConsoleColor.Cyan);

            var response2 = Console.ReadKey();
            if (response2.Key != ConsoleKey.Enter)
            {
                //Do nothing
            }

            //Creating file path for target
            const string targetFileName = "MergeResult.pdf";
            var          targetPath     = string.Join("/", workingPath, targetFileName);

            //Creating new empty list to populate with pdf filepaths
            var pdfList = new List <string>();

            //Instantiating directory info class against working path
            var d = new DirectoryInfo(workingPath);
            #endregion

            #region Build list of pdf documents

            //Looping through pdf documents
            for (var item = 0; item < d.GetFiles($"*.pdf").Length; item++)
            {
                //Returns all .pdf file info
                FileInfo file = d.GetFiles($"*.pdf")[item];

                //Ensuring merge result file is not included in list
                if (!file.Name.Contains("MergeResult"))
                {
                    pdfList.Add(file.FullName);
                }
            }


            if (pdfList.Count <= 1)
            {
                WriteLine(
                    $"You've provided {pdfList.Count} pdf document for merging. You must provide a minimum of two pdf files.\r\n",
                    ConsoleColor.Red);
            }

            WriteLine($"I have found {pdfList.Count} PDF files for merging.\r\n\r\n", ConsoleColor.Cyan);
            System.Threading.Thread.Sleep(1000);
            WriteLine($"Proceeding with merge...\r\n", ConsoleColor.Yellow);
            #endregion

            #region The merge
            WriteLine($"Merge started...", ConsoleColor.Green);
            System.Threading.Thread.Sleep(2000);
            MergeUtilities.MergePdfDocuments(targetPath, pdfList.ToArray());

            System.Threading.Thread.Sleep(2000);
            if (new FileInfo(targetPath).Length == 0)
            {
                WriteLine($"Something went wrong.", ConsoleColor.Red);
                throw new Exception(message: "No data found in merge result file.");
            }

            WriteLine($"Merge completed successfully...", ConsoleColor.Green);
            #endregion

            #region Open file and close app
            System.Threading.Thread.Sleep(2000);
            WriteLine("\r\nPress any key to open the file and close the merge utility...", ConsoleColor.Cyan);
            Console.ReadKey();
            Process.Start(targetPath);
            #endregion
        }