Ejemplo n.º 1
0
 /// <summary>
 /// Возвращает набор идентификаторов версий файлов с удаленного узла.
 /// </summary>
 /// <param name="remoteNode">Удаленный узел хранилища.</param>
 /// <param name="requestStorageID">Идентификатор узла, запрашиваюшего информацию (текущий узел)</param>
 /// <param name="folderUrl">Адрес папки.</param>
 /// <param name="from">Дата, с которой необходимо забрать изменения.</param>
 /// <returns></returns>/// <summary>
 public Tuple <Guid, Guid>[] GetReplicationFiles(IStorageNode remoteNode, Guid requestStorageID, string folderUrl, DateTime @from)
 {
     return
         (this.MakeRequest(
              x => x.GetReplicationFiles(this.CurrentNode.UniqueID, folderUrl, @from),
              remoteNode.Host));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Обмен схем репликации текущего узла с узлом storageHost.
        /// </summary>
        /// <param name="remoteNode">Удаленный узел хранилища.</param>
        /// <param name="currentReplicationSchema">Схема репликации текущего узла.</param>
        /// <returns></returns>
        public IReplicationSchema ExchangeSchema(IStorageNode remoteNode, IReplicationSchema currentReplicationSchema)
        {
            if (remoteNode == null)
            {
                throw new ArgumentNullException("remoteNode");
            }

            if (currentReplicationSchema == null)
            {
                throw new ArgumentNullException("currentReplicationSchema");
            }

            return(this.MakeRequest(x =>
            {
                //схема репликации сети, известная текущему узлу
                WcfReplicationSchema typedCurrentReplicationSchema =
                    new WcfReplicationSchema(currentReplicationSchema);
                WcfReplicationSchemaMessage exchangeMessage =
                    new WcfReplicationSchemaMessage(typedCurrentReplicationSchema);
                //посылаем текущую схему узлу, к которому обращаемся
                //и получаем его схему с узла назначения
                WcfReplicationSchemaMessage remoteSchemaMessage =
                    x.ExchangeSchema(exchangeMessage);
                return new WcfReplicationSchema(remoteSchemaMessage);
            }, remoteNode.Host));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Возвращает версию файла для репликации.
        /// </summary>
        /// <param name="remoteNode">Удаленный узел хранилища.</param>
        /// <param name="folderUrl">Папка файла.</param>
        /// <param name="fileUniqueID">Идентификатор файла.</param>
        /// <param name="fileVersionUniqueID">Идентификатор версии.</param>
        /// <returns></returns>
        public IRemoteFile GetReplicationFile(IStorageNode remoteNode, string folderUrl, Guid fileUniqueID, Guid fileVersionUniqueID)
        {
            if (remoteNode == null)
            {
                throw new ArgumentNullException("remoteNode");
            }

            if (string.IsNullOrEmpty(folderUrl))
            {
                throw new ArgumentNullException("folderUrl");
            }

            WcfRemoteFile remoteFile = null;

            try
            {
                ChannelFactory <IStorageReplicationService> channelFactory = this.CreateServiceChannel(remoteNode.Host);
                using (channelFactory)
                {
                    IStorageReplicationService client   = channelFactory.CreateChannel();
                    WcfRemoteFileInfo          fileInfo = WcfRemoteFileInfo.FromRemoteFileInfo(folderUrl, fileUniqueID, fileVersionUniqueID);
                    remoteFile = client.GetReplicationFile(fileInfo);
                }
            }
            catch (Exception ex)
            {
                this.Logger.WriteMessage(ex.ToString(), LogLevel.Error);
            }

            return(remoteFile);
        }
Ejemplo n.º 4
0
        private void ObserveWorker(object state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            string host      = state.ToString();
            bool   nodeAdded = false;

            while (!nodeAdded)
            {
                try
                {
                    IStorageNode node = this.ReplicationAdapter.Transport.GetStorageInfo(host);
                    if (node != null)
                    {
                        bool justCreated;
                        this.EnsureNode(node.UniqueID, node.Host, out justCreated);
                        //узел добавлен, можно отпустит поток
                        nodeAdded = true;
                    }
                }
                catch (Exception ex)
                {
                    this.Engine.Logger.WriteMessage(ex.ToString());
                }
                finally
                {
                    Thread.Sleep(Timeouts.Observe);
                }
            }
        }
        /// <summary>剪切待办信息</summary>
        /// <param name="applicationId">所属应用标识</param>
        /// <param name="fromReceiverId">待办来源接收者标识</param>
        /// <param name="toReceiverId">待办目标接收者标识</param>
        /// <param name="beginDate">复制待办的开始时间</param>
        /// <param name="endDate">复制待办结束时间</param>
        /// <returns></returns>
        public int Cut(string applicationId, string fromReceiverId, string toReceiverId, DateTime beginDate, DateTime endDate)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query", toReceiverId);

            string whereClause = string.Format(" ApplicationId = ##{0}## AND Status = 0 AND CreateDate BETWEEN ##{0}## AND ##{1}## ", applicationId, beginDate, endDate);

            if (string.IsNullOrEmpty(applicationId))
            {
                whereClause = string.Format(" Status = 0 AND CreateDate BETWEEN ##{0}## AND ##{1}## ", beginDate, endDate);
            }

            IList <TaskWorkItemInfo> list = this.FindAllByReceiverId(fromReceiverId, whereClause);

            foreach (TaskWorkItemInfo item in list)
            {
                Dictionary <string, object> args = new Dictionary <string, object>();

                args.Add("Id", item.Id);
                args.Add("FromReceiverId", fromReceiverId);
                args.Add("ToReceiverId", toReceiverId);
                args.Add("Status", item.Status);
                args.Add("IsRead", 0);
                args.Add("FinishTime", new DateTime(2000, 1, 1));

                this.ibatisMappers[storageNode.Name].Insert(StringHelper.ToProcedurePrefix(string.Format("{0}_Cut", this.tableName)), args);
            }

            return(0);
        }
Ejemplo n.º 6
0
        private TestSuite(string testEnginePath, TestSuiteInstallation testSuiteInstallation, IStorageNode storageRoot)
        {
            TestEnginePath = testEnginePath;

            Id = testSuiteInstallation.Id;

            Name = testSuiteInstallation.Name;

            Description = testSuiteInstallation.Description;

            Removed = testSuiteInstallation.Removed;

            InstallMethod = testSuiteInstallation.InstallMethod;

            Version = testSuiteInstallation.Version;

            StorageRoot = storageRoot;

            // check if Plugin/config.xml can be found in TestSuite, if not then throw a new exception.
            string configXmlPath = Path.Combine(StorageRoot.GetNode(TestSuiteConsts.PluginFolderName).AbsolutePath, TestSuiteConsts.PluginConfigXml);

            if (!File.Exists(configXmlPath))
            {
                throw new Exception($"TestSuite requires plugin xml:{configXmlPath}!");
            }
            this.TestSuiteConfigFilePath = configXmlPath;
        }
Ejemplo n.º 7
0
        public ReplicationFolder(StorageEngine storage, Folder folder, IStorageNode node, IReplicationFolderMetadata metadata)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            this.TypedStorage  = storage;
            this.TypedFolder   = folder;
            this.Metadata      = metadata;
            this.SourceStorage = node;
        }
        /// <summary>转储所有记录信息</summary>
        /// <returns>返回一个<see cref="AccountCacheInfo"/>列表</returns>
        public IList <AccountCacheInfo> Dump()
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            Dictionary <string, object> args = new Dictionary <string, object>();

            return(this.ibatisMappers[storageNode.Name].QueryForList <AccountCacheInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_Dump", tableName)), args));
        }
