Example #1
0
 public CreateShelfService(string serviceName, ShelfType shelfType, Type bootstrapperType, AssemblyName[] assemblyNames)
 {
     ServiceName = serviceName;
     ShelfType = shelfType;
     BootstrapperType = bootstrapperType;
     AssemblyNames = assemblyNames;
 }
Example #2
0
        public ShelfServiceController(Inbox inbox, string name, IServiceChannel coordinatorChannel, ShelfType shelfType,
                                      Type bootstrapperType, AssemblyName[] assemblyNames)
        {
            _inbox            = inbox;
            _name             = name;
            _publish          = new PublishChannel(coordinatorChannel, inbox);
            _shelfType        = shelfType;
            _bootstrapperType = bootstrapperType;
            _assemblyNames    = assemblyNames;

            _inbox.Loop(loop =>
            {
                loop.Receive <ShelfCreated>(x =>
                {
                    ShelfCreated(x);
                    loop.Continue();
                });

                loop.Receive <ServiceUnloaded>(x =>
                {
                    ShelfUnloaded(x);
                    loop.Continue();
                });
            });
        }
Example #3
0
        // DELETE: odata/ShelfTypes(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            ShelfType shelftype = null;

            try
            {
                shelftype = data.ShelfTypeRepository.GetByID(key);
                if (shelftype == null)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "ShelfType cannot be found");
                    throw new Exception("ShelfType cannot be found");
                }
                data.ShelfTypeRepository.Delete(key);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception deleting shelftype by key = '" + Convert.ToString(key) + "' :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception deleting shelftype by key = '" + Convert.ToString(key) + "' :: " + ex.ToString()),
                    ReasonPhrase = "Unable to delete shelftype"
                };
                throw new HttpResponseException(resp);
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        // POST: odata/ShelfTypes
        public IHttpActionResult Post(ShelfType shelfType)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            try
            {
                if (!ModelState.IsValid)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Invalid ModelState");
                    throw new Exception("Invalid modelstate");
                }

                data.ShelfTypeRepository.Insert(shelfType);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception creating shelftype :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception creating shelftype :: " + ex.ToString()),
                    ReasonPhrase = "Unable to create shelftype"
                };
                throw new HttpResponseException(resp);
            }

            return(Created(shelfType));
        }
Example #5
0
 public CreateShelfService(string serviceName, ShelfType shelfType, Type bootstrapperType, AssemblyName[] assemblyNames)
 {
     ServiceName      = serviceName;
     ShelfType        = shelfType;
     BootstrapperType = bootstrapperType;
     AssemblyNames    = assemblyNames;
 }
Example #6
0
        static AppDomainSetup ConfigureAppDomainSettings(string serviceName, ShelfType shelfType)
        {
            AppDomainSetup domainSettings = AppDomain.CurrentDomain.SetupInformation;

            if (shelfType == ShelfType.Internal)
            {
                //_domainSettings.LoaderOptimization = LoaderOptimization.MultiDomain;
                return(domainSettings);
            }

            domainSettings.ShadowCopyFiles = "true";

            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            string servicesDirectory = ConfigurationManager.AppSettings["MonitorDirectory"] ?? "Services";

            domainSettings.ApplicationBase = Path.Combine(baseDirectory, Path.Combine(servicesDirectory, serviceName));
            _log.DebugFormat("[{0}].ApplicationBase = {1}", serviceName, domainSettings.ApplicationBase);

            domainSettings.ConfigurationFile = Path.Combine(domainSettings.ApplicationBase, serviceName + ".config");

            _log.DebugFormat("[{0}].ConfigurationFile = {1} -- {2}", serviceName, domainSettings.ConfigurationFile,
                             File.Exists(domainSettings.ConfigurationFile) ? "Found config file" : "DID NOT FIND CONFIGURATION FILE!");

            return(domainSettings);
        }
Example #7
0
        public ShelfReference(string serviceName, ShelfType shelfType, UntypedChannel controllerChannel)
        {
            _serviceName       = serviceName;
            _shelfType         = shelfType;
            _controllerChannel = controllerChannel;

            _domainSettings = ConfigureAppDomainSettings(_serviceName, _shelfType);

            _domain = AppDomain.CreateDomain(serviceName, null, _domainSettings);
        }
Example #8
0
        // PUT: odata/ShelfTypes(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <ShelfType> patch)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            ShelfType shelftype = null;

            try
            {
                Validate(patch.GetChangedPropertyNames());

                if (!ModelState.IsValid)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Invalid ModelState");
                    throw new Exception("Invalid modelstate");
                }

                shelftype = data.ShelfTypeRepository.GetByID(key);
                if (shelftype == null)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Unable to find ShelfType by Key = '" + Convert.ToString(key) + "'");
                    throw new Exception("Unable to find shelftype by key");
                }

                patch.Put(shelftype);
                try
                {
                    data.Save();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!ShelfTypeExists(key))
                    {
                        NLogWriter.LogMessage(LogType.Error, LogMsg + "DbUpdateConcurrencyException putting shelftype by ID '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                        throw new Exception("DbUpdateConcurrencyException putting shelftype by ID = '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception updating shelftype :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception updating shelftype :: " + ex.ToString()),
                    ReasonPhrase = "Unable to udpate shelftype"
                };
                throw new HttpResponseException(resp);
            }
            return(Updated(shelftype));
        }
        public List <MyBook> GetBooksInShelf(ShelfType type)
        {
            var bookshelves = _library.GetBookshelvesByType(type);

            List <MyBook> books = new List <MyBook>();

            foreach (var bookshelf in bookshelves)
            {
                books.AddRange(bookshelf.Books);
            }

            return(books);
        }
Example #10
0
 public CreateShelfService(string serviceName, ShelfType shelfType, Type bootstrapperType)
     : this(serviceName, shelfType, bootstrapperType, new AssemblyName[] {})
 {
 }
Example #11
0
 public CreateShelfService(string serviceName, ShelfType shelfType)
     : this(serviceName, shelfType, null)
 {
 }
Example #12
0
 public MyBookshelf(ShelfType type, List <MyBook> books)
 {
     ShelfType = type;
     Books     = books;
 }
 public IEnumerable <MyBookshelf> GetBookshelvesByType(ShelfType type)
 {
     return(_library.Where(shelf => shelf.ShelfType == type));
 }
Example #14
0
 public CreateShelfService(string serviceName, ShelfType shelfType, Type bootstrapperType)
     : this(serviceName, shelfType, bootstrapperType, new AssemblyName[] {})
 {
 }