Esempio n. 1
0
    private void FillBasedOnListView(List <TraceDataResult> traceDataResults, ResultTask resultTask, List <RanTaskInfo> ranTaskInfo)
    {
        if (traceDataResults.Count == 0)
        {
            return;
        }

        bool summaryTab = false;

        if (ranTaskInfo == null)
        {
            summaryTab = true;
        }

        int numberOfRows = traceDataResults[0].Values.Count;

        for (int row = 0; row < numberOfRows; row++)
        {
            ListViewItem listViewItem = new ListViewItem();
            List <int>   connections  = traceDataResults[0].Connections;
            listViewItem.Text = connections[row].ToString();

            int columns = traceDataResults.Count;

            for (int column = 0; column < columns; column++)
            {
                List <long> values = traceDataResults[column].Values;

                if (traceDataResults[column].TraceName == "Start Time")
                {
                    if (!summaryTab)
                    {
                        TimeSpan timeValue = TimeSpan.FromMilliseconds(values[row]);
                        listViewItem.SubItems.Add(GenericHelper.FormatTimeSpan(timeValue, true));
                    }
                }
                else
                {
                    listViewItem.SubItems.Add(values[row].ToString());
                }
            }

            if (!summaryTab)
            {
                foreach (RanTaskInfo ranTask in ranTaskInfo)
                {
                    if (ranTask.TaskName == resultTask.Name)
                    {
                        if (ranTask.ConnectionNumber == connections[row])
                        {
                            listViewItem.SubItems.Add(ranTask.Message);
                        }
                    }
                }
            }

            basedOnListView.Items.Add(listViewItem);
        }
    }