Ejemplo n.º 9
0
        public WcfStorageInfo(IStorageNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            this.Node = node;
        }
        /// <summary>设置任务完成</summary>
        /// <param name="receiverId">接收者</param>
        public void SetFinished(string receiverId)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" ReceiverId = '{0}' ", receiverId));

            this.ibatisMappers[storageNode.Name].Update(StringHelper.ToProcedurePrefix(string.Format("{0}_SetFinished", this.tableName)), args);
        }
        private static string GetTestSuiteVersion(IStorageNode testSuiteInstallNode)
        {
            var binNode = testSuiteInstallNode.GetNode(TestSuiteConsts.Bin);

            using var versionFile = binNode.ReadFile(TestSuiteConsts.VersionFile);
            using var rs          = new StreamReader(versionFile);
            var version = rs.ReadLine();

            return(version);
        }
        /// <summary>获取任务标签列表</summary>
        /// <param name="key">匹配标签的关键字, 空值则全部匹配</param>
        public IList <string> GetTaskTags(string key)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.IsNullOrEmpty(key) ? string.Empty : string.Format(" Category LIKE '%{0}%' ", StringHelper.ToSafeSQL(key)));

            return(this.ibatisMappers[storageNode.Name].QueryForList <string>(StringHelper.ToProcedurePrefix(string.Format("{0}_GetTaskTags", this.tableName)), args));
        }
