Beispiel #1
0
        public void Dispose()
        {
            Disconnect();

            _socket          = null;
            _processor       = null;
            acceptAsyncEvent = null;
        }
Beispiel #2
0
        public static async Task ProcessAsync()
        {
            Console.WriteLine("Loading nuget package meta data...");

            var fProcessor  = new FeedProcessor();
            var packageData = await fProcessor.ProcessAsync();

            Console.WriteLine("Processing packages...");

            var results = new List <ProcessResult>();

            Parallel.ForEach <PackageData>(packageData, package =>
            {
                Console.WriteLine($"Processing: {package.Title}");

                using (var aProc = new PackageProcessor(package))
                {
                    var result = aProc.Process();

                    results.Add(result);
                }
            });

            //
            Console.WriteLine("Saving results to database...");

            using (var aDb = new AuditorDbContext())
            {
                //empty the old results
                aDb.Results.RemoveRange(aDb.Results);

                aDb.Results.AddRange(results);

                await aDb.SaveChangesAsync();
            }

            //check for failed packages, that haven't been signed but only after the cutoff date when signing was required
            var failedSignCheck = results.Where(x => x.IsSigned.Equals(false) &&
                                                x.DatePublished >= SettingsHelper.CutOffDateTime);

            if (failedSignCheck.Any())
            {
                var packageIds = failedSignCheck.Select(x => x.PackageId);

                SlackNotifier.Notify(packageIds.ToList());
            }


            Console.WriteLine($"Processed: {results.Count} Packages");
            Console.ReadLine();
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiClient" /> class.
        /// </summary>
        /// <param name="apiBaseUri">The api base URI.</param>
        public ApiClient(string apiBaseUri)
        {
            HttpClient httpClient = new HttpClient {
                BaseAddress = new Uri(apiBaseUri)
            };

            ApiBaseUri = apiBaseUri;

            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");

            AgentProcessor = new AgentProcessor(httpClient);

            JobInstanceProcessor = new JobInstanceProcessor(httpClient);

            PackageProcessor = new PackageProcessor(httpClient);
        }
Beispiel #4
0
        public void Send(string name, string querystring, NameValueCollection exheader = null)
        {
            var headerNc = new NameValueCollection
            {
            };

            foreach (string key in ExHeaders.Keys)
            {
                headerNc.Add(key, ExHeaders[key]);
            }

            headerNc.Add("c", name);
            headerNc.Add("o", $"{O++}");
            headerNc.Add("t", $"{Utils.GetTimestamp()}");
            headerNc.Add("lang", $"{Lang}");
            headerNc.Add("format", "protobuf");
            headerNc.Add("token", HttpUtility.UrlEncode(_token));

            if (exheader != null)
            {
                foreach (var item in exheader.AllKeys)
                {
                    headerNc[item] = exheader[item];
                }
            }


            var reqeustInfo = new PirateXRequestInfo(headerNc, HttpUtility.ParseQueryString(querystring));

            var package   = reqeustInfo.ToRequestPackage();
            var senddatas = PackageProcessor.PackPacketToBytes(package);

            Client.Send(senddatas, 0, senddatas.Length);
            SendTime = DateTime.Now;
            if (OnSend != null)
            {
                OnSend(this, new OutMsgEventArgs(name, reqeustInfo));
            }
        }
Beispiel #5
0
        public virtual void Disconnect()
        {
            if (_socket != null)
            {
                if (_processor != null)
                {
                    _processor.ReleaseBuffer();
                }
                _processor = null;

                try { _socket.Shutdown(SocketShutdown.Both); }
                catch { }

                try { _socket.Close(); }
                catch { }

                try { if (DisconnectHandler != null)
                      {
                          DisconnectHandler();
                      }
                }
                catch { }
            }
        }
Beispiel #6
0
        void client_DataReceived(object sender, DataEventArgs e)
        {
            var sw = new Stopwatch();

            sw.Start();

            var log = new ProcessLog()
            {
                Rid    = Id,
                Name   = CurrentMethod,
                Req    = CurrentReq,
                Ok     = true,
                SendOk = sendOk,
                Start  = SendTime,
                End    = DateTime.Now
            };

            try
            {
                var responsePackage = PackageProcessor.UnPackToPacket(e.Data);
                var responseInfo    = new PirateXResponseInfo(responsePackage);

                var header = responseInfo.Headers;
                sw.Stop();

                log.Resp = header;


                if (Equals(header["i"], "2"))
                {
                    var method   = header["c"];
                    var executor = GetBroadcastExecutor(method);
                    if (executor != null)
                    {
                        executor.Header = header;

                        var type = executor.GetType();
                        var o    = (IPirateXClientExecutor)Activator.CreateInstance(type);

                        o.Header          = header;
                        o.ResponseConvert = _responseConverts[responseInfo.Headers["format"] ?? DefaultFormat];
                        try
                        {
                            o.Excute(this, responsePackage.ContentBytes);
                        }
                        catch (Exception exc)
                        {
                            client_Error(this, new ErrorEventArgs(new Exception("Message handling exception", exc)));
                        }
                    }

                    if (OnNotified != null)
                    {
                        OnNotified(this, new MsgEventArgs(responseInfo.Headers["c"], responseInfo));
                    }
                }
                else if (Equals(header["i"], "1"))
                {
                    if (!Equals(header["code"], "200"))
                    {
                        if (OnServerError != null)
                        {
                            OnServerError(this, new PErrorEventArgs(
                                              Convert.ToInt32(header["errorCode"]),
                                              HttpUtility.UrlDecode(Convert.ToString(header["errorMessage"]))));
                        }

                        log.Ok = false;
                    }
                    else
                    {
                        var method = header["c"].ToString();

                        var executor = GetExecutor(method);

                        if (executor != null)
                        {
                            var type = executor.GetType();
                            var o    = (IPirateXClientExecutor)Activator.CreateInstance(type);

                            o.Header          = header;
                            o.ResponseConvert = _responseConverts[responseInfo.Headers["format"] ?? DefaultFormat];

                            try
                            {
                                o.Excute(this, responsePackage.ContentBytes);
                            }
                            catch (Exception exc)
                            {
                                client_Error(this, new ErrorEventArgs(new Exception("Message handling exception", exc)));
                            }

                            if (type == typeof(NewSeed))
                            {
                                m_StateCode = PSocketStateConst.Open;
                                if (OnOpen != null)
                                {
                                    OnOpen(this, new EventArgs());
                                }
                            }
                        }


                        if (OnReceiveMessage != null)
                        {
                            OnReceiveMessage(this, new MsgEventArgs(responseInfo.Headers["c"], responseInfo));
                        }
                    }

                    if (OnResponseProcessed != null)
                    {
                        OnResponseProcessed(this, log);
                    }
                }
            }
            catch (Exception exc)
            {
                client_Error(this, new ErrorEventArgs(exc));
            }
        }
        public static async Task ProcessAsync()
        {
            try
            {
                LogHelper.WriteLine("Loading nuget package meta data...");

                var fProcessor  = new FeedProcessor();
                var packageData = await fProcessor.ProcessQueryAsync();

                var searchData = await fProcessor.ProcessSearchAsync();


                LogHelper.WriteLine("Processing packages...");

                var results = new List <ProcessResult>();

                var options = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 2
                };

                Parallel.ForEach <PackageData>(packageData, options, package =>
                {
                    LogHelper.WriteLine($"Processing: {package.Title}");

                    var sPackage = searchData.FirstOrDefault(x => x.PackageRegistration.Id.Equals(package.PackageId));

                    using (var aProc = new PackageProcessor(package, sPackage))
                    {
                        var result = aProc.Process();

                        results.Add(result);
                    }
                });

                //
                LogHelper.WriteLine("Saving results to database...");

                using (var aDb = new AuditorDbContext())
                {
                    //empty the old results
                    aDb.Results.RemoveRange(aDb.Results);
                    await aDb.SaveChangesAsync();

                    aDb.Results.AddRange(results);

                    await aDb.SaveChangesAsync();
                }

                //check for failed packages, that haven't been signed but only after the cutoff date when signing was required
                var failedSignCheck = results.Where(x => x.IsSigned.Equals(false) &&
                                                    x.DatePublished >= SettingsHelper.CutOffDateTime);

                if (failedSignCheck.Any())
                {
                    var packageIds = failedSignCheck.Select(x => x.PackageId);

                    SlackNotifier.Notify(packageIds.ToList());
                }


                LogHelper.WriteLine($"Processed: {results.Count} Packages");

                //Console.ReadLine();
            }
            catch (Exception ex)
            {
                var msg = ex.Message;

                if (ex.InnerException != null)
                {
                    msg += Environment.NewLine + Environment.NewLine + ex.InnerException.Message;
                }

                LogHelper.WriteLine(msg);
            }
        }
Beispiel #8
0
 protected void InitProcessor()
 {
     this._processor = new PackageProcessor(this, SendBuffer, ReceiveBuffer);
 }