Ejemplo n.º 1
0
    }     //OnTriggerExit2D

    public override void OnTriggerStay2D(Collider2D collision)
    {
        base.OnTriggerStay2D(collision);
        if (!IsStaying)
        {
            return;
        }

        if (!IsMainTerminal)
        {
            return;
        }

        Imposter imp = this.tryCashImposter(collision.gameObject);

        if (Input.GetAxisRaw("Use") != 0 && !bHasUsed)
        {
            Debug.Log("Shifting -> " + this.name);
            this.IsMainTerminal = true;
            for (int i = 0; i < ShifterConnections.Count; i++)
            {
                ShifterConnections[i].IsMainTerminal = false;
            }//for

            bHasUsed = true;
            Shift(imp);
        }
    }//OnTriggerStay2D
Ejemplo n.º 2
0
 private RequestDelegate EvaluateImposterRules(Imposter imposter)
 {
     return(async context =>
     {
         await EvaluateRules(imposter, context);
     });
 }
Ejemplo n.º 3
0
    }//OnTriggerEnter2D

    public override void OnTriggerExit2D(Collider2D collision)
    {
        base.OnTriggerExit2D(collision);
        if (!HasExited)
        {
            return;
        }

        Imposter imp = this.tryCashImposter(collision.gameObject);

        if (imp == null)
        {
            return;
        }

        imp.SetShifter(null);
        bHasUsed            = false;
        this.IsMainTerminal = true;
        for (int i = 0; i < ShifterConnections.Count; i++)
        {
            if (ShifterConnections[i] == null)
            {
                continue;
            }

            ShifterConnections[i].IsMainTerminal = true;
        } //for
    }     //OnTriggerExit2D
Ejemplo n.º 4
0
        public override void SetUpStubbs()
        {
            Imposter.AddStub()
            .OnPathAndMethodEqual("/Provisioning.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");

            Imposter.AddStub()
            .OnPathAndMethodEqual("/LicenceCheckWebservice.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");

            Imposter.AddStub()
            .OnPathAndMethodEqual("/AssessmentService.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");

            Imposter.AddStub()
            .OnPathAndMethodEqual("/OnlineLearningService.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");

            Imposter.AddStub()
            .OnPathAndMethodEqual("/TaskAllocation.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");

            Imposter.AddStub()
            .OnPathAndMethodEqual("/CourseDataWebservice.asmx", Method.Post)
            .ReturnsBody(HttpStatusCode.OK, "<? xml version = \"1.0\" encoding = \"utf-8\" ?><soap: Envelope xmlns: xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns: xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns: soap = \"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetLicencesForCompanyResponse xmlns = \"http://www.fleetriskmanager.com/ns/LicenceCheck/\"><GetLicencesForCompanyResult><SimpleLicence><Active>boolean</Active><Current>boolean</Current><ID>int</ID><Number>string</Number><ExpiryDate>dateTime</ExpiryDate><DriversLicenceChecks><SimpleLicenceCheck xsi: nil=\"true\" /><SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string </ NomineeLastName >< NomineeDateOfBirth > dateTime </ NomineeDateOfBirth >< LatestMandateSignedDate > dateTime </ LatestMandateSignedDate >< EstimatedNextCheckDate > dateTime </ EstimatedNextCheckDate ></ SimpleLicence >< SimpleLicence >< Active > boolean </ Active >< Current > boolean </ Current >< ID > int </ ID >< Number > string </ Number >< ExpiryDate > dateTime </ ExpiryDate >< DriversLicenceChecks >< SimpleLicenceCheck xsi: nil = \"true\" />< SimpleLicenceCheck xsi: nil = \"true\" /></ DriversLicenceChecks >< Points > int </ Points >< NomineeEmailAddress > string </ NomineeEmailAddress >< UserId > int </ UserId >< NomineeFirstNames > string </ NomineeFirstNames >< NomineeLastName > string</ NomineeLastName><NomineeDateOfBirth>dateTime</ NomineeDateOfBirth><LatestMandateSignedDate> dateTime </ LatestMandateSignedDate><EstimatedNextCheckDate> dateTime </ EstimatedNextCheckDate></ SimpleLicence></ GetLicencesForCompanyResult></ GetLicencesForCompanyResponse></ soap:Body></ soap:Envelope>");
        }