Ejemplo n.º 13
0
 public ReadTransaction(IStorageNode Node, long MinSequenceNumber, Action<long> UpdateSequenceNumber)
 {
     node = Node;
     id = Node.BeginTransaction()
          .Then(n =>
          {
              if (n > MinSequenceNumber) UpdateSequenceNumber(n);
              return Math.Max(n, MinSequenceNumber);
          });
 }
        /// <summary>转储所有记录信息</summary>
        /// <param name="accountCacheValue">帐号缓存的值</param>
        /// <returns>返回一个<see cref="AccountCacheInfo"/>列表</returns>
        public IList <AccountCacheInfo> Dump(string accountCacheValue)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" AccountCacheValue = '{0}' ", StringHelper.ToSafeSQL(accountCacheValue)));

            return(this.ibatisMappers[storageNode.Name].QueryForList <AccountCacheInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_Dump", tableName)), args));
        }
        /// <summary>查找某条记录</summary>
        /// <param name="accountCacheValue">帐号缓存的值</param>
        /// <returns>返回一个实例<see cref="AccountCacheInfo"/>的详细信息</returns>
        public AccountCacheInfo FindByAccountCacheValue(string accountCacheValue)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("AccountCacheValue", StringHelper.ToSafeSQL(accountCacheValue, true));

            return(this.ibatisMappers[storageNode.Name].QueryForObject <AccountCacheInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_FindByAccountCacheValue", tableName)), args));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Создает клиента сервиса репликации.
        /// </summary>
        /// <param name="storageNode">Целевой узел файлового хранилища.</param>
        /// <returns></returns>
        private ChannelFactory <IStorageReplicationService> CreateServiceChannel(IStorageNode storageNode)
        {
            if (storageNode == null)
            {
                throw new ArgumentNullException("storageNode");
            }

            ChannelFactory <IStorageReplicationService> channel = this.CreateServiceChannel(storageNode.Host);

            return(channel);
        }
        /// <summary>查询某条记录</summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="receiverId">接收人标识</param>
        /// <returns>返回一个 TaskWorkReceiverInfo 实例的详细信息</returns>
        public TaskWorkItemInfo FindOne(string taskId, string receiverId)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("TaskId", taskId);
            args.Add("ReceiverId", receiverId);

            return(this.ibatisMappers[storageNode.Name].QueryForObject <TaskWorkItemInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_FindOne", this.tableName)), args));
        }
        /// <summary>清理过期时间之前的缓存记录</summary>
        /// <param name="expiryTime">过期时间</param>
        public int Clear(DateTime expiryTime)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node");

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" ValidTo < '{0}' ", expiryTime.ToString("yyyy-MM-dd HH:mm:ss")));

            this.ibatisMappers[storageNode.Name].Delete(StringHelper.ToProcedurePrefix(string.Format("{0}_Delete", tableName)), args);

            return(0);
        }
        /// <summary>删除记录</summary>
        /// <param name="accountIdentity">帐号会话唯一标识</param>
        public int Delete(string accountIdentity)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", accountIdentity);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" AccountIdentity < '{0}' ", StringHelper.ToSafeSQL(accountIdentity, true)));

            this.ibatisMappers[storageNode.Name].Delete(StringHelper.ToProcedurePrefix(string.Format("{0}_Delete", tableName)), args);

            return(0);
        }
        /// <summary>添加记录</summary>
        /// <param name="param">TaskWorkInfo 实例的详细信息</param>
        public void Insert(TaskWorkInfo param)
        {
            IList <TaskWorkItemInfo> list = param.GetTaskWorkItems();

            // 接收者信息
            foreach (TaskWorkItemInfo item in list)
            {
                IStorageNode storageNode = storageStrategy.GetStorageNode("Node", item.ReceiverId);

                this.ibatisMappers[storageNode.Name].Insert(StringHelper.ToProcedurePrefix(string.Format("{0}_Insert", this.tableName)), item);
            }
        }
        /// <summary>强制设置任务状态</summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="receiverId">接收者的用户名</param>
        /// <param name="status">状态</param>
        public void SetStatus(string taskId, string receiverId, int status)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("Id", taskId);
            args.Add("ReceiverId", receiverId);
            args.Add("Status", status);

            this.ibatisMappers[storageNode.Name].Update(StringHelper.ToProcedurePrefix(string.Format("{0}_SetStatus", this.tableName)), args);
        }
        // -------------------------------------------------------
        // 添加 删除 修改
        // -------------------------------------------------------

        #region 函数:Save(IStorageNode param)
        /// <summary>保存记录</summary>
        /// <param name="param">实例<see cref="IStorageNode"/>详细信息</param>
        /// <returns>实例<see cref="IStorageNode"/>详细信息</returns>
        public IStorageNode Save(IStorageNode param)
        {
            if (!this.IsExist(param.Id))
            {
                this.Insert(param);
            }
            else
            {
                this.Update(param);
            }

            return(param);
        }
