Пример #1
0
 public RegistryLink(RegistryEvent e)
 {
     _item = e.Item;
     if (_item is T r)
     {
         Item = r;
     }
 }
        public bool CreateRegistryEvent(RegistryEventCreate model)
        {
            var entity =
                new RegistryEvent()
            {
                UserProfileId            = (int)_thisUserProfileId,
                RegistryEventTitle       = model.RegistryEventTitle,
                RegistryEventDescription = model.RegistryEventDescription,
                EventLocation            = model.EventLocation,
                EventDate = model.EventDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.RegistryEvents.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #3
0
        void manager_UnhandledEvent(object sender, ManagerEvent e)
        {
            log.Debug("New unhandled event received: " + e.GetType().Name);
            LineControl lc = null;

            //StateServer
            switch (e.GetType().Name)
            {
            case "AGIExecEvent":
                AGIExecEvent agievent = e as AGIExecEvent;
                break;

            case "AlarmClearEvent":
                AlarmClearEvent alarmclear = e as AlarmClearEvent;
                break;

            case "AlarmEvent":
                AlarmEvent alarmevent = e as AlarmEvent;
                break;

            case "AsyncAGIEvent":
                AsyncAGIEvent asyncagievent = e as AsyncAGIEvent;
                break;

            case "BridgeEvent":
                BridgeEvent bridgeevent = e as BridgeEvent;
                break;

            case "CdrEvent":
                CdrEvent cdrevent = e as CdrEvent;
                break;

            case "ChannelReloadEvent":
                ChannelReloadEvent channelreload = e as ChannelReloadEvent;
                break;

            case "ChannelUpdateEvent":
                ChannelUpdateEvent channelupdate = e as ChannelUpdateEvent;
                break;

            case "ConnectEvent":
                ConnectEvent connectevent = e as ConnectEvent;
                break;

            case "ConnectionStateEvent":
                ConnectionStateEvent connectionstate = e as ConnectionStateEvent;
                break;

            case "DBGetResponseEvent":
                DBGetResponseEvent dbget = e as DBGetResponseEvent;
                log.Debug("DBGet response: " + dbget.ToString());
                switch (dbget.Family)
                {
                case "DND":
                    ss.SetLineControl(setLineControlDND(dbget.Key, true));
                    break;

                case "CF":
                    ss.SetLineControl(setLineControlForward(dbget.Key, dbget.Val));
                    break;
                }
                break;

            case "DialEvent":
                DialEvent dial = e as DialEvent;
                log.Debug("Dial event: " + dial.ToString());
                break;

            case "DisconnectEvent":
                DisconnectEvent disconnect = e as DisconnectEvent;
                log.Debug("Disconnect event: " + disconnect.ToString());
                break;

            case "DNDStateEvent":
                DNDStateEvent dndstate = e as DNDStateEvent;
                log.Debug("DND state event: " + dndstate.ToString());
                break;

            case "ExtensionStatusEvent":
                ExtensionStatusEvent extensionstatus = e as ExtensionStatusEvent;
                log.Debug("Extension status event: " + extensionstatus.ToString() + ", status: " + extensionstatus.Status + ", hint: " + extensionstatus.Hint);
                ss.SetLineControl(getLineControlFromExtensionStatusEvent(extensionstatus));
                break;

            case "FaxReceivedEvent":
                FaxReceivedEvent faxreceived = e as FaxReceivedEvent;
                break;

            case "HangupEvent":
                HangupEvent hangup = e as HangupEvent;
                log.Debug("Hangup event: " + hangup.ToString() + " callerid: " + hangup.CallerId + " calleridnum: " + hangup.CallerIdNum);
                //line control
                if (channels.Contains(hangup.Channel))
                {
                    lc = getLineControl((string)channels[hangup.Channel]);
                    int hi = 0;
                    LineControlConnection[] newLCC = null;
                    if (lc.lineControlConnection.Length > 1)
                    {
                        newLCC = new LineControlConnection[lc.lineControlConnection.Length - 1];
                        foreach (LineControlConnection hlcc in lc.lineControlConnection)
                        {
                            if (hlcc.callid != hangup.Channel)
                            {
                                newLCC[hi] = hlcc;
                                hi++;
                            }
                        }
                    }
                    lc.lineControlConnection = newLCC;
                    ss.SetLineControl(lc);
                    channels.Remove(hangup.Channel);
                }

                //missed calls
                callToFind = hangup.UniqueId.Substring(0, 6) + "," + hangup.UniqueId.Substring(6);
                Call mCall = missedCalls.Find(FindCall);
                if (mCall != null)
                {
                    log.Debug("Missed call finded for callid: " + hangup.UniqueId);
                    AddCallLogs(mCall.callee, mCall);
                    if (missedCalls.Remove(mCall))
                    {
                        log.Debug("Call " + mCall.callId + " successfully removed from missedcall cache");
                    }
                    else
                    {
                        log.Debug("Call " + mCall.callId + " cannot be removed from missedcall cache");
                    }
                }
                break;

            case "HoldedCallEvent":
                HoldedCallEvent holdedcall = e as HoldedCallEvent;
                break;

            case "HoldEvent":
                HoldEvent holdevent = e as HoldEvent;
                break;

            case "JabberEvent":
                JabberEvent jabberevent = e as JabberEvent;
                break;

            case "JitterBufStatsEvent":
                JitterBufStatsEvent jitter = e as JitterBufStatsEvent;
                break;

            case "JoinEvent":
                JoinEvent join = e as JoinEvent;
                break;

            case "LeaveEvent":
                LeaveEvent leave = e as LeaveEvent;
                break;

            case "LinkEvent":
                LinkEvent link = e as LinkEvent;
                log.Debug("Link event: " + link.ToString());
                lc = getLineControl(link.CallerId1);
                if (lc != null)
                {
                    foreach (LineControlConnection linklcc in lc.lineControlConnection)
                    {
                        if (linklcc.callid == link.Channel1)
                        {
                            linklcc.contact = link.CallerId2;
                            ss.SetLineControl(lc);
                            break;
                        }
                    }
                }
                lc = getLineControl(link.CallerId2);
                if (lc != null)
                {
                    foreach (LineControlConnection linklcc in lc.lineControlConnection)
                    {
                        if (linklcc.callid == link.Channel2)
                        {
                            linklcc.contact = link.CallerId1;
                            ss.SetLineControl(lc);
                            break;
                        }
                    }
                }
                break;

            case "LogChannelEvent":
                LogChannelEvent logchannel = e as LogChannelEvent;
                break;

            case "ManagerEvent":
                ManagerEvent managerevent = e;
                break;

            case "MeetmeEndEvent":
                MeetmeEndEvent meetmeend = e as MeetmeEndEvent;
                break;

            case "MeetmeJoinEvent":
                MeetmeJoinEvent meetmejoin = e as MeetmeJoinEvent;
                break;

            case "MeetmeLeaveEvent":
                MeetmeLeaveEvent meetmeleave = e as MeetmeLeaveEvent;
                break;

            case "MeetmeMuteEvent":
                MeetmeMuteEvent meetmemute = e as MeetmeMuteEvent;
                break;

            case "MeetmeStopTalkingEvent":
                MeetmeStopTalkingEvent meetmestoptalking = e as MeetmeStopTalkingEvent;
                break;

            case "MeetmeTalkingEvent":
                MeetmeTalkingEvent meetmetalking = e as MeetmeTalkingEvent;
                break;

            case "MeetmeTalkRequestEvent":
                MeetmeTalkRequestEvent meetmetalkrequest = e as MeetmeTalkRequestEvent;
                break;

            case "MessageWaitingEvent":
                MessageWaitingEvent messagewaiting = e as MessageWaitingEvent;
                log.Debug("Message waiting event: " + messagewaiting.ToString());
                lc = getLineControl(messagewaiting.Mailbox.Substring(0, messagewaiting.Mailbox.IndexOf("@")));
                if (lc != null)
                {
                    if (messagewaiting.Waiting > 0)
                    {
                        lc.mwiOn = true;
                    }
                    else
                    {
                        lc.mwiOn = false;
                    }
                    ss.SetLineControl(lc);
                }
                break;

            case "MobileStatusEvent":
                MobileStatusEvent mobilestatus = e as MobileStatusEvent;
                break;

            case "ModuleLoadReportEvent":
                ModuleLoadReportEvent moduleload = e as ModuleLoadReportEvent;
                break;

            case "MonitorStartEvent":
                MonitorStartEvent monitorstart = e as MonitorStartEvent;
                break;

            case "MonitorStopEvent":
                MonitorStopEvent monitorstop = e as MonitorStopEvent;
                break;

            case "NewAccountCodeEvent":
                NewAccountCodeEvent newaccountcode = e as NewAccountCodeEvent;
                break;

            case "NewCallerIdEvent":
                NewCallerIdEvent newcallerid = e as NewCallerIdEvent;
                log.Debug("New caller id envent: " + newcallerid.ToString());
                break;

            case "NewChannelEvent":
                NewChannelEvent newchannel = e as NewChannelEvent;
                log.Debug("New Channel event: " + newchannel.ToString());
                CommandAction   ca = new CommandAction("core show channel " + newchannel.Channel);
                CommandResponse cr = (CommandResponse)manager.SendAction(ca, 10000);
                log.Debug("Channel info: " + cr.ToString());
                string dn = newchannel.CallerIdNum;
                log.Debug("Retreive call information...");
                bool callerIdUnknown = true;
                if (newchannel.CallerIdNum != "<unknown>")
                {
                    callerIdUnknown = false;
                }
                else
                {
                    foreach (string s in cr.Result)
                    {
                        if (s.Contains("Caller ID:"))
                        {
                            dn = s.Substring(s.LastIndexOf(" "));
                            break;
                        }
                    }
                }
                Call newOutboundCall = getOutboundCallFromChannelInfo(cr.Result, callerIdUnknown);
                if (newOutboundCall != null)
                {
                    Call missedCall = newOutboundCall;
                    AddCallLogs(dn, newOutboundCall);
                    dnToFind = newOutboundCall.callee;
                    if (linecontrols.Find(FindLineControl) != null)
                    {
                        log.Debug("This call will be put in missedcall cache: " + missedCall.callId);
                        missedCall.type = CallType.missed;
                        missedCalls.Add(missedCall);
                    }
                }
                break;

            case "NewExtenEvent":
                NewExtenEvent newexten = e as NewExtenEvent;
                log.Debug("New exten event: " + newexten.ToString());
                string   channel      = "";
                char[]   splitter     = { '/' };
                string[] splitchannel = newexten.Channel.Split(splitter);
                splitter[0]  = '-';
                splitchannel = splitchannel[1].Split(splitter);
                channel      = splitchannel[0];
                //DND?
                if (newexten.Extension == Properties.Settings.Default.FeatureCodeDNDToggle && newexten.Application == "Playback")
                {
                    switch (newexten.AppData)
                    {
                    case "do-not-disturb&activated":
                        log.Debug("Successfully activate dnd for channel: " + channel);
                        ss.SetLineControl(setLineControlDND(channel, true));
                        break;

                    case "do-not-disturb&de-activated":
                        log.Debug("Successfully deactivate dnd for channel: " + channel);
                        ss.SetLineControl(setLineControlDND(channel, false));
                        break;
                    }
                }
                //Forward all?
                else if (newexten.Extension.Contains(Properties.Settings.Default.FeatureCodeCallForwardAllActivate) && newexten.Application == "Playback" && newexten.AppData == "call-fwd-unconditional&for&extension")
                {
                    string forward = newexten.Extension.Substring(Properties.Settings.Default.FeatureCodeCallForwardAllActivate.Length);
                    log.Debug("Call forward all from channel: " + channel + " to " + forward);
                    ss.SetLineControl(setLineControlForward(channel, forward));
                }
                // UnForwardAll
                else if (newexten.Extension == Properties.Settings.Default.FeatureCodeCallForwardAllDeactivate && newexten.Application == "Playback" && newexten.AppData == "call-fwd-unconditional&de-activated")
                {
                    log.Debug("Call unforward all from channel: " + channel);
                    ss.SetLineControl(setLineControlForward(channel, ""));
                }
                break;

            case "NewStateEvent":
                NewStateEvent newstate = e as NewStateEvent;
                log.Debug("New State event: " + newstate.ToString());
                LineControl             newstateLc   = getLineControl(newstate.CallerId);
                LineControlConnection[] newStateLccs = null;
                int i = 0;
                if (newstateLc.lineControlConnection != null)
                {
                    bool isContained = false;
                    foreach (LineControlConnection elcc in newstateLc.lineControlConnection)
                    {
                        if (elcc.callid == newstate.Channel)
                        {
                            isContained  = true;
                            newStateLccs = newstateLc.lineControlConnection;
                            break;
                        }
                        i++;
                    }
                    if (!isContained)
                    {
                        i            = 0;
                        newStateLccs = new LineControlConnection[newstateLc.lineControlConnection.Length + 1];
                        foreach (LineControlConnection newstateLcc in newstateLc.lineControlConnection)
                        {
                            newStateLccs[i] = newstateLcc;
                            i++;
                        }
                    }
                }
                else
                {
                    newStateLccs    = new LineControlConnection[1];
                    newStateLccs[0] = new LineControlConnection();
                }
                try
                {
                    switch (newstate.State)
                    {
                    case "Up":
                        //received call?
                        callToFind = newstate.UniqueId;
                        Call rCall = missedCalls.Find(FindCall);
                        if (rCall != null)
                        {
                            log.Debug("Missed call finded: " + callToFind + ", this call will be received");
                            rCall.type = CallType.received;
                            AddCallLogs(rCall.callee, rCall);
                            missedCalls.Remove(rCall);
                        }
                        if (newStateLccs != null)
                        {
                            if (!channels.Contains(newstate.Channel))
                            {
                                channels.Add(newstate.Channel, newstate.CallerId);
                            }
                            newStateLccs[i].callid        = newstate.Channel;
                            newStateLccs[i].remoteState   = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                            newStateLccs[i].state         = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                            newStateLccs[i].terminalState = TerminalState.talking;
                        }
                        break;

                    case "Ringing":
                        if (newStateLccs != null)
                        {
                            if (!channels.Contains(newstate.Channel))
                            {
                                channels.Add(newstate.Channel, newstate.CallerId);
                            }
                            newStateLccs[i].callid        = newstate.Channel;
                            newStateLccs[i].remoteState   = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.established;
                            newStateLccs[i].state         = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.alerting;
                            newStateLccs[i].terminalState = TerminalState.ringing;
                        }
                        break;

                    case "Ring":
                        if (newStateLccs != null)
                        {
                            if (!channels.Contains(newstate.Channel))
                            {
                                channels.Add(newstate.Channel, newstate.CallerId);
                            }
                            newStateLccs[i].callid        = newstate.Channel;
                            newStateLccs[i].remoteState   = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.alerting;
                            newStateLccs[i].state         = Wybecom.TalkPortal.CTI.Proxy.ConnectionState.dialing;
                            newStateLccs[i].terminalState = TerminalState.inuse;
                        }
                        break;
                    }
                }
                catch (Exception stateException)
                {
                    log.Debug("NewState exception: " + stateException.Message);
                }
                if (newstateLc != null)
                {
                    newstateLc.lineControlConnection = newStateLccs;
                    ss.SetLineControl(newstateLc);
                }
                break;

            case "OriginateResponseEvent":
                OriginateResponseEvent originateresponse = e as OriginateResponseEvent;
                break;

            case "ParkedCallEvent":
                ParkedCallEvent parkedcall = e as ParkedCallEvent;
                break;

            case "ParkedCallGiveUpEvent":
                ParkedCallGiveUpEvent parkedcallgiveup = e as ParkedCallGiveUpEvent;
                break;

            case "ParkedCallsCompleteEvent":
                ParkedCallsCompleteEvent parkedcallscomplete = e as ParkedCallsCompleteEvent;
                break;

            case "ParkedCallTimeOutEvent":
                ParkedCallTimeOutEvent parkedcalltimeout = e as ParkedCallTimeOutEvent;
                break;

            case "PeerEntryEvent":
                log.Debug("SipAction: one peer entry event received, " + e.ToString());
                PeerEntryEvent peerentry = e as PeerEntryEvent;
                peers.Add(peerentry);
                ss.SetLineControl(getLineControlFromPeerEntry(peerentry));
                break;

            case "PeerlistCompleteEvent":
                log.Debug("SipAction: peer list completed " + e.ToString());
                PeerlistCompleteEvent peerlistcomplete = e as PeerlistCompleteEvent;
                acs.setPeers(peers);
                break;

            case "PeerStatusEvent":
                PeerStatusEvent peerstatus = e as PeerStatusEvent;
                log.Debug("Peer status: " + peerstatus.ToString());
                break;

            case "PRIEvent":
                PRIEvent pri = e as PRIEvent;
                break;

            case "RegistryEvent":
                RegistryEvent registry = e as RegistryEvent;
                break;

            case "ReloadEvent":
                ReloadEvent reload = e as ReloadEvent;
                break;

            case "RenameEvent":
                RenameEvent rename = e as RenameEvent;
                break;

            case "ResponseEvent":
                ResponseEvent response = e as ResponseEvent;
                break;

            case "RTCPReceivedEvent":
                RTCPReceivedEvent rtcpreceived = e as RTCPReceivedEvent;
                break;

            case "RTCPSentEvent":
                RTCPSentEvent rtcpsent = e as RTCPSentEvent;
                break;

            case "RTPReceiverStatEvent":
                RTPReceiverStatEvent rtpreceiver = e as RTPReceiverStatEvent;
                break;

            case "RTPSenderStatEvent":
                RTPSenderStatEvent rtpsender = e as RTPSenderStatEvent;
                break;

            case "ShowDialPlanCompleteEvent":
                ShowDialPlanCompleteEvent showdialplan = e as ShowDialPlanCompleteEvent;
                break;

            case "ShutdownEvent":
                ShutdownEvent shutdown = e as ShutdownEvent;
                break;

            case "StatusCompleteEvent":
                StatusCompleteEvent statuscomplete = e as StatusCompleteEvent;
                break;

            case "StatusEvent":
                StatusEvent status = e as StatusEvent;
                break;

            case "TransferEvent":
                TransferEvent transfer = e as TransferEvent;
                break;

            case "UnholdEvent":
                UnholdEvent unhold = e as UnholdEvent;
                break;

            case "UnknownEvent":
                UnknownEvent unknown = e as UnknownEvent;
                break;

            case "UnlinkEvent":
                UnlinkEvent unlink = e as UnlinkEvent;
                log.Debug("Unlink event : " + unlink.ToString());
                LineControlConnection[] lccs = null;
                i  = 0;
                lc = getLineControl(unlink.CallerId1);
                if (lc != null)
                {
                    if (lc.lineControlConnection.Length > 1)
                    {
                        lccs = new LineControlConnection[lc.lineControlConnection.Length - 1];
                        foreach (LineControlConnection linklcc in lc.lineControlConnection)
                        {
                            if (linklcc.callid != unlink.Channel1)
                            {
                                lccs[i] = linklcc;
                                i++;
                                break;
                            }
                        }
                    }
                    else
                    {
                        lc.lineControlConnection = null;
                    }
                    ss.SetLineControl(lc);
                }
                i  = 0;
                lc = getLineControl(unlink.CallerId2);
                if (lc != null)
                {
                    if (lc.lineControlConnection.Length > 1)
                    {
                        lccs = new LineControlConnection[lc.lineControlConnection.Length - 1];
                        foreach (LineControlConnection linklcc in lc.lineControlConnection)
                        {
                            if (linklcc.callid != unlink.Channel2)
                            {
                                lccs[i] = linklcc;
                                i++;
                                break;
                            }
                        }
                    }
                    else
                    {
                        lc.lineControlConnection = null;
                    }
                    ss.SetLineControl(lc);
                }
                break;

            case "UnparkedCallEvent":
                UnparkedCallEvent unparked = e as UnparkedCallEvent;
                break;

            case "UserEvent":
                UserEvent user = e as UserEvent;
                break;

            case "VarSetEvent":
                VarSetEvent varset = e as VarSetEvent;
                break;

            case "ZapShowChannelsCompleteEvent":
                ZapShowChannelsCompleteEvent zapshowchannelscomplete = e as ZapShowChannelsCompleteEvent;
                break;

            case "ZapShowChannelsEvent":
                ZapShowChannelsEvent zapshowchannels = e as ZapShowChannelsEvent;
                break;
            }
            //ACDConnector
            switch (e.GetType().Name)
            {
            case "AgentCallbackLoginEvent":
                AgentCallbackLoginEvent agentcallbacklogin = e as AgentCallbackLoginEvent;
                break;

            case "AgentCallbackLogoffEvent":
                AgentCallbackLogoffEvent agentcallbacklogoff = e as AgentCallbackLogoffEvent;
                break;

            case "AgentCalledEvent":
                AgentCalledEvent agentcalled = e as AgentCalledEvent;
                break;

            case "AgentCompleteEvent":
                AgentCompleteEvent agentcomplete = e as AgentCompleteEvent;
                break;

            case "AgentConnectEvent":
                AgentConnectEvent agentconnect = e as AgentConnectEvent;
                break;

            case "AgentDumpEvent":
                AgentDumpEvent agentdump = e as AgentDumpEvent;
                break;

            case "AgentLoginEvent":
                AgentLoginEvent agentlogin = e as AgentLoginEvent;
                break;

            case "AgentLogoffEvent":
                AgentLogoffEvent agentlogoff = e as AgentLogoffEvent;
                break;

            case "AgentsCompleteEvent":
                AgentsCompleteEvent agentscomplete = e as AgentsCompleteEvent;
                break;

            case "AgentsEvent":
                AgentsEvent agentevent = e as AgentsEvent;
                break;

            case "QueueCallerAbandonEvent":
                QueueCallerAbandonEvent queuecallerabandon = e as QueueCallerAbandonEvent;
                break;

            case "QueueEntryEvent":
                QueueEntryEvent queueentry = e as QueueEntryEvent;
                break;

            case "QueueEvent":
                QueueEvent queue = e as QueueEvent;
                break;

            case "QueueMemberEvent":
                QueueMemberEvent queuemember = e as QueueMemberEvent;
                break;

            case "QueueMemberPausedEvent":
                QueueMemberPausedEvent queuememberpaused = e as QueueMemberPausedEvent;
                break;

            case "QueueMemberPenaltyEvent":
                QueueMemberPenaltyEvent queuememberpenalty = e as QueueMemberPenaltyEvent;
                break;

            case "QueueMemberRemovedEvent":
                QueueMemberRemovedEvent queuememberremoved = e as QueueMemberRemovedEvent;
                break;

            case "QueueMemberStatusEvent":
                QueueMemberStatusEvent queuememberstatus = e as QueueMemberStatusEvent;
                break;

            case "QueueParamsEvent":
                QueueParamsEvent queueparams = e as QueueParamsEvent;
                break;

            case "QueueStatusCompleteEvent":
                QueueStatusCompleteEvent queuestatuscomplete = e as QueueStatusCompleteEvent;
                break;
            }
        }
Пример #4
0
        public async Task <ActionResult <bool> > Checkout(string customerId, [FromBody] RegistrationViewModel input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CustomerBasket basket;

            try
            {
                basket = await _repository.GetBasketAsync(customerId);
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }

            var items = basket.Items.Select(i =>
                                            new CheckoutEventItem(i.Id, i.ProductId, i.ProductName, i.UnitPrice, i.Quantity)).ToList();

            var checkoutEvent
                = new CheckoutEvent
                      (customerId, input.Name, input.Email, input.Phone
                      , input.Address, input.AdditionalAddress, input.District
                      , input.City, input.State, input.ZipCode
                      , Guid.NewGuid()
                      , items);


            //Once we complete it, it sends an integration event to API Ordering
            //to convert the basket to order and continue with the order
            //creation process
            await _bus.Publish(checkoutEvent);

            _logger.LogInformation(eventId: EventId_Checkout, message: "Check out event has been dispatched: {CheckoutEvent}", args: checkoutEvent);

            var registryEvent
                = new RegistryEvent
                      (customerId, input.Name, input.Email, input.Phone
                      , input.Address, input.AdditionalAddress, input.District
                      , input.City, input.State, input.ZipCode);

            await _bus.Publish(registryEvent);

            _logger.LogInformation(eventId: EventId_Registry, message: "Registry event has been dispatched: {RegistryEvent}", args: registryEvent);

            try
            {
                await _repository.DeleteBasketAsync(customerId);

                await this._connection
                .InvokeAsync("UpdateUserBasketCount", $"{customerId}", 0);

                return(Accepted(true));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw;
            }
        }
Пример #5
0
 static void RegistryUtility(ConcurrentQueue <RegistryEvent> regQueue, RegistryEvent reg)
 {
     regQueue.Enqueue(reg);
 }
Пример #6
0
        static int Main(string[] args)
        {
            Console.Title = "SysManager";
            //using (var sw = new StreamWriter(@"E:\EventLogInCS\PropertyInfo.txt"))
            //{
            //    sw.Write(FillPropertyInfo(new NetworkEvent()));
            //}
            //Environment.Exit(0);
            GetRuleConfig();
            ProcessEvent  proEvent  = new ProcessEvent();
            RegistryEvent regEvent  = new RegistryEvent();
            NetworkEvent  netEvent  = new NetworkEvent();
            FileEvent     fileEvent = new FileEvent();

            Console.WriteLine("Please Choose One Operation To Manage Your System:");
            int opi;

            while (true)
            {
                Console.WriteLine("For Process Enter 1");
                Console.WriteLine("For Reistry Enter 2");
                Console.WriteLine("For Network Enter 3");
                Console.WriteLine("For File Enter 4");


                Console.Write("Enter Your Choice:");
                var op = Console.ReadLine();

                if (int.TryParse(op, out opi))
                {
                    if (opi < 5 && opi > 0)
                    {
                        gec.Operation            = opi;
                        PipLineManager.operation = opi;
                        break;
                    }
                }
                Console.WriteLine(">>>>>>>>>>  Please Enter A Right One!  <<<<<<<<<<<");
            }
            Console.Clear();
            Thread th = new Thread(FireForm);

            th.SetApartmentState(ApartmentState.STA);
            th.Start();

            var  pipe = PipLineManager.FileAccessCount;
            var  processUseNetWork = PipLineManager.ProcessUseNetwork;
            var  processDic        = PipLineManager.ProcessDictionary;
            var  NetUsage          = PipLineManager.NetworkUsage;
            var  netu       = PipLineManager.netU;
            var  regDic     = PipLineManager.RegistryUsage;
            var  fileEvents = PipLineManager.FileEvents;
            uint pid        = 0;

            Action saveLogAction = null;

            saveLogAction = async() =>
            {
                var conqueEvents = gec.ConqueEvent;
                if (conqueEvents.Count > 0)
                {
                    string da;
                    while (conqueEvents.TryDequeue(out da))
                    {
                        var desxml = JsonConvert.DeserializeXmlNode(da);
                        #region Process

                        if (opi == 1)
                        {
                            int procid = desxml.DocumentElement.HasAttribute("ProcessID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("ProcessID"))
                                : -1;
                            proEvent.ProcessId = procid;
                            int pprocid;
                            if (int.TryParse(desxml.DocumentElement.GetAttribute(ProcessEventProperty.ParentProcessID),
                                             out pprocid))
                            {
                                var imagename = desxml.DocumentElement.HasAttribute("ImageName")
                                    ? desxml.DocumentElement.GetAttribute("ImageName")
                                    : "";
                                proEvent.ProcessImage = imagename;
                                await Task.Run(() => { GetProcessInfo(proEvent, proEvent.ProcessId, pprocid, EventName.Process, imagename, proEvent.ProcessId.ToString()); });
                            }
                            else
                            {
                                await Task.Run(() => { GetProcessInfo(proEvent, procid, null, EventName.Process, null); });
                            }

                            proEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            proEvent.StartAddress = desxml.DocumentElement.HasAttribute("StartAddress")
                                ? desxml.DocumentElement.GetAttribute("StartAddress")
                                : "";
                            proEvent.Win32StartAddress = desxml.DocumentElement.HasAttribute("Win32StartAddress")
                                ? desxml.DocumentElement.GetAttribute("Win32StartAddress")
                                : "";
                            proEvent.CycleTime = desxml.DocumentElement.HasAttribute("CycleTime")
                                ? long.Parse(desxml.DocumentElement.GetAttribute("CycleTime"))
                                : -1;
                            proEvent.FormattedMessage = desxml.DocumentElement.HasAttribute("FormattedMessage")
                                ? desxml.DocumentElement.GetAttribute("FormattedMessage")
                                : "";
                            proEvent.CreateTime = desxml.DocumentElement.HasAttribute("CreateTime")
                                ? desxml.DocumentElement.GetAttribute("CreateTime")
                                : "";
                            proEvent.TaskName = desxml.DocumentElement.HasAttribute("TaskName")
                                ? desxml.DocumentElement.GetAttribute("TaskName")
                                : "";
                            proEvent.SessionId = desxml.DocumentElement.HasAttribute("SessionId")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("SessionId"))
                                : -1;
                            proEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            proEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            if (proEvent.EventName == "ProcessStop/Stop")
                            {
                                proEvent.ExitTime = desxml.DocumentElement.HasAttribute("Time")
                                    ? desxml.DocumentElement.GetAttribute("Time")
                                    : "";
                                proEvent.ExitCode = desxml.DocumentElement.HasAttribute("ExitCode")
                                    ? int.Parse(desxml.DocumentElement.GetAttribute("ExitCode"))
                                    : -1;
                                //string mgs;
                                //processDic.TryRemove(proEvent.ProcessName, out mgs);
                            }
                            else
                            {
                                processDic.AddOrUpdate(proEvent.ProcessName ?? "--", proEvent.ProcessHistory,
                                                       (key, value) => proEvent.ProcessHistory);
                            }
                        }
                        #endregion
                        #region Registry

                        else if (opi == 2)
                        {
                            regEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PID"))
                                : -1;
                            await Task.Run(() => { GetProcessInfo(regEvent, regEvent.ProcessId, null, EventName.Registry, null); });

                            regEvent.BaseName = desxml.DocumentElement.HasAttribute("BaseName")
                                ? desxml.DocumentElement.GetAttribute("BaseName")
                                : "";
                            regEvent.BaseObject = desxml.DocumentElement.HasAttribute("BaseObject")
                                ? desxml.DocumentElement.GetAttribute("BaseObject")
                                : "";
                            regEvent.CapturedData = desxml.DocumentElement.HasAttribute("CapturedData")
                                ? desxml.DocumentElement.GetAttribute("CapturedData")
                                : "";
                            regEvent.CapturedDataSize = desxml.DocumentElement.HasAttribute("CapturedDataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("CapturedDataSize"))
                                : -1;
                            regEvent.DataSize = desxml.DocumentElement.HasAttribute("DataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("DataSize"))
                                : -1;
                            regEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            regEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            regEvent.Disposition = desxml.DocumentElement.HasAttribute("Disposition")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("Disposition"))
                                : -1;
                            regEvent.KeyName = desxml.DocumentElement.HasAttribute("KeyName")
                                ? desxml.DocumentElement.GetAttribute("KeyName")
                                : "";
                            regEvent.KeyObject = desxml.DocumentElement.HasAttribute("KeyObject")
                                ? desxml.DocumentElement.GetAttribute("KeyObject")
                                : "";
                            regEvent.PreviousData = desxml.DocumentElement.HasAttribute("PreviousData")
                                ? desxml.DocumentElement.GetAttribute("PreviousData")
                                : "";
                            regEvent.PreviousDataCapturedSize =
                                desxml.DocumentElement.HasAttribute("PreviousDataCapturedSize")
                                    ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataCapturedSize"))
                                    : -1;
                            regEvent.PreviousDataSize = desxml.DocumentElement.HasAttribute("PreviousDataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataSize"))
                                : -1;
                            regEvent.PreviousDataType = desxml.DocumentElement.HasAttribute("PreviousDataType")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataType"))
                                : -1;
                            regEvent.RelativeName = desxml.DocumentElement.HasAttribute("RelativeName")
                                ? desxml.DocumentElement.GetAttribute("RelativeName")
                                : "";
                            regEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            regEvent.Type = desxml.DocumentElement.HasAttribute("Type")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("Type"))
                                : -1;
                            regEvent.ValueName = desxml.DocumentElement.HasAttribute("ValueName")
                                ? desxml.DocumentElement.GetAttribute("ValueName")
                                : "";
                            //sw.WriteLine(regEvent.ProviderName + regEvent.EventName + regEvent.ProcessHistory);
                            RegistryUtility(regDic, regEvent);
                        }
                        #endregion
                        #region Network
                        else if (opi == 3)
                        {
                            netEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID") ? int.Parse(desxml.DocumentElement.GetAttribute("PID")) : -1;
                            netEvent.ProcessId = desxml.DocumentElement.HasAttribute("PIDD") ? int.Parse(desxml.DocumentElement.GetAttribute("PIDD")) : -1;
                            await Task.Run(() => { GetProcessInfo(netEvent, netEvent.ProcessId, null, EventName.Network); });

                            netEvent.ProviderName       = desxml.DocumentElement.HasAttribute("ProviderName") ? desxml.DocumentElement.GetAttribute("ProviderName") : "";
                            netEvent.EventName          = desxml.DocumentElement.HasAttribute("EventName") ? desxml.DocumentElement.GetAttribute("EventName") : "";
                            netEvent.DestinationAddress = desxml.DocumentElement.HasAttribute("daddr") ? Utility.LongToIpAddress(desxml.DocumentElement.GetAttribute("daddr")) : "-1";
                            netEvent.SourceAddress      = desxml.DocumentElement.HasAttribute("saddr") ? Utility.LongToIpAddress(desxml.DocumentElement.GetAttribute("saddr")) : "-1";
                            netEvent.Dport    = desxml.DocumentElement.HasAttribute("dport") ? int.Parse(desxml.DocumentElement.GetAttribute("dpoort")) : -1;
                            netEvent.Sport    = desxml.DocumentElement.HasAttribute("sport") ? int.Parse(desxml.DocumentElement.GetAttribute("sport")) : -1;
                            netEvent.ConnId   = desxml.DocumentElement.HasAttribute("connid") ? int.Parse(desxml.DocumentElement.GetAttribute("connid")) : -1;
                            netEvent.SeqNum   = desxml.DocumentElement.HasAttribute("seqnum") ? int.Parse(desxml.DocumentElement.GetAttribute("seqnum")) : -1;
                            netEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID") ? int.Parse(desxml.DocumentElement.GetAttribute("TID")) : -1;
                            netEvent.Size     = desxml.DocumentElement.HasAttribute("size") ? int.Parse(desxml.DocumentElement.GetAttribute("size")) : 0;
                            //Task.Run(() => { NetworkUtility(netu, netEvent, processUseNetWork, netEvent.ProcessHistoryD, netEvent.SourceAddress, netEvent.DestinationAddress); });
                            NetUsage.Enqueue(netEvent);
                        }
                        #endregion
                        #region File
                        else
                        {
                            fileEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PID"))
                                : -1;
                            await Task.Run(() => { GetProcessInfo(fileEvent, fileEvent.ProcessId, null, EventName.File); });

                            fileEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            fileEvent.FileName = desxml.DocumentElement.HasAttribute("FileName")
                                ? desxml.DocumentElement.GetAttribute("FileName")
                                : "";
                            fileEvent.FilePath = desxml.DocumentElement.HasAttribute("FilePath")
                                ? desxml.DocumentElement.GetAttribute("FilePath")
                                : "";
                            fileEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            fileEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            fileEvent.Irp = desxml.DocumentElement.HasAttribute("Irp")
                                ? desxml.DocumentElement.GetAttribute("Irp")
                                : "";
                            fileEvent.FileObject = desxml.DocumentElement.HasAttribute("FileObject")
                                ? desxml.DocumentElement.GetAttribute("FileObject")
                                : "";

                            //fileEvent.IssuingThreadId = desxml.DocumentElement.HasAttribute("IssuingThreadId")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("IssuingThreadId"))
                            //    : -1;
                            //fileEvent.CreateOptions = desxml.DocumentElement.HasAttribute("CreateOptions")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("CreateOptions"))
                            //    : -1;
                            //fileEvent.CreateAttributes = desxml.DocumentElement.HasAttribute("CreateAttributes")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("CreateAttributes"))
                            //    : -1;
                            fileEvent.ShareAccess = desxml.DocumentElement.HasAttribute("ShareAccess")
                                ? desxml.DocumentElement.GetAttribute("ShareAccess")
                                : "";
                            fileEvent.FileKey = desxml.DocumentElement.HasAttribute("FileKey")
                                ? desxml.DocumentElement.GetAttribute("FileKey")
                                : "";
                            //long iit = Convert.ToInt64(fileEvent.FileKey, 16)*-1;

                            // var filena = Utility.GetFileNameFromHandle(new IntPtr(Convert.ToInt64(fileEvent.FileKey, 16)));
                            fileEvent.IOSize = desxml.DocumentElement.HasAttribute("IOSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("IOSize"))
                                : -1;
                            //fileEvent.IOFlags = desxml.DocumentElement.HasAttribute("IOFlags")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("IOFlags"))
                            //    : -1;
                            //fileEvent.ExtraFlags = desxml.DocumentElement.HasAttribute("ExtraFlags")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("ExtraFlags"))
                            //    : -1;
                            //fileEvent.ByteOffset = desxml.DocumentElement.HasAttribute("ByteOffset")
                            //    ? long.Parse(desxml.DocumentElement.GetAttribute("ByteOffset"))
                            //    : -1;
                            //fileEvent.ExtraInformation = desxml.DocumentElement.HasAttribute("ExtraInformation")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("ExtraInformation"))
                            //    : -1;
                            //fileEvent.Status = desxml.DocumentElement.HasAttribute("Status")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("Status"))
                            //    : -1;
                            //fileEvent.InfoClass = desxml.DocumentElement.HasAttribute("InfoClass")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("InfoClass"))
                            //    : -1;
                            Task.Run(() => { FileUtility(fileEvents, pipe, fileEvent); });
                        }

                        #endregion
                    }
                }
                try
                {
                    Thread.Sleep(500);
                    Parallel.Invoke(saveLogAction);
                }
                catch (Exception)
                {
                    Thread.Sleep(500);
                    saveLogAction.Invoke();
                }
            };
            Task t = new Task(() => { gec.FetchEvents(); });
            t.Start();
            saveLogAction.Invoke();
            Console.Read();
            return(0);
        }
Пример #7
0
 public PostReg(RegistryEvent e) : base(e)
 {
 }
Пример #8
0
 public PreReg(RegistryEvent e) : base(e)
 {
 }
Пример #9
0
        static void ProcessImport(Int64 resource, Dictionary <String, Object> connectorConf, Dictionary <String, String> mapping)
        {
            TextLog.Log("PluginStarter", "{" + plugin.GetPluginId().AbsoluteUri + "} Starting import thread...");

            try
            {
                if (connectorConf == null)
                {
                    throw new Exception("connectorConf is null");
                }

                if (mapping == null)
                {
                    throw new Exception("mapping is null");
                }

                String id = Guid.NewGuid().ToString();

                JsonGeneric records = new JsonGeneric();
                records.function = "ProcessImport";
                records.fields   = new String[] { "resource", "uri", "importid", "registryid", "dataname", "datavalue", "datatype" };

                String uri = plugin.GetPluginId().AbsoluteUri.ToLower();

                String lastRegistryId = "";

                RegistryEvent reg = new RegistryEvent(delegate(String importId, String registryId, String dataName, String dataValue, String dataType)
                {
                    records.data.Add(new String[] { resource.ToString(), uri, importId, registryId, dataName, dataValue, dataType });

                    //Contabiliza a quantidade de registros para separar em vários arquivos
                    if (records.data.Count >= 2000)
                    {
                        //Após 2000 registros monitora a troca de registryId para salvar o arquivo
                        //Evitando que o mesmo registryId tenha dados em arquivos diferentes
                        //Isso evita problemas no servidor

                        if (lastRegistryId != registryId)
                        {
                            try
                            {
                                SaveToSend(records, importId);
                                records.data.Clear();
                            }
                            catch { }
                        }
                    }

                    lastRegistryId = registryId;
                });

                LogEvent log = new LogEvent(delegate(PluginBase sender, PluginLogType type, string text)
                {
                    TextLog.Log("PluginStarter", "{" + sender.GetPluginId().AbsoluteUri + "} " + type + ", " + text);
                });


                LogEvent2 log2 = new LogEvent2(delegate(PluginBase sender, PluginLogType type, Int64 entityId, Int64 identityId, String text, String additionalData)
                {
                    logProxy.AddLog("Proxy", resource.ToString(), sender.GetPluginId().AbsoluteUri, (UserLogLevel)((Int32)type), entityId, identityId, text, additionalData);
                });


                plugin.Registry += reg;
                plugin.Log      += log;
                plugin.Log2     += log2;

                plugin.ProcessImport(id, connectorConf, mapping);

                plugin.Registry -= reg;
                plugin.Log      -= log;
                plugin.Log2     -= log2;

                reg = null;
                log = null;
                uri = null;

                //Salva os registros remanescentes
                if (records.data.Count > 0)
                {
                    SaveToSend(records, id);
                }

                //Salva os logs para envio
                logProxy.SaveToSend(resource.ToString() + "log");
            }
            finally
            {
                TextLog.Log("PluginStarter", "{" + plugin.GetPluginId().AbsoluteUri + "} Finishing import thread");
            }
        }