protected override void Execute(NativeActivityContext context)
 {
     try
     {
         string  _arguments        = Arguments.Get(context);
         string  _fileName         = ProcessPath.Get(context);
         string  _workingDirectory = WorkingDirectory.Get(context);
         Int32   _timeout          = Timeout.Get(context);
         Process p = new System.Diagnostics.Process();
         if (_arguments != null)
         {
             p.StartInfo.Arguments = _arguments;
         }
         if (_workingDirectory != null)
         {
             p.StartInfo.WorkingDirectory = _workingDirectory;
         }
         p.StartInfo.UseShellExecute = false;
         p.StartInfo.FileName        = _fileName;
         p.Start();
         Thread.Sleep(_timeout);
         context.ScheduleAction(Body, "", OnCompleted, OnFaulted);
     }
     catch (Exception e)
     {
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw new NotImplementedException(e.Message);
         }
     }
 }
Example #2
0
        private void ProcessSourceFile(ProcessPath process, ScanResult result)
        {
            ScannedSourceFile sourceFile = null;
            string            fileKey    = ScannedSourceFile.CalculateKey(process.Path, process.Properties);

            if (!result.SourceFiles.TryGetValue(fileKey, out sourceFile) && !result.UnknownFiles.Contains(process.Path))
            {
                try
                {
                    sourceFile = new ScannedSourceFile(process.Path, process.Properties);
                    if (this.AddSymbols(result, sourceFile))
                    {
                        result.SourceFiles.Add(sourceFile.Key, sourceFile);
                    }
                    else
                    {
                        result.UnknownFiles.Add(process.Path);
                    }
                }
                catch (Exception e)
                {
                    this.OnMessage(ScannerMessageType.Warning, "Skipping non-XML file: {0} - reason: {1}", process.Path, e.Message);
                    result.UnknownFiles.Add(process.Path);
                }
            }

            if (sourceFile != null && process.Project != null)
            {
                process.Project.SourceFiles.Add(sourceFile);
                sourceFile.SourceProjects.Add(process.Project);
                //result.ProjectToSourceFileReferences.Add(new ScannedProjectSourceFileReference() { SourceProject = process.Project, TargetSourceFile = sourceFile });
            }
        }
Example #3
0
 public FileChoosing(IGraph parent, ProcessPath process) :
     base(Gtk.WindowType.Toplevel)
 {
     Build();
     _parent  = parent;
     _process = process;
 }
Example #4
0
        private Image _Render(ProcessPath path, Definition definition, string elemid)
        {
            Size   sz  = Size;
            Bitmap bmp = new Bitmap(sz.Width, sz.Height);
            int    minX;
            int    minY;
            int    maxX;
            int    maxY;

            _CalculateDimensions(out minX, out maxX, out minY, out maxY);
            Graphics gp = Graphics.FromImage(bmp);

            gp.TranslateTransform(Math.Abs(minX), Math.Abs(minY));
            foreach (Shape shape in _Shapes)
            {
                if (shape.bpmnElement == (elemid == null ? shape.bpmnElement : elemid))
                {
                    gp.DrawImage(_RenderShape(shape, path.GetStatus(shape.bpmnElement), shape.GetIcon(definition), definition.LocateElement(shape.bpmnElement)), shape.Rectangle);
                }
            }
            foreach (Edge edge in _Edges)
            {
                if (edge.bpmnElement == (elemid == null ? edge.bpmnElement : elemid))
                {
                    gp.DrawImage(_RenderEdge(edge, path.GetStatus(edge.bpmnElement), definition), edge.Rectangle);
                }
            }
            return(bmp);
        }
Example #5
0
        private IEnumerable <ProcessPath> ProcessProjectFile(ProcessPath process, ScanResult result)
        {
            List <ProcessPath> newFiles = new List <ProcessPath>();

            // If this project is not processed already, read through it all.
            ScannedProject scannedProject;
            string         key = ScannedProject.CalculateKey(process.Path, process.Properties);

            if (!result.ProjectFiles.TryGetValue(key, out scannedProject))
            {
                Project project       = new Project(process.Path, process.Properties, null);
                string  projectFolder = Path.GetDirectoryName(project.FullPath);
                string  type          = project.GetPropertyValue("OutputType");

                scannedProject = new ScannedProject(type, project.FullPath, process.Properties, null);
                ICollection <ProjectItem> projectReferences = project.GetItemsIgnoringCondition("ProjectReference");
                if (this.RecurseProjects && projectReferences != null)
                {
                    foreach (ProjectItem projectReference in projectReferences)
                    {
                        // TODO: process Property metadata.
                        string include = Path.Combine(projectFolder, projectReference.EvaluatedInclude);
                        newFiles.Add(new ProcessPath(include)
                        {
                            Project = scannedProject
                        });
                    }
                }

                ICollection <ProjectItem> compiles = project.GetItemsIgnoringCondition("Compile");
                if (compiles != null)
                {
                    foreach (ProjectItem item in compiles)
                    {
                        // TODO: process DefineConstants property.
                        string include = Path.Combine(projectFolder, item.EvaluatedInclude);
                        newFiles.Add(new ProcessPath(include)
                        {
                            Project = scannedProject
                        });
                    }
                }

                Debug.Assert(key == scannedProject.Key, String.Format("{0} should equal {1}", key, scannedProject.Key));
                result.ProjectFiles.Add(scannedProject.Key, scannedProject);
            }

            // If there is a parent project, create a reference between the two projects.
            if (process.Project != null)
            {
                process.Project.TargetProjects.Add(scannedProject);
                scannedProject.SourceProjects.Add(process.Project);
                //result.ProjectToProjectReferences.Add(new ScannedProjectProjectReference() { SourceProject = process.Project, TargetProject = scannedProject });
            }

            return(newFiles);
        }
