Example #1
0
        AutomationRequestOutput FindProject(AutomationRequest Request)
        {
            BinaryReader Reader      = new BinaryReader(new MemoryStream(Request.Input.Data));
            string       StreamName  = Reader.ReadString();
            string       ProjectPath = Reader.ReadString();

            for (int ExistingTabIdx = 0; ExistingTabIdx < TabControl.GetTabCount(); ExistingTabIdx++)
            {
                WorkspaceControl ExistingWorkspace = TabControl.GetTabData(ExistingTabIdx) as WorkspaceControl;
                if (ExistingWorkspace != null && String.Compare(ExistingWorkspace.StreamName, StreamName, StringComparison.OrdinalIgnoreCase) == 0 && ExistingWorkspace.SelectedProject != null)
                {
                    string ClientPath = ExistingWorkspace.SelectedProject.ClientPath;
                    if (ClientPath != null && ClientPath.StartsWith("//"))
                    {
                        int SlashIdx = ClientPath.IndexOf('/', 2);
                        if (SlashIdx != -1)
                        {
                            string ExistingProjectPath = ClientPath.Substring(SlashIdx);
                            if (String.Compare(ExistingProjectPath, ProjectPath, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                return(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(ExistingWorkspace.SelectedFileName)));
                            }
                        }
                    }
                }
            }

            return(new AutomationRequestOutput(AutomationRequestResult.NotFound));
        }
        void RunTcp()
        {
            for (;;)
            {
                try
                {
                    IAsyncResult TCPResult = Listener.BeginAcceptTcpClient(null, null);

                    int WaitResult = WaitHandle.WaitAny(new WaitHandle[] { ShutdownEvent, TCPResult.AsyncWaitHandle });

                    // Shutting down
                    if (WaitResult == 0)
                    {
                        break;
                    }

                    try
                    {
                        TcpClient Client = Listener.EndAcceptTcpClient(TCPResult);

                        Log.WriteLine("Accepted connection from {0}", Client.Client.RemoteEndPoint);

                        NetworkStream Stream = Client.GetStream();

                        AutomationRequestInput Input = AutomationRequestInput.Read(Stream);
                        Log.WriteLine("Received input: {0} (+{1} bytes)", Input.Type, Input.Data.Length);

                        AutomationRequestOutput Output;
                        using (AutomationRequest Request = new AutomationRequest(Input))
                        {
                            PostRequest(Request);
                            Request.Complete.Wait();
                            Output = Request.Output;
                        }

                        Output.Write(Stream);
                        Log.WriteLine("Sent output: {0} (+{1} bytes)", Output.Result, Output.Data.Length);
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                    finally
                    {
                        TCPResult = null;
                        Log.WriteLine("Closed connection.");
                    }
                }
                catch (Exception Ex)
                {
                    if (!bDisposing)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                }
            }
        }
        public void Run()
        {
            try
            {
                for (;;)
                {
                    TcpClient Client = CurrentClient = Listener.AcceptTcpClient();
                    try
                    {
                        Log.WriteLine("Accepted connection from {0}", Client.Client.RemoteEndPoint);

                        NetworkStream Stream = Client.GetStream();

                        AutomationRequestInput Input = AutomationRequestInput.Read(Stream);
                        Log.WriteLine("Received input: {0} (+{1} bytes)", Input.Type, Input.Data.Length);

                        AutomationRequestOutput Output;
                        using (AutomationRequest Request = new AutomationRequest(Input))
                        {
                            PostRequest(Request);
                            Request.Complete.Wait();
                            Output = Request.Output;
                        }

                        Output.Write(Stream);
                        Log.WriteLine("Sent output: {0} (+{1} bytes)", Output.Result, Output.Data.Length);
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                    finally
                    {
                        Client.Close();
                        Log.WriteLine("Closed connection.");
                    }
                    CurrentClient = null;
                }
            }
            catch (Exception Ex)
            {
                if (!bDisposing)
                {
                    Log.WriteLine("Exception: {0}", Ex.ToString());
                }
            }
            Log.WriteLine("Closing socket.");
        }
Example #4
0
 void PostAutomationRequest(AutomationRequest Request)
 {
     try
     {
         if (!CanFocus)
         {
             Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Busy));
         }
         else if (Request.Input.Type == AutomationRequestType.SyncProject)
         {
             AutomationRequestOutput Output = StartAutomatedSync(Request, true);
             if (Output != null)
             {
                 Request.SetOutput(Output);
             }
         }
         else if (Request.Input.Type == AutomationRequestType.FindProject)
         {
             AutomationRequestOutput Output = FindProject(Request);
             Request.SetOutput(Output);
         }
         else if (Request.Input.Type == AutomationRequestType.OpenProject)
         {
             AutomationRequestOutput Output = StartAutomatedSync(Request, false);
             if (Output != null)
             {
                 Request.SetOutput(Output);
             }
         }
         else
         {
             Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Invalid));
         }
     }
     catch (Exception Ex)
     {
         Log.WriteLine("Exception running automation request: {0}", Ex);
         Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Invalid));
     }
 }
