コード例 #1
0
        /// <summary>
        /// リポジトリ照会
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="responseUrl"></param>
        /// <param name="teamId"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static async Task GetRepository(string channelId, string responseUrl, string teamId, Func <string, Task> func)
        {
            // PartitionKeyがチャンネルIDのEntityを取得するクエリ
            var query = new TableQuery <ChannelIdEntity>()
                        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, channelId));

            // クエリ実行
            var entityList = StorageOperation.GetTableIfNotExistsCreate("channel").ExecuteQuery(query);

            // クエリ実行結果で要素がひとつでもあるかどうか
            var channelIdEntities = entityList.ToList();

            if (channelIdEntities.Any())
            {
                await func(channelIdEntities.First().Repository);
            }
            else
            {
                var model = new PostMessageModel()
                {
                    Channel       = channelId,
                    Text          = "登録リポジトリが存在しません。",
                    Response_type = "ephemeral"
                };

                var slackApi = new SlackApi();

                await slackApi.ExecutePostApiAsJson(model, responseUrl, teamId);
            }
        }
コード例 #2
0
        /// <summary>
        /// 开始处理任务
        /// </summary>
        /// <returns></returns>
        public async Task StartJob(JsonFile jsonFile, string tempFilePath)
        {
            if (jsonFile.Values.Count > 0)
            {
                StorageOperation       storage     = new StorageOperation();
                TempStorageOperation   tempStorage = new TempStorageOperation();
                Queue <JsonFileValues> queues      = new Queue <JsonFileValues>();
                for (int i = 0; i < jsonFile.Values.Count; i++)
                {
                    queues.Enqueue(jsonFile.Values[i]);
                }

                jsonFile.Values.Clear();
                if (queues.Count > 0)
                {
                    JsonFileValues job = null;
                    while (queues.TryDequeue(out job))
                    {
                        //预览图处理
                        if (job.Key == "Medium")
                        {
                            jsonFile.Values.Add(new Jobs.ToMediumJob().Run(tempFilePath, job));
                        }
                        //缩略图处理
                        if (job.Key == "Small")
                        {
                            jsonFile.Values.Add(new Jobs.CreateSmallJob().Run(tempFilePath, job));
                        }
                    }
                }
                //保存Json文件
                await jsonFile.SaveAs(tempStorage.GetJsonFilePath(jsonFile.Id));
            }
        }
コード例 #3
0
        public void New_storage_operation_with_default_settings_has_correct_values_at_each_depth()
        {
            using(var op = new StorageOperation())
            {
                Assert.IsNotNull(op.Connection);
                Assert.IsNotNull(op.ConnectionSource);
                Assert.IsNotNull(op.ConnectionSource.Provider);
                Assert.IsTrue(op.ConnectionSource.Provider.GetType() == typeof(FakeDbProviderFactory));
                Assert.AreEqual(1, op.Depth);

                using(var nested = new StorageOperation())
                {
                    Assert.IsNotNull(nested.Connection);
                    Assert.IsNotNull(nested.ConnectionSource);
                    Assert.AreEqual(1, op.Depth);
                    Assert.AreEqual(2, nested.Depth);
                }

                Assert.AreEqual(1, op.Depth);

                using(var trans = new AtomicStorageOperation())
                {
                    Assert.IsNotNull(trans.Connection);
                    Assert.IsNotNull(trans.ConnectionSource);
                    Assert.AreEqual(1, op.Depth);
                    Assert.AreEqual(2, trans.Depth);
                    trans.Complete();
                }

                Assert.AreEqual(1, op.Depth);
            }
        }
コード例 #4
0
 private static GridEvent <StorageEvent> CreateEvent(
     string name,
     StorageOperation operation,
     string collection,
     string data,
     string subject      = Services.ASupervisor,
     string eventType    = Events.StorageEvent,
     DateTime?eventTime  = null,
     Guid?organizationId = null,
     Guid?subscriptionId = null,
     Guid?userId         = null)
 {
     return(new GridEvent <StorageEvent>(
                Guid.NewGuid(),
                eventTime ?? TestNewEventDate,
                subject,
                eventType,
                new StorageEvent(
                    name,
                    operation,
                    collection,
                    data == null ? null : Json.DeserializeObject(data),
                    organizationId ?? TestOrganizationId,
                    subscriptionId ?? TestSubscriptionId,
                    userId ?? TestUserId)));
 }