Example #6
0
        protected string Process(string fileName, params string[] arguments)
        {
            var outp = "";
            var args = string.Join(" ", arguments);

            Log.Info($"{fileName} {args}");

            if (ProcessPath.TryGetValue(fileName, out string processPath))
            {
                fileName = processPath;
                Log.Info($"Using {fileName}");
            }

            void errorDataReceived(object sender, DataReceivedEventArgs e)
            {
                var data = e?.Data;

                if (data != null)
                {
                    Log.Warn(data);
                }
            }

            void outputDataReceived(object sender, DataReceivedEventArgs e)
            {
                var data = e?.Data;

                if (data != null)
                {
                    outp += data;
                    Log.Info(data);
                }
            }

            using (var process = new Process()) {
                process.StartInfo.FileName               = fileName;
                process.StartInfo.Arguments              = args;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.WorkingDirectory       = Directory.Exists(CodeBase.Path) ? CodeBase.Path : "";
                process.ErrorDataReceived  += errorDataReceived;
                process.OutputDataReceived += outputDataReceived;
                process.Start();
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                process.WaitForExit();

                var exitCode = process.ExitCode;
                if (exitCode != 0)
                {
                    throw new Exception("Process error (exit code '" + exitCode + "')");
                }
            }

            return(outp);
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ProcessHandle != null ? ProcessHandle.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ProcessName != null ? ProcessName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ProcessPath != null ? ProcessPath.GetHashCode() : 0);
         return(hashCode);
     }
 }
Example #8
0
 internal ProcessState(ProcessStepComplete complete, ProcessStepError error)
 {
     _evnt = new AutoResetEvent(true);
     _doc  = new XmlDocument();
     _doc.LoadXml(_BASE_STATE);
     _stateElement = (XmlElement)_doc.GetElementsByTagName(_PROCESS_STATE_ELEMENT)[0];
     _log          = (XmlElement)_doc.GetElementsByTagName(_PROCESS_LOG_ELEMENT)[0];
     _variables    = new StateVariableContainer(this);
     _suspensions  = new SuspendedStepContainer(this);
     _path         = new ProcessPath(complete, error, new processStateChanged(_stateChanged), this);
 }
Example #9
0
        public override bool Equals(object obj)
        {
            var other = obj as ReAttachTarget;

            if (other == null)
            {
                return(false);
            }
            return(ProcessPath.Equals(other.ProcessPath, StringComparison.OrdinalIgnoreCase) &&
                   ProcessUser.Equals(other.ProcessUser, StringComparison.OrdinalIgnoreCase) &&
                   ServerName.Equals(other.ServerName, StringComparison.OrdinalIgnoreCase));
        }
Example #10
0
        public override bool IsIncomingFlowComplete(string incomingID, ProcessPath path)
        {
            bool ret = true;

            foreach (string str in Incoming)
            {
                if (path.GetStatus(str) != StepStatuses.Succeeded)
                {
                    ret = false;
                    break;
                }
            }
            return(ret);
        }
Example #11
0
        private IEnumerable<ProcessPath> ProcessFile(ProcessPath process, ScanResult result)
        {
            IEnumerable<ProcessPath> moreFiles;

            string extension = Path.GetExtension(process.Path);
            if (extension.Equals(".wixproj", StringComparison.OrdinalIgnoreCase))
            {
                moreFiles = this.ProcessProjectFile(process, result);
            }
            else
            {
                this.ProcessSourceFile(process, result);
                moreFiles = new List<ProcessPath>();
            }

            return moreFiles;
        }
Example #12
0
        private IEnumerable <ProcessPath> ProcessFile(ProcessPath process, ScanResult result)
        {
            IEnumerable <ProcessPath> moreFiles;

            string extension = Path.GetExtension(process.Path);

            if (extension.Equals(".wixproj", StringComparison.OrdinalIgnoreCase))
            {
                moreFiles = this.ProcessProjectFile(process, result);
            }
            else
            {
                this.ProcessSourceFile(process, result);
                moreFiles = new List <ProcessPath>();
            }

            return(moreFiles);
        }
Example #13
0
        public ScanResult Scan(IEnumerable <string> paths, IList <string> includeSymbols, IList <string> excludeSymbols)
        {
            ScanResult result = new ScanResult();

            Queue <ProcessPath> queue = new Queue <ProcessPath>();

            foreach (string path in paths)
            {
                queue.Enqueue(new ProcessPath(path));
            }

            while (0 < queue.Count)
            {
                ProcessPath process = queue.Dequeue();
                if (process.Project == null && Directory.Exists(process.Path))
                {
                    foreach (string directory in Directory.GetDirectories(process.Path))
                    {
                        queue.Enqueue(new ProcessPath(directory));
                    }

                    foreach (string file in Directory.GetFiles(process.Path))
                    {
                        IEnumerable <ProcessPath> more = this.ProcessFile(process, result);
                        foreach (ProcessPath item in more)
                        {
                            queue.Enqueue(item);
                        }
                    }
                }
                else
                {
                    IEnumerable <ProcessPath> more = this.ProcessFile(process, result);
                    foreach (ProcessPath item in more)
                    {
                        queue.Enqueue(item);
                    }
                }
            }

            this.ResolveSymbols(result);
            return(result);
        }
