示例#1
0
        public void Add(TaskSessionsInfo taskSessions, TargetId targetId)
        {
            if (taskSessions.Sessions?.Count > 0)
            {
                foreach (var session in taskSessions.Sessions)
                {
                    AddSession(session);
                }
            }

            if (taskSessions.Executions?.Count > 0)
            {
                foreach (var execution in taskSessions.Executions)
                {
                    AddExecution(execution, targetId);
                }
            }

            if (taskSessions.Results?.Count > 0)
            {
                foreach (var commandResult in taskSessions.Results)
                {
                    AddCommandResult(commandResult);
                }
            }
        }
示例#2
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(LogTime.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.Append(": ");
            if (Operation != GroupMemberOperations.None)
            {
                sb.Append(Operation.ToString());
                sb.Append("ed ");
            }
            else
            {
                sb.Append("Did nothing to ");
            }
            sb.Append(TargetDisplayName ?? TargetId.ToString());
            if (Operation == GroupMemberOperations.Add)
            {
                sb.Append(" to ");
            }
            else if (Operation == GroupMemberOperations.Remove)
            {
                sb.Append(" from ");
            }
            else
            {
                sb.Append(" for ");
            }
            sb.Append(GroupDisplayName ?? GroupId.ToString());
            return(sb.ToString());
        }
