Пример #1
0
            public override object GetValue(object component)
            {
                if (!(component is DynamicObject dynComponent))
                {
                    return(_originalDescriptor?.GetValue(component));
                }

                return(dynComponent.TryGetMember(new GetMemberBinderEx(_propertyName), out var result)
                  ? result
                  : _originalDescriptor?.GetValue(component));
            }
Пример #2
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var custom_field_option_id = Id.Get(context);
            var name = Name.Get(context);
            PropertyDescriptor zendeskProperty = context.DataContext.GetProperties()[ZendeskScope.ParentContainerPropertyTag];
            var objectContainer = zendeskProperty?.GetValue(context.DataContext) as IObjectContainer;
            //var objectContainer = context.GetFromContext<IObjectContainer>(ZendeskScope.ParentContainerPropertyTag);
            TicketFieldOptionResponse resp;
            IList <TicketFieldOption> list = null;

            var client = objectContainer.Get <ZendeskApi>();
            ///////////////////////////
            // Add execution logic HERE
            ///////////////////////////

            var result = client.Requests.RunRequest(string.Format("ticket_fields/{0}/options", custom_field_option_id), "GET");

            if (result.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                resp = JsonConvert.DeserializeObject <TicketFieldOptionResponse>(result.Content, this.jsonSettings);
                list = resp.TicketFieldOptions.Where(p => p.Name == name).ToList();
            }

            // Outputs
            return((ctx) => {
                TicketFieldOption.Set(ctx, list);
            });
        }
Пример #3
0
        protected override void Execute(CodeActivityContext context)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            try
            {
                if (ftpSession == null)
                {
                    throw new InvalidOperationException(Resources.FTPSessionNotFoundException);
                }
                ftpSession.Move(RemotePath.Get(context), NewPath.Get(context), Overwrite);
            }
            catch (Exception e)
            {
                if (ContinueOnError.Get(context))
                {
                    Trace.TraceError(e.ToString());
                }
                else
                {
                    throw;
                }
            }
        }
Пример #4
0
        void Snippet()
        {
            CodeActivityContext context = null;

            PropertyDescriptor property = context.DataContext.GetProperties()["PropertyName"];
            string             value    = property?.GetValue(context.DataContext) as string;
        }
        private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            PropertyDescriptor dropboxSessionProperty = faultContext.DataContext.GetProperties()[DropboxSessionPropertyName];
            IDropboxSession    dropboxSession         = dropboxSessionProperty?.GetValue(faultContext.DataContext) as IDropboxSession;

            dropboxSession?.Dispose();
        }
Пример #6
0
        private object GetSubPropertyValue(string propertyPath, object dataObject)
        {
            PropertyDescriptor innerDescriptor = (PropertyDescriptor)null;
            object             innerObject     = (object)null;

            this.GetSubPropertyByPath(propertyPath, dataObject, out innerDescriptor, out innerObject);
            return(innerDescriptor?.GetValue(innerObject));
        }
Пример #7
0
        private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            PropertyDescriptor ftpSessionProperty = faultContext.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(faultContext.DataContext) as IFtpSession;

            ftpSession?.Close();
            ftpSession?.Dispose();
        }
Пример #8
0
 public override object GetValue(object component)
 {
     if (component is DynamicObject dynComponent)
     {
         if (dynComponent.TryGetMember(new GetMemberBinderEx(_propertyName), out var result))
         {
             var command = result as DelegateCommand;
             command?.SignalCanExecuteChanged();
             return(result);
         }
     }
     return(_originalDescriptor?.GetValue(component));
 }
Пример #9
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor dropboxSessionFactory = context.DataContext.GetProperties()[WithDropboxSession.DropboxSessionPropertyName];
            IDropboxSession    dropboxSession        = dropboxSessionFactory?.GetValue(context.DataContext) as IDropboxSession;

            if (dropboxSession == null)
            {
                throw new InvalidOperationException(Resources.DropboxSessionNotFoundException);
            }

            await dropboxSession.CreateFolderAsync(FolderPath.Get(context), cancellationToken);

            return((asyncCodeActivityContext) => { });
        }