Ejemplo n.º 5
0
        public void CreateImposter(Imposter imposter)
        {
            var json     = JsonConvert.SerializeObject(imposter);
            var response = ExecutePost(ImpostersResource, json);

            HandleResponse(response, HttpStatusCode.Created,
                           $"Failed to create the imposter with port {imposter.Port} and protocol {imposter.Protocol}.");
        }
Ejemplo n.º 6
0
        EvaluateRules(Imposter imposter,
                      HttpContext context,
                      Request request)
        {
            var response = RulesEvaluator.Evaluate(imposter,
                                                   request,
                                                   out Expression <Func <Request, bool> > matchedCondition);

            return(response, matchedCondition);
        }
Ejemplo n.º 7
0
        public override void SetUpStubbs()
        {
            Imposter.AddStub()
            .OnPathAndMethodEqual("/AccountPeriods", Method.Get)
            .ReturnsJson(HttpStatusCode.OK, TestAccountPeriods());

            Imposter.AddStub()
            .OnPathAndMethodEqual("/AccountPeriods/21", Method.Get)
            .ReturnsJson(HttpStatusCode.OK, TestAccountPeriod21());
        }
Ejemplo n.º 8
0
        public void CreateImposter(Imposter imposter)
        {
            var request = new RestRequest(ImpostersResource, Method.POST);

            var json = JsonConvert.SerializeObject(imposter);

            request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            ExecuteRequestAndCheckStatusCode(request, HttpStatusCode.Created, string.Format("Failed to create the imposter with port {0} and protocol {1}.", imposter.Port, imposter.Protocol));
        }
Ejemplo n.º 9
0
        public async Task CreateImposterAsync(Imposter imposter)
        {
            var json = JsonConvert.SerializeObject(imposter);

            using (var response = await ExecutePostAsync(ImpostersResource, json).ConfigureAwait(false))
            {
                await HandleResponse(response, HttpStatusCode.Created,
                                     $"Failed to create the imposter with port {imposter.Port} and protocol {imposter.Protocol}.").ConfigureAwait(false);
                await HandleDynamicPort(response, imposter).ConfigureAwait(false);
            }
        }
Ejemplo n.º 10
0
    }//SetImposter

    public void UnsetImposter(Imposter imp)
    {
        if (ImposteredBy == null)
        {
            ImposteredBy = new List <Imposter>();
        }

        if (ImposteredBy.Contains(imp))
        {
            ImposteredBy.Remove(imp);
        }
    }//UnsetImposter
Ejemplo n.º 11
0
    }//ToggleSprite

    public void SetImposter(Imposter imp)
    {
        if (ImposteredBy == null)
        {
            ImposteredBy = new List <Imposter>();
        }

        if (!ImposteredBy.Contains(imp))
        {
            ImposteredBy.Add(imp);
        }
    }//SetImposter
Ejemplo n.º 12
0
        public override void SetUpStubbs()
        {
            Imposter.AddStub()
            .OnPathAndMethodEqual("/", Method.Get)
            .Returns(AllUsersResponse());

            Imposter.AddStub()
            .OnPathAndMethodEqual("/SpecificUser", Method.Get)    //{id}
            .ReturnsJson(HttpStatusCode.OK, SpecificUser());

            Imposter.AddStub()
            .OnPathAndMethodEqual("/InactiveUsers", Method.Get)    //Inactive
            .ReturnsJson(HttpStatusCode.OK, InactiveUsers());
        }