示例#3
0
 public void MergeFrom(UserOptions other)
 {
     if (other == null)
     {
         return;
     }
     if (other.HasTargetId)
     {
         if (!HasTargetId)
         {
             TargetId = new global::Bgs.Protocol.Account.V1.AccountId();
         }
         TargetId.MergeFrom(other.TargetId);
     }
     if (other.HasType)
     {
         Type = other.Type;
     }
     if (other.HasSource)
     {
         Source = other.Source;
     }
     if (other.HasItem)
     {
         if (!HasItem)
         {
             Item = new global::Bgs.Protocol.Report.V2.ReportItem();
         }
         Item.MergeFrom(other.Item);
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
示例#4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasTargetId)
            {
                hash ^= TargetId.GetHashCode();
            }
            if (HasType)
            {
                hash ^= Type.GetHashCode();
            }
            if (HasSource)
            {
                hash ^= Source.GetHashCode();
            }
            if (HasItem)
            {
                hash ^= Item.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
示例#5
0
        private async Task ExecuteAttender(TargetId id, IServiceProvider services, CancellationToken cancellationToken)
        {
            var execution = new TaskExecutionDto
            {
                TaskExecutionId = Guid.NewGuid(),
                TaskSessionId   = _taskSession.TaskSessionId,
                TargetId        = id.IsServer ? (int?)null : id.ClientId,
                CreatedOn       = DateTimeOffset.UtcNow,
                TaskReferenceId = _mazeTask.Id
            };

            if (!await _taskResultStorage.CreateTaskExecution(execution))
            {
                return;
            }

            await _hubContext.Clients.All.SendAsync(HubEventNames.TaskExecutionCreated, execution, cancellationToken);

            var machineStatus = _activeTasksManager.ActiveCommands.GetOrAdd(id, _ => new TasksMachineStatus());

            foreach (var commandInfo in _mazeTask.Commands)
            {
                await ExecuteCommand(id, services, commandInfo, machineStatus, execution.TaskExecutionId, cancellationToken);
            }
        }
示例#6
0
            protected override Stream openStream()
            {
                try
                {
                    String         url  = wire.url + "?serverId=" + TargetId.getServerId() + "&messageid=" + TargetId.getMessageId() + "&streamid=" + TargetId.getStreamId();
                    HttpWebRequest conn = (HttpWebRequest)HttpWebRequest.Create(url);
                    request = wire.createRequestForGetStream(TargetId, this);
                    request.setConnection(conn);

                    conn.Method = "GET";
                    wire.applySession(conn);

                    response           = (HttpWebResponse)conn.GetResponse();
                    ContentType        = response.ContentType;
                    ContentLength      = response.ContentLength;
                    ContentDisposition = response.Headers["Content-Disposition"];

                    responseStream = response.GetResponseStream();
                }
                catch (Exception ex)
                {
                    BException bex = new BException(BExceptionC.IOERROR, "", ex);
                    setAsyncResult(null, bex);
                    wire.removeRequest(request, null, bex);
                }

                throwExceptionIf();

                return(responseStream);
            }
示例#7
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (CanonicalName != null ? CanonicalName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TargetId != null ? TargetId.GetHashCode() : 0);
         return(hashCode);
     }
 }
示例#8
0
        /// <summary>
        /// Generates the relationship string for the relationship object.
        /// </summary>
        /// <returns>The Cypher string representing the relationship object</returns>
        public string GetCypherRelationshipString()
        {
            SourceId = SourceId.Split(':')[1];
            TargetId = TargetId.Split(':')[1];

            string rolesPropertyString = "{roles:" + CypherQueryUtils.GetCypherStringArray(Roles) + "}";

            return($"({SourceId})-[:{CypherQueryUtils.GetCypherRelationshipType(Type)} {rolesPropertyString}]-({TargetId})");
        }
示例#9
0
        public int CompareTo(TargetPrivilegePair other)
        {
            var res = TargetId.CompareTo(other.TargetId);

            if (res == 0)
            {
                res = PrivilegeId.CompareTo(other.PrivilegeId);
            }
            return(res);
        }
示例#10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasSenderId)
            {
                hash ^= SenderId.GetHashCode();
            }
            if (HasTargetId)
            {
                hash ^= TargetId.GetHashCode();
            }
            if (HasType)
            {
                hash ^= Type.GetHashCode();
            }
            hash ^= attribute_.GetHashCode();
            if (HasSenderAccountId)
            {
                hash ^= SenderAccountId.GetHashCode();
            }
            if (HasTargetAccountId)
            {
                hash ^= TargetAccountId.GetHashCode();
            }
            if (HasSenderBattleTag)
            {
                hash ^= SenderBattleTag.GetHashCode();
            }
            if (HasTargetBattleTag)
            {
                hash ^= TargetBattleTag.GetHashCode();
            }
            if (HasPeer)
            {
                hash ^= Peer.GetHashCode();
            }
            if (HasForwardingIdentity)
            {
                hash ^= ForwardingIdentity.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
示例#11
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (from_ != null)
            {
                hash ^= From.GetHashCode();
            }
            if (TargetId.Length != 0)
            {
                hash ^= TargetId.GetHashCode();
            }
            if (Timestamp != 0L)
            {
                hash ^= Timestamp.GetHashCode();
            }
            return(hash);
        }
示例#12
0
        private void AddExecution(TaskExecutionDto taskExecutionDto, TargetId targetId)
        {
            if (taskExecutionDto.Validate(new ValidationContext(taskExecutionDto)).Any())
            {
                return;
            }

            if (taskExecutionDto.TaskReferenceId != _taskId)
            {
                return;
            }

            taskExecutionDto.TargetId = targetId.IsServer ? (int?)null : targetId.ClientId;

            if (_executions.TryAdd(taskExecutionDto.TaskExecutionId, taskExecutionDto))
            {
                TaskExecutionAdded?.Invoke(this, taskExecutionDto);
            }
        }
示例#13
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasTargetId)
            {
                hash ^= TargetId.GetHashCode();
            }
            hash ^= attribute_.GetHashCode();
            if (HasReason)
            {
                hash ^= Reason.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (senderId_ != null)
            {
                hash ^= SenderId.GetHashCode();
            }
            if (targetId_ != null)
            {
                hash ^= TargetId.GetHashCode();
            }
            if (Type.Length != 0)
            {
                hash ^= Type.GetHashCode();
            }
            hash ^= attribute_.GetHashCode();
            if (senderAccountId_ != null)
            {
                hash ^= SenderAccountId.GetHashCode();
            }
            if (targetAccountId_ != null)
            {
                hash ^= TargetAccountId.GetHashCode();
            }
            if (SenderBattleTag.Length != 0)
            {
                hash ^= SenderBattleTag.GetHashCode();
            }
            if (TargetBattleTag.Length != 0)
            {
                hash ^= TargetBattleTag.GetHashCode();
            }
            if (peer_ != null)
            {
                hash ^= Peer.GetHashCode();
            }
            if (forwardingIdentity_ != null)
            {
                hash ^= ForwardingIdentity.GetHashCode();
            }
            return(hash);
        }