コード例 #5
0
ファイル: SlackApi.cs プロジェクト: ishizuka-shota/IssueApp
        /// <summary>
        /// Json送信SlackApi用ヘッダー作成
        /// </summary>
        /// <returns></returns>
        public HttpClient CreateHeaderAsJson(string teamId)
        {
            // PartitionKeyがチームIDのEntityを取得するクエリ
            var query = new TableQuery <TeamIdEntity>()
                        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, teamId));

            var entityList = StorageOperation.GetTableIfNotExistsCreate("team").ExecuteQuery(query);

            // クエリ実行結果で要素がひとつでもあるかどうか
            var teamIdEntities = entityList.ToList();

            if (teamIdEntities.Any())
            {
                // クライアント作成
                var client = new HttpClient();

                // ヘッダー情報挿入
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", teamIdEntities.First().Token);

                return(client);
            }

            throw new Exception();
        }
コード例 #6
0
        /// <summary>
        /// GitHubクライアントにアクセストークンセット
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="gitHub"></param>
        /// <returns></returns>
        public GitHubClient SetCredencial(string userId, string userName, GitHubClient gitHub)
        {
            // クレデンシャル情報に適当な値を入れ、認証エラーが起きるようにする
            github.Credentials = new Credentials("aaaaaaaaaaaaaa");

            EntityOperation <UserEntity> entityOperation = new EntityOperation <UserEntity>();

            //検索操作を行う変数を生成
            TableOperation retrieveOperation = TableOperation.Retrieve <UserEntity>(userId, userName);

            //RowKeyがlabelのEntityを取得するクエリ
            TableQuery <UserEntity> query = new TableQuery <UserEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, userId));

            //Entityリストから
            var entityList = StorageOperation.GetTableIfNotExistsCreate("user").ExecuteQuery(query);

            // Entityリストが空じゃなかったら
            if (entityList.Count() != 0)
            {
                // Entityリストをリスト形式に直す
                List <UserEntity> userEntityList = entityList.ToList();

                // Entityは一つしか取得されないため、リストの0番目を取得する
                UserEntity userEntity = userEntityList[0];

                // Entityのクレデンシャル情報をセットする
                github.Credentials = new Credentials(userEntity.AccessToken);
            }
            return(github);
        }
コード例 #7
0
        /// <summary>
        /// テンプレート作成・編集(作成か編集か)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public async Task TemplateMethod(IDialogContext context, IAwaitable <string> argument)
        {
            var way = await argument;

            //現在チャンネルのリポジトリ取得
            string repository = RedisCacheOperation.Connection.StringGet(GitHubDialog.channelId);

            //対象リポジトリのラベルをすべて取得
            var labelList = await GitHubDialog.github.Issue.Labels.GetAllForRepository(repository.Split('/')[0], repository.Split('/')[1]);

            //ラベルリストからラベル名のリストを生成
            var labelNameList_project = labelList.ToList().ConvertAll(x => x.Name);

            //RowKeyがlabelのEntityを取得するクエリ
            TableQuery <TemplateEntity> query = new TableQuery <TemplateEntity>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, "label"));

            //Entityリストから
            List <string> labelNameList_table = StorageOperation.GetTableIfNotExistsCreate(string.Empty).ExecuteQuery(query).ToList().ConvertAll(x => x.PartitionKey);

            switch (way)
            {
            case "作成":
            {
                var labelNameList = labelNameList_project.Except(labelNameList_table).ToList();


                if (labelNameList.Count != 0)
                {
                    labelNameList.Add("キャンセルする");
                    PromptDialog.Choice(context, this.TemplateCreateInput, labelNameList, "作成したいテンプレートのラベルを選択してください");
                }
                else
                {
                    await context.PostAsync("テンプレートが未作成のラベルはありません");

                    context.Done <object>(context);
                }
                break;
            }

            case "編集":
            {
                if (labelNameList_table.Count != 0)
                {
                    labelNameList_table.Add("キャンセルする");
                    PromptDialog.Choice(context, this.TemplateEditInput, labelNameList_table, "編集したいラベルを選択してください");
                }
                else
                {
                    await context.PostAsync("テンプレートが作成済のラベルはありません");

                    context.Done <object>(context);
                }
                break;
            }
            }
        }
