public ListAliasesResult ListAliases(AuthenticatedData data)
        {
            try
            {
                if (!data.Authenticate())
                {
                    return(null);
                }

                ListAliasesResult result = new ListAliasesResult();

                using (var db = new CSSDataContext())
                {
                    result.Aliases = Alias.ListDecoratedAliases(db, data.Username, true);

                    result.AvailableAliasCount = Alias.GetAliasCount(db, data.Username);
                }

                return(result);
            }
            catch (Exception error)
            {
                Error.Write(error);
                throw;
            }
        }
Ejemplo n.º 2
0
        public static void RetrieveCallsigns(RetrieveCallsignsCompleteDelegate onCompleteDelegate, bool reloadFromServer)
        {
            //Check the datastore to see if callsigns have already been loaded
            var callsigns = DataStore.Callsigns;

            if (callsigns == null || reloadFromServer == true)
            {
                callsigns = new List <Callsign>();

                //If not, retrieve the callsign list from the server
                TaskHandler.RunTask(delegate(object data)
                {
                    var parameters          = data as object[];
                    var signal              = parameters[0] as RetrieveCallsignsCompleteDelegate;
                    var list                = parameters[1] as List <Callsign>;
                    int availableAliasCount = (int)parameters[2];

                    try
                    {
                        ListAliasesResult aliases = ServiceHandler.Service.ListAliases(new AuthenticatedData());

                        if (aliases == null)
                        {
                            signal(new List <Callsign>(), 0);
                            return;
                        }

                        list = new List <Callsign>();
                        bool foundLastAliasMatch = false;
                        foreach (var alias in aliases.Aliases)
                        {
                            list.Add(new Callsign()
                            {
                                Default = alias.IsDefault,
                                Name    = alias.Callsign,
                                Active  = alias.IsActive,
                                Id      = alias.Id
                            });

                            if (DataStore.LastAlias == alias.Callsign)
                            {
                                foundLastAliasMatch = true;
                            }
                        }

                        if (foundLastAliasMatch == false || DataStore.LastAlias == null)
                        {
                            if (list.Count > 0)
                            {
                                DataStore.LastAlias = list[0].Name;
                            }
                            else
                            {
                                DataStore.LastAlias = null;
                            }
                        }

                        DataStore.AvailableAliasCount = aliases.AvailableAliasCount;

                        //Store callsign list to datastore
                        DataStore.Callsigns = list;
                        DataStore.Instance.Save();
                    }
                    catch (Exception error)
                    {
                        Log.Write(error);
                    }

                    //Signal to the calling thread that the operation is complete
                    signal(DataStore.Callsigns, DataStore.AvailableAliasCount);
                }, onCompleteDelegate, DataStore.Callsigns, DataStore.AvailableAliasCount);
            }
            else
            {
                onCompleteDelegate(DataStore.Callsigns, DataStore.AvailableAliasCount);
            }
        }