Example #14
0
 internal Image RenderElement(ProcessPath path, Definition definition, string elementID, out RectangleF?rectangle)
 {
     foreach (Shape shape in _Shapes)
     {
         if (shape.bpmnElement == elementID)
         {
             rectangle = _ShiftRectangle(shape.Rectangle);
             return(_RenderShape(shape, path.GetStatus(shape.bpmnElement), shape.GetIcon(definition), definition.LocateElement(shape.bpmnElement)));
         }
     }
     foreach (Edge edge in _Edges)
     {
         if (edge.bpmnElement == elementID)
         {
             rectangle = _ShiftRectangle(edge.Rectangle);
             return(_RenderEdge(edge, path.GetStatus(edge.bpmnElement), definition));
         }
     }
     rectangle = null;
     return(null);
 }
Example #15
0
        static void TcpIpPerformance()
        {
            long tableTime, processTimeTotal, sidTimeTotal;

            var sw = new Stopwatch();

            sw.Start();

            var tcpTable = TcpTable.GetAllTcpConnections();

            sw.Stop();
            tableTime = sw.ElapsedMilliseconds;

            var itemCount = tcpTable.Length;
            //=====================================================
            var processPaths = new string[tcpTable.Length];

            sw.Reset();
            sw.Start();
            for (int i = 0; i < tcpTable.Length; i++)
            {
                if (tcpTable[i].owningPid != 0)
                {
                    processPaths[i] = ProcessPath.GetProcessPath((uint)tcpTable[i].owningPid);
                }
                else
                {
                    processPaths[i] = "SystemIdle";
                }
            }
            sw.Stop();
            processTimeTotal = sw.ElapsedMilliseconds;

            //=====================================================
            var processSid = new string[tcpTable.Length];
            var myProcess  = Process.GetCurrentProcess();

            sw.Reset(); sw.Start();
            //for (int i = 0; i < tcpTable.Length; i++)
            //{
            //    if (processPaths[i] != "")
            //    {
            //        processSid[i] = ProcessUser.sidFromProcess((uint)tcpTable[i].owningPid);
            //    }
            //}
            Action <string> loggerSample = new Action <string>((text) => Console.WriteLine(text));

            Console.WriteLine(ProcessUserSid.sidFromProcess((uint)myProcess.Id, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess((uint)myProcess.Id, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess((uint)myProcess.Id, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess((uint)myProcess.Id, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess((uint)myProcess.Id, loggerSample));

            sw.Stop();
            Console.WriteLine("Only fast sid: " + sw.ElapsedMilliseconds + "ms");

            sw.Reset(); sw.Start();
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));
            Console.WriteLine(ProcessUserSid.sidFromProcess(4, loggerSample));

            sw.Stop();
            sidTimeTotal = sw.ElapsedMilliseconds;

            Console.WriteLine($"Results\n======\nTcpTable: {tableTime}ms\nPaths: {processTimeTotal}ms\nSids: {sidTimeTotal}ms");
        }
        //  Class Functions:
        // =================================================


        public HTTPTaskResult StartListener(IPAddress ip, int port, Func <bool> isCancelled)
        {
            HTTPTaskResult result
                = HTTPTaskResult.Fail(HTTPResultEnum.NOTOKEN_ERROR, "init");

            TcpListener tcpServer = new TcpListener(ip, port);

            tcpServer.Start();

            _actual_port = ((IPEndPoint)tcpServer.LocalEndpoint).Port;

            // Timeout for accepting client -> Just check if pending (https://stackoverflow.com/a/3315200)
            int acceptTimePassedMS = 0;

            acceptTimePassedMS = WaitForTcpClient(isCancelled, tcpServer, acceptTimePassedMS);

            if (acceptTimePassedMS >= AcceptTimeout.TotalMilliseconds || isCancelled())
            {
                result = HTTPTaskResult
                         .Fail(HTTPResultEnum.NOTOKEN_ERROR,
                               "Accept socket timeout", resultObj: isCancelled());
            }
            else
            {
                TcpClient client = tcpServer.AcceptTcpClient();
                client.ReceiveTimeout = (int)TotalRequestTimeout.TotalMilliseconds;
                client.SendTimeout    = (int)TotalResponseTimeout.TotalMilliseconds;

                NetworkStream ns = client.GetStream();
                try
                {
                    if (!ns.CanTimeout)
                    {
                        result = HTTPTaskResult
                                 .Fail(HTTPResultEnum.NOTOKEN_ERROR,
                                       "Networkstream can't timeout!", resultObj: isCancelled());
                    }
                    else
                    {
                        ns.ReadTimeout  = client.ReceiveTimeout;
                        ns.WriteTimeout = client.SendTimeout;

                        int    bytesRecieved = 0;
                        byte[] RequestBuffer = new byte[BufferSize];
                        string requestData   = RecieveHTTPRequest(isCancelled, ns, ref bytesRecieved, RequestBuffer);

                        if (!requestData.EndsWith(HTTPHeadersEnd))
                        {
                            result = HTTPTaskResult
                                     .Fail(HTTPResultEnum.NOTOKEN_ERROR,
                                           "Error getting a valid HTTP request", resultObj: isCancelled());
                        }
                        else
                        {
                            bool validReq = true;
                            foreach (string item in findInRequest)
                            {
                                if (!requestData.Contains(item.ToLower()))
                                {
                                    validReq = false;
                                    break;
                                }
                            }

                            if (!validReq)
                            {
                                // Because we also check Agent header here, so from this point it is all security
                                result = HTTPTaskResult
                                         .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                               "Didn't find all required text in request:\n" + requestData, resultObj: isCancelled());
                            }
                            else
                            {
                                int pid = pidFromConnection(client);
                                if (pid < 0)
                                {
                                    result = HTTPTaskResult
                                             .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                                   "Can't find token req PID owner", resultObj: isCancelled());
                                }
                                else
                                {
                                    LocalGroupsAndUsers users = new LocalGroupsAndUsers();
                                    string processPath        = ProcessPath.GetProcessPath((uint)pid);
                                    string userSid            = ProcessUserSid.sidFromProcess((uint)pid, (s) => { });
                                    string userName           = users.getUserName(userSid);

                                    if (processPath == "" || userName == "" || userSid == "")
                                    {
                                        result = HTTPTaskResult
                                                 .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                                       "Error getting process owner information", resultObj: isCancelled());
                                    }
                                    else
                                    {
                                        Properties.Settings config = Properties.Settings.Default;
                                        bool isCallerAllowed       =
                                            config.AllowedClientUsernames.ToLower().Contains(userName.ToLower()) &&
                                            config.AllowedClientPaths.ToLower().Contains(processPath.ToLower()) &&
                                            !isCancelled();

                                        if (!isCallerAllowed)
                                        {
                                            result = HTTPTaskResult
                                                     .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                                           string.Format(
                                                               "Token acces denied problem!\nProcess: {0}\nUserSid: {1}\nUserName: {2}",
                                                               processPath, userSid, userName
                                                               ),
                                                           resultObj: isCancelled());
                                        }
                                        else
                                        {
                                            byte[] responseBuffer = CreateTokenHTTPResponse(DataToServe);

                                            Stopwatch sendTimer = new Stopwatch();
                                            sendTimer.Start();
                                            ns.Write(responseBuffer, 0, responseBuffer.Length);
                                            sendTimer.Stop();

                                            if (sendTimer.ElapsedMilliseconds >= ns.WriteTimeout)
                                            {
                                                // Because maybe he got the token and stopped responding (reading) => TOKEN_AUTH_ERROR
                                                result = HTTPTaskResult
                                                         .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                                               "Error sending response, got timeout.", resultObj: isCancelled());
                                            }
                                            else
                                            {
                                                result = HTTPTaskResult.Success(HTTPResultEnum.SUCCESS, "Token sent!");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = HTTPTaskResult
                             .Fail(HTTPResultEnum.TOKEN_AUTH_ERROR,
                                   "Error in token process", resultObj: isCancelled(), error: ex);
                }
                finally
                {
                    ns.Close();
                    client.Close();
                    tcpServer.Stop();
                }
            }

            return(result);
        }
Example #17
0
 public override bool IsIncomingFlowComplete(string incomingID, ProcessPath path)
 {
     return(true);
 }
Example #18
0
 internal Image UpdateState(ProcessPath path, Definition elem, string nextStep)
 {
     return(_Render(path, elem, nextStep));
 }
Example #19
0
 public bool IsWaiting(ProcessPath path)
 {
     return(path.GetStatus(this.id) == StepStatuses.Waiting);
 }
Example #20
0
 public override int GetHashCode()
 {
     return(ProcessPath.ToLower().GetHashCode() +
            ProcessUser.ToLower().GetHashCode() +
            ServerName.ToLower().GetHashCode());
 }
Example #21
0
        public MainWindowViewModel()
        {
            // Load
            LoadDefaultConfiguration();

            var useConnectionType = UseConnectionTypeSelectedIndex
                                    .Select(x => (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), UseConnectionType[x]))
                                    .ToReactiveProperty();

            // Setup peer
            peer = new ReactiveProperty <ObservablePhotonPeer>(new UseJsonObservablePhotonPeer(useConnectionType.Value));
            peer.Select(x => x.ObserveStatusChanged())
            .Switch()
            .Subscribe(x =>
            {
                if (x == StatusCode.Connect)
                {
                    CurrentConnectionStatus.Value = "Connecting : " + Address.Value + " " + AppName.Value;
                }
                else
                {
                    CurrentConnectionStatus.Value = x.ToString();
                }
                Log.WriteLine(CurrentConnectionStatus.Value);
            });

            // Setup Properties

            HubInfoListSelectedIndex.Subscribe(x =>
            {
                foreach (var item in OperationInfoList)
                {
                    item.Dispose();
                }
                OperationInfoList.Clear();
                if (x == -1)
                {
                    return;
                }
                if (HubInfoList.Count - 1 < x)
                {
                    return;
                }

                var hub = HubInfoList[x];
                foreach (var item in hub.Operations)
                {
                    OperationInfoList.Add(new OperationItemViewModel(peer, Log, item));
                }
            });

            // Setup Commands

            var photonProcessExists = Observable.Interval(TimeSpan.FromSeconds(1)).Select(x => Process.GetProcessesByName("PhotonSocketserver").Any());

            KillPhotonProcess = photonProcessExists.ToReactiveCommand();
            KillPhotonProcess.Subscribe(_ =>
            {
                var processes = Process.GetProcessesByName("PhotonSocketServer");
                foreach (var item in processes)
                {
                    item.Kill();
                }
            });

            StartPhotonProcess = ProcessPath.CombineLatest(WorkingDir, (processPath, workingDir) => new { processPath, workingDir })
                                 .Select(x => !string.IsNullOrWhiteSpace(x.processPath + x.workingDir))
                                 .CombineLatest(photonProcessExists, (x, y) => x && !y)
                                 .ToReactiveCommand();
            StartPhotonProcess.Subscribe(_ =>
            {
                try
                {
                    var processPath = ProcessPath.Value;
                    var workingDir  = WorkingDir.Value;

                    var pi = new ProcessStartInfo
                    {
                        FileName         = ProcessPath.Value,
                        Arguments        = ProcessArgument.Value,
                        WorkingDirectory = workingDir
                    };
                    System.Diagnostics.Process.Start(pi);

                    SaveConfiguration(); // can start, save path
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            });

            ReloadDll = DllPath.Select(x => File.Exists(x.Trim('\"'))).ToReactiveCommand(ImmediateScheduler.Instance); // needs Immediate check for InitialLoad(see:bottom code)
            ReloadDll.Subscribe(_ =>
            {
                try
                {
                    HubInfoList.Clear();
                    var hubInfos = HubAnalyzer.LoadHubInfos(DllPath.Value.Trim('\"'));
                    SaveConfiguration(); // can load, save path

                    hubInfoLookup = hubInfos.ToDictionary(x => x.HubId);

                    foreach (var hub in hubInfos)
                    {
                        HubInfoList.Add(hub);
                    }
                    HubInfoListSelectedIndex.Value = 0;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            });

            Connect = peer.Select(x => x.ObserveStatusChanged())
                      .Switch()
                      .CombineLatest(Address, (x, y) => x != StatusCode.Connect && !string.IsNullOrEmpty(y))
                      .ToReactiveCommand();
            Connect.Subscribe(async _ =>
            {
                try
                {
                    peer.Value.Dispose();
                    peer.Value = new UseJsonObservablePhotonPeer(useConnectionType.Value);
                    var b      = await peer.Value.ConnectAsync(Address.Value, AppName.Value);
                    Log.WriteLine("Connect:" + b);
                    if (b)
                    {
                        SaveConfiguration(); // can connect, save path

                        // Register Listener
                        listenerSubscription.Disposable = peer.Value.ObserveReceiveEventData().Subscribe(ReceiveEvent);
                    }
                    else
                    {
                        listenerSubscription.Disposable = System.Reactive.Disposables.Disposable.Empty;
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLine("Can't connect:" + ex.ToString());
                    listenerSubscription.Disposable = System.Reactive.Disposables.Disposable.Empty;
                }
            });

            Disconnect = peer.Select(x => x.ObserveStatusChanged())
                         .Switch()
                         .Select(x => x == StatusCode.Connect)
                         .ToReactiveCommand();
            Disconnect.Subscribe(_ =>
            {
                try
                {
                    peer.Value.Disconnect();
                }
                catch (Exception ex)
                {
                    Log.WriteLine("Can't disconnect:" + ex.ToString());
                }
            });

            LogClear = new ReactiveCommand();
            LogClear.Subscribe(_ =>
            {
                Log.Value = "";
            });

            // Initial Load
            if (ReloadDll.CanExecute())
            {
                ReloadDll.Execute();
            }

            // Initial VersionInfo
            VersionInfo = Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version.ToString();
            if (peer.Value.ObserveStatusChanged().FirstAsync().GetAwaiter().GetResult() == StatusCode.Disconnect)
            {
                CurrentConnectionStatus.Value = "PhotonWire.HubInvoker " + VersionInfo;
            }
        }
Example #22
0
 public abstract bool IsIncomingFlowComplete(string incomingID, ProcessPath path);
 public AddProcessDialog()
 {
     InitializeComponent();
     ProcessPath.Focus();
 }
Example #24
0
        private void ProcessSourceFile(ProcessPath process, ScanResult result)
        {
            ScannedSourceFile sourceFile = null;
            string fileKey = ScannedSourceFile.CalculateKey(process.Path, process.Properties);
            if (!result.SourceFiles.TryGetValue(fileKey, out sourceFile) && !result.UnknownFiles.Contains(process.Path))
            {
                try
                {
                    sourceFile = new ScannedSourceFile(process.Path, process.Properties);
                    if (this.AddSymbols(result, sourceFile))
                    {
                        result.SourceFiles.Add(sourceFile.Key, sourceFile);
                    }
                    else
                    {
                        result.UnknownFiles.Add(process.Path);
                    }
                }
                catch (Exception e)
                {
                    this.OnMessage(ScannerMessageType.Warning, "Skipping non-XML file: {0} - reason: {1}", process.Path, e.Message);
                    result.UnknownFiles.Add(process.Path);
                }
            }

            if (sourceFile != null && process.Project != null)
            {
                process.Project.SourceFiles.Add(sourceFile);
                sourceFile.SourceProjects.Add(process.Project);
                //result.ProjectToSourceFileReferences.Add(new ScannedProjectSourceFileReference() { SourceProject = process.Project, TargetSourceFile = sourceFile });
            }
        }
Example #25
0
 public Image Render(ProcessPath path, Definition definition)
 {
     return(_Render(path, definition, null));
 }
Example #26
0
        private IEnumerable<ProcessPath> ProcessProjectFile(ProcessPath process, ScanResult result)
        {
            List<ProcessPath> newFiles = new List<ProcessPath>();

            // If this project is not processed already, read through it all.
            ScannedProject scannedProject;
            string key = ScannedProject.CalculateKey(process.Path, process.Properties);
            if (!result.ProjectFiles.TryGetValue(key, out scannedProject))
            {
                Project project = new Project(process.Path, process.Properties, null);
                string projectFolder = Path.GetDirectoryName(project.FullPath);
                string type = project.GetPropertyValue("OutputType");

                scannedProject = new ScannedProject(type, project.FullPath, process.Properties, null);
                ICollection<ProjectItem> projectReferences = project.GetItemsIgnoringCondition("ProjectReference");
                if (this.RecurseProjects && projectReferences != null)
                {
                    foreach (ProjectItem projectReference in projectReferences)
                    {
                        // TODO: process Property metadata.
                        string include = Path.Combine(projectFolder, projectReference.EvaluatedInclude);
                        newFiles.Add(new ProcessPath(include) { Project = scannedProject });
                    }
                }

                ICollection<ProjectItem> compiles = project.GetItemsIgnoringCondition("Compile");
                if (compiles != null)
                {
                    foreach (ProjectItem item in compiles)
                    {
                        // TODO: process DefineConstants property.
                        string include = Path.Combine(projectFolder, item.EvaluatedInclude);
                        newFiles.Add(new ProcessPath(include) { Project = scannedProject });
                    }
                }

                Debug.Assert(key == scannedProject.Key, String.Format("{0} should equal {1}", key, scannedProject.Key));
                result.ProjectFiles.Add(scannedProject.Key, scannedProject);
            }

            // If there is a parent project, create a reference between the two projects.
            if (process.Project != null)
            {
                process.Project.TargetProjects.Add(scannedProject);
                scannedProject.SourceProjects.Add(process.Project);
                //result.ProjectToProjectReferences.Add(new ScannedProjectProjectReference() { SourceProject = process.Project, TargetProject = scannedProject });
            }

            return newFiles;
        }
Example #27
0
        private Image _Render(ProcessPath path, Definition definition, string elemid)
        {
            Size   sz   = Size;
            Bitmap bmp  = new Bitmap(sz.Width, sz.Height);
            int    minX = 0;
            int    maxX = 0;
            int    minY = 0;
            int    maxY = 0;

            foreach (IElement elem in Children)
            {
                _RecurGetDimensions(elem, ref minX, ref maxX, ref minY, ref maxY);
            }
            Graphics gp = Graphics.FromImage(bmp);

            gp.TranslateTransform(Math.Abs(minX), Math.Abs(minY));
            foreach (Shape shape in _Shapes)
            {
                if (shape.bpmnElement == (elemid == null ? shape.bpmnElement : elemid))
                {
                    StepStatuses status = path.GetStatus(shape.bpmnElement);
                    BPMIcons?    icon   = shape.GetIcon(definition);
                    IElement     elem   = definition.LocateElement(shape.bpmnElement);
                    if (icon.HasValue)
                    {
                        Image     img  = Bitmap.FromStream(Utility.LocateEmbededResource(_GetImageStreamName(status)));
                        Rectangle rect = new Rectangle(0, 0, 0, 0);
                        switch (icon.Value)
                        {
                        case BPMIcons.Task:
                        case BPMIcons.SendTask:
                        case BPMIcons.ReceiveTask:
                        case BPMIcons.UserTask:
                        case BPMIcons.ManualTask:
                        case BPMIcons.ServiceTask:
                        case BPMIcons.ScriptTask:
                        case BPMIcons.BusinessRuleTask:
                            Pen p = new Pen(_GetBrush(status), Constants.PEN_WIDTH);
                            gp.DrawEllipse(p, new RectangleF(shape.Rectangle.X, shape.Rectangle.Y, 11, 11));
                            gp.DrawEllipse(p, new RectangleF(shape.Rectangle.X, shape.Rectangle.Y + shape.Rectangle.Height - 11, 11, 11));
                            gp.DrawEllipse(p, new RectangleF(shape.Rectangle.X + shape.Rectangle.Width - 11, shape.Rectangle.Y, 11, 11));
                            gp.DrawEllipse(p, new RectangleF(shape.Rectangle.X + shape.Rectangle.Width - 11, shape.Rectangle.Y + shape.Rectangle.Height - 11, 11, 11));
                            gp.FillPolygon(Brushes.White, new PointF[] {
                                new PointF(shape.Rectangle.X, shape.Rectangle.Y + 5),
                                new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y + 5),
                                new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y + 5),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width, shape.Rectangle.Y + 5),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width, shape.Rectangle.Y + shape.Rectangle.Height - 5),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y + shape.Rectangle.Height - 5),
                                new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y + shape.Rectangle.Height),
                                new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y + shape.Rectangle.Height),
                                new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y + shape.Rectangle.Height - 5),
                                new PointF(shape.Rectangle.X, shape.Rectangle.Y + shape.Rectangle.Height - 5),
                                new PointF(shape.Rectangle.X, shape.Rectangle.Y + 5)
                            });
                            gp.DrawLine(p, new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y), new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y));
                            gp.DrawLine(p, new PointF(shape.Rectangle.X + shape.Rectangle.Width, shape.Rectangle.Y + 5), new PointF(shape.Rectangle.X + shape.Rectangle.Width, shape.Rectangle.Y + shape.Rectangle.Height - 5));
                            gp.DrawLine(p, new PointF(shape.Rectangle.X + 5, shape.Rectangle.Y + shape.Rectangle.Height), new PointF(shape.Rectangle.X + shape.Rectangle.Width - 5, shape.Rectangle.Y + shape.Rectangle.Height));
                            gp.DrawLine(p, new PointF(shape.Rectangle.X, shape.Rectangle.Y + 5), new PointF(shape.Rectangle.X, shape.Rectangle.Y + shape.Rectangle.Height - 5));
                            switch (icon.Value)
                            {
                            case BPMIcons.Task:
                                rect = new Rectangle(0, 0, 1, 1);
                                break;

                            case BPMIcons.SendTask:
                                rect = new Rectangle(278, 10, 46, 30);
                                break;

                            case BPMIcons.ReceiveTask:
                                rect = new Rectangle(330, 10, 46, 30);
                                break;

                            case BPMIcons.UserTask:
                                rect = new Rectangle(274, 52, 40, 47);
                                break;

                            case BPMIcons.ManualTask:
                                rect = new Rectangle(327, 53, 55, 36);
                                break;

                            case BPMIcons.ServiceTask:
                                rect = new Rectangle(335, 100, 48, 45);
                                break;

                            case BPMIcons.ScriptTask:
                                rect = new Rectangle(385, 8, 33, 37);
                                break;

                            case BPMIcons.BusinessRuleTask:
                                rect = new Rectangle(272, 111, 49, 30);
                                break;
                            }
                            gp.DrawImage(img, new RectangleF(shape.Rectangle.X + 5, shape.Rectangle.Y + 5, 15, 15), rect, GraphicsUnit.Pixel);
                            break;

                        default:
                            switch (icon.Value)
                            {
                            case BPMIcons.StartEvent:
                                rect = new Rectangle(7, 5, 46, 46);
                                break;

                            case BPMIcons.MessageStartEvent:
                                rect = new Rectangle(62, 5, 46, 46);
                                break;

                            case BPMIcons.TimerStartEvent:
                                rect = new Rectangle(115, 5, 46, 46);
                                break;

                            case BPMIcons.ConditionalStartEvent:
                                rect = new Rectangle(168, 5, 46, 46);
                                break;

                            case BPMIcons.SignalStartEvent:
                                rect = new Rectangle(220, 5, 46, 46);
                                break;

                            case BPMIcons.MessageIntermediateThrowEvent:
                                rect = new Rectangle(8, 56, 46, 46);
                                break;

                            case BPMIcons.EscalationIntermediateThrowEvent:
                                rect = new Rectangle(62, 56, 46, 46);
                                break;

                            case BPMIcons.LinkIntermediateThrowEvent:
                                rect = new Rectangle(116, 56, 46, 46);
                                break;

                            case BPMIcons.CompensationIntermediateThrowEvent:
                                rect = new Rectangle(169, 56, 46, 46);
                                break;

                            case BPMIcons.SignalIntermediateThrowEvent:
                                rect = new Rectangle(221, 56, 46, 46);
                                break;

                            case BPMIcons.MessageIntermediateCatchEvent:
                                rect = new Rectangle(8, 107, 46, 46);
                                break;

                            case BPMIcons.TimerIntermediateCatchEvent:
                                rect = new Rectangle(62, 107, 46, 46);
                                break;

                            case BPMIcons.ConditionalIntermediateCatchEvent:
                                rect = new Rectangle(116, 107, 46, 46);
                                break;

                            case BPMIcons.LinkIntermediateCatchEvent:
                                rect = new Rectangle(169, 107, 46, 46);
                                break;

                            case BPMIcons.SignalIntermediateCatchEvent:
                                rect = new Rectangle(221, 107, 46, 46);
                                break;

                            case BPMIcons.EndEvent:
                                rect = new Rectangle(6, 160, 48, 48);
                                break;

                            case BPMIcons.MessageEndEvent:
                                rect = new Rectangle(61, 160, 48, 48);
                                break;

                            case BPMIcons.EscalationEndEvent:
                                rect = new Rectangle(114, 160, 48, 48);
                                break;

                            case BPMIcons.ErrorEndEvent:
                                rect = new Rectangle(167, 160, 48, 48);
                                break;

                            case BPMIcons.CompensationEndEvent:
                                rect = new Rectangle(220, 160, 48, 48);
                                break;

                            case BPMIcons.SignalEndEvent:
                                rect = new Rectangle(274, 160, 48, 48);
                                break;

                            case BPMIcons.TerminateEndEvent:
                                rect = new Rectangle(332, 160, 48, 48);
                                break;

                            case BPMIcons.ExclusiveGateway:
                                rect = new Rectangle(8, 214, 63, 63);
                                break;

                            case BPMIcons.ParallelGateway:
                                rect = new Rectangle(77, 214, 63, 63);
                                break;

                            case BPMIcons.InclusiveGateway:
                                rect = new Rectangle(149, 214, 63, 63);
                                break;

                            case BPMIcons.ComplexGateway:
                                rect = new Rectangle(222, 214, 63, 63);
                                break;

                            case BPMIcons.EventBasedGateway:
                                rect = new Rectangle(292, 214, 63, 63);
                                break;
                            }
                            gp.DrawImage(img, shape.Rectangle, rect, GraphicsUnit.Pixel);
                            break;
                        }
                    }
                    if (elem != null)
                    {
                        if (elem is TextAnnotation)
                        {
                            gp.DrawLines(new Pen(_GetBrush(status), Constants.PEN_WIDTH), new PointF[] {
                                new PointF(shape.Rectangle.X + 20, shape.Rectangle.Y),
                                new PointF(shape.Rectangle.X, shape.Rectangle.Y),
                                new PointF(shape.Rectangle.X, shape.Rectangle.Y + shape.Rectangle.Height),
                                new PointF(shape.Rectangle.X + 20, shape.Rectangle.Y + shape.Rectangle.Height)
                            });
                        }
                        else if (elem is Lane || elem is Participant)
                        {
                            gp.DrawRectangle(new Pen(_GetBrush(status), Constants.PEN_WIDTH), Rectangle.Round(shape.Rectangle));
                        }
                        else if (elem is SubProcess)
                        {
                            gp.DrawPath(new Pen(_GetBrush(status), Constants.PEN_WIDTH), _GenerateRoundedRectangle(shape.Rectangle.X, shape.Rectangle.Y, shape.Rectangle.Width, shape.Rectangle.Height));
                        }
                        if (elem.ToString() != "")
                        {
                            if (shape.Label != null)
                            {
                                SizeF sf = gp.MeasureString(elem.ToString(), Constants.FONT, new SizeF(shape.Label.Bounds.Rectangle.Width, float.MaxValue), Constants.STRING_FORMAT);
                                gp.DrawString(elem.ToString(), Constants.FONT, _GetBrush(status), new RectangleF(shape.Label.Bounds.Rectangle.X, shape.Label.Bounds.Rectangle.Y, Math.Max(shape.Label.Bounds.Rectangle.Width, sf.Width), Math.Max(shape.Label.Bounds.Rectangle.Height, sf.Height)), Constants.STRING_FORMAT);
                            }
                            else
                            {
                                SizeF size = gp.MeasureString(elem.ToString(), Constants.FONT);
                                if (size.Height != 0 || size.Width != 0)
                                {
                                    if (elem is Lane || elem is LaneSet || elem is Participant)
                                    {
                                        Bitmap   tbmp = new Bitmap((int)size.Height * 2, (int)size.Width);
                                        Graphics g    = Graphics.FromImage(tbmp);
                                        g.TranslateTransform(tbmp.Width / 2, tbmp.Height);
                                        g.RotateTransform(-90);
                                        g.TranslateTransform(0, 0);
                                        g.DrawString(elem.ToString(), Constants.FONT, _GetBrush(status), 0, 0);
                                        g.Save();
                                        gp.DrawImage(tbmp, new PointF(shape.Rectangle.X - 7, shape.Rectangle.Y + ((shape.Rectangle.Height - tbmp.Height) / 2)));
                                    }
                                    else
                                    {
                                        gp.DrawString(elem.ToString(), Constants.FONT, _GetBrush(status), new RectangleF(shape.Rectangle.X + 0.5f, shape.Rectangle.Y + 15, shape.Rectangle.Width - 1, shape.Rectangle.Height - 15.5f), Constants.STRING_FORMAT);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            foreach (Edge edge in _Edges)
            {
                if (edge.bpmnElement == (elemid == null ? edge.bpmnElement : elemid))
                {
                    StepStatuses status = path.GetStatus(edge.bpmnElement);
                    gp.DrawLines(edge.ConstructPen(_GetBrush(status), definition), edge.Points);
                    edge.AppendEnds(gp, _GetBrush(status), definition);
                    if (edge.Label != null)
                    {
                        IElement elem = definition.LocateElement(edge.bpmnElement);
                        if (elem != null)
                        {
                            SizeF sf = gp.MeasureString(elem.ToString(), Constants.FONT, new SizeF(edge.Label.Bounds.Rectangle.Width, edge.Label.Bounds.Rectangle.Height), Constants.STRING_FORMAT);
                            gp.DrawString(elem.ToString(), Constants.FONT, _GetBrush(status), new RectangleF(edge.Label.Bounds.Rectangle.X, edge.Label.Bounds.Rectangle.Y, Math.Max(edge.Label.Bounds.Rectangle.Width, sf.Width), Math.Max(edge.Label.Bounds.Rectangle.Height, sf.Height)), Constants.STRING_FORMAT);
                        }
                    }
                }
            }
            return(bmp);
        }