Ejemplo n.º 13
0
        private async Task EvaluateRules(Imposter imposter,
                                         HttpContext context)
        {
            var request = BuildRequest(context);

            var(response, matchedCondition) = _rulesEvaluator.EvaluateRules(imposter,
                                                                            context,
                                                                            request);

            StoreRequestAndResponse(imposter, request, response, matchedCondition);

            context.Response.StatusCode = response.StatusCode;
            await context.Response.WriteAsync(response.Content);
        }
Ejemplo n.º 14
0
        private void StoreRequestAndResponse(Imposter imposter,
                                             Request request,
                                             Response response,
                                             Expression <Func <Request, bool> > matchedCondition)
        {
            var requestId = _configuration.DataStore.StoreRequest(imposter.Resource,
                                                                  imposter.Method,
                                                                  Encoding.ASCII.GetBytes(request.Content));

            _configuration.DataStore.StoreResponse(requestId,
                                                   imposter.Name,
                                                   matchedCondition?.ToString(),
                                                   Encoding.ASCII.GetBytes(response.Content));
        }
Ejemplo n.º 15
0
        public TestServerBuilder UsingImpostersMiddleware(Imposter imposter)
        {
            var impostersAsStubConfiguration = new ImpostersAsStubConfiguration(new[]
            {
                imposter
            });

            Action <IApplicationBuilder> action =
                app => app.UseStubImposters(impostersAsStubConfiguration);

            _webHostBuilder.Configure(action);

            return(this);
        }
 private void HandleDynamicPort(HttpResponseMessage response, Imposter imposter)
 {
     if (imposter.Port == default(int))
     {
         try
         {
             var content          = response.Content.ReadAsStringAsync().Result;
             var returnedImposter = JsonConvert.DeserializeObject <CreateImposterResponse>(content);
             imposter.SetDynamicPort(returnedImposter.Port);
         }
         catch (Exception e)
         {
             throw new MountebankException($"Unable to retrieve port for imposter with name [{imposter.Name}]", e);
         }
     }
 }
Ejemplo n.º 17
0
        public async Task UpdateImposterAsync(Imposter imposter, CancellationToken cancellationToken = default)
        {
            var json = JsonConvert.SerializeObject(imposter);

            using (
                var response = await _httpClient.PutAsync(
                    $"{ImpostersResource}/{imposter.Port}/stubs",
                    new StringContent(json),
                    cancellationToken
                    ).ConfigureAwait(false))
            {
                await HandleResponse(response, HttpStatusCode.OK,
                                     $"Failed to replace stubs for the imposter with port {imposter.Port}.",
                                     (message) => new ImposterNotFoundException(message)).ConfigureAwait(false);
            }
        }
Ejemplo n.º 18
0
        public static Response Evaluate(Imposter imposter, Request request, out Expression <Func <Request, bool> > matchedCondition)
        {
            foreach (var imposterRule in imposter.Rules)
            {
                var condition = imposterRule.Condition.Compile();

                if (condition(request))
                {
                    matchedCondition = imposterRule.Condition;
                    return(imposterRule.ResponseCreatorAction.CreateResponse());
                }
            }

            matchedCondition = null;
            return(CreateInternalServerErrorResponse());
        }
Ejemplo n.º 19
0
        public async Task CreateImposterAsync(Imposter imposter, CancellationToken cancellationToken = default)
        {
            var json = JsonConvert.SerializeObject(imposter);

            using (
                var response = await _httpClient.PostAsync(
                    ImpostersResource,
                    new StringContent(json),
                    cancellationToken
                    ).ConfigureAwait(false))
            {
                await HandleResponse(response, HttpStatusCode.Created,
                                     $"Failed to create the imposter with port {imposter.Port} and protocol {imposter.Protocol}.").ConfigureAwait(false);
                await HandleDynamicPort(response, imposter).ConfigureAwait(false);
            }
        }
