示例#1
0
        private string GetColorStyleOfNode(Office.SmartArtNode node, string text)
        {
            try
            {
                switch (node.Shapes.Fill.Type)
                {
                case Office.MsoFillType.msoFillTextured:
                    //Texture
                    //System.Diagnostics.Debug.WriteLine("Textur Type: " + node.Shapes.Fill.TextureType);
                    text = text.Replace("#Farbe#", "texturierten");
                    break;

                case Office.MsoFillType.msoFillSolid:
                    //one Backgroundcolor
                    string colorName = ShapeColor.GetColorName(node.Shapes.Fill.ForeColor.RGB);
                    text = text.Replace("#Farbe#", colorName);

                    break;

                case Office.MsoFillType.msoFillGradient:
                    //two and more Backgroundcolors
                    switch (node.Shapes.Fill.GradientStyle)
                    {
                    case Office.MsoGradientStyle.msoGradientHorizontal:
                        //System.Diagnostics.Debug.WriteLine("horizontaler Farbverlauf");
                        text = text.Replace("#Farbe#", "horizontal farbverlaufenden");
                        break;

                    case Office.MsoGradientStyle.msoGradientVertical:
                        //System.Diagnostics.Debug.WriteLine("vertikaler Farbverlauf");
                        text = text.Replace("#Farbe#", "vertikal farbverlaufenden");
                        break;

                    default:
                        //System.Diagnostics.Debug.WriteLine("zwei oder mehrfarbig: " + node.Shapes.Fill.GradientStyle);
                        text = text.Replace("#Farbe#", "farbverlaufenden");
                        break;
                    }
                    break;

                case Office.MsoFillType.msoFillPatterned:
                    //TODO: Verbesserung: Musterart erkennen und übersetzen
                    //if (node.Shapes.Fill.Pattern.ToString().IndexOf("Percent") > 0)
                    //{
                    //    System.Diagnostics.Debug.WriteLine("im Hintergrund liegt ein Punktmuster");
                    //}
                    //System.Diagnostics.Debug.WriteLine(node.Shapes.Fill.BackColor.Type);
                    text = text.Replace("#Farbe#", "gemusterten");
                    break;
                }
            }catch (Exception e) {
                text = "";
            }
            return(text);
        }