Example #5
0
 void CompleteAutomatedSync(WorkspaceUpdateResult Result, string SelectedFileName, AutomationRequest Request)
 {
     if (Result == WorkspaceUpdateResult.Success)
     {
         Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(SelectedFileName)));
     }
     else if (Result == WorkspaceUpdateResult.Canceled)
     {
         Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Canceled));
     }
     else
     {
         Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Error));
     }
 }
Example #6
0
 private void StartAutomatedSyncAfterStartup(WorkspaceControl Workspace, bool bCancel, AutomationRequest Request)
 {
     if (bCancel)
     {
         Request.SetOutput(new AutomationRequestOutput(AutomationRequestResult.Canceled));
     }
     else
     {
         Workspace.SyncLatestChange(Result => CompleteAutomatedSync(Result, Workspace.SelectedFileName, Request));
     }
 }
Example #7
0
        AutomationRequestOutput StartAutomatedSync(AutomationRequest Request, bool bForceSync)
        {
            ShowAndActivate();

            BinaryReader Reader      = new BinaryReader(new MemoryStream(Request.Input.Data));
            string       StreamName  = Reader.ReadString();
            string       ProjectPath = Reader.ReadString();

            AutomatedSyncWindow.WorkspaceInfo WorkspaceInfo;
            if (!AutomatedSyncWindow.ShowModal(this, StreamName, ProjectPath, out WorkspaceInfo, Log))
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Canceled));
            }

            if (WorkspaceInfo.bRequiresStreamSwitch)
            {
                // Close any tab containing this window
                for (int ExistingTabIdx = 0; ExistingTabIdx < TabControl.GetTabCount(); ExistingTabIdx++)
                {
                    WorkspaceControl ExistingWorkspace = TabControl.GetTabData(ExistingTabIdx) as WorkspaceControl;
                    if (ExistingWorkspace != null && ExistingWorkspace.ClientName.Equals(WorkspaceInfo.WorkspaceName))
                    {
                        TabControl.RemoveTab(ExistingTabIdx);
                        break;
                    }
                }

                // Switch the stream
                PerforceConnection Perforce = new PerforceConnection(WorkspaceInfo.UserName, WorkspaceInfo.WorkspaceName, WorkspaceInfo.ServerAndPort);
                if (!Perforce.SwitchStream(StreamName, Log))
                {
                    Log.WriteLine("Unable to switch stream");
                    return(new AutomationRequestOutput(AutomationRequestResult.Error));
                }
            }

            UserSelectedProjectSettings SelectedProject = new UserSelectedProjectSettings(WorkspaceInfo.ServerAndPort, WorkspaceInfo.UserName, UserSelectedProjectType.Client, String.Format("//{0}{1}", WorkspaceInfo.WorkspaceName, ProjectPath), null);

            int TabIdx = TryOpenProject(SelectedProject, -1, OpenProjectOptions.None);

            if (TabIdx == -1)
            {
                Log.WriteLine("Unable to open project");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            WorkspaceControl Workspace = TabControl.GetTabData(TabIdx) as WorkspaceControl;

            if (Workspace == null)
            {
                Log.WriteLine("Workspace was unable to open");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            if (!bForceSync && Workspace.CanLaunchEditor())
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(Workspace.SelectedFileName)));
            }

            Workspace.AddStartupCallback((Control, bCancel) => StartAutomatedSyncAfterStartup(Control, bCancel, Request));
            return(null);
        }