Ejemplo n.º 20
0
        public TestServerBuilder UsingImposterMiddleWareWithSpyDataStore(Imposter imposter,
                                                                         IDataStore spyDataStore)
        {
            var imposterConfiguration = new ImpostersAsMockConfiguration(new[]
            {
                imposter
            },
                                                                         spyDataStore);

            Action <IApplicationBuilder> action =
                app => app.UseMockImposters(imposterConfiguration);

            _webHostBuilder.Configure(action);

            return(this);
        }
Ejemplo n.º 21
0
    }     //Start

    public override void OnTriggerEnter2D(Collider2D collision)
    {
        base.OnTriggerEnter2D(collision);
        if (!HasEntered)
        {
            return;
        }

        Imposter imp = this.tryCashImposter(collision.gameObject);

        if (imp == null)
        {
            return;
        }

        imp.SetShifter(this);
    }//OnTriggerEnter2D
Ejemplo n.º 22
0
    }//OnTriggerStay2D

    private Imposter tryCashImposter(GameObject go)
    {
        Imposter imp    = null;
        int      goHash = go.GetHashCode();
        bool     hasKey = this.imposters.ContainsKey(goHash);

        if (hasKey)
        {
            imp    = this.imposters[goHash];
            hasKey = true;
        }
        else
        {
            imp = go.GetComponent <Imposter>();
        }//if else

        return(imp);
    }//tryCashImposter
Ejemplo n.º 23
0
    void HandleSleep(SleepTypes sleepType)
    {
        if (sleepType == SleepTypes.FoundImposter || sleepType == SleepTypes.GotTired)
        {
            active = Imposter.story.PlayIteration == activeIteration;
        }
        else if (active)
        {
            active = sleepType == SleepTypes.GaveUp;
        }

        if (active)
        {
            Imposter.current = this;
            lastCallOutLight = Time.timeSinceLevelLoad;
            lastCallOutTime  = lastCallOutLight;
        }
        imposterLight.enabled = active;
    }
Ejemplo n.º 24
0
    }//tryCashImposter

    public void Shift(Imposter cameInImp)
    {
        if (cameInImp == null)
        {
            return;
        }

        List <Imposter> toShift = new List <Imposter>();

        if (cameInImp.Target == null)
        {
            //The one who came in is the one being Impostered.
            toShift.AddRange(cameInImp.ImposteredBy);
        }
        else
        {
            if (cameInImp.Impostered == null)
            {
                #if UNITY_EDITOR
                Debug.LogWarning("Impostered not set while trying to Shift() by " + cameInImp.gameObject.name);
                #endif
                return;
            }
            //The one who came in is The Imposter.
            toShift.Add(cameInImp);
        }

        for (int i = 0; i < toShift.Count; i++)
        {
            if (toShift[i].IsCanShift)
            {
                toShift[i].ShowTrueSprite();
            }
        }//for

        CameraShake shaker = Camera.main.GetComponent <CameraShake>();
        if (shaker != null)
        {
            shaker.ShakeRandomly();
        }
    }//Shift
