Example #1
0
        public IDictionary <string, IStorageContext> GenerateStorageContexts <T>(string rountingName, int top,
                                                                                 IFilterCondition[] where,
                                                                                 IOrderByCondition[] orderby)
            where T : class, IAlbianObject, new()
        {
            IDictionary <string, IStorageContext> storageContexts = new Dictionary <string, IStorageContext>();
            IFakeCommandBuilder   fakeBuilder           = new FakeCommandBuilder();
            IFakeCommandAttribute fakeCommandAttrribute = fakeBuilder.GenerateQuery <T>(rountingName, top, where, orderby);

            if (null == fakeCommandAttrribute) //the PermissionMode is not enough
            {
                if (null != Logger)
                {
                    Logger.WarnFormat("The permission is not enough in the {0} routing.", rountingName);
                }
                throw new PersistenceException(string.Format("The permission is not enough in the {0} routing.",
                                                             rountingName));
            }

            IStorageContext storageContext = new StorageContext
            {
                FakeCommand = new List <IFakeCommandAttribute>(),
                StorageName = fakeCommandAttrribute.StorageName,
            };

            storageContext.FakeCommand.Add(fakeCommandAttrribute);
            storageContexts.Add(fakeCommandAttrribute.StorageName, storageContext);
            return(storageContexts);
        }
Example #2
0
        public ITask BuildQueryTask <T>(string rountingName, int top, IFilterCondition[] where,
                                        IOrderByCondition[] orderby)
            where T : class, IAlbianObject, new()
        {
            ITask task = new Task();
            IFakeCommandBuilder    fakeBuilder                    = new FakeCommandBuilder();
            IStorageContextBuilder storageContextBuilder          = new StorageContextBuilder();
            IDictionary <string, IStorageContext> storageContexts =
                storageContextBuilder.GenerateStorageContexts <T>(rountingName, top, where, orderby);

            task.Context = storageContexts;
            foreach (KeyValuePair <string, IStorageContext> context in task.Context)
            {
                IStorageContext storageContext = context.Value;
                object          oStorage       = StorageCache.Get(context.Key);
                if (null == oStorage)
                {
                    if (null != Logger)
                    {
                        Logger.ErrorFormat("There is no {0} storage attribute in the storage cached.",
                                           storageContext.StorageName);
                    }
                    return(null);
                }
                IStorageAttribute storage = (IStorageAttribute)oStorage;
                storageContext.Storage = storage;
            }
            return(task);
        }
Example #3
0
        public ITask BuildSaveTask <T>(T target)
            where T : IAlbianObject
        {
            ITask task = new Task();
            IFakeCommandBuilder    fakeBuilder           = new FakeCommandBuilder();
            IStorageContextBuilder storageContextBuilder = new StorageContextBuilder();

            task.Context = storageContextBuilder.GenerateStorageContexts(target,
                                                                         fakeBuilder.GenerateFakeCommandByRoutings,
                                                                         fakeBuilder.BuildSaveFakeCommandByRouting);
            foreach (KeyValuePair <string, IStorageContext> context in task.Context)
            {
                IStorageContext storageContext = context.Value;
                object          oStorage       = StorageCache.Get(context.Key);
                if (null == oStorage)
                {
                    if (null != Logger)
                    {
                        Logger.ErrorFormat("There is no {0} storage attribute in the storage cached.",
                                           storageContext.StorageName);
                    }
                    return(null);
                }
                IStorageAttribute storage = (IStorageAttribute)oStorage;
                storageContext.Storage = storage;
            }
            return(task);
        }
Example #4
0
        public ITask BuildCreateTask <T>(IList <T> target)
            where T : IAlbianObject
        {
            ITask task = new Task();
            IFakeCommandBuilder    fakeBuilder           = new FakeCommandBuilder();
            IStorageContextBuilder storageContextBuilder = new StorageContextBuilder();

            foreach (T o in target)
            {
                IDictionary <string, IStorageContext> storageContexts = storageContextBuilder.GenerateStorageContexts(o,
                                                                                                                      fakeBuilder
                                                                                                                      .
                                                                                                                      GenerateFakeCommandByRoutings,
                                                                                                                      fakeBuilder
                                                                                                                      .
                                                                                                                      BuildCreateFakeCommandByRouting);
                if (null == storageContexts || 0 == storageContexts.Count)
                {
                    if (null != Logger)
                    {
                        Logger.Error("The storagecontexts is empty.");
                    }
                    throw new Exception("The storagecontexts is null.");
                }
                if (null == task.Context || 0 == task.Context.Count)
                {
                    task.Context = storageContexts;
                    continue;
                }
                foreach (KeyValuePair <string, IStorageContext> storageContext in storageContexts)
                {
                    if (task.Context.ContainsKey(storageContext.Key))
                    {
                        task.Context[storageContext.Key].FakeCommand = task.Context.ContainsKey(storageContext.Key)
                                                                           ? Utils.Concat(
                            task.Context[storageContext.Key].
                            FakeCommand,
                            storageContext.Value.FakeCommand)
                                                                           : storageContext.Value.FakeCommand;
                    }
                    else
                    {
                        task.Context.Add(storageContext);
                    }
                }
            }

            foreach (KeyValuePair <string, IStorageContext> context in task.Context)
            {
                IStorageContext storageContext = context.Value;
                object          oStorage       = StorageCache.Get(context.Key);
                if (null == oStorage)
                {
                    if (null != Logger)
                    {
                        Logger.ErrorFormat("There is no {0} storage attribute in the storage cached.",
                                           storageContext.StorageName);
                    }
                    return(null);
                }
                IStorageAttribute storage = (IStorageAttribute)oStorage;
                storageContext.Storage = storage;
            }
            return(task);
        }