Beispiel #1
0
            public void Stop_StillWorks_Eventually()
            {
                Container1 = CreateContainer(Container1Handle);
                string userid = null;

                Container1.ImpersonateContainerUser(() =>
                {
                    userid = WindowsIdentity.GetCurrent().User.ToString();
                });
                var pSpec = new ProcessSpec
                {
                    ExecutablePath     = "cmd.exe",
                    DisablePathMapping = true,
                    Arguments          = new string[] { @"/C ""FOR /L %% IN () DO ping 127.0.0.1 -n 2""" },
                };

                // START THE LONG RUNNING PROCESS
                var io          = new StringProcessIO();
                var process     = Container1.Run(pSpec, io);
                var realProcess = Process.GetProcessById(process.Id);

                Process containerHost = FindProcessByUserAndName(userid, "IronFrame.Host");

                ProcessInfoHelper.SuspendProcess(containerHost.Id);

                Container1.Stop(true);

                Assert.True(realProcess.HasExited);
            }
Beispiel #2
0
        private void CallHost(StrongIdentifierValue methodName,
                              KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters,
                              bool isSync)
        {
#if DEBUG
            //Log($"methodName = {methodName}");
            //Log($"kindOfParameters = {kindOfParameters}");
            //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}");
            //Log($"positionedParameters = {positionedParameters.WriteListToString()}");
            //Log($"isSync = {isSync}");
#endif

            var command = new Command();
            command.Name = methodName;

            switch (kindOfParameters)
            {
            case KindOfFunctionParameters.NoParameters:
                break;

            case KindOfFunctionParameters.NamedParameters:
                command.ParamsDict = namedParameters.ToDictionary(p => p.Key, p => p.Value);
                break;

            case KindOfFunctionParameters.PositionedParameters:
                command.ParamsList = positionedParameters.ToList();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null);
            }

#if DEBUG
            //Log($"command = {command}");
#endif
            var processCreatingResult = _hostListener.CreateProcess(command);

#if DEBUG
            //Log($"processCreatingResult = {processCreatingResult}");
#endif

            if (processCreatingResult.IsSuccessful)
            {
                var processInfo = processCreatingResult.Process;
                processInfo.ParentProcessInfo = _currentCodeFrame.ProcessInfo;

                _instancesStorage.AppendAndTryStartProcessInfo(processInfo);

                if (isSync)
                {
                    ProcessInfoHelper.Wait(processInfo);
                }

                _currentCodeFrame.CurrentPosition++;

                return;
            }

            throw new NotImplementedException();
        }
        void smMaster_DataLoading(object sender, DataLoadingEventArgs e)
        {
            e.Cancel = true;

            ISearchExpression    searchExpression = e.SearchExpression;
            IList <ISearchOrder> searchOrders     = e.SearchOrders;

            if (this.SearchManager != null)
            {
                for (int i = 0; i < m_reportDataInfos.Count; ++i)
                {
                    m_sms[i].EnablePage       = this.SearchManager.EnablePage;
                    m_sms[i].FirstResult      = this.SearchManager.FirstResult;
                    m_sms[i].MaxResult        = this.SearchManager.MaxResult;
                    m_sms[i].IsResultDistinct = this.SearchManager.IsResultDistinct;
                }
            }

            bool haveSetMasterSearchManager = false;

            for (int i = 0; i < m_reportDataInfos.Count; ++i)
            {
                object data = m_sms[i].GetData(searchExpression, searchOrders);
                System.Collections.IEnumerable dataList = data as System.Collections.IEnumerable;
                if (dataList == null)
                {
                    dataList = (data as System.Data.DataTable).DefaultView;
                }

                System.Data.DataTable dt = this.ReportViewer.TemplateDataSet.Tables[m_reportDataInfos[i].DatasetTableName];
                dt.Rows.Clear();
                GenerateReportData.Generate(dt, dataList, m_reportDataInfos[i].GridName);

                if (!haveSetMasterSearchManager)
                {
                    this.SearchManager.Count   = m_sms[i].GetCount(searchExpression);
                    haveSetMasterSearchManager = true;
                    this.SearchManager.OnDataLoaded(new DataLoadedEventArgs(m_sms[i].Result, m_sms[i].Count));
                }
            }

            // Set Parameter
            ReportGenerator.SetParameter(this.ReportViewer.CrystalHelper, searchExpression);

            if (m_reportInfo.AfterProcess != null)
            {
                ProcessInfoHelper.ExecuteProcess(ADInfoBll.Instance.GetProcessInfo(m_reportInfo.AfterProcess.Name),
                                                 new Dictionary <string, object> {
                    { "masterForm", this }
                });
            }

            this.ReportViewer.OpenReport();
        }
 internal static void InitializeWindowProcess(WindowInfo windowInfo, MyChildForm masterForm)
 {
     if (windowInfo.AutoProcess != null)
     {
         ProcessInfoHelper.ExecuteProcess(ADInfoBll.Instance.GetProcessInfo(windowInfo.AutoProcess.Name),
                                          new Dictionary <string, object> {
             { "masterForm", masterForm }
         });
     }
     if (!string.IsNullOrEmpty(windowInfo.EventInitialized))
     {
         EventProcessUtils.ExecuteEventProcess(ADInfoBll.Instance.GetEventProcessInfos(windowInfo.EventInitialized), masterForm, System.EventArgs.Empty);
     }
 }
        private void ExecuteProcess(string processId)
        {
            if (!string.IsNullOrEmpty(processId))
            {
                ProcessInfo info;
                lock (m_processExecuting)
                {
                    if (m_processExecuting.ContainsKey(processId) && m_processExecuting[processId])
                    {
                        println("process " + processId + " is still executing!");
                        return;
                    }

                    m_processExecuting[processId] = true;
                    info = ADInfoBll.Instance.GetProcessInfo(processId);
                }

                println("process " + processId + " start to execute!");

                Feng.Async.AsyncHelper asyncHelper = new Feng.Async.AsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                {
                    try
                    {
                        ProcessInfoHelper.ExecuteProcess(info);
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        println(ex.Message);
                    }
                    return(false);
                }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                {
                    println("process " + processId + " has executed!");
                    lock (m_processExecuting)
                    {
                        m_processExecuting[processId] = false;
                    }
                }));
            }
            else
            {
                debug("there is no process property!");
            }
        }