Ejemplo n.º 23
0
        // 6.代理类型 ProxyTypes
        public static void Main26(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            ProxyGenerator generator = new ProxyGenerator();
            IStorageNode   node      = generator.CreateInterfaceProxyWithTargetInterface <IStorageNode>(new StorageNode("master"), new DualNodeInterceptor(new StorageNode("slave")), new CallingLogInterceptor());

            node.Save($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:message"); //应该调用master对象
            node.IsDead = true;
            node.Save($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:message"); //应该调用master对象
            node.Save($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:message"); //应该调用master对象

            Console.Read();
        }
Ejemplo n.º 24
0
        public void Intercept(IInvocation invocation)
        {
            IStorageNode master = invocation.InvocationTarget as IStorageNode;

            if (master.IsDead)
            {
                IChangeProxyTarget cpt = invocation as IChangeProxyTarget;
                // 将补代理对象master更换为slave
                cpt.ChangeProxyTarget(_slave);
                // 测试中恢复master状态,以便看到随后调用仍然使用master这一效果
                master.IsDead = false;
            }
            invocation.Proceed();
        }
Ejemplo n.º 25
0
        // -------------------------------------------------------
        // 查询
        // -------------------------------------------------------

        #region 函数:FindOne(XmlDocument doc)
        /// <summary>获取详细信息</summary>
        /// <param name="doc">Xml 文档对象</param>
        /// <returns>返回操作结果</returns>
        public string FindOne(XmlDocument doc)
        {
            StringBuilder outString = new StringBuilder();

            string id = XmlHelper.Fetch("id", doc);

            IStorageNode param = this.service.FindOne(id);

            outString.Append("{\"data\":" + AjaxUtil.Parse <IStorageNode>(param) + ",");

            outString.Append(MessageObject.Stringify("0", I18n.Strings["msg_query_success"], true) + "}");

            return(outString.ToString());
        }
        /// <summary>检测记录是否存在</summary>
        /// <param name="accountCacheValue">帐号缓存值</param>
        public bool IsExistAccountCacheValue(string accountCacheValue)
        {
            if (string.IsNullOrEmpty(accountCacheValue))
            {
                throw new Exception("帐号缓存值不能为空。");
            }

            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" AccountCacheValue = '{0}' ", StringHelper.ToSafeSQL(accountCacheValue, true)));

            return(((int)this.ibatisMappers[storageNode.Name].QueryForObject(StringHelper.ToProcedurePrefix(string.Format("{0}_IsExist", tableName)), args) == 0) ? false : true);
        }
        /// <summary>查询是否存在相关的记录</summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="receiverId">接收者标识</param>
        /// <returns>布尔值</returns>
        public bool IsExist(string taskId, string receiverId)
        {
            if (string.IsNullOrEmpty(taskId) || string.IsNullOrEmpty(receiverId))
            {
                throw new Exception("实例标识不能为空。");
            }

            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("WhereClause", string.Format(" TaskId = '{0}' AND ReceiverId = '{1}' ", StringHelper.ToSafeSQL(taskId), StringHelper.ToSafeSQL(receiverId)));

            return((Convert.ToInt32(this.ibatisMappers[storageNode.Name].QueryForObject(StringHelper.ToProcedurePrefix(string.Format("{0}_IsExist", this.tableName)), args)) == 0) ? false : true);
        }
Ejemplo n.º 28
0
        public ReplicationSchema(IStorageNode storage, List <ReplicationSchemaItem> strongSchemaItems, List <ReplicationSchemaItem> weakSchemaItems)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            this.Storage = storage;
            if (strongSchemaItems != null)
            {
                this.StrongItems = strongSchemaItems.ToArray();
            }
            if (weakSchemaItems != null)
            {
                this.WeakItems = weakSchemaItems.ToArray();
            }
        }
        /// <summary>设置任务未完成</summary>
        /// <param name="receiverId">接收者</param>
        /// <param name="taskIds">任务编号,多个以逗号分开</param>
        public void SetUnfinished(string receiverId, string taskIds)
        {
            if (string.IsNullOrEmpty(taskIds))
            {
                return;
            }

            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            taskIds = "'" + StringHelper.ToSafeSQL(taskIds).Replace(",", "','") + "'";

            args.Add("WhereClause", string.Format(" ReceiverId = '{0}' AND Id IN ({1}) ", receiverId, taskIds));

            this.ibatisMappers[storageNode.Name].Update(StringHelper.ToProcedurePrefix(string.Format("{0}_SetUnfinished", this.tableName)), args);
        }
        private Configuration(TestSuiteConfiguration testSuiteConfiguration, ITestSuite testSuite, IStorageNode storageRoot)
        {
            Id = testSuiteConfiguration.Id;

            TestSuite = testSuite;

            Name = testSuiteConfiguration.Name;

            Description = testSuiteConfiguration.Description;

            StorageRoot = storageRoot;

            var ptfConfigStorage = StorageRoot.GetNode(ConfigurationConsts.PtfConfig);

            PtfConfig = new PtfConfig(ptfConfigStorage.GetFiles().ToList());

            LoadFeatureMappingFromXml();
        }
        /// <summary>查询所有相关记录</summary>
        /// <param name="receiverId">接收者帐号标识</param>
        /// <param name="whereClause">SQL 查询条件</param>
        /// <param name="length">条数</param>
        /// <returns>返回所有 TaskWorkItemInfo 实例的详细信息</returns>
        public IList <TaskWorkItemInfo> FindAllByReceiverId(string receiverId, string whereClause, int length)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Node", receiverId);

            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("Length", length);

            if (string.IsNullOrEmpty(whereClause))
            {
                args.Add("WhereClause", string.Format(" ReceiverId = '{0}' ORDER BY CreateDate DESC ", StringHelper.ToSafeSQL(receiverId)));
            }
            else
            {
                args.Add("WhereClause", string.Format(" ReceiverId = '{0}' AND {1} ", StringHelper.ToSafeSQL(receiverId), StringHelper.ToSafeSQL(whereClause)));
            }

            return(this.ibatisMappers[storageNode.Name].QueryForList <TaskWorkItemInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_FindAll", this.tableName)), args));
        }
Ejemplo n.º 32
0
 public Client(IStorageNode Node)
 {
     node = Node;
 }
Ejemplo n.º 33
0
 public StorageSlice(IStorageNode storageNode, long startTime, int timeStep)
 {
     this.storageNode = storageNode;
     StartTime = startTime;
     TimeStep = timeStep;
 }