コード例 #8
0
 public StorageEvent(string name, StorageOperation operation, string collection, dynamic data, Guid?organizationId, Guid?subscriptionId, Guid?userId)
 {
     Name           = name;
     Operation      = operation;
     Collection     = collection;
     Data           = data;
     OrganizationId = organizationId;
     SubscriptionId = subscriptionId;
     UserId         = userId;
 }
コード例 #9
0
ファイル: ImageController.cs プロジェクト: Moiraines/WebNews
        public IHttpActionResult Get()
        {
            var          client  = StorageAuthentication.GetUserCredentials();
            DriveService service = StorageAuthentication.AuthenticateOauth(client.ClientId, client.ClientSecret, "root");

            string q            = "mimeType = 'application/vnd.google-apps.photo'";
            var    newsPictures = StorageOperation.GetFiles(service, q);

            return(this.Ok(newsPictures));
        }
コード例 #10
0
 public StorageOperationOutput(StorageOperation operation)
 {
     this.Id                  = operation.Id;
     this.Type                = operation.Type;
     this.OrderId             = operation.OrderId;
     this.WarehouseCode       = operation.WarehouseCode;
     this.LogisticCode        = operation.LogisticCode;
     this.LogisticOrderNumber = operation.LogisticOrderNumber;
     this.LogisticFee         = operation.LogisticFee;
     this.Comment             = operation.Comment;
     this.Details             = operation.Details.Select(d => new StorageOperationDetailOutput(d)).ToArray();
 }
コード例 #11
0
        /// <summary>
        /// GitHubアクセストークンセット
        /// </summary>
        /// <param name="slackUserId"></param>
        public static void SetCredential(string slackUserId)
        {
            // PartitionKeyがSlackユーザIDのEntityを取得するクエリ
            TableQuery <UserEntity> query = new TableQuery <UserEntity>()
                                            .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, slackUserId));

            // クエリ実行
            var entityList = StorageOperation.GetTableIfNotExistsCreate("user").ExecuteQuery(query);

            // クエリ実行結果で要素がひとつでもあるかどうか
            var userEntities = entityList.ToList();

            Client.Credentials = userEntities.Any() ? new Credentials(userEntities.First().AccessToken) : new Credentials("aaaaaaaaaaaaaa");
        }
コード例 #12
0
 public StorageOperationListOutput(StorageOperation operation)
 {
     this.Id                  = operation.Id;
     this.Type                = operation.Type;
     this.OrderId             = operation.OrderId;
     this.WarehouseCode       = operation.WarehouseCode;
     this.LogisticCode        = operation.LogisticCode;
     this.LogisticOrderNumber = operation.LogisticOrderNumber;
     this.LogisticFee         = operation.LogisticFee;
     this.CreateBy            = operation.CreateBy.ToString();
     this.CreateDate          = operation.CreateDate;
     this.UpdateBy            = operation.UpdateBy.ToString();
     this.UpdateDate          = operation.UpdateDate;
 }
