public SiteControllerMethods(SiteQueries _dbQuery, AdminQueries _AdbQuery)
 {
     dbQuery       = _dbQuery;
     _dataLimiter  = new DataLimiter(_AdbQuery);
     authenticator = new SiteAuth(_AdbQuery, _dbQuery, _dataLimiter);
     validator     = new SiteCreationValidator(dbQuery);
 }
        /// <summary>
        /// Creates a PowerShell script file (.ps1) in the users temporary folder to support PowerShell based on CSOM.
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public static string CreatePowerShellScript(SiteAuth site)
        {
            string tempPSFilePath = Path.Combine(Path.GetTempPath(), "spcb_ps_startup.ps1");

            if (File.Exists(tempPSFilePath))
            {
                File.Delete(tempPSFilePath);
            }

            File.AppendAllText(tempPSFilePath, string.Format("$loc = \"{0}\"\n", Environment.CurrentDirectory));
            File.AppendAllText(tempPSFilePath, string.Format("$siteUrl = \"{0}\"\n", site.Url));
            File.AppendAllText(tempPSFilePath, string.Format("$loginname = \"{0}\"\n", site.Username));

            File.AppendAllText(tempPSFilePath, "Set-Location $loc\n");
            File.AppendAllText(tempPSFilePath, "Add-Type -Path (Resolve-Path \"Microsoft.SharePoint.Client.dll\")\n");
            File.AppendAllText(tempPSFilePath, "Add-Type -Path (Resolve-Path \"Microsoft.SharePoint.Client.Runtime.dll\")\n");

            File.AppendAllText(tempPSFilePath, "$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)\n");

            if (!string.IsNullOrEmpty(site.Username))
            {
                File.AppendAllText(tempPSFilePath, "Write-Host \"Please enter password for $($siteUrl):\"\n");
                File.AppendAllText(tempPSFilePath, "$pwd = Read-Host -AsSecureString\n");

                if (site.Authentication == AuthN.Default)
                {
                    File.AppendAllText(tempPSFilePath, "$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)\n");
                }
                else
                {
                    File.AppendAllText(tempPSFilePath, "$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $pwd)\n");
                }
            }

            File.AppendAllText(tempPSFilePath, "$web = $ctx.Web \n");
            File.AppendAllText(tempPSFilePath, "$ctx.Load($web) \n");
            File.AppendAllText(tempPSFilePath, "$ctx.ExecuteQuery() \n");

            File.AppendAllText(tempPSFilePath, "Write-Host \"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"HOW TO\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"Variables:\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$siteUrl: URL for current site collection\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$ctx: The client context for current site collection\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$web: The current web within the client context\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"Sample code:\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$web = `$ctx.Web\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$ctx.Load(`$web)\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" `$ctx.ExecuteQuery()\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" Write-Host `\" Current web title is '`$(`$web.Title)', `$(`$web.Url)`\"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"Output:\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \" Current web title is '$($web.Title)', $($web.Url)\"\n");
            File.AppendAllText(tempPSFilePath, "Write-Host \"\"");

            return(tempPSFilePath);
        }
Esempio n. 3
0
        private void LoadOldConfigFile()
        {
            Log.Info("Trying to load old config file format");

            _configFile = new WebepgConfigFile();

            Xml xmlreader = new Xml(_configFileDir + "\\WebEPG.xml");

            _configFile.Info            = new WebepgInfo();
            _configFile.Info.GrabDays   = xmlreader.GetValueAsInt("General", "MaxDays", 2);
            _configFile.Info.GrabberDir = xmlreader.GetValueAsString("General", "GrabberDir", null);

            int AuthCount = xmlreader.GetValueAsInt("AuthSites", "Count", 0);

            if (AuthCount > 0)
            {
                _configFile.Sites = new List <SiteAuth>();
                for (int i = 1; i <= AuthCount; i++)
                {
                    SiteAuth site = new SiteAuth();
                    site.id       = xmlreader.GetValueAsString("Auth" + i.ToString(), "Site", "");
                    site.username = xmlreader.GetValueAsString("Auth" + i.ToString(), "Login", "");
                    site.password = xmlreader.GetValueAsString("Auth" + i.ToString(), "Password", "");
                    _configFile.Sites.Add(site);
                }
            }

            _configFile.Channels = new List <ChannelMap>();

            int channelCount = xmlreader.GetValueAsInt("ChannelMap", "Count", 0);

            for (int i = 1; i <= channelCount; i++)
            {
                ChannelMap channel = new ChannelMap();
                channel.displayName = xmlreader.GetValueAsString(i.ToString(), "DisplayName", "");
                string grabber = xmlreader.GetValueAsString(i.ToString(), "Grabber1", "");
                ;
                //if (mergedList.ContainsKey(channel.displayName))
                //{
                //  channel.merged = mergedList[channel.displayName];
                //  foreach (MergedChannel mergedChannel in channel.merged)
                //    mergedChannel.grabber = grabber;
                //}
                //else
                //{
                channel.id      = xmlreader.GetValueAsString(i.ToString(), "ChannelID", "");
                channel.grabber = grabber;
                //}
                _configFile.Channels.Add(channel);
            }

            int mergeCount = xmlreader.GetValueAsInt("MergeChannels", "Count", 0);
            Dictionary <string, List <MergedChannel> > mergedList = new Dictionary <string, List <MergedChannel> >();

            if (mergeCount > 0)
            {
                for (int i = 1; i <= mergeCount; i++)
                {
                    int channelcount = xmlreader.GetValueAsInt("Merge" + i.ToString(), "Channels", 0);
                    if (channelcount > 0)
                    {
                        List <MergedChannel> mergedChannels = new List <MergedChannel>();
                        ChannelMap           channel        = new ChannelMap();
                        channel.displayName = xmlreader.GetValueAsString("Merge" + i.ToString(), "DisplayName", "");
                        channel.merged      = new List <MergedChannel>();
                        for (int c = 1; c <= channelcount; c++)
                        {
                            MergedChannel mergedChannel = new MergedChannel();
                            mergedChannel.id    = xmlreader.GetValueAsString("Merge" + i.ToString(), "Channel" + c.ToString(), "");
                            mergedChannel.start = xmlreader.GetValueAsString("Merge" + i.ToString(), "Start" + c.ToString(), "0:0");
                            mergedChannel.end   = xmlreader.GetValueAsString("Merge" + i.ToString(), "End" + c.ToString(), "0:0");
                            channel.merged.Add(mergedChannel);
                        }

                        _configFile.Channels.Add(channel);
                    }
                }
            }

            xmlreader.Clear();
            xmlreader.Dispose();
        }