예제 #1
0
 public List <LoginMessage> GetLoginsForMarkers([FromBody] CheckMessage message)
 {
     if (message?.UserId == null)
     {
         return(null);
     }
     try
     {
         var result  = new List <LoginMessage>();
         var context = (FriendlistContext)MainContext.Instance.Friendlist;
         var friends = context.GetFriendOfUser((int)message.UserId)?.ToList();
         result = MainContext.Instance.User.GetBy(x => friends.Contains(x.UserId))?
                  .Select(x => new LoginMessage()
         {
             UserId = x.UserId, Login = x.Login
         }).ToList();
         result.Add(MainContext.Instance.User.GetBy(x => x.UserId == message.UserId)
                    ?.Select(x => new LoginMessage()
         {
             UserId = x.UserId, Login = x.Login
         }).FirstOrDefault());
         return(result);
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Exception in MarkerController.cs: {ex.Message}");
         throw;
     }
 }
예제 #2
0
 public List <SosMessage> ReturnSos([FromBody] CheckMessage message)
 {
     if (message?.UserId == null)
     {
         return(null);
     }
     try
     {
         var result  = new List <SosMessage>();
         var context = (FriendlistContext)MainContext.Instance.Friendlist;
         var friends = context.GetFriendOfUser((int)message.UserId)?.ToList();
         var diff    = new System.TimeSpan(0, 0, 15, 0);
         List <SosMessage> temp;
         if (friends != null && friends.Count != 0)
         {
             friends.Add((int)message.UserId);
             temp = StaticInfo.SosList.Where(x => friends.Contains(x.UserId) && DateTime.Now.TimeOfDay.Subtract(x.Timestamp.TimeOfDay) < diff).ToList();
         }
         else
         {
             temp = StaticInfo.SosList.Where(x => x.UserId == message.UserId)?.ToList();
         }
         result.AddRange(temp);
         return(result);
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Exception in MarkerController.cs: {e.Message}");
         return(null);
     }
 }
예제 #3
0
 public List <Log> GetSosLog([FromBody] CheckMessage message)
 {
     if (message?.UserId == null)
     {
         return(null);
     }
     try
     {
         var context = (FriendlistContext)MainContext.Instance.Friendlist;
         var friends = context.GetFriendOfUser((int)message.UserId).ToList();
         friends.Add((int)message.UserId);
         var deviceIndexes = MainContext.Instance.User.GetBy(x => friends.Contains(x.UserId))
                             .Select(x => x.DeviceId).ToList();
         var eventIndexes = MainContext.Instance.Event
                            .GetBy(x => x.Name == "SOS_BUTTON_CLICK")?
                            .Select(x => x.EventId).ToList();
         if (eventIndexes == null)
         {
             return(null);
         }
         return(MainContext.Instance.Log
                .GetBy(x => deviceIndexes.Contains(x.DeviceId) && eventIndexes.Contains(x.EventId))?.OrderByDescending(x => x.LogId).ToList());
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Internal server exception in LogController.cs: {ex.Message}");
         return(null);
     }
 }
예제 #4
0
        public JsonResult Register()
        {
            var ret = new CheckMessage()
            {
                Status = CheckMessageStatus.Ok,
                Data   = Guid.NewGuid().ToString()
            };

            return(Json(ret));
        }
 public Task Handle(CheckMessage message, IMessageHandlerContext context)
 {
     if (Data.PersistedFailingMessageResult)
     {
         CriticalError.Raise("Failure", new Exception());
     }
     else
     {
         CriticalError.Raise("Success", new Exception());
     }
     return(Task.FromResult(0));
 }
예제 #6
0
 public User LogInOnId([FromBody] CheckMessage message)
 {
     try
     {
         return(MainContext.Instance.User.GetBy(x => x.UserId == message.UserId)?.ToList()[0]);
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Exception in UserController.cs : {e.Message}");
         return(null);
     }
 }
예제 #7
0
 public List <Marker> ReturnByUserId([FromBody] CheckMessage message)
 {
     if (message?.UserId == null)
     {
         return(null);
     }
     try
     {
         var result  = new List <Marker>();
         var context = (FriendlistContext)MainContext.Instance.Friendlist;
         var friends = context.GetFriendOfUser((int)message.UserId)?.ToList();
         if (friends != null && friends.Count != 0)
         {
             friends.Add((int)message.UserId);
             result.AddRange(StaticInfo.MarkerList.Where(x => friends.Contains(x.UserId)).ToList());
         }
         if (result.Any())
         {
             return(result);
         }
         friends.Add((int)message.UserId);
         var markers = MainContext.Instance.Marker.GetAll();
         if (markers == null)
         {
             return(null);
         }
         var groups = (from marker in markers
                       group marker by marker.UserId).ToList();
         if (groups.Count == 0)
         {
             return(null);
         }
         var    keys = groups.Select(x => x.Key).Distinct().ToList();
         int    temp;
         Marker tempMarker;
         foreach (var key in keys)
         {
             temp       = groups.Single(x => x.Key == key).ToList().Max(x => x.MarkerId);
             tempMarker = MainContext.Instance.Marker
                          .GetBy(x => x.MarkerId == temp && friends.Contains(x.UserId))?.ToList()[0];
             if (tempMarker != null)
             {
                 result.Add(tempMarker);
             }
         }
         return(result);
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Exception in MarkerController.cs: {e.Message}");
         return(null);
     }
 }