Beispiel #6
0
        public Process FindProcessByUserAndName(string userSid, string procName)
        {
            Process[] processlist = Process.GetProcesses();

            foreach (Process theprocess in processlist)
            {
                string ProcessUserSID = "";
                ProcessInfoHelper.ExGetProcessInfoByPID(theprocess.Id, out ProcessUserSID);

                if (theprocess.ProcessName == procName && ProcessUserSID == userSid)
                {
                    return(theprocess);
                }
            }

            return(null);
        }
Beispiel #7
0
        private static void TstWaitIProcessInfo()
        {
            _logger.Log("Begin");

            var processInfo = new ProcessInfo();

            var task = new Task(() => {
                processInfo.Status = ProcessStatus.Running;

                Thread.Sleep(10000);

                processInfo.Status = ProcessStatus.Completed;
            });

            task.Start();

            _logger.Log("task.Start()");

            ProcessInfoHelper.Wait(processInfo);

            _logger.Log("End");
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            ProcessInfoHelper procHelper = new ProcessInfoHelper();

            SystemStatus sysStat = procHelper.GetSystemInfo();

            Console.WriteLine($"Machine Name: .. {sysStat.MachineName}");
            Console.WriteLine($"O.S. Info: ..... {sysStat.OSInfo}");
            Console.WriteLine($"Architecture: .. {sysStat.Architecture}");
            Console.WriteLine();
            Console.WriteLine("Memory:");
            Console.WriteLine($"  Total: ....... {sysStat.Memory.Total}");
            Console.WriteLine($"  Used: ........ {sysStat.Memory.Used}");
            Console.WriteLine($"  Free: ........ {sysStat.Memory.Free}");
            Console.WriteLine();
            Console.WriteLine("Process (this):");
            Console.WriteLine($"  Name: ........ {sysStat.Process.Name}");
            Console.WriteLine($"  Id: .......... {sysStat.Process.Id}");
            Console.WriteLine($"  Status: ...... {sysStat.Process.Status}");
            Console.WriteLine($"  Start Time: .. {sysStat.Process.StartTime}");
            Console.WriteLine($"  Mem. Usage: .. {sysStat.Process.MemoryUsed}");
        }
