Ejemplo n.º 1
0
        public ReportMessage ExecuteQuery(string query)
        {
            ReportMessage message = null;

            MySqlTransaction transaction = null;

            try {
                transaction = Connection.Instance.BeginTransaction();
                MySqlCommand command = Connection.Instance.GetCommand(query, transaction);
                int          rows    = command.ExecuteNonQuery();

                if (rows > 0)
                {
                    transaction.Commit();
                    message = new ReportMessage(true, "Success!", ReportStatus.Success);
                }
                else
                {
                    message = new ReportMessage(true, "No errors occured, however, no rows were affected.", ReportStatus.Warning);
                }
            } catch (MySqlException ex) {
                message = new ReportMessage(false, "Error occured: " + ex.Message, ReportStatus.Error);
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                Console.WriteLine("Error in DbFlyAway.ExecuteQuery: " + ex.Message);
            }

            return(message);
        }
Ejemplo n.º 2
0
        public static async Task ExportFiles(DbConnectionString dbConnectionString, string sqlQuery, string folderPath, CancellationToken Ct, IProgress <ReportMessage> progress)
        {
            using (SqlConnection dbCon = new SqlConnection(dbConnectionString.ConnectionString))
            {
                dbCon.Open();
                using (SqlCommand cmd = new SqlCommand(sqlQuery, dbCon))
                {
                    // 10 hours
                    cmd.CommandTimeout = 60 * 60 * 10;
                    using (SqlDataReader reader = await cmd.ExecuteReaderAsync())
                    {
                        try
                        {
                            while (await reader.ReadAsync())
                            {
                                Ct.ThrowIfCancellationRequested();

                                var    fileName      = Convert.ToString(reader.GetValue(0));
                                string validFileName = MakeValidFileName(progress, fileName);
                                var    bytes         = (byte[])reader.GetValue(1);
                                var    fullPath      = Path.Combine(folderPath, validFileName);
                                File.WriteAllBytes(fullPath, bytes);

                                progress.Report(ReportMessage.Standard("Exported: " + validFileName));
                            }
                        }
                        finally
                        {
                            cmd.Cancel();
                            reader.Close();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Report(int id, string reason)
        {
            var userId  = userManager.GetUserId(User);
            var message = messageContext.Messages
                          .Single(c => c.Id == id && c.RecevierId == userId);

            if (message.IsReported)
            {
                return(Ok());
            }

            message.IsReported = true;

            var report = new ReportMessage
            {
                UserId     = userId,
                MessageId  = id,
                Reason     = reason,
                ReportTime = DateTime.UtcNow
            };

            messageContext.Add(report);
            await messageContext.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 4
0
 private void HandleDiscovery()
 {
     // discovery message received.
     int[] time = Group.EngineTimeData;
     Response = new ReportMessage(
         VersionCode.V3,
         new Header(
             new Integer32(Request.MessageId()),
             new Integer32(Messenger.MaxMessageSize),
             0), // no need to encrypt for discovery.
         new SecurityParameters(
             Group.EngineId,
             TimeIncluded ? new Integer32(time[0]) : Integer32.Zero,
             TimeIncluded ? new Integer32(time[1]) : Integer32.Zero,
             OctetString.Empty,
             OctetString.Empty,
             OctetString.Empty),
         new Scope(
             Group.EngineId,
             OctetString.Empty,
             new ReportPdu(
                 Request.RequestId(),
                 ErrorCode.NoError,
                 0,
                 new List <Variable>(1)
     {
         Group.UnknownEngineId
     })),
         DefaultPrivacyProvider.DefaultPair,
         null);
     if (TooBig)
     {
         GenerateTooBig();
     }
 }
Ejemplo n.º 5
0
        public async Task <bool> SendReport(Report report, ReportMessage reportMessage, User user)
        {
            if (report == null || user == null || reportMessage == null)
            {
                throw new EntityNotFoundException();
            }

            if (user.Reports.Count == 3)
            {
                return(false);
            }

            user.Reports.Add(report);
            user.ReportMessages.Add(reportMessage);
            report.ReportMessages.Add(reportMessage);

            if (!await database.Complete())
            {
                return(false);
            }

            await notificationSystem.PushNotificationToUsersByRoles(StaticExpressions.NewReportCreated(user.UserName), AdminRoles);

            return(true);
        }
Ejemplo n.º 6
0
 public ReportPackage(string urlParameters, IEnumerable <ReportMessage.Session> sessions)
 {
     this.Key            = string.Format(Memory.ActiveBox.KeyFormat, (object)Guid.NewGuid());
     this.UrlParameters  = urlParameters;
     this._reportMessage = ReportPackage.ToReportMessage(sessions);
     this._rawStream     = this.GetRawStream();
 }
Ejemplo n.º 7
0
        public async Task <bool> SendMailAsync(ReportMessage message)
        {
            try
            {
                var smtpInfo = new UriBuilder(message.SmtpConfiguration.SmtpHost);
                using (var smtpClient = new SmtpClient(smtpInfo.Host))
                {
                    // if Url is provided in https://host:port format
                    if (!smtpInfo.Uri.IsDefaultPort)
                    {
                        smtpClient.Port = smtpInfo.Port;
                    }
                    // Enable SSL required for mail addresses outside corp net
                    smtpClient.EnableSsl   = message.SmtpConfiguration.EnableSSL;
                    smtpClient.Credentials = new NetworkCredential(message.SmtpConfiguration.UserName, message.SmtpConfiguration.Password);

                    _logger.LogInformation($"Sending Mail using SmtpHost as '{smtpInfo.Host}:{smtpInfo.Port}' and EnableSSL as '{smtpClient.EnableSsl}'");
                    await smtpClient.SendMailAsync(message.MailMessage);

                    return(true);
                }
            }
            catch (Exception)
            {
                // ignore for now
            }
            return(false);
        }
Ejemplo n.º 8
0
        public override void Walk(IDefinition definition)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                Logger.Info("User name need to be specified for v3.");
                return;
            }

            Discovery        discovery = Messenger.NextDiscovery;
            ReportMessage    report    = discovery.GetResponse(Timeout, Agent);
            IList <Variable> list      = new List <Variable>();

            Messenger.BulkWalk(
                VersionCode.V3,
                Agent,
                new OctetString(UserName),
                new ObjectIdentifier(definition.GetNumericalForm()),
                list,
                Timeout,
                10,
                WalkMode.WithinSubtree,
                _privacy,
                report);

            foreach (Variable v in list)
            {
                Logger.Info(v.ToString(Objects));
            }
        }
        private void BtnInformV3Click(object sender, EventArgs e)
        {
            IPAddress ip = IPAddress.Parse(txtIP.Text);

            try
            {
                IPEndPoint    receiver  = new IPEndPoint(ip, int.Parse(txtPort.Text, CultureInfo.InvariantCulture));
                Discovery     discovery = Messenger.GetNextDiscovery(SnmpType.InformRequestPdu);
                ReportMessage report    = discovery.GetResponse(2000, receiver);

                Messenger.SendInform(
                    0,
                    VersionCode.V3,
                    receiver,
                    new OctetString("neither"),
                    OctetString.Empty,
                    new ObjectIdentifier(new uint[] { 1, 3, 6 }),
                    0,
                    new List <Variable>(),
                    2000,
                    DefaultPrivacyProvider.DefaultPair,
                    report);
            }
            catch (SnmpException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns a list of OID values as Variable's.
        /// </summary>
        /// <param name="requestedVariables"></param>
        /// <returns></returns>
        public List <Variable> GetOidValues(List <Variable> requestedVariables)
        {
            List <Variable> oidResults;

            try
            {
                // SNMPv2
                if (snmpVersion != VersionCode.V3)
                {
                    oidResults = new List <Variable>(Messenger.Get(snmpVersion, snmpEndpoint, snmpCommunity, requestedVariables, snmpTimeout));
                }
                // SNMPv3
                else
                {
                    Discovery         snmpDiscovery = Messenger.NextDiscovery;
                    ReportMessage     snmpRepMsg    = snmpDiscovery.GetResponse(snmpTimeout, snmpEndpoint);
                    GetRequestMessage snmpRequest   = new GetRequestMessage(snmpVersion, Messenger.NextMessageId, Messenger.NextRequestId, snmpUser, requestedVariables, snmpPriv, Messenger.MaxMessageSize, snmpRepMsg);
                    ISnmpMessage      snmpRespMsg   = snmpRequest.GetResponse(snmpTimeout, snmpEndpoint);
                    if (snmpRespMsg.Pdu().ErrorStatus.ToInt32() != 0)
                    {
                        throw Lextm.SharpSnmpLib.Messaging.ErrorException.Create("Error in SNMP Response, ", snmpEndpoint.Address, snmpRespMsg);
                    }
                    oidResults = new List <Variable>(snmpRespMsg.Pdu().Variables);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(oidResults);
        }
Ejemplo n.º 11
0
        internal override void GetTable(IDefinition def)
        {
            Discovery        discovery = Messenger.NextDiscovery;
            ReportMessage    report    = discovery.GetResponse(Timeout, Agent);
            IList <Variable> list      = new List <Variable>();
            int rows = Messenger.BulkWalk(
                VersionCode.V3,
                Agent,
                new OctetString(UserName),
                new ObjectIdentifier(def.GetNumericalForm()),
                list,
                Timeout,
                10,
                WalkMode.WithinSubtree,
                _privacy,
                report);

            // How many rows are there?
            if (rows > 0)
            {
                FormTable newTable = new FormTable(def);
                newTable.SetRows(rows);
                newTable.PopulateGrid(list);
                newTable.Show();
            }
            else
            {
                foreach (Variable t in list)
                {
                    Logger.Info(t.ToString());
                }
            }
        }
Ejemplo n.º 12
0
        public async Task Handle(SetV3Command command)
        {
            Discovery     discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
            ReportMessage report    = discovery.GetResponse(10000, new IPEndPoint(command.IpAddress, command.Port));

            var provider = GetPrivacyProvider(command.Password, command.PasswordType, command.Encryption, command.EncryptionType);

            SetRequestMessage request = new SetRequestMessage(
                Lextm.SharpSnmpLib.VersionCode.V3,
                Messenger.NextMessageId,
                Messenger.NextRequestId,
                new OctetString(command.UserName),
                new List <Variable>
            {
                new Variable(new ObjectIdentifier(command.OID.Id), new OctetString(command.OID.Value))
            },
                provider, report);

            ISnmpMessage reply = await request.GetResponseAsync(new IPEndPoint(command.IpAddress, command.Port));

            if (reply.Pdu().ErrorStatus.ToInt32() != 0) // != ErrorCode.NoError
            {
                throw ErrorException.Create("error in response", command.IpAddress, reply);
            }
        }
Ejemplo n.º 13
0
                    public bool isEqual(ReportMessage value)
                    {
                        if (this.m_Length != value.m_Length)
                        {
                            return(false);
                        }

                        if ((this.m_Data != null) && (value.m_Data != null))
                        {
                            for (int i = 0; i < value.m_Length; i++)
                            {
                                if (this.m_Data[i] != value.m_Data[i])
                                {
                                    return(false);
                                }
                            }
                        }
                        // This case should never be true since it should not be possible
                        // for the two variables to have equal lengths but one has no data.
                        // This check is placed here as a secondary check.
                        else if ((this.m_Data != null) || (value.m_Data != null))
                        {
                            return(false);
                        }

                        return(true);
                    }
Ejemplo n.º 14
0
        /// <summary>
        /// 添加报告数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="type"></param>
        private void AddReportMessage(string message, ReportMessageType type)
        {
            var reportMessage = new ReportMessage(type, message);

            Instance.ReportData.Add(reportMessage);
            OnReportDataAdded(EventArgs.Empty);
        }
Ejemplo n.º 15
0
 private void HandleFailure(Variable failure)
 {
     var defaultPair = DefaultPrivacyProvider.DefaultPair;
     Response = new ReportMessage(
         Request.Version,
         new Header(
             new Integer32(Request.MessageId()),
             new Integer32(Messenger.MaxMessageSize),
             0), // no need to encrypt.
         new SecurityParameters(
             Group.EngineId,
             new Integer32(Group.EngineBoots),
             new Integer32(Group.EngineTime),
             Request.Parameters.UserName,
             defaultPair.AuthenticationProvider.CleanDigest,
             defaultPair.Salt),
         new Scope(
             Group.EngineId,
             OctetString.Empty,
             new ReportPdu(
                 Request.RequestId(),
                 ErrorCode.NoError,
                 0,
                 new List<Variable>(1) { failure })),
         defaultPair,
         null);
     if (TooBig)
     {
         GenerateTooBig();
     }
 }
Ejemplo n.º 16
0
 private void HandleDiscovery()
 {         
     // discovery message received.
     // TODO: pick up time information from Group instead of using raw data.
     Response = new ReportMessage(
         VersionCode.V3,
         new Header(
             new Integer32(Request.MessageId()),
             new Integer32(Messenger.MaxMessageSize),
             0), // no need to encrypt for discovery.
         new SecurityParameters(
             Group.EngineId,
             TimeIncluded ? Integer32.Zero : Integer32.Zero,
             TimeIncluded ? new Integer32(Environment.TickCount) : Integer32.Zero,
             OctetString.Empty,
             OctetString.Empty,
             OctetString.Empty),
         new Scope(
             Group.EngineId,
             OctetString.Empty,
             new ReportPdu(
                 Request.RequestId(),
                 ErrorCode.NoError,
                 0,
                 new List<Variable>(1) { Group.UnknownEngineID })),
         DefaultPrivacyProvider.DefaultPair,
         null);
     if (TooBig)
     {
         GenerateTooBig();
     }
 }
Ejemplo n.º 17
0
        public static void RunPatch(string script)
        {
            try
            {
                script = script.Replace("[ReflexMobile]", $"[{MobileCommon.DatabaseName}]");

                using (SqlConnection connection = new SqlConnection(MobileCommon.MobileDB))
                {
                    //Server server = new Server(new ServerConnection(connection));
                    //server.ConnectionContext.ExecuteNonQuery(script);

                    IEnumerable <string> commandStrings = Regex.Split(script, @"^\s*GO\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase);

                    connection.Open();
                    foreach (string commandString in commandStrings)
                    {
                        if (commandString.Trim() != "")
                        {
                            using (var command = new SqlCommand(commandString, connection))
                            {
                                command.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ReportMessage?.Invoke(e.Message);
            }
        }
Ejemplo n.º 18
0
        private void ExecuteQuery()
        {
            if (this.txtQuery.Text.Trim().Length > 0)
            {
                //Cache values
                string             query = this.txtQuery.Text;
                List <DTO.DataRow> rows  = this.table.DataRows;
                string             id    = string.Empty;
                if (this.ctrlToIncrement != null)
                {
                    id = this.ctrlToIncrement.Text;
                }

                ReportMessage message = this.dbFlyAway.ExecuteQuery(this.txtQuery.Text);
                this.LoadTable((string)this.cmbTables.SelectedItem);

                this.txtQuery.Text  = query;
                this.table.DataRows = rows;
                if (this.ctrlToIncrement != null)
                {
                    this.ctrlToIncrement.Text = id;
                }

                MessageBox.Show(this, message.Message, "Execute query", MessageBoxButtons.OK, message.GetIconOfStatus());
            }
        }
Ejemplo n.º 19
0
        internal override void Get(Variable variable)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                Logger.Info("User name need to be specified for v3.");
                return;
            }

            Discovery         discovery = Messenger.NextDiscovery;
            ReportMessage     report    = discovery.GetResponse(Timeout, Agent);
            GetRequestMessage request   = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(UserName), new List <Variable> {
                variable
            }, _privacy, Messenger.MaxMessageSize, report);
            ISnmpMessage response = request.GetResponse(Timeout, Agent, _registry);

            if (response.Pdu().ErrorStatus.ToInt32() != 0)
            {
                throw ErrorException.Create(
                          "error in response",
                          Agent.Address,
                          response);
            }

            Logger.Info(response.Pdu().Variables[0].ToString(Objects));
        }
        // Token: 0x06000620 RID: 1568 RVA: 0x00030A78 File Offset: 0x0002EC78
        public static void RenderReadBody(TextWriter output, Item item, OwaSafeHtmlCallbackBase callBack, bool isJunkOrPhishing)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (item == null)
            {
                return;
            }
            ReportMessage reportMessage = item as ReportMessage;
            bool          flag          = null != reportMessage;

            if (Utilities.IsOpaqueSigned(item))
            {
                MessageItem messageItem = item as MessageItem;
                Item        item2       = null;
                if (messageItem != null && ItemConversion.TryOpenSMimeContent(messageItem, OwaContext.Current.UserContext.Configuration.DefaultAcceptedDomain.Name, out item2))
                {
                    item = item2;
                }
            }
            if (item.Body == null || (flag && item.Body.Size <= 0L))
            {
                if (flag)
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        Charset charset;
                        reportMessage.GenerateReportBody(memoryStream, out charset);
                        item.OpenAsReadWrite();
                        BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, charset.Name);
                        using (Stream stream = item.Body.OpenWriteStream(configuration))
                        {
                            memoryStream.Position = 0L;
                            memoryStream.WriteTo(stream);
                        }
                        goto IL_DC;
                    }
                }
                return;
            }
IL_DC:
            Body body = item.Body;

            if (!OwaContext.Current.UserContext.IsBasicExperience && OwaContext.Current.UserContext.IsIrmEnabled && Utilities.IsIrmRestrictedAndDecrypted(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            if (body.Size > 0L)
            {
                Markup markup = Markup.Html;
                if (isJunkOrPhishing)
                {
                    markup = Markup.PlainText;
                }
                BodyConversionUtilities.ConvertAndOutputBody(output, body, markup, callBack, false);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// 添加消息信息
 /// </summary>
 /// <param name="message">报告消息</param>
 private void AppendMessage(ReportMessage message)
 {
     TxtMessageContainer.AppendText($"消息:[{DateTime.Now.ToString(Appconfig.FullDateFormat)}]", OutPutDataColor.DateTimeColor);
     TxtMessageContainer.AppendText("=>\r", OutPutDataColor.DefualtColor);
     TxtMessageContainer.AppendText($"{message.Message}", message.MessageColor);
     TxtMessageContainer.AppendText("\r\n");
     TxtMessageContainer.ScrollToEnd();
 }
Ejemplo n.º 22
0
 public EventRec()
 {
     m_parent         = null;
     m_EventID        = 0;
     m_SequenceNumber = 0;
     m_ReportMessage  = new ReportMessage();
     m_ReportMessage.setParent(this);
 }
Ejemplo n.º 23
0
        private void HandleReportMessage(ReportMessage rpt)
        {
            var delay = Rnd.Next(5, 10);

            ColorConsole.WriteLineYellow($"Generating Report for Job #{rpt.JobId}. Should take { delay }s to finish.it");
            Thread.Sleep(delay * 1000);
            ColorConsole.WriteLineCyan($"{ ActorClassName } { _actorId }: Report '{rpt.ReportTitle}' for Job #{rpt.JobId} completed.");
            Sender.Tell($"Report #{rpt.JobId} completed.");
        }
Ejemplo n.º 24
0
 public static string ToProtobufString <T>(this T obj) where T : ReportMessage
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         ReportMessage.Serialize((Stream)memoryStream, (ReportMessage)obj);
         byte[] array = memoryStream.ToArray();
         return(Encoding.UTF8.GetString(array, 0, array.Length));
     }
 }
Ejemplo n.º 25
0
 public void Keep()
 {
     if (this._reportMessage == null)
     {
         return;
     }
     using (Stream writeStream = Memory.ActiveBox.Storage.GetWriteStream(this.Key))
         ReportMessage.Serialize(writeStream, this._reportMessage);
 }
Ejemplo n.º 26
0
        private Item BindToItemWithItemClass(StoreObjectId id, string itemClass, PropertyDefinition[] properties)
        {
            Item result;

            if (ObjectClass.IsReport(itemClass))
            {
                result = ReportMessage.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsMessage(itemClass, false))
            {
                result = MessageItem.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsPost(itemClass))
            {
                result = PostItem.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsCalendarItem(itemClass))
            {
                result = CalendarItem.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsMeetingRequest(itemClass))
            {
                result = MeetingRequest.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsMeetingResponse(itemClass))
            {
                result = MeetingResponse.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsMeetingCancellation(itemClass))
            {
                result = MeetingCancellation.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsContact(itemClass))
            {
                result = Contact.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsTask(itemClass))
            {
                Task task = Task.Bind(this.mailboxSession, id, true, properties);
                task.SuppressRecurrenceAdjustment = true;
                result = task;
            }
            else if (ObjectClass.IsDistributionList(itemClass))
            {
                result = DistributionList.Bind(this.mailboxSession, id, properties);
            }
            else if (ObjectClass.IsGenericMessage(itemClass))
            {
                result = MessageItem.Bind(this.mailboxSession, id, properties);
            }
            else
            {
                result = Item.Bind(this.mailboxSession, id, properties);
            }
            return(result);
        }
Ejemplo n.º 27
0
 private static RawShaderAnalysisMessage ConvertToRawMessage(ReportMessage message)
 {
     return(new RawShaderAnalysisMessage()
     {
         Span = ConvertToRawLocation(message.Span),
         Text = message.Text,
         Code = message.Code,
         Type = ConvertToStringLevel(message.Level)
     });
 }
 public static ReferenceIntegrityCheckReport NotOk(ReportMessage message, string source, Reference reference)
 {
     return new ReferenceIntegrityCheckReport
     {
         Reference = reference,
         Source = source,
         IsOk = false,
         Message = message
     };
 }
Ejemplo n.º 29
0
        public void TestResponseVersion3()
        {
            var engine = CreateEngine();

            engine.Listener.ClearBindings();
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, Port.NextId);

            engine.Listener.AddBinding(serverEndPoint);
            engine.Start();

            try
            {
                IAuthenticationProvider auth = new MD5AuthenticationProvider(new OctetString("authentication"));
                IPrivacyProvider        priv = new DefaultPrivacyProvider(auth);

                var           ending    = new AutoResetEvent(false);
                var           timeout   = 3000;
                Discovery     discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
                ReportMessage report    = discovery.GetResponse(timeout, serverEndPoint);

                var expected = Messenger.NextRequestId;
                GetRequestMessage request = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, expected, new OctetString("authen"), OctetString.Empty, new List <Variable> {
                    new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.1.0"))
                }, priv, Messenger.MaxMessageSize, report);

                var source = Observable.Defer(() =>
                {
                    ISnmpMessage reply = request.GetResponse(timeout, serverEndPoint);
                    return(Observable.Return(reply));
                })
                             .RetryWithBackoffStrategy(
                    retryCount: 4,
                    retryOnError: e => e is Messaging.TimeoutException
                    );

                source.Subscribe(reply =>
                {
                    ISnmpPdu snmpPdu = reply.Pdu();
                    Assert.Equal(SnmpType.ResponsePdu, snmpPdu.TypeCode);
                    Assert.Equal(expected, reply.RequestId());
                    Assert.Equal(ErrorCode.NoError, snmpPdu.ErrorStatus.ToErrorCode());
                    ending.Set();
                });
                Assert.True(ending.WaitOne(MaxTimeout));
            }
            finally
            {
                if (SnmpMessageExtension.IsRunningOnWindows)
                {
                    engine.Stop();
                }
            }
        }
Ejemplo n.º 30
0
        private static void Main(string[] args)
        {
            var jobId = 1;

            ColorConsole.WriteLineGray("Creating Client Actor System");
            var serverLocation = ConfigurationManager.AppSettings["serverLocation"];

            var actorSystem = ActorSystem.Create("ConsoleClient");

            ColorConsole.WriteLineGray("Creating actor supervisory hierarchy");
            var    logger   = actorSystem.ActorSelection($"akka.tcp://{ serverLocation }/user/LogCoordinator");
            var    reporter = actorSystem.ActorSelection($"akka.tcp://{ serverLocation }/user/Report");
            string command;

            do
            {
                ShortPause();

                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.DarkGray;
                ColorConsole.WriteLineGray("enter a command and hit enter");

                command = Console.ReadLine() ?? string.Empty;

                if (command.StartsWith("log"))
                {
                    var appId  = command.Split(',')[1];
                    var logMsg = command.Split(',')[2];

                    var message = new LogEntryMessage(appId, LogEventType.Info, logMsg);
                    logger.Tell(message);
                }

                if (command.StartsWith("rpt"))
                {
                    var report = new ReportMessage(jobId++, command.Split(',')[1]);

                    Task.Run(async() =>
                    {
                        var r   = reporter.Ask(report);
                        var ack = await r;
                        ColorConsole.WriteLineCyan(ack.ToString());
                        ColorConsole.WriteLineGray("");
                    });
                }
            } while (command != "exit");

            actorSystem.Terminate();
            actorSystem.WhenTerminated.Wait();
            ColorConsole.WriteLineGray("Actor system terminated");
            Console.ReadKey();
            Environment.Exit(1);
        }
Ejemplo n.º 31
0
        private static string MakeValidFileName(IProgress <ReportMessage> progress, string fileName)
        {
            bool changed;
            var  validFileName = FileExtensions.MakeValidFileName(fileName, out changed, (invalidChar) => "_", true);

            if (changed)
            {
                progress.Report(ReportMessage.Warning("Invalid filename: " + fileName));
                progress.Report(ReportMessage.Warning("Replacement: " + validFileName));
            }

            return(validFileName);
        }
Ejemplo n.º 32
0
                public EventRec(EventRec value)
                {
                    /// Initiliaze the protected variables
                    m_parent = null;
                    m_EventID = 0;
                    m_SequenceNumber = 0;
                    m_ReportMessage = new ReportMessage();
                    m_ReportMessage.setParent(this);

                    /// Copy the values
                    m_EventID = value.m_EventID;
                    m_SequenceNumber = value.m_SequenceNumber;
                    m_ReportMessage = value.getReportMessage();
                }
Ejemplo n.º 33
0
 public EventRec()
 {
     m_parent = null;
     m_EventID = 0;
     m_SequenceNumber = 0;
     m_ReportMessage = new ReportMessage();
     m_ReportMessage.setParent(this);
 }
Ejemplo n.º 34
0
 public void setReportMessage(ReportMessage value)
 {
     m_ReportMessage = value;
     setParentPresenceVector();
 }
Ejemplo n.º 35
0
                public Event.Body.EventRec setEventRec(EventRec value)
                {
                    m_EventID = value.m_EventID;
                    m_SequenceNumber = value.m_SequenceNumber;
                    m_ReportMessage = value.getReportMessage();

                    return this;
                }
Ejemplo n.º 36
0
                    public Event.Body.EventRec.ReportMessage setReportMessage(ReportMessage value)
                    {
                        this.m_Length = value.m_Length;

                        m_Data = null;

                        if (m_Length > 0)
                        {
                        m_Data = new byte[(int)m_Length];
                        this.m_Data = value.m_Data;
                        }

                        return this;
                    }
Ejemplo n.º 37
0
                    public bool isEqual(ReportMessage value)
                    {
                        if (this.m_Length != value.m_Length)
                        {
                        return false;
                        }

                        if ((this.m_Data != null) && (value.m_Data!= null))
                        {
                        for(int i = 0; i < value.m_Length; i++)
                        {
                            if (this.m_Data[i] != value.m_Data[i])
                            {
                                return false;
                            }
                        }
                        }
                        // This case should never be true since it should not be possible
                        // for the two variables to have equal lengths but one has no data.
                        // This check is placed here as a secondary check.
                        else if ((this.m_Data != null) || (value.m_Data != null))
                        {
                        return false;
                        }

                        return true;
                    }
Ejemplo n.º 38
0
 public bool notEquals(ReportMessage value)
 {
     return !this.isEqual(value);
 }
Ejemplo n.º 39
0
                    public ReportMessage(ReportMessage value)
                    {
                        /// Initiliaze the protected variables
                        m_parent = null;
                        m_Length = 0;
                        m_Data = null;

                        /// Copy the values
                        this.m_Length = value.m_Length;

                        m_Data = null;

                        if (m_Length > 0)
                        {
                        m_Data = new byte[(int)m_Length];
                        this.m_Data = value.m_Data;
                        }
                    }
Ejemplo n.º 40
0
 public void TestConstructorV3Auth1()
 {
     const string bytes = "30 73" +
                          "02 01  03 " +
                          "30 0F " +
                          "02  02 35 41 " +
                          "02  03 00 FF E3" +
                          "04 01 05" +
                          "02  01 03" +
                          "04 2E  " +
                          "30 2C" +
                          "04 0D  80 00 1F 88 80 E9 63 00  00 D6 1F F4  49 " +
                          "02 01 0D  " +
                          "02 01 57 " +
                          "04 05 6C 65 78  6C 69 " +
                          "04 0C  1C 6D 67 BF  B2 38 ED 63 DF 0A 05 24  " +
                          "04 00 " +
                          "30 2D  " +
                          "04 0D 80 00  1F 88 80 E9 63 00 00 D6  1F F4 49 " +
                          "04  00 " +
                          "A0 1A 02  02 01 AF 02 01 00 02 01  00 30 0E 30  0C 06 08 2B  06 01 02 01 01 03 00 05  00";
     ReportMessage report = new ReportMessage(
         VersionCode.V3,
         new Header(
             new Integer32(13633),
             new Integer32(0xFFE3),
             0),
         new SecurityParameters(
             new OctetString(ByteTool.Convert("80 00 1F 88 80 E9 63 00  00 D6 1F F4  49")),
             new Integer32(0x0d),
             new Integer32(0x57),
             new OctetString("lexli"),
             new OctetString(new byte[12]),
             OctetString.Empty),
         new Scope(
             new OctetString(ByteTool.Convert("80 00 1F 88 80 E9 63 00  00 D6 1F F4  49")),
             OctetString.Empty,
             new ReportPdu(
                 0x01AF,
                 ErrorCode.NoError,
                 0,
                 new List<Variable>(1) { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.3.0")) })),
         DefaultPrivacyProvider.DefaultPair,
         null);
     
     IPrivacyProvider privacy = new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("testpass")));
     GetRequestMessage request = new GetRequestMessage(
         VersionCode.V3,
         13633,
         0x01AF,
         new OctetString("lexli"),
         new List<Variable>(1) { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.3.0")) },
         privacy,
         Messenger.MaxMessageSize,
         report);
     
     Assert.AreEqual(Levels.Authentication | Levels.Reportable, request.Header.SecurityLevel);
     Assert.AreEqual(ByteTool.Convert(bytes), request.ToBytes());
 }