private void StartBridge()
        {
            try
            {
                //IChannel ichannel = new IpcChannel("myClient");
                //ChannelServices.RegisterChannel(ichannel, false);
                string channelName = "SPSF" + Guid.NewGuid().ToString();

                bridgeProcess = new System.Diagnostics.Process();
                bridgeProcess.StartInfo.FileName               = toolsPath;
                bridgeProcess.StartInfo.CreateNoWindow         = true;
                bridgeProcess.StartInfo.Arguments              = channelName;
                bridgeProcess.StartInfo.UseShellExecute        = false;
                bridgeProcess.StartInfo.RedirectStandardInput  = true;
                bridgeProcess.StartInfo.RedirectStandardOutput = true;
                bridgeProcess.StartInfo.RedirectStandardError  = true;
                bridgeProcess.StartInfo.WorkingDirectory       = Path.GetDirectoryName(toolsPath);
                bridgeProcess.OutputDataReceived              += new DataReceivedEventHandler(bridgeProcess_OutputDataReceived);
                bridgeProcess.ErrorDataReceived  += new DataReceivedEventHandler(bridgeProcess_ErrorDataReceived);
                bridgeProcess.EnableRaisingEvents = true;
                bridgeProcess.Start();
                bridgeProcess.BeginOutputReadLine();

                TimeSpan waitTime = new TimeSpan(0, 0, 5);
                System.Threading.Thread.Sleep(waitTime);

                try
                {
                    remoteObj = Activator.GetObject(typeof(SharePointRemoteObject), "ipc://" + channelName + "/RemoteObj") as SharePointRemoteObject;
                }
                catch { }

                if (remoteObj == null)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        System.Threading.Thread.Sleep(waitTime);
                        remoteObj = Activator.GetObject(typeof(SharePointRemoteObject), "ipc://" + channelName + "/RemoteObj") as SharePointRemoteObject;

                        if (remoteObj == null)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not start SPSF SharePointBridge. Make sure that IIS and SharePoint are running (" + ex.Message + ")");
            }
            if (remoteObj == null)
            {
                throw new Exception("Could not access SharePointRemoteObject");
            }

            //Helpers.LogMessage(dte, dte, "SharePointBridge started");
        }
        public SharePointBrigdeHelper(DTE dte)
        {
            this.dte = dte;
            string        version             = Helpers.GetInstalledSharePointVersion();
            string        sharePointBridgeExe = "SharePointBridge" + version + ".exe";
            DirectoryInfo assemblyFolder      = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            toolsPath = assemblyFolder + @"\" + sharePointBridgeExe;

            if (!File.Exists(toolsPath))
            {
                //ok, file is not in the current directory (issue that executing assembly is located in a different folder
                //let's check the registry for the installation location of SPSF

                RegistryKey packageKey = Registry.LocalMachine.OpenSubKey(dte.RegistryRoot + @"\BindingPaths\{93c68916-6e2b-43fb-9940-bf7c943cf0d9}", true);
                if (packageKey != null)
                {
                    foreach (string s in packageKey.GetValueNames())
                    {
                        toolsPath = s + @"\" + sharePointBridgeExe;
                        if (File.Exists(s))
                        {
                            break;
                        }
                    }
                    if (!File.Exists(toolsPath))
                    {
                        Helpers.LogMessage(dte, dte, "Error: SharePointBridge '" + sharePointBridgeExe + "' not found ('" + toolsPath + "')");
                        throw new Exception("File not found " + toolsPath);
                    }
                }
            }
            Helpers.ShowProgress(dte, string.Format("Connecting to SharePoint {0}...", version == "14"?"2010":"2013"), 10);
            Helpers.LogMessage(dte, dte, string.Format("Connecting to SharePoint {0}. Please wait...", version == "14" ? "2010" : "2013"));

            if (IsBridgeNeeded)
            {
                StartBridge();
            }
            else
            {
                remoteObj = new SharePointRemoteObject();
            }
        }
    public SharePointBrigdeHelper(DTE dte)
    {

      this.dte = dte;
      string version = Helpers.GetInstalledSharePointVersion();
      string sharePointBridgeExe = "SharePointBridge" + version + ".exe";
      DirectoryInfo assemblyFolder = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
      toolsPath = assemblyFolder + @"\" + sharePointBridgeExe;

      if (!File.Exists(toolsPath))
      {
        //ok, file is not in the current directory (issue that executing assembly is located in a different folder
        //let's check the registry for the installation location of SPSF

        RegistryKey packageKey = Registry.LocalMachine.OpenSubKey(dte.RegistryRoot + @"\BindingPaths\{93c68916-6e2b-43fb-9940-bf7c943cf0d9}", true);
        if (packageKey != null)
        {
          foreach (string s in packageKey.GetValueNames())
          {
            toolsPath = s + @"\" + sharePointBridgeExe;
            if (File.Exists(s))
            {
              break;
            }
          }
          if (!File.Exists(toolsPath))
          {
            Helpers.LogMessage(dte, dte, "Error: SharePointBridge '" + sharePointBridgeExe + "' not found ('" + toolsPath + "')");
            throw new Exception("File not found " + toolsPath);
          }
        }
      }
      Helpers.ShowProgress(dte, string.Format("Connecting to SharePoint {0}...", version == "14"?"2010":"2013"), 10);
      Helpers.LogMessage(dte, dte, string.Format("Connecting to SharePoint {0}. Please wait...", version == "14" ? "2010" : "2013"));

      if (IsBridgeNeeded)
      {
        StartBridge();
      }
      else
      {
        remoteObj = new SharePointRemoteObject();
      }
    }
        private void StartBridge()
        {
            try
              {

            //IChannel ichannel = new IpcChannel("myClient");
            //ChannelServices.RegisterChannel(ichannel, false);
            string channelName = "SPSF" + Guid.NewGuid().ToString();

            bridgeProcess = new Process();
            bridgeProcess.StartInfo.FileName = toolsPath;
            bridgeProcess.StartInfo.CreateNoWindow = true;
            bridgeProcess.StartInfo.Arguments = channelName;
            bridgeProcess.StartInfo.UseShellExecute = false;
            bridgeProcess.StartInfo.RedirectStandardInput = true;
            bridgeProcess.StartInfo.RedirectStandardOutput = true;
            bridgeProcess.StartInfo.RedirectStandardError = true;
            bridgeProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(toolsPath);
            bridgeProcess.OutputDataReceived += new DataReceivedEventHandler(bridgeProcess_OutputDataReceived);
            bridgeProcess.ErrorDataReceived += new DataReceivedEventHandler(bridgeProcess_ErrorDataReceived);
            bridgeProcess.EnableRaisingEvents = true;
            bridgeProcess.Start();
            bridgeProcess.BeginOutputReadLine();

            TimeSpan waitTime = new TimeSpan(0, 0, 5);
            Thread.Sleep(waitTime);

            try
            {
              remoteObj = Activator.GetObject(typeof(SharePointRemoteObject), "ipc://" + channelName + "/RemoteObj") as SharePointRemoteObject;
            }
            catch { }

            if (remoteObj == null)
            {
              for (int i = 0; i < 5; i++)
              {
            Thread.Sleep(waitTime);
            remoteObj = Activator.GetObject(typeof(SharePointRemoteObject), "ipc://" + channelName + "/RemoteObj") as SharePointRemoteObject;

            if (remoteObj == null)
            {
              break;
            }
              }
            }
              }
              catch (Exception ex)
              {
            throw new Exception("Could not start SPSF SharePointBridge. Make sure that IIS and SharePoint are running (" + ex.Message + ")");
              }
              if (remoteObj == null)
              {
            throw new Exception("Could not access SharePointRemoteObject");
              }

              //Helpers.LogMessage(dte, dte, "SharePointBridge started");
        }
		static void Main(string[] args)
		{
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            if (args.Length == 0)
            {
                try
                {
                    SharePointRemoteObject obj = new SharePointRemoteObject();
                    Console.WriteLine(obj.GetSharePointVersion());
                    
                    foreach (SharePointWebApplication s in obj.GetAllWebApplications())
                    {
                        Console.WriteLine(s.Name);
                    }                    
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Console.ReadLine();
                return;
            }

            IChannel ichannel = null;
            string channelName = "";
            try
            {
                channelName = args[0];
                if (channelName == "")
                {
                    throw new Exception("No channel name as parameter available");
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(logFile, ex.ToString());
                //throw new Exception("Ex1", ex);
            }

			try
			{
				BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
				serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
				BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

				System.Collections.IDictionary properties = new System.Collections.Hashtable();
				properties["name"] = channelName;
				properties["priority"] = "20";
				properties["portName"] = channelName; //"ipc://" + channelName + "/RemoteObj"

				// Create the channel. 
				ichannel = new IpcChannel(properties, clientProv, serverProv);

				//ichannel = new IpcChannel(properties, clientProv, serverProv); 
				ChannelServices.RegisterChannel(ichannel, false);

				RemotingConfiguration.RegisterWellKnownServiceType(typeof(SharePointRemoteObject), "RemoteObj", WellKnownObjectMode.Singleton);

				// keep the process alive
				TimeSpan waitTime = new TimeSpan(0, 0, 5);
				while (1 == 1)
				{
					// pump messages
					Thread.CurrentThread.Join(waitTime);
					Thread.Sleep(waitTime);
				}
			}
			catch (Exception e)
			{
                File.AppendAllText(logFile, e.ToString());
				Console.WriteLine(e.ToString());
				Console.WriteLine(e.InnerException);
			}
			Console.ReadLine();
		}
示例#6
0
        static void Main(string[] args)
        {
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            if (args.Length == 0)
            {
                try
                {
                    SharePointRemoteObject obj = new SharePointRemoteObject();
                    Console.WriteLine(obj.GetSharePointVersion());

                    foreach (SharePointWebApplication s in obj.GetAllWebApplications())
                    {
                        Console.WriteLine(s.Name);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Console.ReadLine();
                return;
            }

            IChannel ichannel    = null;
            string   channelName = "";

            try
            {
                channelName = args[0];
                if (channelName == "")
                {
                    throw new Exception("No channel name as parameter available");
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(logFile, ex.ToString());
                //throw new Exception("Ex1", ex);
            }

            try
            {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

                System.Collections.IDictionary properties = new System.Collections.Hashtable();
                properties["name"]     = channelName;
                properties["priority"] = "20";
                properties["portName"] = channelName;                 //"ipc://" + channelName + "/RemoteObj"

                // Create the channel.
                ichannel = new IpcChannel(properties, clientProv, serverProv);

                //ichannel = new IpcChannel(properties, clientProv, serverProv);
                ChannelServices.RegisterChannel(ichannel, false);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(SharePointRemoteObject), "RemoteObj", WellKnownObjectMode.Singleton);

                // keep the process alive
                TimeSpan waitTime = new TimeSpan(0, 0, 5);
                while (1 == 1)
                {
                    // pump messages
                    Thread.CurrentThread.Join(waitTime);
                    Thread.Sleep(waitTime);
                }
            }
            catch (Exception e)
            {
                File.AppendAllText(logFile, e.ToString());
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.InnerException);
            }
            Console.ReadLine();
        }