Beispiel #9
0
        /// <summary>
        /// 根据Entity的值设置row's cell值
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="entity"></param>
        /// <param name="row"></param>
        public static void SetDataRowsIListData(this IBoundGrid grid, object entity, Xceed.Grid.DataRow row)
        {
            // 如果同一个实体类,只是里面内容变了,重新设置不会设置成功
            row.Tag = null;
            if (entity == null)
            {
                return;
            }

            row.Tag = entity;

            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
            {
                try
                {
                    switch (info.GridColumnType)
                    {
                    case GridColumnType.Normal:
                        if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                        {
                            row.Cells[info.GridColumnName].Value = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                        }
                        break;

                    case GridColumnType.WarningColumn:
                        row.Cells[info.GridColumnName].Value = (row.Cells[info.GridColumnName].ParentColumn as WarningColumn).Calculate(entity);
                        break;

                    case GridColumnType.StatColumn:
                    {
                        if (row.DetailGrids.Count == 0)
                        {
                            return;
                            //throw new ArgumentException("stateColumn should has detailgrids.");
                        }

                        row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                            MySummaryRow.GetSummaryResult(row.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), row.Cells[info.GridColumnName].ParentColumn.DataType);
                    }
                    break;

                    case GridColumnType.ExpressionColumn:
                    {
                        //var info2 = info;
                        //var row2 = row;
                        //Feng.Async.AsyncHelper.Start(() =>
                        //{
                        //    if (info2.PropertyName.Contains("%"))
                        //    {
                        //        return EntityScript.CalculateExpression(info2.PropertyName, entity);
                        //    }
                        //    else
                        //    {
                        //        return Feng.Utils.ProcessInfoHelper.TryExecutePython(info2.PropertyName,
                        //            new Dictionary<string, object>() { { "entity", entity }, { "row", row2 } });
                        //    }
                        //}, (result) =>
                        //{
                        //    row2.Cells[info2.GridColumnName].Value = result;
                        //});
                        if (info.PropertyName.Contains("%"))
                        {
                            row.Cells[info.GridColumnName].Value = EntityScript.CalculateExpression(info.PropertyName, entity);
                        }
                        else
                        {
                            row.Cells[info.GridColumnName].Value = ProcessInfoHelper.TryExecutePython(info.PropertyName,
                                                                                                      new Dictionary <string, object>()
                                {
                                    { "entity", entity }, { "row", row }
                                });
                        }
                    }
                    break;

                    case GridColumnType.ImageColumn:
                    {
                        var i = Feng.Windows.ImageResource.Get(info.PropertyName);
                        row.Cells[info.GridColumnName].Value = i == null ? null : i.Reference;
                    }
                    break;

                    case GridColumnType.CheckColumn:
                    {
                        row.Cells[info.GridColumnName].Value = false;
                    }
                    break;

                    case GridColumnType.NoColumn:
                    case GridColumnType.SplitColumn:
                        break;

                    case GridColumnType.UnboundColumn:
                    {
                        try
                        {
                            row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(info.PropertyName, Feng.Utils.ReflectionHelper.GetTypeFromName(info.TypeName));
                        }
                        catch (Exception)
                        {
                        }
                    }
                    break;

                    case GridColumnType.IndexColumn:
                    {
                        row.Cells[info.GridColumnName].Value = row.Index + 1;
                    }
                    break;

                    default:
                        throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionProcess.ProcessWithResume(new ArgumentException(info.PropertyName + " info is invalid!", ex));
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="entity"></param>
        public override void Submit(IRepository rep, 对账单 entity)
        {
            if (!entity.关账日期.HasValue)
            {
                throw new InvalidUserOperationException("请输入 关账日期!");
            }

            entity.Submitted = true;

            rep.Initialize(entity.费用, entity);
            decimal sum = 0;

            foreach (费用 i in entity.费用)
            {
                if (i.收付标志 == 收付标志.收)
                {
                    sum += i.金额.Value;
                }
                else
                {
                    sum -= i.金额.Value;
                }

                if (i.凭证费用明细 != null)
                {
                    throw new InvalidUserOperationException("费用已经出凭证!");
                }
            }
            if (entity.收付标志 == 收付标志.收)
            {
                entity.金额 = sum;
            }
            else
            {
                entity.金额 = -sum;
            }

            this.Update(rep, entity);

            费用Dao fyDao = new 费用Dao();

            switch (entity.对账单类型)
            {
            case (int)货代对账单类型.自动凭证应付对账单:
                Dictionary <string, object> dict = ProcessInfoHelper.ExecuteProcess("自动凭证应付对账单", new Dictionary <string, object> {
                    { "entity", entity }
                }) as Dictionary <string, object>;
                自动对账单生成凭证(rep, entity, dict);
                break;

            case (int)货代对账单类型.货代应付对账单:
            case (int)货代对账单类型.货代应收对账单:
                foreach (费用 i in entity.费用)
                {
                    fyDao.Update(rep, i);
                }

                GenerateDzdYsyf(rep, entity);
                break;

            default:
                throw new NotSupportedException("Not Supported 对账单类型 of " + entity.对账单类型 + "!");
            }
        }
Beispiel #11
0
        public static bool InternalExecuteWindowMenu(IDisplayManager dm, WindowMenuInfo info, Form parentForm)
        {
            object entity = dm.CurrentItem;
            int    pos    = dm.Position;

            //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm;
            switch (info.Type)
            {
            case WindowMenuType.ReportSingle:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要打印的项!");
                    break;
                }

                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        MyReportForm form = new MyReportForm(info.ExecuteParam);
                        form.FillDataSet(entity);
                        return(form);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                        if (result != null)
                        {
                            MyReportForm form = result as MyReportForm;
                            form.Show(parentForm);
                        }
                    }),
                    parentForm, "生成");
            }
            break;

            case WindowMenuType.ReportMulti:
            {
                if (dm.Count == 0)
                {
                    MessageForm.ShowError("请选择要打印的项!");
                    break;
                }
                object[] entities = new object[dm.Count];
                for (int i = 0; i < entities.Length; ++i)
                {
                    entities[i] = dm.Items[i];
                }
                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        MyReportForm form = new MyReportForm(info.ExecuteParam);
                        form.FillDataSet(entities);
                        return(form);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                        if (result != null)
                        {
                            MyReportForm form = result as MyReportForm;
                            form.Show(parentForm);
                        }
                    }),
                    parentForm, "生成");
            }
            break;

            case WindowMenuType.MsReportSingle:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要打印的项!");
                    break;
                }

                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        MsReportForm form = new MsReportForm(info.ExecuteParam);
                        form.FillDataSet(entity);
                        return(form);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                        if (result != null)
                        {
                            MsReportForm form = result as MsReportForm;
                            form.Show(parentForm);

                            // 焦点会转变到其他程序,只能这样
                            form.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
                            {
                                parentForm.ParentForm.Activate();
                            });
                        }
                    }),
                    parentForm, "生成");
            }
            break;

            case WindowMenuType.MsReportMulti:
            {
                if (dm.Count == 0)
                {
                    MessageForm.ShowError("请选择要打印的项!");
                    break;
                }
                object[] entities = new object[dm.Count];
                for (int i = 0; i < entities.Length; ++i)
                {
                    entities[i] = dm.Items[i];
                }

                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        MsReportForm form = new MsReportForm(info.ExecuteParam);
                        form.FillDataSet(entities);
                        return(form);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                        if (result != null)
                        {
                            MsReportForm form = result as MsReportForm;
                            form.Show(parentForm);

                            form.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
                            {
                                parentForm.ParentForm.Activate();
                            });
                        }
                    }),
                    parentForm, "生成");
            }
            break;

            case WindowMenuType.DatabaseCommand:
            {
                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        Feng.Data.DbHelper.Instance.ExecuteNonQuery(info.ExecuteParam);
                        return(null);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                    }),
                    parentForm, "执行");
            }
            break;

            case WindowMenuType.DatabaseCommandMulti:
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < dm.Count; ++i)
                {
                    string s = EntityHelper.ReplaceEntity(info.ExecuteParam, dm.Items[i]);
                    sb.Append(s);
                    sb.Append(System.Environment.NewLine);
                }
                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        Feng.Data.DbHelper.Instance.ExecuteNonQuery(sb.ToString());
                        return(null);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                    }),
                    parentForm, "执行");
            }
            break;

            case WindowMenuType.DatabaseCommandMultiParam:
            {
                object[] entities = new object[dm.Count];
                for (int i = 0; i < dm.Count; ++i)
                {
                    entities[i] = dm.Items[i];
                }
                string s = EntityHelper.ReplaceEntities(info.ExecuteParam, entities, '\'');

                ProgressAsyncHelper asyncHelper = new ProgressAsyncHelper(
                    new Feng.Async.AsyncHelper.DoWork(delegate()
                    {
                        Feng.Data.DbHelper.Instance.ExecuteNonQuery(s);
                        return(null);
                    }),
                    new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
                    {
                    }),
                    parentForm, "执行");
            }
            break;

            case WindowMenuType.Process:
            {
                ProcessInfoHelper.ExecuteProcess(info.ExecuteParam, new Dictionary <string, object> {
                        { "masterForm", parentForm }
                    });
            }
            break;

            case WindowMenuType.Action:
            {
                ServiceProvider.GetService <IApplication>().ExecuteAction(info.ExecuteParam);
            }
            break;

            default:
                return(false);
            }
            return(true);
        }