コード例 #13
0
        public StorageOperationOutput Create(CreateStorageOperationInput input)
        {
            if (input.Type == StorageOperationType.Out)
            {
                if (!input.OrderId.HasValue)
                {
                    //TODO:为了方便前端测试,出库操作暂时不需要提供订单id
                    //throw new Exception("out storage operation must contain an order id");
                }
                else
                {
                    using (var dbContext = new AllureContext())
                    {
                        var order = dbContext.Set <Order>().SingleOrDefault(o => o.Id == input.OrderId.Value);
                        if (order == null)
                        {
                            throw new Exception(string.Format("invalid order id: {0}", input.OrderId.Value.ToString()));
                        }
                    }
                }
            }

            var operation = new StorageOperation
            {
                Type                = input.Type,
                OrderId             = input.OrderId,
                WarehouseCode       = input.WarehouseCode,
                LogisticCode        = input.LogisticCode,
                LogisticOrderNumber = input.LogisticOrderNumber,
                LogisticFee         = input.LogisticFee,
                Comment             = input.Comment,
                CreateDate          = DateTime.Today,
                UpdateDate          = DateTime.Today
            };

            using (var dbContext = new AllureContext())
            {
                var productIds = input.Details.Select(d => d.ProductId).ToArray();
                var balances   = dbContext.Set <ProductStorage>()
                                 .Where(s => productIds.Contains(s.ProductId))
                                 .ToDictionary(s => s.ProductId);

                foreach (var detail in input.Details)
                {
                    operation.Details.Add(new StorageOperationDetail
                    {
                        ProductId      = detail.ProductId,
                        CurrentBalance = balances[detail.ProductId].Balance,
                        OperationCount = detail.OperationCount
                    });

                    if (input.Type == StorageOperationType.In)
                    {
                        balances[detail.ProductId].Balance += detail.OperationCount;
                    }
                    else if (input.Type == StorageOperationType.Out)
                    {
                        balances[detail.ProductId].Frozen -= detail.OperationCount;
                    }
                }

                dbContext.Set <StorageOperation>().Add(operation);
                dbContext.SaveChanges();

                return(new StorageOperationOutput(operation));
            }
        }
コード例 #14
0
ファイル: ModelBase.cs プロジェクト: vlapchenko/nfx
    /// <summary>
    /// Deletes data from external store with specified key. When key is omitted instance's DataStoreKey is used.
    /// After this call model state is DataState.Uninitialized
    /// </summary>
    public void Delete(IModelDataStore store, IDataStoreKey key, params object[] extra)
    {
      CheckDeleteAllowed();


      m_StorageOperation = StorageOperation.Deleting;
      try
      {
       DoDelete(store, key ?? this.DataStoreKey, extra);
      }
      finally
      {
        m_StorageOperation = StorageOperation.None;
      }
      
      m_DataStoreKey = null;
      setState(DataState.Uninitialized);
      m_LastPostedChange = ChangeType.Deleted;
    }
コード例 #15
0
ファイル: ModelBase.cs プロジェクト: vlapchenko/nfx
 /// <summary>
 /// Initializes an instance for data loading and loads data if store is not null from external source.
 /// This call has to be followed by EndLoad()
 /// </summary>
 public void BeginLoad(IModelDataStore store, IDataStoreKey key, params object[] extra)
 {
   CheckLoadAllowed();
   
   
   setState(DataState.Initializing);
   
   m_StorageOperation = StorageOperation.Loading;
   try
   {      
     DoCreate();
     
     if (store!=null)
       DoLoad(store, key, extra);
   }
   finally
   {
     m_StorageOperation = StorageOperation.None;
   }    
    
   m_DataStoreKey = key; 
 }
コード例 #16
0
ファイル: ModelBase.cs プロジェクト: vlapchenko/nfx
 /// <summary>
 /// Saves data into external store using specified key. If key is null then provider may elect to build key from fields with KeyField attribute set to true
 /// </summary>
 public void Save(IModelDataStore store, IDataStoreKey key, params object[] extra)
 {
   CheckSaveAllowed();
   
   m_StorageOperation = StorageOperation.Saving;
   try
   {
      DoSave(store, key ?? this.DataStoreKey, extra);
      m_DataStoreKey = key;
   }
   finally
   {
      m_StorageOperation = StorageOperation.None;
   }
   
 }
コード例 #17
0
ファイル: StorageAction.cs プロジェクト: glueckkanja/yas4
 public StorageAction(FileProperties properties, StorageOperation action)
     : this()
 {
     Properties = properties;
     Operation = action;
 }