Пример #10
0
 private Image GetItemImage(object item)
 {
     try
     {
         if (_imageProperty == null)
         {
             RefreshImageProp();
         }
         return(_imageProperty?.GetValue(item) as Image);
     }
     catch
     {
         return(null);
     }
 }
Пример #11
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            PropertyDescriptor zendeskProperty = context.DataContext.GetProperties()[ZendeskScope.ParentContainerPropertyTag];
            var objectContainer = zendeskProperty?.GetValue(context.DataContext) as IObjectContainer;

            var client = objectContainer.Get <ZendeskApi>();
            // Inputs
            var assignee_id = Id.Get(context);
            var user_resp   = client.Users.GetUser(assignee_id);

            // Outputs
            return((ctx) => {
                User.Set(ctx, user_resp.User);
            });
        }
Пример #12
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            if (ftpSession == null)
            {
                throw new InvalidOperationException(Resources.FTPSessionNotFoundException);
            }

            await ftpSession.DeleteAsync(RemotePath.Get(context), cancellationToken);

            return((asyncCodeActivityContext) =>
            {
            });
        }
Пример #13
0
        protected override async Task<Action<AsyncCodeActivityContext>> ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession ftpSession = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            if (ftpSession == null)
            {
                throw new InvalidOperationException("FTPSessionNotFoundException");
            }

            bool exists = await ftpSession.DirectoryExistsAsync(RemotePath.Get(context), cancellationToken);

            return (asyncCodeActivityContext) =>
            {
                Exists.Set(asyncCodeActivityContext, exists);
            };
        }
Пример #14
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor dropboxSessionProperty = context.DataContext.GetProperties()[WithDropboxSession.DropboxSessionPropertyName];
            IDropboxSession    dropboxSession         = dropboxSessionProperty?.GetValue(context.DataContext) as IDropboxSession;

            if (dropboxSession == null)
            {
                throw new InvalidOperationException(Resources.DropboxSessionNotFoundException);
            }

            IEnumerable <DropboxFileMetadata> files = await dropboxSession.ListFolderContentAsync(FolderPath.Get(context), Recursive, cancellationToken);

            return((asyncCodeActivityContext) =>
            {
                Files.Set(asyncCodeActivityContext, files);
            });
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            if (ftpSession == null)
            {
                throw new InvalidOperationException(Resources.FTPSessionNotFoundException);
            }

            IEnumerable <FtpObjectInfo> files = await ftpSession.EnumerateObjectsAsync(RemotePath.Get(context), Recursive, cancellationToken);

            return((asyncCodeActivityContext) =>
            {
                Files.Set(asyncCodeActivityContext, files);
            });
        }
Пример #16
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            PropertyDescriptor zendeskProperty = context.DataContext.GetProperties()[ZendeskScope.ParentContainerPropertyTag];
            var objectContainer = zendeskProperty?.GetValue(context.DataContext) as IObjectContainer;
            // Inputs
            //var ticketId = Id.Get(context);
            var ticket = Ticket.Get(context);

            var client = objectContainer.Get <ZendeskApi>();
            ///////////////////////////
            // Add execution logic HERE
            ///////////////////////////
            var resp = client.Tickets.UpdateTicket(ticket);

            // Outputs
            return((ctx) => {
                UpdatedTicket.Set(ctx, resp.Ticket); // updated ticket
            });
        }
Пример #17
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            PropertyDescriptor zendeskProperty = context.DataContext.GetProperties()[ZendeskScope.ParentContainerPropertyTag];
            var objectContainer            = zendeskProperty?.GetValue(context.DataContext) as IObjectContainer;
            var client                     = objectContainer.Get <ZendeskApi>();
            UserFieldsResponse user_fields = null;


            var result = client.Requests.RunRequest("user_fields", "GET");

            if (result.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                user_fields = JsonConvert.DeserializeObject <UserFieldsResponse>(result.Content, this.jsonSettings);
            }

            // Outputs
            return((ctx) => {
                UserFields.Set(ctx, user_fields.UserFields);
            });
        }