예제 #8
0
 public User GetUserByLogin([FromBody] CheckMessage message)
 {
     if (string.IsNullOrEmpty(message?.Login))
     {
         return(null);
     }
     try
     {
         return(MainContext.Instance.User.GetBy(x => x.Login == message.Login)?.ToList()[0]);
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Exception in UserController.cs : {e.Message}");
         return(null);
     }
 }
예제 #9
0
 public List <User> GetFriendlistRequests([FromBody] CheckMessage message)
 {
     if (message?.UserId == null)
     {
         return(null);
     }
     try
     {
         var context = (FriendlistContext)MainContext.Instance.Friendlist;
         var indexes = context.GetRequests((int)message.UserId)?.ToList();
         return(MainContext.Instance.User.GetBy(x => indexes.Contains(x.UserId))?.ToList());
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Internal server error: {e.Message}");
         return(null);
     }
 }
예제 #10
0
 public List <User> RegexpByDeviceId([FromBody] CheckMessage message)
 {
     if (string.IsNullOrEmpty(message?.DeviceId))
     {
         return(null);
     }
     try
     {
         var rx      = new Regex(message.DeviceId + @".", RegexOptions.IgnoreCase);
         var indexes = MainContext.Instance.User.GetAll()?.Select(x => x.DeviceId).AsEnumerable();
         var result  = indexes?.Where(x => rx.IsMatch(x)).ToList();
         return(MainContext.Instance.User.GetBy(x => result.Contains(x.DeviceId))?.ToList());
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Exception in UserController.cs : {e.Message}");
         return(null);
     }
 }
        public JsonResult Validate(string data, string app)
        {
            dynamic json     = (new JsonReader()).Read(data);
            var     appToVal = OdiAppRepo.Apps.Where(a => a.Name == app).FirstOrDefault();
            var     message  = new CheckMessage()
            {
                Status = CheckMessageStatus.Ok, Message = ODI.Resources.Controllers.AppResource.MessageValidationOK
            };

            foreach (var val in appToVal.Validations)
            {
                var ret = val.Validate(json);
                if (!string.IsNullOrEmpty(ret))
                {
                    message.Status  = CheckMessageStatus.Error;
                    message.Message = ret;
                    break;
                }
            }

            return(Json(message));
        }
예제 #12
0
        public async Task Handle(CheckMessage message, IMessageHandlerContext context)
        {
            int count;
            var session     = context.SynchronizedStorageSession.SqlPersistenceSession();
            var commandText = "SELECT COUNT(*) from [dbo].[SqlTransportIntegration_UserDataConsistencyTests_Data] where Id = @Id";

            using (var command = session.Connection.CreateCommand())
            {
                command.Transaction = session.Transaction;
                command.CommandText = commandText;
                command.AddParameter("@Id", message.EntityId);
                count = (int)await command.ExecuteScalarAsync().ConfigureAwait(false);
            }

            if (count > 0)
            {
                CriticalError.Raise("Failure", new Exception());
            }
            else
            {
                CriticalError.Raise("Success", new Exception());
            }
        }
예제 #13
0
 public ResultMessage CheckExist([FromBody] CheckMessage message)
 {
     try
     {
         if (message.DeviceId.Length != 16)
         {
             return(new ResultMessage()
             {
                 Type = ResultType.Decline,
                 Message = "Device id != 16"
             });
         }
         if (MainContext.Instance.User.GetBy(x => message.DeviceId == x.DeviceId) != null)
         {
             return(new ResultMessage()
             {
                 Type = ResultType.Success,
                 Message = "There's an user in db with this deviceId"
             });
         }
         return(new ResultMessage()
         {
             Type = ResultType.Decline,
             Message = "There's no user in db with this deviceId"
         });
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Internal server exception: {ex.Message}");
         return(new ResultMessage()
         {
             Type = ResultType.UnknownError,
             Message = "Internal server error " +
                       $"{ex.Message}"
         });
     }
 }