示例#2
0
        private void btnLoadForm_Click(object sender, EventArgs e)
        {
            // ===================== Populate Date Generated ==============================
            Word.ContentControl ccDateGenerated = GetContentControl("txtDateGenerated");
            ccDateGenerated.Range.Text = DateTime.Now.ToString("MM/dd/yyyy");

            String Stage = "Page Load";

            WebCollection childWebs = null;

            String txtURL = String.Empty;

            Word.ContentControl ccURL = GetContentControl("txtURL");

            // Clear errors
            SetContentControl("txtSmartArtError", "");
            SetContentControl("txtURLError", "");

            if (ccURL != null)
            {
                Stage = "Load Action Pane";
                // http://oigportal.hhsoig.gov/sites/OAS/AATS/TMSIS
                txtURL = ccURL.Range.Text;

                txtURL = txtURL.Replace("SitePages/Home.aspx", "");

                txtURL = txtURL.TrimEnd('/');

                actionPane.URL = txtURL;
                actionPane.LoadControl();



                try
                {
                    Stage = "Load Web";
                    ClientContext clientContext = new ClientContext(txtURL);
                    Web           currentWeb    = clientContext.Web;

                    clientContext.Load(currentWeb);
                    clientContext.ExecuteQuery();

                    // Get Web details
                    Guid webId = currentWeb.Id;
                    SetContentControl("txtTitle", currentWeb.Title);
                    SetContentControl("txtCreated", currentWeb.Created.ToString("MM/dd/yyyy"));
                    SetContentControl("txtModified", currentWeb.LastItemModifiedDate.ToString("MM/dd/yyyy"));

                    long webSize = GetWebSize(currentWeb);
                    SetContentControl("txtSize", webSize.ToString("N0"));

                    // Set document properties
                    Microsoft.Office.Core.DocumentProperties properties;
                    properties = (Office.DocumentProperties) this.CustomDocumentProperties;

                    // properties["Title"].Value = currentWeb.Title;

                    #region Smart Art Population
                    // ============ Smart Art =====================================================

                    try
                    {
                        // Set up for diagram
                        Stage = "Modify Smart Art";
                        // for background color of the current web cell in the smartart.
                        const int OrangeCell = unchecked ((int)0xED7D31);

                        Site tempSite = clientContext.Site;
                        clientContext.Load(tempSite);
                        clientContext.ExecuteQuery();

                        string siteUrl = tempSite.Url + "/";                          // http://oigportal.hhsoig.gov/sites/OAS

                        Web tmpRoot = tempSite.RootWeb;
                        clientContext.Load(tmpRoot);
                        clientContext.ExecuteQuery();

                        string rootTitle = tmpRoot.Title;

                        // Get site names by breaking down URL.
                        //  SharePoint 2010 client Web class doesn't have any way to get the parent web.
                        //  example: AATS/TMSIS
                        string   navTree = txtURL.Replace(siteUrl, "");
                        string[] nodes   = navTree.Split('/');

                        // Find the diagram and get a reference to it.
                        Word.InlineShape treeShape = null;

                        foreach (Word.InlineShape tmpShape in this.InlineShapes)
                        {
                            if (tmpShape.Type == Word.WdInlineShapeType.wdInlineShapeSmartArt)
                            {
                                treeShape = tmpShape;
                            }
                        }

                        Office.SmartArt treeArt = treeShape.SmartArt;
                        // treeShape.Height

                        // clear out existing nodes
                        foreach (Office.SmartArtNode tmpNode in treeArt.Nodes)
                        {
                            if (tmpNode != null)
                            {
                                tmpNode.Delete();
                            }
                        }

                        Office.SmartArtNode rootNode = treeArt.Nodes.Add();
                        rootNode.TextFrame2.TextRange.Text = rootTitle;

                        // Nodes from root to current site
                        foreach (string tmpNodeText in nodes)
                        {
                            Office.SmartArtNode tmpChildNode = treeArt.Nodes.Add();
                            tmpChildNode.TextFrame2.TextRange.Text = tmpNodeText;
                        }

                        // Root node - add then node, then set the text.
                        Office.SmartArtNode currentNode = treeArt.Nodes[treeArt.Nodes.Count];
                        currentNode.TextFrame2.TextRange.Text = currentWeb.Title;
                        // set root node color

                        currentNode.Shapes.Fill.ForeColor.RGB = 0xED7D31;                         // OrangeCell;

                        // Child webs for SmartArt
                        childWebs = currentWeb.Webs;
                        clientContext.Load(childWebs);
                        clientContext.ExecuteQuery();

                        foreach (Web tmpWeb in childWebs)
                        {
                            Office.SmartArtNode childNode = currentNode.AddNode(Office.MsoSmartArtNodePosition.msoSmartArtNodeBelow);
                            childNode.TextFrame2.TextRange.Text = tmpWeb.Title;
                        }
                    }
                    catch (Exception ex)
                    {
                        Word.ContentControl smartArtError = GetContentControl("txtSmartArtError");
                        Word.Range          tagRange      = smartArtError.Range;
                        tagRange.Text       = String.Concat("ERROR: ", ex.Message);
                        tagRange.Font.Color = Word.WdColor.wdColorRed;
                    }

                    #endregion

                    #region Build Child Web Table
                    // ============ Child Web Table ===============================================
                    Stage = "Load Child Web Table";

                    Word.Table webTable = GetTable("ChildWebs");

                    if (webTable != null)
                    {
                        foreach (Web tmpWeb in childWebs)
                        {
                            Word.Row newRow = webTable.Rows.Add();

                            newRow.Cells[1].Range.Text = tmpWeb.Title;
                            newRow.Cells[2].Range.Text = tmpWeb.ServerRelativeUrl;
                            // newRow.Cells[3].Range.Text = Owners
                            newRow.Cells[4].Range.Text = tmpWeb.Created.ToString("MM/dd/yyyy");

                            long WebSize = GetWebSize(tmpWeb);
                            newRow.Cells[5].Range.Text = WebSize.ToString("N0");
                        }
                    }
                    #endregion

                    #region Build Child Object Table
                    // ================== Child Object Table =========================================
                    Microsoft.SharePoint.Client.ListCollection webLists = currentWeb.Lists;
                    clientContext.Load(webLists);
                    clientContext.ExecuteQuery();

                    Word.Table objTable = GetTable("tblContentObjects");

                    if (objTable != null)
                    {
                        foreach (List tmpList in webLists)
                        {
                            Word.Row newRow = objTable.Rows.Add();

                            newRow.Cells[1].Range.Text = tmpList.BaseType.ToString();
                            newRow.Cells[2].Range.Text = tmpList.Title;
                            newRow.Cells[3].Range.Text = tmpList.ItemCount.ToString();
                            newRow.Cells[4].Range.Text = tmpList.LastItemModifiedDate.ToString("MM/dd/yyyy");
                        }
                    }
                    #endregion

                    #region Build Permissions Table
                    // =================== Permissions Table ==============================================
                    Stage = "Load Permissions Table";
                    Word.Table permTable = GetTable("tblPermissions");

                    RoleAssignmentCollection roleAssignments = currentWeb.RoleAssignments;
                    clientContext.Load(roleAssignments);
                    clientContext.ExecuteQuery();

                    Stage = "Role Assignments";
                    foreach (RoleAssignment assign in roleAssignments)
                    {
                        clientContext.Load(assign);
                        clientContext.ExecuteQuery();

                        Stage = "Load Role Principal";
                        Principal tmpMember = assign.Member;
                        clientContext.Load(tmpMember);
                        clientContext.ExecuteQuery();

                        Word.Row newRow = permTable.Rows.Add();

                        newRow.Cells[1].Range.Text = assign.Member.Title;
                        newRow.Cells[2].Range.Text = assign.Member.PrincipalType.ToString();
                        newRow.Cells[3].Range.Text = assign.Member.LoginName;

                        Stage = "Role Collection";
                        RoleDefinitionBindingCollection roles = assign.RoleDefinitionBindings;
                        clientContext.Load(roles);
                        clientContext.ExecuteQuery();

                        Stage = "Role Definitions";
                        foreach (RoleDefinition roleDef in roles)
                        {
                            clientContext.Load(roleDef);
                            clientContext.ExecuteQuery();

                            switch (roleDef.Name)
                            {
                            case "Full Control":
                                newRow.Cells[4].Range.Text = "X";
                                break;

                            case "Design":
                                newRow.Cells[5].Range.Text = "X";
                                break;

                            case "Contribute":
                                newRow.Cells[6].Range.Text = "X";
                                break;

                            case "Read":
                                newRow.Cells[7].Range.Text = "X";
                                break;
                            }
                        }
                    }
                    #endregion

                    #region Fill Workflow Table
                    Stage = "Load Workflow Table";

                    Word.Table workflowTable = GetTable("tblWorkflows");

                    WorkflowAssociationCollection workflows = currentWeb.WorkflowAssociations;

                    clientContext.Load(workflows);
                    clientContext.ExecuteQuery();

                    foreach (WorkflowAssociation workflow in workflows)
                    {
                        clientContext.Load(workflow);
                        clientContext.ExecuteQuery();

                        Word.Row newRow = workflowTable.Rows.Add();

                        newRow.Cells[1].Range.Text = workflow.Name;
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    Word.ContentControl urlError = GetContentControl("txtURLError");
                    Word.Range          rngError = urlError.Range;
                    rngError.Text       = String.Concat("ERROR at stage ", Stage, ": ", ex.Message);
                    rngError.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed;
                }
            }
        }