Пример #18
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor dropboxSessionFactory = context.DataContext.GetProperties()[WithDropboxSession.DropboxSessionPropertyName];
            IDropboxSession    dropboxSession        = dropboxSessionFactory?.GetValue(context.DataContext) as IDropboxSession;

            if (dropboxSession == null)
            {
                throw new InvalidOperationException(Resources.DropboxSessionNotFoundException);
            }

            var fileContent = FileContent.Get(context);

            if (string.IsNullOrEmpty(fileContent))
            {
                await dropboxSession.CreateEmptyFileAsync(FilePath.Get(context), cancellationToken);
            }
            else
            {
                await dropboxSession.CreateFileWithContentAsync(FilePath.Get(context), fileContent, cancellationToken);
            }

            return((asyncCodeActivityContext) => { });
        }
Пример #19
0
 public override object GetValue(object component)
 {
     return(_wrappedPropertyDescriptor.GetValue(component));
 }
Пример #20
0
        /// <summary>
        /// 取值
        /// </summary>
        /// <param name="descriptor">属性解释器</param>
        /// <param name="entity">实体类</param>
        /// <param name="row">数据行</param>
        private static void GetValue(PropertyDescriptor descriptor, T entity, ref DataRow row)
        {
            TypeCode code = TypeCode.Object;

            if (Enum.TryParse <TypeCode>(descriptor.PropertyType.Name, out code))
            {
                switch (code)
                {
                case TypeCode.Boolean:
                    row[descriptor.Name] = Convert.ToBoolean(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Byte:
                    row[descriptor.Name] = Convert.ToByte(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Char:
                    row[descriptor.Name] = Convert.ToChar(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.DBNull:
                    row[descriptor.Name] = System.DBNull.Value;
                    break;

                case TypeCode.DateTime:
                    row[descriptor.Name] = Convert.ToDateTime(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Decimal:
                    row[descriptor.Name] = Convert.ToDecimal(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Double:
                    row[descriptor.Name] = Convert.ToDouble(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Empty:
                    row[descriptor.Name] = string.Empty;
                    break;

                case TypeCode.Int16:
                    row[descriptor.Name] = Convert.ToInt16(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Int32:
                    row[descriptor.Name] = Convert.ToInt32(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Int64:
                    row[descriptor.Name] = Convert.ToInt64(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Object:
                    row[descriptor.Name] = descriptor.GetValue(entity);
                    break;

                case TypeCode.SByte:
                    row[descriptor.Name] = Convert.ToSByte(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.Single:
                    row[descriptor.Name] = Convert.ToSingle(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.String:
                    row[descriptor.Name] = Convert.ToString(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.UInt16:
                    row[descriptor.Name] = Convert.ToUInt16(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.UInt32:
                    row[descriptor.Name] = Convert.ToUInt32(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                case TypeCode.UInt64:
                    row[descriptor.Name] = Convert.ToUInt64(descriptor.GetValue(entity), CultureInfo.CurrentCulture);
                    break;

                default:
                    break;
                }
            }
            else
            {
                row[descriptor.Name] = (descriptor.GetValue(entity).GetType().IsGenericType&& descriptor.GetValue(entity).GetType().Name.Equals(typeof(Nullable <>))) ?
                                       Convert.ChangeType(descriptor.GetValue(entity), Nullable.GetUnderlyingType(descriptor.GetValue(entity).GetType())) :
                                       Convert.ChangeType(descriptor.GetValue(entity), descriptor.GetValue(entity).GetType());
            }
        }
Пример #21
0
        public override void InsertRange <TEntity>(List <TEntity> entities, bool keepIdentity = false, string table = null)
        {
            /*
             * 将 entities 分批插入数据库
             * 每批生成 insert into TableName(...) values(...),(...)...
             * 该方法相对循环一条一条插入,速度提升 2/3 这样
             */

            PublicHelper.CheckNull(entities);
            if (entities.Count == 0)
            {
                return;
            }

            int maxParameters = 2100;
            int batchSize     = 50; /* 每批实体大小,此值通过测试得出相对插入速度比较快的一个值 */

            TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(typeof(TEntity));

            var e = typeDescriptor.PropertyDescriptors as IEnumerable <PropertyDescriptor>;

            if (keepIdentity == false)
            {
                e = e.Where(a => a.IsAutoIncrement == false);
            }
            List <PropertyDescriptor> mappingPropertyDescriptors = e.ToList();
            int maxDbParamsCount = maxParameters - mappingPropertyDescriptors.Count; /* 控制一个 sql 的参数个数 */

            DbTable dbTable     = string.IsNullOrEmpty(table) ? typeDescriptor.Table : new DbTable(table, typeDescriptor.Table.Schema);
            string  sqlTemplate = AppendInsertRangeSqlTemplate(dbTable, mappingPropertyDescriptors);

            Action insertAction = () =>
            {
                int            batchCount = 0;
                List <DbParam> dbParams   = new List <DbParam>();
                StringBuilder  sqlBuilder = new StringBuilder();
                for (int i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];

                    if (batchCount > 0)
                    {
                        sqlBuilder.Append(",");
                    }

                    sqlBuilder.Append("(");
                    for (int j = 0; j < mappingPropertyDescriptors.Count; j++)
                    {
                        if (j > 0)
                        {
                            sqlBuilder.Append(",");
                        }

                        PropertyDescriptor mappingPropertyDescriptor = mappingPropertyDescriptors[j];
                        object             val = mappingPropertyDescriptor.GetValue(entity);
                        if (val == null)
                        {
                            sqlBuilder.Append("NULL");
                            continue;
                        }

                        Type valType = val.GetType();
                        if (valType.IsEnum)
                        {
                            val     = Convert.ChangeType(val, Enum.GetUnderlyingType(valType));
                            valType = val.GetType();
                        }

                        if (Utils.IsToStringableNumericType(valType))
                        {
                            sqlBuilder.Append(val.ToString());
                            continue;
                        }

                        if (val is bool)
                        {
                            if ((bool)val == true)
                            {
                                sqlBuilder.AppendFormat("1");
                            }
                            else
                            {
                                sqlBuilder.AppendFormat("0");
                            }
                            continue;
                        }

                        string  paramName = UtilConstants.ParameterNamePrefix + dbParams.Count.ToString();
                        DbParam dbParam   = new DbParam(paramName, val)
                        {
                            DbType = mappingPropertyDescriptor.Column.DbType
                        };
                        dbParams.Add(dbParam);
                        sqlBuilder.Append(paramName);
                    }
                    sqlBuilder.Append(")");

                    batchCount++;

                    if ((batchCount >= 20 && dbParams.Count >= 120 /*参数个数太多也会影响速度*/) || dbParams.Count >= maxDbParamsCount || batchCount >= batchSize || (i + 1) == entities.Count)
                    {
                        sqlBuilder.Insert(0, sqlTemplate);
                        string sql = sqlBuilder.ToString();
                        this.Session.ExecuteNonQuery(sql, dbParams.ToArray());

                        sqlBuilder.Clear();
                        dbParams.Clear();
                        batchCount = 0;
                    }
                }
            };

            Action fAction = () =>
            {
                bool   shouldTurnOff_IDENTITY_INSERT = false;
                string tableName = null;
                if (keepIdentity == true)
                {
                    tableName = AppendTableName(typeDescriptor.Table);
                    this.Session.ExecuteNonQuery(string.Format("SET IDENTITY_INSERT {0} ON ", tableName));
                    shouldTurnOff_IDENTITY_INSERT = true;
                }

                insertAction();
                if (shouldTurnOff_IDENTITY_INSERT == true)
                {
                    this.Session.ExecuteNonQuery(string.Format("SET IDENTITY_INSERT {0} OFF ", tableName));
                }
            };

            if (this.Session.IsInTransaction)
            {
                fAction();
            }
            else
            {
                /* 因为分批插入,所以需要开启事务保证数据一致性 */
                this.Session.BeginTransaction();
                try
                {
                    fAction();
                    this.Session.CommitTransaction();
                }
                catch
                {
                    if (this.Session.IsInTransaction)
                    {
                        this.Session.RollbackTransaction();
                    }
                    throw;
                }
            }
        }
Пример #22
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            if (ftpSession == null)
            {
                throw new InvalidOperationException(Resources.FTPSessionNotFoundException);
            }

            string localPath  = LocalPath.Get(context);
            string remotePath = RemotePath.Get(context);

            if (Directory.Exists(localPath))
            {
                if (string.IsNullOrWhiteSpace(Path.GetExtension(remotePath)))
                {
                    if (!(await ftpSession.DirectoryExistsAsync(remotePath, cancellationToken)))
                    {
                        if (Create)
                        {
                            await ftpSession.CreateDirectoryAsync(remotePath, cancellationToken);
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(Resources.PathNotFoundException, remotePath));
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException(Resources.IncompatiblePathsException);
                }
            }
            else
            {
                if (File.Exists(localPath))
                {
                    if (string.IsNullOrWhiteSpace(Path.GetExtension(remotePath)))
                    {
                        remotePath = FtpConfiguration.CombinePaths(remotePath, Path.GetFileName(localPath));
                    }

                    string directoryPath = FtpConfiguration.GetDirectoryPath(remotePath);

                    if (!(await ftpSession.DirectoryExistsAsync(directoryPath, cancellationToken)))
                    {
                        if (Create)
                        {
                            await ftpSession.CreateDirectoryAsync(directoryPath, cancellationToken);
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format(Resources.PathNotFoundException, directoryPath));
                        }
                    }
                }
                else
                {
                    throw new ArgumentException(string.Format(Resources.PathNotFoundException, localPath));
                }
            }

            await ftpSession.UploadAsync(localPath, remotePath, Overwrite, Recursive, cancellationToken);

            return((asyncCodeActivityContext) =>
            {
            });
        }
 public override object GetValue(object component)
 {
     return(_descriptor.GetValue(component));
 }
Пример #24
0
        public object GetPropertyHyperDescriptor([NotNull] object obj)
        {
            PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(obj).Find(UIntArrayPropertyName, false);

            return(propertyDescriptor?.GetValue(obj));
        }
Пример #25
0
 public override object GetValue(object component)
 {
     return(_orig?.GetValue(GetEffectiveComponent(component)) ?? "");
 }
Пример #26
0
		protected virtual void GenerateChildPropertySet (GeneratorContext ctx, CodeVariableReferenceExpression var, ClassDescriptor containerChildClass, PropertyDescriptor prop, object child)
		{
			if (containerChildClass.InitializationProperties != null && Array.IndexOf (containerChildClass.InitializationProperties, prop) != -1)
				return;
			
			// Design time
			if (prop.Name == "AutoSize")
				return;
				
			object oval = prop.GetValue (child);
			if (oval == null || (prop.HasDefault && prop.IsDefaultValue (oval)))
				return;
				
			CodePropertyReferenceExpression cprop = new CodePropertyReferenceExpression (var, prop.Name);
			CodeExpression val = ctx.GenerateValue (oval, prop.RuntimePropertyType, prop.Translatable);
			ctx.Statements.Add (new CodeAssignStatement (cprop, val));
		}
Пример #27
0
 public string PropertyDescriptor()
 {
     descriptor.SetValue(obj, "abc");
     return((string)descriptor.GetValue(obj));
 }
Пример #28
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            Excel::Application excelApp = property.GetValue(context.DataContext) as Excel::Application;

            try
            {
                string sheetName        = SheetName.Get(context);
                string cellName_Begin   = CellName_Begin.Get(context);
                string cellName_End     = CellName_End.Get(context);
                int    cellRow_Begin    = CellRow_Begin.Get(context);
                int    cellColumn_Begin = CellColumn_Begin.Get(context);
                int    cellRow_End      = CellRow_End.Get(context);
                int    cellColumn_End   = CellColumn_End.Get(context);

                Excel::_Worksheet sheet;
                if (sheetName != null)
                {
                    sheet = excelApp.ActiveWorkbook.Sheets[sheetName];
                }
                else
                {
                    sheet = excelApp.ActiveSheet;
                }

                Excel::Range range1, range2;
                range1 = cellName_Begin == null ? sheet.Cells[cellRow_Begin, cellColumn_Begin] : sheet.Range[cellName_Begin];
                range2 = cellName_End == null ? sheet.Cells[cellRow_End, cellColumn_End] : sheet.Range[cellName_End];
                Excel::Range range3 = sheet.Range[range1, range2];

                System.Data.DataTable dt = new System.Data.DataTable();
                int iRowCount            = range3.Rows.Count;
                int iColCount            = range3.Columns.Count;
                int rowBegin             = range3.Row;
                int colBegin             = range3.Column;

                //生成列头
                for (int i = 0; i < iColCount; i++)
                {
                    var name = "column" + i;
                    if (isTitle)
                    {
                        var txt = ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[rowBegin, i + colBegin]).Text.ToString();
                        if (!string.IsNullOrEmpty(txt))
                        {
                            name = txt;
                        }
                    }
                    while (dt.Columns.Contains(name))
                    {
                        name = name + "_1";//重复行名称会报错。
                    }
                    dt.Columns.Add(new System.Data.DataColumn(name, typeof(string)));
                }
                //生成行数据
                Microsoft.Office.Interop.Excel.Range range;
                int rowIdx = isTitle ? 2 : 1;
                for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
                {
                    System.Data.DataRow dr = dt.NewRow();
                    for (int iCol = 1; iCol <= iColCount; iCol++)
                    {
                        range        = (Microsoft.Office.Interop.Excel.Range)sheet.Cells[iRow + rowBegin - 1, iCol + colBegin - 1];
                        dr[iCol - 1] = (range.Value2 == null) ? "" : range.Value2;
                    }
                    dt.Rows.Add(dr);
                }
                DataTable.Set(context, dt);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
                sheet = null;
                GC.Collect();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "EXCEL读取区域执行过程出错", e.Message);
                new CommonVariable().realaseProcessExit(excelApp);
            }
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Пример #29
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            if (ftpSession == null)
            {
                throw new InvalidOperationException("FTPSessionNotFoundException");
            }

            string remotePath = RemotePath.Get(context);
            string localPath  = LocalPath.Get(context);

            FtpObjectType objectType = await ftpSession.GetObjectTypeAsync(remotePath, cancellationToken);

            if (objectType == FtpObjectType.Directory)
            {
                if (string.IsNullOrWhiteSpace(Path.GetExtension(localPath)))
                {
                    if (!Directory.Exists(localPath))
                    {
                        if (Create)
                        {
                            Directory.CreateDirectory(localPath);
                        }
                        else
                        {
                            throw new ArgumentException("PathNotFoundException", localPath);
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException("IncompatiblePathsException");
                }
            }
            else
            {
                if (objectType == FtpObjectType.File)
                {
                    if (string.IsNullOrWhiteSpace(Path.GetExtension(localPath)))
                    {
                        localPath = Path.Combine(localPath, Path.GetFileName(remotePath));
                    }

                    string directoryPath = Path.GetDirectoryName(localPath);

                    if (!Directory.Exists(directoryPath))
                    {
                        if (Create)
                        {
                            Directory.CreateDirectory(directoryPath);
                        }
                        else
                        {
                            throw new InvalidOperationException("PathNotFoundException");
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("UnsupportedObjectTypeException");
                }
            }

            if (Overwrite)
            {
                await ftpSession.DownloadAsync(remotePath, localPath, FtpLocalExists.Overwrite, Recursive, cancellationToken);
            }
            else
            {
                await ftpSession.DownloadAsync(remotePath, localPath, FtpLocalExists.Append, Recursive, cancellationToken);
            }

            return((asyncCodeActivityContext) =>
            {
            });
        }
Пример #30
0
        /// <internalonly/>
        /// <summary>
        /// Gets the value of an option defined in this package.
        /// </summary>
        object IDesignerOptionService.GetOptionValue(string pageName, string valueName)
        {
            PropertyDescriptor optionProp = GetOptionProperty(pageName, valueName);

            return(optionProp?.GetValue(null));
        }
Пример #31
0
 public int Compare(T x, T y)
 {
     return(_reverse * _comparer.Compare(_propertyDescriptor.GetValue(x), _propertyDescriptor.GetValue(y)));
 }