示例#1
0
        static void Main(string[] args)
        {
            //lets create config file for funnelback and read it first
            Dictionary <string, string> fnb_config = new Dictionary <string, string>();

            try
            {
                using (StreamReader sr = new StreamReader("funnelback.cfg"))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        // Console.WriteLine(line);
                        //Dictionary<string, string> fnb_dictionary = new Dictionary<string, string>();
                        string[] words = line.Split('=');
                        fnb_config.Add(words[0], words[1]);
                        // Console.WriteLine(words[0] + words[1]);
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            // Console.WriteLine(fnb_config);

            foreach (KeyValuePair <string, string> pair in fnb_config)
            {
                Console.WriteLine("{0}, {1}",
                                  pair.Key,
                                  pair.Value);
            }

            string[] wanted_fields = { "" };
            // wanted_fields=new string[] {""};
            if (fnb_config.ContainsKey("wanted_fields"))
            {
                string wanted_fields_string = fnb_config["wanted_fields"];
                wanted_fields = wanted_fields_string.Split(',');
            }
            string[] cdata_fields = { "" };
            if (fnb_config.ContainsKey("cdata_fields"))
            {
                string cdata_fields_string = fnb_config["cdata_fields"];
                wanted_fields = cdata_fields_string.Split(',');
            }
            string[] lookup_fields = { "" };
            if (fnb_config.ContainsKey("lookup_fields"))
            {
                string lookup_fields_string = fnb_config["lookup_fields"];
                wanted_fields = lookup_fields_string.Split(',');
            }

            string target_site   = fnb_config["target_site"];
            string username      = fnb_config["username"];
            string password      = fnb_config["password"];
            string output_folder = fnb_config["output_folder"];
            string auth_method   = fnb_config["auth_method"];

            FunnelbackXmlConfig fbx = new FunnelbackXmlConfig();

            fbx.outputFolder = output_folder;
            fbx.targetSite   = target_site;
            fbx.WantedFields = wanted_fields;
            fbx.CDataFields  = cdata_fields;
            fbx.LookupFields = lookup_fields;



            //get all we need for claims authentication

            MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(target_site, username, password);

            //from now on we can use sharepoint being authenticated
            using (ClientContext ctx = new ClientContext(target_site))
            {
                ctx.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;

                ctx.Load(ctx.Web);
                ctx.ExecuteQuery();

                //
                //List all users
                FunnelbackConfig config = new FunnelbackConfig("funnelback.cfg");
                FunnelbackUser   m      = new FunnelbackUser(ctx, config);
                m.ListUsers();
                //End of users


                if (ctx != null)
                {
                    using (StreamWriter writer = new StreamWriter(fbx.outputFolder + "\\first.xml"))
                    {
                        Site              oSite = ctx.Site;
                        WebCollection     oWebs = oSite.RootWeb.Webs;
                        FunnelbackXmlSite fbxs  = new FunnelbackXmlSite();
                        fbxs.ww    = oSite.RootWeb;
                        fbxs.myfbx = fbx;
                        fbxs.Process();
                        ctx.Load(oWebs);
                        ctx.ExecuteQuery();
                        writer.WriteLine(@"<?xml version='1.0'?>");
                        writer.WriteLine(@"<sharepoint>");
                        foreach (Web oWebsite in oWebs)
                        {
                            ListCollection collList = oWebsite.Lists;
                            ctx.Load(collList); // Query for Web
                            ctx.ExecuteQuery(); // Execute

                            writer.WriteLine(@"<site>");
                            writer.WriteLine("<title>{0}</title>", oWebsite.Title);
                            foreach (List oList in collList)
                            {
                                writer.WriteLine("<list>{0}</list>", oList.Title);
                                List      oListy    = collList.GetByTitle(oList.Title);
                                CamlQuery camlQuery = new CamlQuery();
                                camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";
                                ListItemCollection collListItem = oListy.GetItems(camlQuery);
                                ctx.Load(collListItem,
                                         items => items.IncludeWithDefaultProperties(
                                             item => item.DisplayName,
                                             item => item.HasUniqueRoleAssignments
                                             ));
                                ctx.ExecuteQuery();
                                foreach (ListItem oListItem in collListItem)
                                {
                                    FunnelbackXmlRecord oFXR = new FunnelbackXmlRecord();
                                    oFXR.myfbx = fbx;
                                    oFXR.li    = oListItem;
                                    oFXR.FunnelbackWriteXml();

                                    FunnelbackItem oFI = new FunnelbackItem(oListItem);
                                    oFI.config = new FunnelbackConfig("funnelback.cfg");

                                    XmlSerializer ser = new XmlSerializer(typeof(FunnelbackItem));
                                    XmlWriter     tx  = XmlWriter.Create(fbx.outputFolder + "\\" + oFI.GetSafeFilename("xml"));
                                    ser.Serialize(tx, oFI);
                                    tx.Close();
                                }
                            }
                            writer.WriteLine(@"</site>");
                        }
                        writer.WriteLine(@"</sharepoint>");
                    }
                }
            }
        }
示例#2
0
文件: Program.cs 项目: pivko/funn_sp
        static void Main(string[] args)
        {
            //lets create config file for funnelback and read it first
            Dictionary<string, string> fnb_config = new Dictionary<string, string>();

            try
            {
                using (StreamReader sr = new StreamReader("funnelback.cfg"))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                       // Console.WriteLine(line);
                        //Dictionary<string, string> fnb_dictionary = new Dictionary<string, string>();
                        string[] words = line.Split('=');
                        fnb_config.Add(words[0],words[1]);
                       // Console.WriteLine(words[0] + words[1]);
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
               // Console.WriteLine(fnb_config);

            foreach (KeyValuePair<string, string> pair in fnb_config)
            {
                Console.WriteLine("{0}, {1}",
                pair.Key,
                pair.Value);
            }

            string[] wanted_fields = { "" };
               // wanted_fields=new string[] {""};
            if (fnb_config.ContainsKey("wanted_fields"))
            {
                string wanted_fields_string = fnb_config["wanted_fields"];
                 wanted_fields = wanted_fields_string.Split(',');

            }
            string[] cdata_fields = { "" };
            if (fnb_config.ContainsKey("cdata_fields"))
            {
                string cdata_fields_string = fnb_config["cdata_fields"];
                wanted_fields = cdata_fields_string.Split(',');

            }
            string[] lookup_fields = { "" };
            if (fnb_config.ContainsKey("lookup_fields"))
            {
                string lookup_fields_string = fnb_config["lookup_fields"];
                wanted_fields = lookup_fields_string.Split(',');

            }

            string target_site = fnb_config["target_site"];
            string username = fnb_config["username"];
            string password = fnb_config["password"];
            string output_folder = fnb_config["output_folder"];
            string auth_method = fnb_config["auth_method"];

            FunnelbackXmlConfig fbx = new FunnelbackXmlConfig();

            fbx.outputFolder = output_folder;
            fbx.targetSite = target_site;
            fbx.WantedFields = wanted_fields;
            fbx.CDataFields = cdata_fields;
            fbx.LookupFields = lookup_fields;

            //get all we need for claims authentication

            MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(target_site,username,password);

            //from now on we can use sharepoint being authenticated
            using (ClientContext ctx = new ClientContext(target_site))
            {
                ctx.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;

                ctx.Load(ctx.Web);
                ctx.ExecuteQuery();

                //
                //List all users
                FunnelbackConfig config = new FunnelbackConfig("funnelback.cfg");
                FunnelbackUser m = new FunnelbackUser(ctx,config);
                m.ListUsers();
                //End of users

                if (ctx != null)
                {
                    using (StreamWriter writer = new StreamWriter(fbx.outputFolder + "\\first.xml"))
                    {
                        Site oSite = ctx.Site;
                        WebCollection oWebs = oSite.RootWeb.Webs;
                        FunnelbackXmlSite fbxs = new FunnelbackXmlSite();
                        fbxs.ww = oSite.RootWeb;
                        fbxs.myfbx = fbx;
                        fbxs.Process();
                        ctx.Load(oWebs);
                        ctx.ExecuteQuery();
                        writer.WriteLine(@"<?xml version='1.0'?>");
                        writer.WriteLine(@"<sharepoint>");
                        foreach (Web oWebsite in oWebs)
                        {

                            ListCollection collList = oWebsite.Lists;
                            ctx.Load(collList); // Query for Web
                            ctx.ExecuteQuery(); // Execute

                            writer.WriteLine(@"<site>");
                            writer.WriteLine("<title>{0}</title>", oWebsite.Title);
                            foreach (List oList in collList)
                            {
                                writer.WriteLine("<list>{0}</list>", oList.Title);
                                List oListy = collList.GetByTitle(oList.Title);
                                CamlQuery camlQuery = new CamlQuery();
                                camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";
                                ListItemCollection collListItem = oListy.GetItems(camlQuery);
                                ctx.Load(collListItem,
                                         items => items.IncludeWithDefaultProperties(
                                            item => item.DisplayName,
                                            item => item.HasUniqueRoleAssignments
                                         ));
                                ctx.ExecuteQuery();
                                foreach (ListItem oListItem in collListItem)
                                {
                                    FunnelbackXmlRecord oFXR = new FunnelbackXmlRecord();
                                    oFXR.myfbx = fbx;
                                    oFXR.li = oListItem;
                                    oFXR.FunnelbackWriteXml();

                                    FunnelbackItem oFI = new FunnelbackItem(oListItem);
                                    oFI.config = new FunnelbackConfig("funnelback.cfg");

                                    XmlSerializer ser = new XmlSerializer(typeof(FunnelbackItem));
                                    XmlWriter tx = XmlWriter.Create(fbx.outputFolder +  "\\" + oFI.GetSafeFilename("xml"));
                                    ser.Serialize(tx, oFI);
                                    tx.Close();
                                }
                            }
                            writer.WriteLine(@"</site>");
                        }
                        writer.WriteLine(@"</sharepoint>");

                    }
                }

            }
        }