예제 #14
0
    async Task RunTest(Action <EndpointConfiguration> testCase)
    {
        manualResetEvent.Reset();
        string message = null;

        Execute(endpointName, OutboxScriptBuilder.BuildDropScript(BuildSqlDialect.MsSqlServer));
        Execute(endpointName, OutboxScriptBuilder.BuildCreateScript(BuildSqlDialect.MsSqlServer));
        Execute(createUserDataTableText);

        var endpointConfiguration = EndpointConfigBuilder.BuildEndpoint(endpointName);

        //Hack: enable outbox to force sql session since we have no saga
        endpointConfiguration.EnableOutbox();
        var typesToScan = TypeScanner.NestedTypes <UserDataConsistencyTests>();

        endpointConfiguration.SetTypesToScan(typesToScan);
        endpointConfiguration.DisableFeature <TimeoutManager>();
        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();

        testCase(endpointConfiguration);
        transport.UseCustomSqlConnectionFactory(async() =>
        {
            var connection = MsSqlConnectionBuilder.Build();
            await connection.OpenAsync().ConfigureAwait(false);
            return(connection);
        });
        var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

        persistence.SqlDialect <SqlDialect.MsSqlServer>();
        persistence.ConnectionBuilder(MsSqlConnectionBuilder.Build);
        persistence.DisableInstaller();
        persistence.SubscriptionSettings().DisableCache();
        endpointConfiguration.DefineCriticalErrorAction(c =>
        {
            message = c.Error;
            manualResetEvent.Set();
            return(Task.FromResult(0));
        });
        endpointConfiguration.LimitMessageProcessingConcurrencyTo(1);
        endpointConfiguration.Pipeline.Register(new FailureTrigger(), "Failure trigger");

        var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

        var dataId = Guid.NewGuid();

        var failingMessage = new FailingMessage
        {
            EntityId = dataId
        };
        await endpoint.SendLocal(failingMessage).ConfigureAwait(false);

        var checkMessage = new CheckMessage
        {
            EntityId = dataId
        };
        await endpoint.SendLocal(checkMessage).ConfigureAwait(false);

        manualResetEvent.WaitOne();
        await endpoint.Stop().ConfigureAwait(false);

        Assert.AreEqual("Success", message);
    }
예제 #15
0
 public Person GetPersonByUserId([FromBody] CheckMessage message)
 {
     return(MainContext.Instance.Person.GetBy(x => x.UserId == message.UserId)?.ToList()[0]);
 }
예제 #16
0
        public JsonResult InitAzure(string id, string subId, string name, string key)
        {
            CheckMessage ret;
            string       errorMessage = null;

            if (string.IsNullOrEmpty(subId))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorSubscriptionId;
            }
            else if (string.IsNullOrEmpty(name))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorStorageAccountName;
            }
            else if (string.IsNullOrEmpty(key))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorPrimaryAccessKey;
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                try
                {
                    var creds = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", name, key);
                    CloudStorageAccount sa = CloudStorageAccount.Parse(creds);
                    CloudBlobClient     bc = sa.CreateCloudBlobClient();
                    bc.ListContainers();
                }
                catch (Exception e)
                {
                    errorMessage = string.Format(ODPI.Resources.Controllers.CheckResource.StorageAccountException, e.Message);
                }
            }

            string xml = null;

            if (string.IsNullOrEmpty(errorMessage))
            {
                try
                {
                    xml = AzureManagement.GetHostedServices(subId, CertificateBuilder.GetPrivateKey(id));
                    XNamespace xmlns = "http://schemas.microsoft.com/windowsazure";
                    var        doc   = XDocument.Parse(xml);

                    var services = from hs in doc.Descendants(xmlns + "HostedService")
                                   select hs.Element(xmlns + "ServiceName").Value;

                    if (services.Count() > 0)
                    {
                        ret = new CheckMessage()
                        {
                            Status = CheckMessageStatus.Ok,
                            Data   = new
                            {
                                Services = services.ToArray <string>()
                            }
                        };

                        return(Json(ret));
                    }
                    else
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorNoHostedServiceFound;
                    }
                }
                catch (WebException we)
                {
                    var resp = we.Response as HttpWebResponse;

                    if (resp.StatusCode == HttpStatusCode.NotFound)
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorCouldNotConnectToAzure;
                    }
                    if (resp.StatusCode == HttpStatusCode.Forbidden)
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorCouldNotMakeSecureConnection;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage = ODPI.Resources.Controllers.CheckResource.UnknownError + ex.Message;
                }
            }



            ret = new CheckMessage()
            {
                Status  = CheckMessageStatus.Error,
                Message = errorMessage
            };

            return(Json(ret));
        }