示例#15
0
 public void MergeFrom(AddBanOptions other)
 {
     if (other == null)
     {
         return;
     }
     if (other.HasTargetId)
     {
         if (!HasTargetId)
         {
             TargetId = new global::Bgs.Protocol.Club.V1.MemberId();
         }
         TargetId.MergeFrom(other.TargetId);
     }
     attribute_.Add(other.attribute_);
     if (other.HasReason)
     {
         Reason = other.Reason;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (Topic.Length != 0)
            {
                hash ^= Topic.GetHashCode();
            }
            if (SenderId.Length != 0)
            {
                hash ^= SenderId.GetHashCode();
            }
            if (TargetId.Length != 0)
            {
                hash ^= TargetId.GetHashCode();
            }
            hash ^= data_.GetHashCode();
            return(hash);
        }
示例#17
0
        public async Task <HttpResponseMessage> InvokeAsync(ServerTestCommandInfo commandInfo, TargetId targetId, TaskExecutionContext context,
                                                            CancellationToken cancellationToken)
        {
            for (int i = 0; i < 100; i++)
            {
                await Task.Delay(100, cancellationToken);

                context.ReportProgress(i / 100d);
                context.ReportStatus($"Doing some stuff ({i}%)");
            }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        // ToXml()

        public override void ToJSON(JObject ParentObject)
        {
            ParentObject[_QuantitySubField.ToXmlNodeName(true)]    = (!Double.IsNaN(Quantity)) ? CswConvert.ToString(Quantity) : string.Empty;
            ParentObject[_Val_kg_SubField.ToXmlNodeName(true)]     = (!Double.IsNaN(Quantity)) ? CswConvert.ToString(Val_kg) : string.Empty;
            ParentObject[_Val_Liters_SubField.ToXmlNodeName(true)] = (!Double.IsNaN(Quantity)) ? CswConvert.ToString(Val_Liters) : string.Empty;

            ParentObject["minvalue"]           = MinValue.ToString();
            ParentObject["maxvalue"]           = MaxValue.ToString();
            ParentObject["precision"]          = Precision;
            ParentObject["excludeRangeLimits"] = ExcludeRangeLimits;
            ParentObject["quantityoptional"]   = QuantityOptional;

            ParentObject[_UnitIdSubField.ToXmlNodeName(true)] = string.Empty;
            CswNbtNode RelatedNode = null;

            if (CswTools.IsPrimaryKey(UnitId))
            {
                ParentObject[_UnitIdSubField.ToXmlNodeName(true)] = UnitId.ToString();
                RelatedNode = _CswNbtResources.Nodes[UnitId];
            }
            ParentObject[_UnitNameSubField.ToXmlNodeName(true)] = CachedUnitName;

            ParentObject["nodetypeid"] = string.Empty;
            if (TargetType == CswEnumNbtViewRelatedIdType.NodeTypeId)
            {
                ParentObject["nodetypeid"] = TargetId.ToString();
            }

            ParentObject["fractional"] = CswConvert.ToBoolean(TargetFractional);

            if (IsEditModeEditable)
            {
                ParentObject["relatednodeid"]   = string.Empty;
                ParentObject["relatednodelink"] = string.Empty;
                if (null != RelatedNode)
                {
                    ParentObject["relatednodeid"]   = RelatedNode.NodeId.ToString();
                    ParentObject["relatednodelink"] = RelatedNode.NodeLink;
                }


                if (false == ReadOnly)
                {
                    JArray JOptions = new JArray();
                    ParentObject["options"] = JOptions;

                    foreach (CswNbtNode Node in UnitNodes)
                    {
                        JObject JOption = new JObject();
                        if (Node.NodeId != null && Node.NodeId.PrimaryKey != Int32.MinValue)
                        {
                            JOption["id"]         = Node.NodeId.ToString();
                            JOption["value"]      = Node.NodeName;
                            JOption["fractional"] = CswConvert.ToBoolean(Node.Properties[CswNbtObjClassUnitOfMeasure.PropertyName.Fractional].AsLogical.Checked);
                        }
                        else if (false == Required)
                        {
                            JOption["id"]         = "";
                            JOption["value"]      = "";
                            JOption["fractional"] = false;
                        }
                        JOptions.Add(JOption);
                    }
                }
            } // if( ForEdit )
        }
示例#19
0
        private async Task ExecuteCommand(TargetId id, IServiceProvider services, CommandInfo commandInfo, TasksMachineStatus status, Guid executionId, CancellationToken cancellationToken)
        {
            var executorType = _executorTypes[commandInfo];

            if (executorType == null)
            {
                return;
            }

            var service = services.GetService(executorType);

            if (service == null)
            {
                return;
            }

            var commandName   = commandInfo.GetType().Name.TrimEnd("CommandInfo", StringComparison.Ordinal);
            var commandResult = new CommandResultDto
            {
                CommandResultId = Guid.NewGuid(),
                TaskExecutionId = executionId,
                CommandName     = commandName
            };

            var commandProcessDto = new CommandProcessDto
            {
                CommandResultId = commandResult.CommandResultId, TaskExecutionId = executionId, CommandName = commandName
            };

            Task UpdateStatus(CommandProcessDto arg)
            {
                commandProcessDto.StatusMessage = arg.StatusMessage;
                commandProcessDto.Progress      = arg.Progress;

                return(_hubContext.Clients.All.SendAsync(HubEventNames.TaskCommandProcess, commandProcessDto, cancellationToken));
            }

            var executionMethod = _executionMethods[executorType];

            status.Processes.TryAdd(commandProcessDto.CommandResultId, commandProcessDto);
            try
            {
                using (var context = new DefaultTaskExecutionContext(_taskSession, _mazeTask, services, UpdateStatus))
                {
                    context.ReportProgress(null); //important to notify about the start of the operation

                    var task = (Task <HttpResponseMessage>)executionMethod.Invoke(service,
                                                                                  new object[] { commandInfo, id, context, cancellationToken });
                    var response = await task;

                    using (var memoryStream = new MemoryStream())
                    {
                        await HttpResponseSerializer.Format(response, memoryStream);

                        commandResult.Result = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
                        commandResult.Status = (int)response.StatusCode;
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "An error occurred when executing {method}", executorType.FullName);
                commandResult.Result = e.ToString();
            }
            finally
            {
                status.Processes.TryRemove(commandProcessDto.CommandResultId, out _);
            }

            commandResult.FinishedAt = DateTimeOffset.UtcNow;

            try
            {
                await _taskResultStorage.CreateCommandResult(commandResult);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Executing CreateCommandResult failed.");
            }

            await _hubContext.Clients.All.SendAsync(HubEventNames.TaskCommandResultCreated, commandResult);
        }
示例#20
0
 public void MergeFrom(Notification other)
 {
     if (other == null)
     {
         return;
     }
     if (other.HasSenderId)
     {
         if (!HasSenderId)
         {
             SenderId = new global::Bgs.Protocol.EntityId();
         }
         SenderId.MergeFrom(other.SenderId);
     }
     if (other.HasTargetId)
     {
         if (!HasTargetId)
         {
             TargetId = new global::Bgs.Protocol.EntityId();
         }
         TargetId.MergeFrom(other.TargetId);
     }
     if (other.HasType)
     {
         Type = other.Type;
     }
     attribute_.Add(other.attribute_);
     if (other.HasSenderAccountId)
     {
         if (!HasSenderAccountId)
         {
             SenderAccountId = new global::Bgs.Protocol.EntityId();
         }
         SenderAccountId.MergeFrom(other.SenderAccountId);
     }
     if (other.HasTargetAccountId)
     {
         if (!HasTargetAccountId)
         {
             TargetAccountId = new global::Bgs.Protocol.EntityId();
         }
         TargetAccountId.MergeFrom(other.TargetAccountId);
     }
     if (other.HasSenderBattleTag)
     {
         SenderBattleTag = other.SenderBattleTag;
     }
     if (other.HasTargetBattleTag)
     {
         TargetBattleTag = other.TargetBattleTag;
     }
     if (other.HasPeer)
     {
         if (!HasPeer)
         {
             Peer = new global::Bgs.Protocol.ProcessId();
         }
         Peer.MergeFrom(other.Peer);
     }
     if (other.HasForwardingIdentity)
     {
         if (!HasForwardingIdentity)
         {
             ForwardingIdentity = new global::Bgs.Protocol.Account.V1.Identity();
         }
         ForwardingIdentity.MergeFrom(other.ForwardingIdentity);
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
 public void MergeFrom(Notification other)
 {
     if (other == null)
     {
         return;
     }
     if (other.senderId_ != null)
     {
         if (senderId_ == null)
         {
             senderId_ = new Bgs.Protocol.EntityId();
         }
         SenderId.MergeFrom(other.SenderId);
     }
     if (other.targetId_ != null)
     {
         if (targetId_ == null)
         {
             targetId_ = new Bgs.Protocol.EntityId();
         }
         TargetId.MergeFrom(other.TargetId);
     }
     if (other.Type.Length != 0)
     {
         Type = other.Type;
     }
     attribute_.Add(other.attribute_);
     if (other.senderAccountId_ != null)
     {
         if (senderAccountId_ == null)
         {
             senderAccountId_ = new Bgs.Protocol.EntityId();
         }
         SenderAccountId.MergeFrom(other.SenderAccountId);
     }
     if (other.targetAccountId_ != null)
     {
         if (targetAccountId_ == null)
         {
             targetAccountId_ = new Bgs.Protocol.EntityId();
         }
         TargetAccountId.MergeFrom(other.TargetAccountId);
     }
     if (other.SenderBattleTag.Length != 0)
     {
         SenderBattleTag = other.SenderBattleTag;
     }
     if (other.TargetBattleTag.Length != 0)
     {
         TargetBattleTag = other.TargetBattleTag;
     }
     if (other.peer_ != null)
     {
         if (peer_ == null)
         {
             peer_ = new Bgs.Protocol.ProcessId();
         }
         Peer.MergeFrom(other.Peer);
     }
     if (other.forwardingIdentity_ != null)
     {
         if (forwardingIdentity_ == null)
         {
             forwardingIdentity_ = new Bgs.Protocol.Account.V1.Identity();
         }
         ForwardingIdentity.MergeFrom(other.ForwardingIdentity);
     }
 }
示例#22
0
 public override string ToString()
 {
     return($"{Set.ToString()}->{TargetId.ToString()}");
 }
示例#23
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            _context        = executionContext.GetExtension <IWorkflowContext>();
            _serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            _service        = _serviceFactory.CreateOrganizationService(_context.UserId);
            _tracing        = executionContext.GetExtension <ITracingService>();
            Logic logic = new Logic(_service);

            try
            {
                AuditChanges auditChanges = new AuditChanges()
                {
                    AuditHistories = logic.RetrieveRecordChangeHistory(new EntityReference(EntityLogicalName.Get(executionContext).Trim(), Guid.Parse(TargetId.Get(executionContext).Trim())))
                };
                var Output = Serializer.SerializeToJson(auditChanges);
                JsonResponse.Set(executionContext, Output);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message + Environment.NewLine + ex.StackTrace, ex);
            }
        }
示例#24
0
 public override int GetHashCode()
 {
     return(Reason.GetHashCode() * (!string.IsNullOrEmpty(PlayerId) ? PlayerId.GetHashCode() : 10) * (!string.IsNullOrEmpty(TargetId) ? TargetId.GetHashCode() : 11)
            * (!string.IsNullOrEmpty(SkillName) ? SkillName.GetHashCode() : 12) * (!string.IsNullOrEmpty(EventName) ? EventName.GetHashCode() : 13));
 }
示例#25
0
 public override int GetHashCode()
 {
     return((SourceId.GetHashCode() + TargetId.GetHashCode()) / 2);
 }
示例#26
0
 public override bool Equals(object obj)
 {
     return((this == obj) ||
            (obj is Edge edge && SourceId.Equals(edge.SourceId) && TargetId.Equals(edge.TargetId) &&
             Math.Abs(Weight - edge.Weight) < 0.01));
 }
示例#27
0
        public async Task <HttpResponseMessage> InvokeAsync(WakeOnLanCommandInfo commandInfo, TargetId targetId, TaskExecutionContext context, CancellationToken cancellationToken)
        {
            if (targetId.IsServer)
            {
                return(NotExecuted("The server cannot execute this command as it must be already running which renders this command useless."));
            }

            if (_connectionManager.ClientConnections.ContainsKey(targetId.ClientId))
            {
                this.LogInformation("The client is already connected.");
                return(Log(HttpStatusCode.OK));
            }

            var client = await _context.Clients.FindAsync(targetId.ClientId);

            var macAddress = PhysicalAddress.Parse(client.MacAddress);

            this.LogInformation("Send magic package from server to {address}", macAddress);
            context.ReportStatus("Send magic package from server...");

            WakeOnLan(macAddress);
            if (commandInfo.TryOverClient)
            {
                this.LogDebug("Querying clients that had the same ip address like the targeted client...");

                var clientsInSameNetwork = await _context.Query <ClientReference>().FromSql($"SELECT CS1.ClientId FROM ClientSession AS CS1 INNER JOIN ClientSession AS CS2 ON CS1.IpAddress = CS2.IpAddress WHERE CS1.ClientId = {targetId.ClientId} AND CS2.ClientId != {targetId.ClientId} GROUP BY CS2.ClientId ORDER BY CS2.CreatedOn DESC").ToListAsync();

                if (clientsInSameNetwork.Any())
                {
                    context.ReportStatus("Send magic package over clients network...");
                }

                this.LogInformation("{amount} clients with the same ip address were found.", clientsInSameNetwork.Count);

                foreach (var clientInSameNetwork in clientsInSameNetwork)
                {
                    if (_connectionManager.ClientConnections.TryGetValue(clientInSameNetwork.ClientId, out var connection))
                    {
                        this.LogDebug("Send magic package from client #{id}", clientInSameNetwork.ClientId);

                        try
                        {
                            await WakeOnLanResource.WakeOnLan(macAddress, connection);
                        }
                        catch (Exception e)
                        {
                            this.LogWarning(e, "Sending magic package from client #{id} failed.", clientInSameNetwork.ClientId);
                            continue;
                        }

                        this.LogInformation("Magic package sent from client #{id}.", clientInSameNetwork.ClientId);
                    }
                }
            }

            return(Log(HttpStatusCode.OK));
        }