Esempio n. 2
0
        private void ReceiveCallback(IAsyncResult result)
        {
            StateObject state   = (StateObject)result.AsyncState;
            Socket      handler = state.WorkSocket;

            try
            {
                int bytesRead = handler.EndReceive(result);
                state.Builder.Add(state.Buffer, 0, bytesRead);
                int total = state.Builder.GetInt32(0);
                if (total == state.Builder.Count)
                {
                    DataEventArgs dex = DataEventArgs.Parse(state.Builder);
                    lock (ResultTask)
                    {
                        state.Builder.ReSet();
                        try
                        {
                            DataEventArgs timout = _timeoutTask.FirstOrDefault(o => o.TaskId == dex.TaskId);
                            if (timout == null)
                            {
                                ResultTask.AddOrUpdate(dex.TaskId, dex, (key, value) => value = dex);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            ResultTask.AddOrUpdate(dex.TaskId, dex, (key, value) => value = dex);
                        }
                    }
                    try
                    {
                        TaskTicks time = new TaskTicks();
                        if (RunTime.TryGetValue(dex.TaskId, out time))
                        {
                            time.OutQueTime = DateTime.Now.Ticks;
                            RunTime.TryUpdate(dex.TaskId, time, time);
                        }
                    }
                    catch (Exception ex)
                    { Console.WriteLine(ex); }
                }
                else
                {
                    handler.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
                }
            }

            catch (Exception ex)
            {
                state.Builder.ReSet();
                GC.Collect();
                Console.WriteLine(ex);
                _log.Error(ex);
            }
        }
        async Task HandleSelection(InputFileChangeEventArgs files)
        {
            byte[] buffer = new byte[512000];
            error = "";
            makeFiles.Clear();
            var mf = new List <string>();

            foreach (var f in files.GetMultipleFiles())
            {
                var resultTask = new ResultTask
                {
                    InputFile  = f.Name,
                    OutPutFile = f.Name + ".xml",
                    Result     = "Ok"
                };

                if (bankType != EBankType.iFobs)
                {
                    try
                    {
                        using (MemoryStream memStream = new MemoryStream(512000))
                        {
                            await f.OpenReadStream().CopyToAsync(memStream);

                            string r = _1CClientBankExchange.ConvertTo1CFormat(bankType, memStream, accountNumber);
                            await JSRuntime.InvokeAsync <object>("sabatex.downloadFile", resultTask.OutPutFile, r);
                        }
                    }
                    catch (Exception e)
                    {
                        resultTask.Result = e.Message;
                    }
                }
                else
                {
                    try {
                        var result = (new _1CClientBankExchange()) as IiFobs;
                        await result.ImportFromFileAsync(f.OpenReadStream(), Path.GetExtension(f.Name));

                        if (result.Count() > 0)
                        {
                            await JSRuntime.InvokeAsync <object>("sabatex.downloadFile", resultTask.OutPutFile, result.GetAsXML());
                        }
                        else
                        {
                            resultTask.Result = "Пропущений";
                        }
                    }
                    catch (Exception e)
                    {
                        resultTask.Result = e.Message;
                    }
                }
                makeFiles.Add(resultTask);
            }
        }
        public async Task <ActionResult <Models.Task> > Create([FromBody] ResultTask newTask)
        {
            Models.Task dbTask = new Models.Task()
            {
                TaskDate = new DateTime(newTask.Year, newTask.Month, newTask.Day), TaskText = newTask.Text
            };

            dbContext.Tasks.Add(dbTask);
            await dbContext.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 5
0
    private void SetBasedOnData(List <TraceDataResult> traceDataResults, ResultTask resultTask, List <RanTaskInfo> ranTaskInfo)
    {
        _basedOnListViewColumnSorter       = new ListViewColumnSorter();
        basedOnListView.ListViewItemSorter = _basedOnListViewColumnSorter;

        bool summaryTab = false;

        if (ranTaskInfo == null)
        {
            summaryTab = true;
        }

        SetupBasedOnColumns(traceDataResults, summaryTab);
        FillBasedOnListView(traceDataResults, resultTask, ranTaskInfo);
    }
Esempio n. 6
0
    private static TabPage GetTabPage(ResultTask resultTask, List <ImportTraceDataValue> traceDataList, List <RanTaskInfo> ranTaskInfo, int connections)
    {
        TabPage newTabPage = new TabPage();

        newTabPage.Name        = resultTask.Name;
        newTabPage.Text        = resultTask.Name;
        newTabPage.ToolTipText = resultTask.Description;
        newTabPage.ImageIndex  = 0;

        TabPageUserControl tabPageUserControl = GetNewTabPageUserControl(resultTask, traceDataList, ranTaskInfo, connections);

        newTabPage.Controls.Add(tabPageUserControl);

        return(newTabPage);
    }
Esempio n. 7
0
    private static TabPageUserControl GetNewTabPageUserControl(ResultTask resultTask, List <ImportTraceDataValue> traceDataList, List <RanTaskInfo> ranTaskInfo, int connections)
    {
        TabPageUserControl tabPageUserControl = new TabPageUserControl();

        tabPageUserControl.Dock = DockStyle.Fill;

        for (int i = 0; i < traceDataList.Count; i++)
        {
            if (traceDataList[i].TaskName == resultTask.Name)
            {
                tabPageUserControl.FillTraceDataResults(traceDataList[i].ColumnName, traceDataList[i].Value, traceDataList[i].Connection);
            }
        }

        tabPageUserControl.SetData(resultTask, ranTaskInfo, connections);

        return(tabPageUserControl);
    }
Esempio n. 8
0
        public virtual DataEventArgs GetResult(DataEventArgs e)
        {
            DataEventArgs arg = new DataEventArgs();

            try
            {
                var cts = new CancellationTokenSource(150000);
                while (!cts.Token.IsCancellationRequested)
                {
                    if (ResultTask.TryGetValue(e.TaskId, out arg))
                    {
                        arg.StatusCode = StatusCode.Success;
                        Channels[arg.CallHashCode].ActiveHash = 0;
                        try
                        {
                            StateObject oo = new StateObject();
                            RunStateObjects.TryRemove(arg.TaskId, out oo);
                            oo.Builder.ReSet();
                            DataEventArgs outarg = new DataEventArgs();
                            ResultTask.TryRemove(arg.TaskId, out outarg);
                            RuningTask.TryRemove(arg.TaskId, out outarg);
                        }
                        catch { }
                        return(arg);
                    }
                    Thread.Sleep(3);
                }
            }
            catch (Exception ex)
            {
                arg.StatusCode = StatusCode.Serious;
                _log.Error(ex);
                Console.WriteLine(ex);
                Channels[e.CallHashCode].ActiveHash = 0;
                return(arg);
            }
            _log.Info(e.TaskId + "超时");
            _timeoutTask.Add(e);
            e.StatusCode = StatusCode.TimeOut;
            return(e);
        }
Esempio n. 9
0
    private void AddTraceToXml(StringBuilder stringBuilder, ResultTask resultTask)
    {
        stringBuilder.Append("<data>");

        ListView traceDataResultsListView = GetTraceDataResults(resultTask.Name);

        foreach (ListViewItem item in traceDataResultsListView.Items)
        {
            string name    = item.SubItems[0].Text;
            string minimum = item.SubItems[1].Text;
            string maximum = item.SubItems[2].Text;
            string average = item.SubItems[3].Text;
            string sum     = item.SubItems[4].Text;

            stringBuilder.Append(string.Format("<value name=\"{0}\" minimum=\"{1}\" maximum=\"{2}\" average=\"{3}\" sum=\"{4}\" />", System.Security.SecurityElement.Escape(name), minimum, maximum, average, sum));
        }

        AddBasedOnTraceToXml(stringBuilder, resultTask.Name);

        stringBuilder.Append("</data>");
    }
Esempio n. 10
0
    public void SetData(ResultTask resultTask, List <RanTaskInfo> ranTaskInfo, int connections)
    {
        bool summaryTab = false;

        if (resultTask.Name == "Summary")
        {
            summaryTab = true;
        }

        ShowTraceResults(summaryTab);
        SetBasedOnData(_traceDataResults, resultTask, ranTaskInfo);

        if (!summaryTab)
        {
            firstConnectionStartTimeLabel.Text = string.Format("First Connection Start Time: {0}", GenericHelper.FormatDateTime(resultTask.FirstConnectionStartTime, true));
        }
        else
        {
            firstConnectionStartTimeLabel.Visible = false;
        }

        resultSummaryHeaderLabel.Text = string.Format("::: Result Statistics ({0}) :::::::", GetBasedOnLabel(connections));
    }
Esempio n. 11
0
        public override void Call(object obj, int len)
        {
            DataEventArgs outDea = new DataEventArgs();
            DataEventArgs ea     = (DataEventArgs)obj;

            try
            {
                if (RuningTask == null)
                {
                    RuningTask = new ConcurrentDictionary <int, DataEventArgs>();
                }
                RuningTask.AddOrUpdate(ea.TaskId, ea, (key, value) => value = ea);
                string url = "http://" + Channels[len].IpPoint.Address.ToString() + ":" + (Channels[len].IpPoint.Port + 1);
                Dictionary <string, string> header = new Dictionary <string, string>();
                header.Add("Authorization", "Basic " + this.Authorization);

                int           p                   = ea.ActionParam.LastIndexOf(".");
                List <object> eabinary            = Serializer.ToEntity <List <object> >(ea.Binary);
                string        code                = ea.ActionParam.Substring(p + 1);
                Dictionary <string, string> param = new Dictionary <string, string>();
                param.Add("", Serializer.ToString(eabinary));
                var           result = HttpPost.Post(url + "/" + code, param, header);
                DataEventArgs redata = Serializer.ToEntity <DataEventArgs>(result.Item2);

                if (result.Item1 == HttpStatusCode.OK)
                {
                    ea.StatusCode = StatusCode.Success;
                    dynamic dyjs = Serializer.ToEntity <dynamic>(redata.Json);

                    ea.Json = dyjs.data.ToString();

                    ea.Param = redata.Param;
                    ResultTask.AddOrUpdate(ea.TaskId, ea, (key, value) => value = ea);
                }
                else
                {
                    ea.StatusCode = StatusCode.Error;
                    if (HttpStatusCode.Moved == result.Item1)
                    {
                        ea.Json = result.Item2;
                        RuningTask.TryRemove(ea.TaskId, out outDea);
                        Channels[len].Available = false;
                        ClientTask.Enqueue(ea);
                        CheckServer();
                    }
                    else
                    {
                        ea.Json = result.Item2;
                        ResultTask.AddOrUpdate(ea.TaskId, ea, (key, value) => value = ea);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                _log.Error(ex + ex.StackTrace);
                ea.StatusCode = StatusCode.TimeOut;
                ea.TryTimes++;
                if (ea.TryTimes < 3)
                {
                    RuningTask.TryRemove(ea.TaskId, out outDea);
                    ClientTask.Enqueue(ea);
                    return;
                }

                ResultTask.AddOrUpdate(ea.TaskId, ea, (key, value) => value = ea);
                return;
            }
            finally
            {
                for (int i = 0; i < Channels.Count; i++)
                {
                    if (Channels[i].ActiveHash == ea.TaskId)
                    {
                        Channels[i].ActiveHash = 0;
                    }
                }
                RuningTask.TryRemove(ea.TaskId, out outDea);
            }
        }
Esempio n. 12
0
    private static TabPage GetSummaryTab(int connections, List <ImportTraceDataValue> summaryTraceDataList)
    {
        ResultTask summary = new ResultTask("Summary", "Summary");

        return(GetTabPage(summary, summaryTraceDataList, null, connections));
    }
Esempio n. 13
0
        public virtual DataEventArgs GetResult(DataEventArgs e)
        {
            DataEventArgs arg = new DataEventArgs();

            try
            {
                var cts = new CancellationTokenSource(_config.GetValue("server", "timeout", 15) * 1000);
                while (!cts.Token.IsCancellationRequested)
                {
                    if (ResultTask.TryGetValue(e.TaskId, out arg))
                    {
                        arg.StatusCode = StatusCode.Success;
                        Channels[arg.CallHashCode].ActiveHash = 0;
                        try
                        {
                            StateObject oo = new StateObject();
                            RunStateObjects.TryRemove(arg.TaskId, out oo);
                            if (oo != null)
                            {
                                oo.Builder.ReSet();
                            }
                            DataEventArgs outarg = new DataEventArgs();
                            ResultTask.TryRemove(arg.TaskId, out outarg);
                            RuningTask.TryRemove(arg.TaskId, out outarg);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                        try
                        {
                            TaskTicks time = new TaskTicks();
                            if (RunTime.TryGetValue(arg.TaskId, out time))
                            {
                                time.EndTime = DateTime.Now.Ticks;
                                RunTime.TryUpdate(arg.TaskId, time, time);
                                _log.Debug("RunTime:\r\n" + arg + "\r\n" + time + "\r\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                        return(arg);
                    }
                    Thread.Sleep(3);
                }
            }
            catch (Exception ex)
            {
                arg.StatusCode = StatusCode.Serious;
                _log.Error(ex);
                Console.WriteLine(ex);
                Channels[e.CallHashCode].ActiveHash = 0;
                return(arg);
            }
            _log.Info(e.TaskId + "超时");
            _timeoutTask.Add(e);
            e.StatusCode = StatusCode.TimeOut;
            return(e);
        }
Esempio n. 14
0
 public static Task <IActionResult> ToActionResult <TValue, TError>(this ResultTask <TValue, TError> result)
 => result.ToActionResult(_ => StatusCodes.Status200OK, _ => StatusCodes.Status500InternalServerError);
Esempio n. 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        ///
        public override void Call(object dataev, int i)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            DataEventArgs e       = (DataEventArgs)dataev;
            ChannelPool   channel = Channels[i];

            try
            {
                e.CallHashCode = i;
                Socket _client = channel.Client;
                if (_client == null || _client.Connected != true)
                {
                    channel.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    channel.Client.Connect(channel.IpPoint);
                    channel.Available = true;
                }
                _client = channel.Client;

                byte[] _bf = e.ToByteArray();
                #region 異步
                _client.BeginSend(_bf, 0, _bf.Length, SocketFlags.None, null, null);
                #endregion
                #region 異步接收
                StateObject state = new StateObject();
                RunStateObjects.TryAdd(e.TaskId, state);
                state.WorkSocket = _client;
                state.Builder.ReSet();
                SocketError error;
                _client.BeginReceive(state.Buffer, 0, StateObject.BufferSize, SocketFlags.None, out error, ReceiveCallback, state);
                #endregion
                watch.Stop();
                monitor.Write(e.TaskId, e.ActionCmd, "...", watch.ElapsedMilliseconds, _bf.LongLength.ToString());
                Channels[i].PingActives = DateTime.Now.Ticks;
            }
            catch (SocketException sex)
            {
                foreach (ChannelPool p in Channels)
                {
                    if (p.IpPoint == channel.IpPoint)
                    {
                        p.Available = false;
                    }
                }
                e.StatusCode = StatusCode.Error;
                lock (ResultTask)
                {
                    e.StatusCode = StatusCode.Serious;
                    DataEventArgs timout = _timeoutTask.FirstOrDefault(o => o.TaskId == e.TaskId);
                    if (timout == null)
                    {
                        ResultTask.AddOrUpdate(e.TaskId, e, (key, value) => value = e);
                    }
                    else
                    {
                        _timeoutTask.Remove(timout);
                    }
                }
                _log.Error(sex);
            }
            catch (Exception ex)
            {
                lock (ResultTask)
                {
                    e.StatusCode = StatusCode.Serious;
                    DataEventArgs timout = _timeoutTask.FirstOrDefault(o => o.TaskId == e.TaskId);
                    if (timout == null)
                    {
                        ResultTask.AddOrUpdate(e.TaskId, e, (key, value) => value = e);
                    }
                    else
                    {
                        _timeoutTask.Remove(timout);
                    }
                }
                _log.Error(ex);
            }
        }
Esempio n. 16
0
 public static Task <IActionResult> ToActionResult <TValue, TError>(this ResultTask <TValue, TError> result, Func <TValue, int> ok, Func <TError, int> err)
 => result.ToActionResult(ok, err, _ => None <TError>());    // Default to none to prevent errors from potentially leaking out
Esempio n. 17
0
        => result.ToActionResult(ok, err, _ => None <TError>());    // Default to none to prevent errors from potentially leaking out

        public static Task <IActionResult> ToActionResult <TValue, TError>(this ResultTask <TValue, TError> result, Func <TValue, int> ok, Func <TError, int> err, Func <TError, Option <TError> > opt)
        => result.Map <IActionResult>(value => new ObjectResult(value)
        {
            StatusCode = ok(value)
        })
        .UnwrapOrElseAsync(error => ToErrorActionResult(error, err, opt));