Beispiel #1
0
        public async Task <ActionResult <ConnectionSet> > GetShares()
        {
            ConnectionSet connectionSet = new ConnectionSet();

            try
            {
                var profile    = _profileStorage.Current;
                var connection = _connectionFinder.GetPrimaryLITEConnection(profile);
                var dirs       = Directory.GetDirectories(connection.resourcePath + Path.DirectorySeparatorChar + connection.name);

                foreach (var dir in dirs)
                {
                    ShareDestinations dest = new ShareDestinations
                    {
                        boxUuid = dir.Replace(profile.tempPath + Path.DirectorySeparatorChar + connection.name + Path.DirectorySeparatorChar, "")
                    };
                    connectionSet.shareDestinations.Add(dest);
                    connectionSet.connectionName = connection.ServicePoint;
                }
            }
            catch (DirectoryNotFoundException)
            {
            }

            return(connectionSet);
        }
Beispiel #2
0
        public override void Init()
        {
            if (Connection.Boxes.Count == 0)
            {
                //add sample box
                ShareDestinations shareDestinations = new ShareDestinations
                {
                    boxUuid = "19db62ba-128d-412c-8c4f-df28351e8ae0",
                    boxName = "LITESample"
                };
                Connection.Boxes.Add(shareDestinations);
            }

            List <string> fileEntries;

            string dir;

            lock (InitLock)
            {
                LITETask.Register($"{Connection.name}.Wado", Connection.maxWadoTasks);
                LITETask.Register($"{Connection.name}.Stow", Connection.maxStowTasks);
                LITETask.Register($"{Connection.name}.downloadStudy", Connection.maxStudyDownloadTasks);
                LITETask.Register($"{Connection.name}.putHL7", Connection.maxHL7UploadTasks);
                LITETask.Register($"{Connection.name}.PostResponse", Connection.maxPostResponseTasks);

                if (loginNeeded)
                {
                    base.Init();
                    int newTaskID = LITETask.NewTaskID();


                    // Register is a one-time operation.  Once you have your tenantID, don't call this again, but populate the tenantID upon class instantiation.
                    if (Connection.tenantID == null)
                    {
                        register(newTaskID).Wait();
                    }

                    // if you tried to register and you still don't have a tenantID, we're done.
                    if (Connection.tenantID == null)
                    {
                        _logger.Log(LogLevel.Warning, $"Account is not registered.");
                        return;
                    }

                    // //login
                    // newTaskID = LITETask.newTaskID();
                    // var result = login(newTaskID).Result;
                    // if (result != "OK")
                    // {
                    //     return;  //this is to prevent reading in work below if we don't login.
                    // }
                }

                //read the persisted RoutedItems bound for Cloud

                dir = _profileStorage.Current.tempPath +
                      Path.DirectorySeparatorChar +
                      Connection.name +
                      Path.DirectorySeparatorChar +
                      Constants.Dirs.ToCloud +
                      Path.DirectorySeparatorChar +
                      Constants.Dirs.Meta;

                Directory.CreateDirectory(dir);
                fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

                foreach (string file in fileEntries)
                {
                    var st = _routedItemLoader.LoadFromFile(file);
                    if (st == null)
                    {
                        continue;
                    }

                    st.fromConnection = Connection.name;

                    if (!Connection.toCloud.Contains(st))
                    {
                        Connection.toCloud.Add(st);
                    }
                }
            }

            //read the persisted RoutedItems bound for Rules

            dir = _profileStorage.Current.tempPath +
                  Path.DirectorySeparatorChar +
                  Connection.name +
                  Path.DirectorySeparatorChar +
                  Constants.Dirs.ToRules +
                  Path.DirectorySeparatorChar +
                  Constants.Dirs.Meta;

            Directory.CreateDirectory(dir);
            fileEntries = _util.DirSearch(dir, Constants.Extensions.MetaExt.ToSearchPattern());

            foreach (string file in fileEntries)
            {
                RoutedItem ri = _routedItemLoader.LoadFromFile(file);
                if (ri == null)
                {
                    continue;
                }

                ri.fromConnection = Connection.name;

                if (!toRules.Contains(ri))
                {
                    toRules.Add(ri);
                }
            }

            Connection.started = true;
        }
        /// <summary>
        /// Evaluate the rule sets to see which ones match the from connection and send on to the toConnections.
        /// </summary>
        /// <param name="Item"></param>
        /// <param name="routedItem"></param>
        /// <returns></returns>
        public List <ConnectionSet> Eval(Rules Item, RoutedItem routedItem)
        {
            Throw.IfNull(Item);
            var taskInfo = $"task: {routedItem.TaskID} id: {routedItem.id}";

            var connList = new List <ConnectionSet>();

            if (routedItem.toConnections.Count > 0)
            {
                //we've already been told where to send the request, just return it
                _logger.Log(LogLevel.Debug, $"{taskInfo} toConnections already populated, skipping eval.");

                return(routedItem.toConnections);
            }
            else
            {
                foreach (var destRule in Item.destRules.FindAll(e => e.fromConnectionName == routedItem.fromConnection && e.enabled == true))
                {
                    //2018-08-07 shb BOUR-630 check the destination connections to see if they are enabled.  If there is no enabled destination then don't add the connection set
                    int enabledDest = 0;
                    foreach (var dest in destRule.toConnections)
                    {
                        enabledDest += _profileStorage.Current.connections.FindAll(e => e.name == dest.connectionName && e.enabled == true).Count;
                    }
                    if (enabledDest > 0)
                    {
                        if (_doesRuleMatchService.DoesRuleMatch(routedItem, destRule))
                        {
                            _logger.Log(LogLevel.Debug, $"{taskInfo} evaluates to {destRule.toConnections.Count} connections.");

                            connList.AddRange(destRule.toConnections);
                            if (destRule.Type == DestRule.RuleType.AddressableRoute)
                            {
                                foreach (var con in connList)
                                {
                                    //amend the connlist sharing destintations with matches
                                    foreach (var match in destRule.matches)
                                    {
                                        ShareDestinations sd = new ShareDestinations
                                        {
                                            boxUuid = match.ToString()
                                        };
                                        con.shareDestinations.Add(sd);
                                    }
                                }
                            }
                        }
                    }
                }

                if (connList.Count == 0)
                {
                    _logger.Log(LogLevel.Warning, $"{taskInfo} There are no routes for {routedItem.fromConnection}.");
                }
            }

            //do we need to flatten in case of duplicates?

            // foreach (var conn in profile.connections.FindAll(e => e.enabled == true))
            // {
            //     if (conn.enabled == true)
            //     {
            //         foreach (var connectionSet in connListNames)
            //         {
            //             if (conn.name.Equals(connectionSet.connectionName))
            //             {
            //                 if(Logger.logger.FileTraceLevel == "Verbose") _logger.Log(LogLevel.Debug, $"conn {conn.name} succeeds because == {connectionSet.connectionName}");
            //                 connList.Add(connectionSet);
            //             }
            //             else
            //             {

            //                 if(Logger.logger.FileTraceLevel == "Verbose") _logger.Log(LogLevel.Debug, $"conn {conn.name} fails because != {connectionSet.connectionName}");

            //             }
            //         }
            //     }
            // }

            //for request/response mechanism route to connections that can provide this functionality
            //trim the connList to only those connections that  support request/response
            if (routedItem.type == RoutedItem.Type.RPC)
            {
                foreach (var conn in connList.ToArray())
                {
                    if (_profileStorage.Current.connections.FindAll(e => e.name == conn.connectionName && e.enabled && e.requestResponseEnabled).Count == 0)
                    {
                        _logger.Log(LogLevel.Debug, $"{conn.connectionName} is being removed from destinations because requestResponseEnabled: false");
                        connList.Remove(conn);
                    }
                }
            }

            return(connList);
        }