Ejemplo n.º 25
0
 /// <summary>
 /// Submits imposter to be created in mountebank.
 /// <exception cref="MbDotNet.Exceptions.MountebankException">Thrown if unable to create the imposter.</exception>
 /// </summary>
 public void Submit(Imposter imposter)
 {
     Submit(new [] { imposter });
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Submits imposter to be created in mountebank.
 /// <exception cref="MbDotNet.Exceptions.MountebankException">Thrown if unable to create the imposter.</exception>
 /// </summary>
 public async Task SubmitAsync(Imposter imposter)
 {
     await SubmitAsync(new [] { imposter }).ConfigureAwait(false);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Overwrites the stubs of an existing imposter without restarting it.
 /// </summary>
 /// <param name="imposter">The imposter to be updated with new stubs</param>
 /// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
 public async Task UpdateImposterAsync(Imposter imposter, CancellationToken cancellationToken = default)
 {
     await _requestProxy.UpdateImposterAsync(imposter, cancellationToken);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Submits imposter to be created in mountebank.
 /// <exception cref="MbDotNet.Exceptions.MountebankException">Thrown if unable to create the imposter.</exception>
 /// </summary>
 public async Task SubmitAsync(Imposter imposter, CancellationToken cancellationToken = default)
 {
     await SubmitAsync(new [] { imposter }, cancellationToken).ConfigureAwait(false);
 }
Ejemplo n.º 29
0
        // lagrer alle opplastede filer til disk (G:\), oppretter hjelpefiler og returnerer mappeadressen
        private Response <string> SaveFilesToDisk(HttpPostedFileBase hoveddokument, IEnumerable <HttpPostedFileBase> vedlegg, string hovedfilnavn, string journalpostnavn, int sak = 0, bool sendCopy = false, Dictionary <string, string> helperFiles = null)
        {
            sak = sak >= _websakMapper.Length || sak < 0 ? 0 : sak;

            // sett mimetype avhengig av hvilken fil som skal lagres
            var allowedMime   = sendCopy ? "text/html" : "application/pdf";
            var fileExtension = "";

            if (hovedfilnavn.Equals(Dokumenter.GenereltDokument))
            {
                fileExtension = "." + hoveddokument.FileName.Split('.').Last();
            }
            else
            {
                fileExtension = sendCopy ? ".html" : ".pdf";
            }

            var ansatt = GetAnsattFromSession();

            try
            {
                // sjekk filtypen
                if (hoveddokument.ContentType.Equals(allowedMime) || hovedfilnavn.Equals(Dokumenter.GenereltDokument))
                {
                    // bruker impersonate for å få skrivetilgang på G:\ for asp.net-prosessen
                    Imposter.ImpersonateRobot();

                    // gjør klar diverse filnavn
                    hovedfilnavn = hovedfilnavn.Replace(" ", "_");

                    var mappenavn          = CreateUniqueFoldername();
                    var opplastingsmappe   = $"{Paths.UNC_ADDRESS}{Paths.INPUT_FOLDER}{Paths.UPLOAD_FOLDER}{mappenavn}\\";  // asp.net-prosessen vil ha adressen på formen \\server\user$
                    var mappenavnForUiPath = $"{Paths.DRIVE_LETTER}{Paths.INPUT_FOLDER}{Paths.UPLOAD_FOLDER}{mappenavn}\\"; // UiPath vil ha adressen på formen G:\mappe

                    // opprett en ny mappe for dokumentene til denne journalposten
                    Directory.CreateDirectory(opplastingsmappe);

                    // gi hoveddokumentet et standard navn slik at det kan finnes av roboten i WebSak
                    var hovedfiladresse = $"{opplastingsmappe}{hovedfilnavn}{fileExtension}";
                    hoveddokument.SaveAs(hovedfiladresse);

                    var filListe = "";
                    if (!sendCopy)
                    {
                        filListe += $"{mappenavnForUiPath}{hovedfilnavn}{fileExtension}"; // html-dokumentet skal ikke importeres i WebSak
                    }
                    var vedleggteller = 0;

                    // lagre alle vedlegg hvis de eksisterer
                    if (vedlegg != null)
                    {
                        foreach (var fil in vedlegg)
                        {
                            if (fil != null)
                            {
                                // lager filnavn som brukes av roboten når den skal importere i WebSak. Legger til "vedlegg_" for å unngå navnekonflikt med hovedfil/vedlegg
                                var vedleggAdresse   = opplastingsmappe + Path.GetFileName("vedlegg_" + fil.FileName);
                                var hjelpefiladresse = mappenavnForUiPath + Path.GetFileName("vedlegg_" + fil.FileName);
                                fil.SaveAs(vedleggAdresse);

                                Debug.WriteLine(fil.FileName);

                                filListe += System.Environment.NewLine + hjelpefiladresse;
                                vedleggteller++;
                            }
                        }
                    }

                    // loggfør valgt dokument for statistikk
                    var basePath = Paths.UNC_ADDRESS + Paths.PORTAL_LOG;

                    if (sak == Mappetype.Sykefravær)
                    {
                        basePath += $@"Sykefravær\";
                    }
                    else if (sak == Mappetype.Ansattforhold)
                    {
                        basePath += $@"Ansattforhold\";
                    }

                    var logContent = $"{journalpostnavn}{System.Environment.NewLine}";
                    System.IO.File.AppendAllText(basePath + $"{DateTime.Now.ToString("dd.MM.yyyy")}.txt", logContent);

                    // opprett hjelpfiler for robot
                    System.IO.File.WriteAllText($"{opplastingsmappe}{HelperFile.FILE_LIST}", filListe);
                    var lederInfoResult = ADHelper.GetLederBundle(GetUsername());

                    if (lederInfoResult.Success)
                    {
                        var hrmLederInfo    = lederInfoResult.Get();
                        var websakLederInfo = HardCodeDB.TryCorrect(hrmLederInfo); // må håndtere avvik mellom navn i WebSak og HRM

                        SaveFile(HelperFile.MANAGER_AD, websakLederInfo.AD);
                        SaveFile(HelperFile.DEPARTMENT, websakLederInfo.Enhet);         // enhet for å sette riktig saksbehandler  i WebSak
                        //-------------------------------------//
                        SaveFile(HelperFile.MANAGER_EMAIL, hrmLederInfo.EPost);         // e-postadresse til leder for evt. e-postvarsel fra robot (den som laster opp)
                        SaveFile(HelperFile.FOLDER_TYPE, _websakMapper[sak]);           // hvilken sakstype roboten skal opprette under 'Ny sak' i WebSak
                        SaveFile(HelperFile.DATE, DateTime.Now.ToString("dd/MM/yyyy")); // dato dokumentet ble lastet opp
                        SaveFile(HelperFile.POST_NAME, journalpostnavn);

                        // prøv å finne ansattinfo i HRM-databasen slik at roboten slipper å åpne HRM-programmet
                        // sparer tid og er mer stabilt
                        var personnrResult = HRMHelper.FinnPersonnrForAnsatt(ansatt);
                        if (personnrResult.Success)
                        {
                            SaveFile(HelperFile.EMPLOYEE_NAME, $"{ansatt.Etternavn} {ansatt.Fornavn}");
                            SaveFile(HelperFile.SSIN, personnrResult.Get());
                            SaveFile(HelperFile.EMPLOYEE_ID, ansatt.AnsattNr);
                        }
                        else
                        {
                            SaveFile(HelperFile.EMPLOYEE_ID, ansatt.AnsattNr);
                            SaveFile(HelperFile.HRM_ERROR, personnrResult.Message); // lagre feilmelding i egen fil
                        }

                        if (sendCopy)
                        {
                            SaveFile(HelperFile.SVARUT, "NULL");
                        }

                        // skriv tillegsshjelpefiler til disk
                        if (helperFiles != null)
                        {
                            foreach (var file in helperFiles)
                            {
                                SaveFile(file.Key, file.Value);
                            }
                        }

                        void SaveFile(string name, string content)
                        {
                            System.IO.File.WriteAllText($"{opplastingsmappe}{name}", content, Encoding.UTF8);
                        }

                        Imposter.UndoImpersonation();

                        var msg = $"Notatet '{hoveddokument.FileName}' og {vedleggteller} vedlegg har blitt lastet opp!";
                        return(new Response <string>(opplastingsmappe, msg, Codes.Code.OK));
                    }
                    else
                    {
                        Imposter.UndoImpersonation();
                        return(new Response <string>(null, lederInfoResult.Message, Codes.Code.ERROR));
                    }
                }
                else
                {
                    var msg = $"Feil: Hoveddokumentet '{hoveddokument.FileName}' var ikke i pdf-format.";
                    return(new Response <string>(null, msg, Codes.Code.ERROR));
                }
            }

            catch (Exception e)
            {
                Imposter.UndoImpersonation();
                //if (_writeLog)
                //    System.IO.File.AppendAllText(@"C:\inetpub\logs\error.txt", $"{GetUsername()} {e.Message}{System.Environment.NewLine}"); // for debugging
                //Logger.Log();
                return(new Response <string>(null, e.Message, Codes.Code.ERROR));
            }
        }
Ejemplo n.º 30
0
        public async Task <ActionResult> MakeEsignatureJob(IEnumerable <string> mottakere, int dokID, bool selfSign, string fornavn = null, string etternavn = null, HttpPostedFileBase arbeidsavtale = null, bool sendConfirmation = false)
        {
            if (Session["ansatt"] != null)
            {
                ViewBag.AnsattNr = GetAnsattFromSession().AnsattNr;
            }
            else
            {
                TempData["statusCode"] = (int)Codes.Code.ERROR;
                TempData["errorMsg"]   = StringConstants.ERROR_GENERIC;
                return(RedirectToAction("Index", "Signeringsportal", null));
            }

            Imposter.ImpersonateRobot();
            var currentPersonnr = ""; // ta vare på personnr i tilfelle en feil oppstår

            try
            {
                // hvis serveren ikke klarer å laste ned dokumentet fra drive (feil med robotpassord el.),
                // bruke lokale kopier
                var    fileName = _dokumentNavn[dokID];
                byte[] docBytes;

                if (dokID == 0 && arbeidsavtale != null)
                {
                    if (arbeidsavtale.ContentType.Equals("application/pdf"))
                    {
                        MemoryStream target = new MemoryStream();
                        arbeidsavtale.InputStream.CopyTo(target);
                        docBytes = target.ToArray();
                    }
                    else
                    {
                        var msg = $"Feil: Hoveddokumentet '{arbeidsavtale.FileName}' var ikke i pdf-format.";
                        ViewBag.Response = new Response <bool>(false, msg, Codes.Code.ERROR);
                        return(View());
                    }
                }
                else
                {
                    var res = GoogleDriveDownloader.DownloadDocs(_avtaleURLs[dokID], false);
                    if (res.Success)
                    {
                        docBytes = res.Get();
                    }
                    else
                    {
                        ViewBag.Response = new Response <bool>(false, res.Message, res.Code);
                        return(View());
                    }
                }
                var documentToSign = new Document(fileName, StringConstants.SIGN_REQUEST, FileType.Pdf, docBytes);
                var signers        = new List <Signer>();
                var hjelperfiler   = new Dictionary <string, string>(); // hjelpefiler som skal skrives til disk senere

                // legg til mottakere
                foreach (var personnr in mottakere)
                {
                    if (personnr.Equals(HRMHelper.HRM_FLAG))
                    {
                        // bruker en ansatt, fødselsnummer skal hentes fra HRM
                        var personnrResponse = HRMHelper.FinnPersonnrForAnsatt(GetAnsattFromSession());
                        if (personnrResponse.Success)
                        {
                            signers.Add(new Signer(new PersonalIdentificationNumber(personnrResponse.Get()), new NotificationsUsingLookup()
                            {
                                SmsIfAvailable = true
                            }));
                            continue;
                        }
                        else
                        {
                            ViewBag.Response = new Response <bool>(false, personnrResponse.Message, Codes.Code.ERROR);
                            return(View());
                        }
                    }

                    else if (fornavn != null && etternavn != null)
                    {
                        currentPersonnr = personnr;
                        signers.Add(new Signer(new PersonalIdentificationNumber(personnr), new NotificationsUsingLookup()
                        {
                            SmsIfAvailable = true
                        }));
                        hjelperfiler.Add(HelperFile.EMPLOYEE_NAME, $"{etternavn} {fornavn}");
                        hjelperfiler.Add(HelperFile.SSIN, personnr);

                        // innlogget bruker settes automatisk som nærmeste leder/saksbehandler i WebSak
                        hjelperfiler.Add(HelperFile.MANAGER_AD, GetUsername()); // hvis fødselsnummeret ikke er i HRM antas det at det er nærmeste leder som lastet opp, og AD settes til innlogget bruker
                    }
                    else
                    {
                        ViewBag.Response = new Response <bool>(false, StringConstants.ERROR_MISSING_NAME, Codes.Code.ERROR);
                        return(View());
                    }
                }

                // hvis bruker skal motta varsel på e-post når dokumentet har blitt signert og arkivert i WebSak
                if (sendConfirmation)
                {
                    hjelperfiler.Add(HelperFile.ARCHIVE_CONFIRMATION, "true");
                }

                // finn leders fødselsnummer hvis leder også skal signere
                // leder SKAL ALLTID signere på arbeidskontrakt
                if (selfSign || dokID == 0)
                {
                    var lederInfoResponse = ADHelper.GetAnsattInfoForLeder(GetUsername());
                    if (lederInfoResponse.Success)
                    {
                        var personnrResponse = HRMHelper.FinnPersonnrForAnsatt(lederInfoResponse.Get());

                        if (personnrResponse.Success)
                        {
                            // setter onBehalfOf.other for å ikke havne i leders private postkasse
                            signers.Add(new Signer(new PersonalIdentificationNumber(personnrResponse.Get()), new Notifications(new Email(lederInfoResponse.Get().AnsattEPost)))
                            {
                                OnBehalfOf = OnBehalfOf.Other
                            });
                        }
                        else
                        {
                            ViewBag.Response = new Response <bool>(false, personnrResponse.Message, Codes.Code.ERROR);
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Response = new Response <bool>(false, lederInfoResponse.Message, Codes.Code.ERROR);
                        return(View());
                    }
                }


                // lag en unik kø-id for dette signeringsoppdraget
                var queueID      = GetUsername() + DateTime.Now.ToShortDateString() + "." + DateTime.Now.ToLongTimeString();
                var portalClient = new CustomPortalClient(queueID, fileName);

                hjelperfiler.Add(HelperFile.SIGNATURE_STATUS, "false"); // hjelpefil som sier noe om status på signeringsoppdrag (false er usignert)
                // ta vare på referansen til dette signeringsoppdraget for å kunne polle senere
                hjelperfiler.Add(HelperFile.REFERENCE, portalClient.GetReference());

                // lagre filene til disk mens vi venter på signaturen
                var response = SaveFilesToDisk(new NotatFil(docBytes, fileName), null, fileName, $"{fileName}{Datotype.Signaturdato}", 1, false, hjelperfiler);

                if (response.Success)
                {
                    var portalJob = new Job(documentToSign, signers, queueID)
                    {
                        IdentifierInSignedDocuments = IdentifierInSignedDocuments.Name
                    };                                                                                                                            // fødselsnummer skal ikke vises i det signerte dokumentet

#if !DEBUG
                    await portalClient.Create(portalJob);
#endif
                    var responseString = string.Format(StringConstants.ESIGN_SUCCESS, signers.Count() + (signers.Count() == 1 ? " mottaker" : " mottakere"));
                    ViewBag.Response = new Response <bool>(true, responseString, Codes.Code.OK);
                }
                else
                {
                    ViewBag.Response = new Response <bool>(false, response.Message, Codes.Code.ERROR);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The Pattern constraint failed"))
                {
                    ViewBag.Response = new Response <bool>(false, string.Format(StringConstants.INVALID_SSN, currentPersonnr), Codes.Code.ERROR);
                }
                else
                {
                    ViewBag.Response = new Response <bool>(false, ex.Message, Codes.Code.ERROR);
                }
            }
            Imposter.UndoImpersonation();

            return(View());
        }
Ejemplo n.º 31
0
 public bool getPreloadLock(Imposter imposter)
 {
     if (preloadCounter++ < preloadRate) return true;
     else return false;
 }