private static NameWrapper AddNameToUniqueStrings(string name, Dictionary <string, string> dontShortenStrings,
                                                          CaseInsensitiveDictionary <StringWrapper> uniqueStrings)
        {
            NameWrapper nameWrapper = new NameWrapper();

            List <string> nameStrings = StringUtils.SplitAndReallyRemoveEmptyEntries(name, Utils.NAME_SEPARATOR, StringComparison.OrdinalIgnoreCase);

            foreach (string nameString in nameStrings)
            {
                bool          canShorten = !dontShortenStrings.ContainsKey(nameString);
                StringWrapper stringWrapper;
                if (uniqueStrings.TryGetValue(nameString, out stringWrapper))
                {
                    DebugUtils.AssertDebuggerBreak(stringWrapper.CanShorten == canShorten);
                }
                else
                {
                    stringWrapper = new StringWrapper(nameString, canShorten);
                    uniqueStrings.Add(nameString, stringWrapper);
                }
                nameWrapper.AddString(stringWrapper);
            }

            return(nameWrapper);
        }
        public virtual bool SaveData <T>(string username, UserSettingsDataType dataType, T data)
        {
            bool success = ObjectCacheDao.CacheObject(data, GetDataStorageName(username, dataType), DateTime.Now + CacheDuration);

            DebugUtils.AssertDebuggerBreak(success);
            return(success);
        }
        public static void Test()
        {
            string            baseFolder = @"D:\PROJECTS\OpenNode2-google\TestFiles\";
            CommonContentType?type       = GetFileTypeFromContent(baseFolder + "ResultsXml.dat");

            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.XML);
            type = GetFileTypeFromContent(baseFolder + "ResultsXmlUnicode.dat");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.XML);
            type = GetFileTypeFromContent(baseFolder + "ResultsXmlUTF8.dat");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.XML);
            type = GetFileTypeFromContent(baseFolder + "ResultsXml.zip");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.ZIP);
            type = GetFileTypeFromContent(baseFolder + "UpgradeLog.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
            type = GetFileTypeFromContent(baseFolder + "UpgradeLogUnicode.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
            type = GetFileTypeFromContent(baseFolder + "UpgradeLogUTF8.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
            type = GetFileTypeFromContent(baseFolder + "Migration Report.pdf");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.PDF);

            type = GetFileTypeFromContent(baseFolder + "Bears.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
            type = GetFileTypeFromContent(baseFolder + "BearsUnicode.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
            type = GetFileTypeFromContent(baseFolder + "BearsUTF8.htm");
            DebugUtils.AssertDebuggerBreak(type.HasValue && type.Value == CommonContentType.HTML);
        }
Exemple #4
0
        public virtual object GetInsertColumnValue(object parentOfObjectToSave, object objectToSave, ColumnCachedValues cachedValues)
        {
            object value = null;

            if (MemberInfo == null)
            {
                if (objectToSave != null)
                {
                    // This would be string, int, double, etc. virtual table
                    DebugUtils.AssertDebuggerBreak(Utils.IsValidColumnType(objectToSave.GetType()));
                    value = objectToSave;
                }
            }
            else
            {
                value = GetMemberValue(objectToSave);
            }
            if (value == null)
            {
                if (this.IsNullable)
                {
                    value = DBNull.Value;
                }
                else
                {
                    throw new MappingException("A column.MemberInfo \"{0}\" has a null value, but the column is specified as non-null: {1}",
                                               MemberInfo.ToString(), this.ToString());
                }
            }
            else if (m_IsDbBoolString)
            {
                value = ((bool)value) ? "Y" : "N";
            }
            else if (m_IsTenDigitDateString)
            {
                value = DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd");
            }
            else if (m_IsTimeType)
            {
                if (m_MemberType == typeof(string))
                {
                    TimeSpan timeSpan = TimeSpan.Parse(value.ToString());
                    value = new DateTime(1900, 1, 1, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
                }
                else
                {
                    DateTime existingValue = DateTime.Parse(value.ToString());
                    value = new DateTime(1900, 1, 1, existingValue.Hour, existingValue.Minute, existingValue.Second);
                }
            }
            else if ((m_ColumnType == DbType.DateTime) || (m_ColumnType == DbType.Date))
            {
                DateTime dateTime = DateTime.Parse(value.ToString());
                return(MakeValidDbDateTime(dateTime));
            }
            return(value);
        }
            public virtual void Release()
            {
                int useCount = Interlocked.Decrement(ref _useCount);

                DebugUtils.AssertDebuggerBreak(useCount >= 0);
                DebugUtils.AssertDebuggerBreak(!IsDisposed);
                if (useCount == 0)
                {
                    this.Dispose();
                }
            }
 protected override void OnCreateMainForm()
 {
     if (m_StartupMutex != null)
     {
         DebugUtils.AssertDebuggerBreak(CreateMainForm != null); // This should be set so that the main form can be created
         if (CreateMainForm != null)
         {
             CreateMainFormArgs args = new CreateMainFormArgs();
             CreateMainForm(this, args);
             base.MainForm = args.MainForm;
         }
     }
 }
        public virtual void ProcessTask(string requestId)
        {
            ProcessTaskInit(requestId);

            _submissionTrackingDataType = SubmissionTrackingTableHelper.GetActiveSubmissionTrackingElement(_baseDao, out _submissionTrackingDataTypePK);
            if (_submissionTrackingDataType == null)
            {
                AppendAuditLogEvent("There are no pending submissions in the submission tracking table, existing plugin ...");
                return;
            }
            DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);
            if (!_submissionTrackingDataType.SubmissionDateTimeSpecified)
            {
                AppendAuditLogEvent("There is a pending row in the submission tracking table, \"{0},\" but it does not have a submission date/time yet, existing plugin ...",
                                    _submissionTrackingDataTypePK);
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(_submissionTrackingDataType.SubmissionTransactionId))
                {
                    throw new ArgumentException("There is a pending row in the submission tracking table, \"{0},\" with a submission date/time, but the submission transaction id is missing",
                                                _submissionTrackingDataTypePK);
                }

                // Attempt to get status of the active submission and download the response documents
                IList <string> documentNames;
                string         localTransactionId;

                if (!DoGetStatusAndDownloadDocuments(out localTransactionId, out documentNames))
                {
                    return;
                }

                Windsor.Node2008.WNOSDomain.Document zipResponseFile;
                if (!DoProcessResponseDocuments(localTransactionId, documentNames, out zipResponseFile))
                {
                    return;
                }

                _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Completed;
                _submissionTrackingDataType.WorkflowStatusMessage = string.Format("Successfully downloaded response data and inserted into database");
                SubmissionTrackingTableHelper.Update(_baseDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);

                DoEmailNotifications(zipResponseFile, localTransactionId);
            }
            catch (WorkflowStatusFailedException workflowStatusFailedException)
            {
                string errorMessage =
                    string.Format("An error occurred during processing: {0}",
                                  ExceptionUtils.GetDeepExceptionMessage(workflowStatusFailedException));
                if (_submissionTrackingDataTypePK != null)
                {
                    _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                    _submissionTrackingDataType.WorkflowStatusMessage = errorMessage;
                    SubmissionTrackingTableHelper.Update(_baseDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
                }
                throw new ArgException(errorMessage);
            }
            catch (Exception)
            {
                // Continue on, do not set workflow status to failed, per Bill
                throw;
            }
        }
        public IList <UserAccessPolicy> CleanseFlowPoliciesForUser(SystemRoleType userRole, IList <UserAccessPolicy> policies)
        {
            if (CollectionUtils.IsNullOrEmpty(policies))
            {
                return(null);
            }
            if (userRole == SystemRoleType.Admin)
            {
                return(null);    // Admin is allowed everything
            }
            List <UserAccessPolicy> cleansedPolicies = new List <UserAccessPolicy>(policies.Count);
            IList <string>          protectedFlows   = _flowManager.GetProtectedFlowNames();

            foreach (UserAccessPolicy policy in policies)
            {
                if (policy.PolicyType != ServiceRequestAuthorizationType.Flow)
                {
                    cleansedPolicies.Add(policy);
                }
                else
                {
                    if (!IsFlowRoleTypePermittedForUserRole(userRole, policy.FlowRoleType))
                    {
                        throw new ArgumentException(string.Format("Invalid user role (\"{0}\") specified for flow role (\"{0}\")",
                                                                  EnumUtils.ToDescription(userRole), EnumUtils.ToDescription(policy.FlowRoleType)));
                    }

                    bool isFlowProtected =
                        (CollectionUtils.IndexOf(protectedFlows, policy.TypeQualifier,
                                                 StringComparison.InvariantCultureIgnoreCase) >= 0);

                    if (userRole == SystemRoleType.Authed)
                    {
                        DebugUtils.AssertDebuggerBreak(policy.FlowRoleType == FlowRoleType.Endpoint);
                        if (isFlowProtected)
                        {
                            cleansedPolicies.Add(policy);
                        }
                        else
                        {
                            // Don't add, must be FlowRoleType.Endpoint and flow is not protected
                        }
                    }
                    else if (userRole == SystemRoleType.Program)
                    {
                        if (isFlowProtected)
                        {
                            cleansedPolicies.Add(policy);
                        }
                        else
                        {
                            if ((policy.FlowRoleType == FlowRoleType.Modify) ||
                                (policy.FlowRoleType == FlowRoleType.View))
                            {
                                // Only add in these cases, not if FlowRoleType == FlowRoleType.Endpoint
                                // since flow is not protected
                                cleansedPolicies.Add(policy);
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Unrecognized user role specified: \"(0)\"",
                                                    EnumUtils.ToDescription(userRole));
                    }
                }
            }
            return(CollectionUtils.IsNullOrEmpty(cleansedPolicies) ? null : cleansedPolicies);
        }
Exemple #9
0
        public override void ProcessTask(string requestId)
        {
            ProcessTaskInit(requestId);

            _submissionTrackingDataType = SubmissionTrackingTableHelper.GetActiveSubmissionTrackingElement(_stagingDao, out _submissionTrackingDataTypePK);

            if (_submissionTrackingDataType == null)
            {
                _submissionTrackingDataType = new SubmissionTrackingDataType();
            }

            if (_submissionTrackingDataType.WorkflowStatus == TransactionStatusCode.Pending && _submissionTrackingDataType.ETLCompletionDateTimeSpecified == false)
            {
                AppendAuditLogEvent("Previous ETL execution in the tracking table with primary key \"{0}\" did not complete due to unrecoverable database error. Setting transaction to Failed."
                                    , _submissionTrackingDataTypePK);
                // Update submission status in tracking table
                _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                _submissionTrackingDataType.WorkflowStatusMessage = "ETL did not complete due to unrecoverable database error";
                SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);

                //create a new submission tracking record for the current workflow execution
                _submissionTrackingDataType   = new SubmissionTrackingDataType();
                _submissionTrackingDataTypePK = null;
            }
            else if (_submissionTrackingDataType.SubmissionDateTimeSpecified)
            {
                DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);
                AppendAuditLogEvent("There is a pending partner submission in the tracking table with primary key \"{0}\", exiting plugin ...",
                                    _submissionTrackingDataTypePK);
                return;
            }

            try
            {
                // Attempt to run the ETL to populate staging tables
                if (!DoExtract())
                {
                    return;
                }
                DebugUtils.AssertDebuggerBreak(_submissionTrackingDataTypePK != null);

                // Attempt to load the submission file from staging
                string submitFilePath;
                if (!DoXmlLoad(out submitFilePath))
                {
                    return;
                }

                // Attempt to submit file
                string submitTransactionId;
                if (!DoSubmission(submitFilePath, out submitTransactionId))
                {
                    return;
                }

                // Update submission status in tracking table
                _submissionTrackingDataType.WorkflowStatus              = TransactionStatusCode.Pending;
                _submissionTrackingDataType.WorkflowStatusMessage       = "The ICIS data has been submitted";
                _submissionTrackingDataType.SubmissionDateTime          = DateTime.Now;
                _submissionTrackingDataType.SubmissionDateTimeSpecified = true;
                _submissionTrackingDataType.SubmissionTransactionId     = submitTransactionId;
                SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
            }
            catch (Exception ex)
            {
                if (_submissionTrackingDataTypePK != null)
                {
                    _submissionTrackingDataType.WorkflowStatus        = TransactionStatusCode.Failed;
                    _submissionTrackingDataType.WorkflowStatusMessage = string.Format("An error occurred during processing: {0}", ExceptionUtils.GetDeepExceptionMessage(ex));
                    SubmissionTrackingTableHelper.Update(_stagingDao, _submissionTrackingDataTypePK, _submissionTrackingDataType);
                }
                throw;
            }
        }
Exemple #10
0
 public override void SetSelectColumnValue <T>(T objectToSet, object value, ColumnCachedValues cachedValues)
 {
     DebugUtils.AssertDebuggerBreak(cachedValues != null);
     cachedValues.ObjectToPrimaryKeyMap[objectToSet] = value;
 }
        protected virtual void SaveToDatabase(object parentOfObjectToSave, object objectToSave,
                                              Table tableOfObjectToSave, ColumnCachedValues cachedValues, MappingContext mappingContext,
                                              Dictionary <string, int> insertRowCounts, IDbCommand command)
        {
            if (objectToSave == null)
            {
                return;
            }

            Type objectToSaveType = objectToSave.GetType();

            if (tableOfObjectToSave == null)
            {
                tableOfObjectToSave = mappingContext.GetTableForType(objectToSaveType);
            }

            Table parentTable = null;

            if (parentOfObjectToSave != null)
            {
                parentTable = mappingContext.GetTableForType(parentOfObjectToSave.GetType());
            }

            if (tableOfObjectToSave.PopulateInsertValues(command, parentOfObjectToSave, parentTable, objectToSave, cachedValues))
            {
                DebugUtils.AssertDebuggerBreak(command.Parameters.Count == tableOfObjectToSave.AllColumns.Count);
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    DebugUtils.CheckDebuggerBreak();
                    throw;
                }
                if (insertRowCounts != null)
                {
                    int value;
                    if (insertRowCounts.TryGetValue(tableOfObjectToSave.TableName, out value))
                    {
                        value++;
                    }
                    else
                    {
                        value = 1;
                    }
                    insertRowCounts[tableOfObjectToSave.TableName] = value;
                }
            }
            // Save children
            if (tableOfObjectToSave.ChildRelationMembers != null)
            {
                try
                {
                    Dictionary <object, bool> alreadyProcessedMemberValues = new Dictionary <object, bool>(tableOfObjectToSave.ChildRelationMembers.Count);

                    foreach (ChildRelationInfo childRelation in tableOfObjectToSave.ChildRelationMembers)
                    {
                        object relationMember = objectToSave;
                        if (childRelation.ParentToMemberChain != null)
                        {
                            foreach (SameTableElementInfo sameTableElementInfo in childRelation.ParentToMemberChain)
                            {
                                relationMember = sameTableElementInfo.GetMemberValue(relationMember);
                                if (relationMember == null)
                                {
                                    break;
                                }
                            }
                        }

                        if (relationMember != null)
                        {
                            if (childRelation.IsOneToMany)
                            {
                                IEnumerable memberEnumerable = childRelation.GetMemberEnumerable(relationMember);
                                if (memberEnumerable != null)
                                {
                                    if (alreadyProcessedMemberValues.ContainsKey(memberEnumerable))
                                    {
                                        // This is for object[] members that may be mapped to multiple types
                                    }
                                    else
                                    {
                                        bool insertedAny = false;
                                        alreadyProcessedMemberValues[memberEnumerable] = true;
                                        Table elementTable = null;
                                        if (Utils.IsValidColumnType(childRelation.ValueType))
                                        {
                                            elementTable = childRelation.ChildTable;
                                        }
                                        foreach (object element in memberEnumerable)
                                        {
                                            if (element != null)
                                            {
                                                SaveToDatabase(objectToSave, element, elementTable, cachedValues, mappingContext,
                                                               insertRowCounts, command);
                                                insertedAny = true;
                                            }
                                        }
                                        if (!insertedAny)
                                        {
                                        }
                                    }
                                }
                            }
                            else // One to one
                            {
                                object element = childRelation.GetMemberValue(relationMember);
                                if (element != null)
                                {
                                    if (alreadyProcessedMemberValues.ContainsKey(element))
                                    {
                                        // This is for object members that may be mapped to multiple types
                                    }
                                    else
                                    {
                                        alreadyProcessedMemberValues[element] = true;
                                        Table elementTable = null;
                                        if (Utils.IsValidColumnType(childRelation.ValueType))
                                        {
                                            elementTable = childRelation.ChildTable;
                                        }
                                        if (element != null)
                                        {
                                            SaveToDatabase(objectToSave, element, elementTable, cachedValues, mappingContext,
                                                           insertRowCounts, command);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    DebugUtils.CheckDebuggerBreak();
                    throw;
                }
            }
        }
Exemple #12
0
        protected virtual Dictionary <object, IList> LoadObjectInstancesToList(Table tableOfObjectsToLoad, Dictionary <object, object> parentPKToObjectMap,
                                                                               IDictionary <string, DbAppendSelectWhereClause> appendSelectWhereClauseMap,
                                                                               ColumnCachedValues cachedValues, MappingContext mappingContext,
                                                                               IDbCommand command)
        {
            Dictionary <object, IList>  list = null;
            Dictionary <object, bool>   anyInstanceFieldsWereSetMap = null;
            Dictionary <object, object> pkToObjectMap = null;

            bool isVirtualObjectTable             = tableOfObjectsToLoad.IsVirtualTable;
            bool isCustomXmlStringFormatTypeTable = false;

            if (isVirtualObjectTable)
            {
                isCustomXmlStringFormatTypeTable = tableOfObjectsToLoad.TableRootType.IsSubclassOf(typeof(CustomXmlStringFormatTypeBase));
            }

            using (IDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    int    readerIndex = 0;
                    object pk = null, fk = null, pkKey = null, fkKey = null;
                    bool   skip = false;
                    bool   anyObjectToSetFieldsWereSet = false;
                    Column pkColumn = null, fkColumn = null;
                    object objectToSet = null;
                    // isVirtualObjectTable == true if this table represents a string[], int[], etc. member
                    foreach (Column column in tableOfObjectsToLoad.DirectColumns)
                    {
                        if (!column.NoLoad)
                        {
                            object value = reader.GetValue(readerIndex++);

                            if (value == DBNull.Value)
                            {
                                value = null;
                            }

                            if (column.IsPrimaryKey)
                            {
                                pkKey    = value + "_" + tableOfObjectsToLoad.TableName;
                                pkColumn = column;
                                pk       = value;
                            }
                            else if (column.IsForeignKey)
                            {
                                if (value != null)
                                {
                                    fkKey = value + "_" + ((ForeignKeyColumn)column).ForeignTable.TableName;
                                    if (fkColumn != null)
                                    {
                                        if (pk != null)
                                        {
                                            throw new ArgException("The table \"{0}\" has a row with a primary key of \"{1}\" that has more than one foreign key specified.  Please specify only one foreign key per row for this table.",
                                                                   column.Table.TableName, pk.ToString());
                                        }
                                        else
                                        {
                                            throw new ArgException("The table \"{0}\" has a row that has more than one foreign key specified.  Please specify only one foreign key per row for this table.",
                                                                   column.Table.TableName);
                                        }
                                    }
                                    if (!parentPKToObjectMap.ContainsKey(fkKey))
                                    {
                                        // This object has no parent, assume we skip it
                                        skip = true;
                                        break;
                                    }
                                    fkColumn = column;
                                    fk       = value;
                                }
                            }
                            else
                            {
                                if (value != null)
                                {
                                    if (isVirtualObjectTable)
                                    {
                                        if (isCustomXmlStringFormatTypeTable)
                                        {
                                            CustomXmlStringFormatTypeBase newObjectToSet = (CustomXmlStringFormatTypeBase)Activator.CreateInstance(tableOfObjectsToLoad.TableRootType);
                                            newObjectToSet.SetValue(value);
                                            objectToSet = newObjectToSet;
                                        }
                                        else
                                        {
                                            objectToSet = column.GetSetMemberValue(value);
                                        }
                                    }
                                    else
                                    {
                                        if (objectToSet == null)
                                        {
                                            objectToSet = Activator.CreateInstance(tableOfObjectsToLoad.TableRootType);
                                        }
                                        column.SetSelectColumnValue(objectToSet, value, cachedValues);
                                        anyObjectToSetFieldsWereSet = true;
                                    }
                                }
                            }
                        }
                    }
                    if (skip)
                    {
                        continue;
                    }

                    if (objectToSet == null)
                    {
                        objectToSet = Activator.CreateInstance(tableOfObjectsToLoad.TableRootType);
                    }
                    ExceptionUtils.ThrowIfNull(pkColumn, "pkColumn");
                    ExceptionUtils.ThrowIfNull(pk, "pk");
                    if (!isVirtualObjectTable)
                    {
                        pkColumn.SetSelectColumnValue(objectToSet, pk, cachedValues);

                        if (fkColumn != null)
                        {
                            fkColumn.SetSelectColumnValue(objectToSet, fk, cachedValues);
                        }
                        else
                        {
                            if (parentPKToObjectMap != null)
                            {
                                throw new ArgException("The table \"{0}\" has a row with a primary key of \"{1}\" that does not have a foreign key specified.",
                                                       pkColumn.Table.TableName, pk.ToString());
                            }
                            fk    = pk;
                            fkKey = pkKey;
                        }
                        if (mappingContext.UseNewSameTableMapping)
                        {
                            LoadSameTableInstancesNew(objectToSet, tableOfObjectsToLoad.ChildSameTableElements, cachedValues,
                                                      reader, ref readerIndex, ref anyObjectToSetFieldsWereSet);
                        }
                        else
                        {
                            LoadSameTableInstances(objectToSet, tableOfObjectsToLoad.ChildSameTableElements, cachedValues,
                                                   reader, ref readerIndex, ref anyObjectToSetFieldsWereSet);
                        }
                    }

                    int fieldCount = reader.FieldCount;
                    if (readerIndex != fieldCount)
                    {
                        throw new IndexOutOfRangeException(string.Format("The number of selected column values ({0}) is less than the expected number ({1}) for the object \"{2}\" and sql \"{3}\".",
                                                                         reader.FieldCount.ToString(), readerIndex.ToString(),
                                                                         tableOfObjectsToLoad.TableRootType.Name, tableOfObjectsToLoad.SelectSql));
                    }
                    if (list == null)
                    {
                        list          = new Dictionary <object, IList>();
                        pkToObjectMap = new Dictionary <object, object>();
                        anyInstanceFieldsWereSetMap = new Dictionary <object, bool>();
                    }
                    IList listInstance;
                    if (!list.TryGetValue(fkKey, out listInstance))
                    {
                        listInstance = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(tableOfObjectsToLoad.TableRootType));
                        list.Add(fkKey, listInstance);
                    }
                    try
                    {
                        listInstance.Add(objectToSet);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    if (!isVirtualObjectTable)
                    {
                        pkToObjectMap.Add(pkKey, objectToSet);
                        anyInstanceFieldsWereSetMap.Add(objectToSet, anyObjectToSetFieldsWereSet);
                    }
                }
            }
            if (!isVirtualObjectTable)
            {
                if (list != null)
                {
                    // Load children
                    if (tableOfObjectsToLoad.ChildRelationMembers != null)
                    {
                        foreach (ChildRelationInfo childRelation in tableOfObjectsToLoad.ChildRelationMembers)
                        {
                            Table elementTable = null;
                            if (Utils.IsValidColumnType(childRelation.ValueType))
                            {
                                elementTable = childRelation.ChildTable;
                            }
                            if (childRelation.IsOneToMany)
                            {
                                Dictionary <object, IList> fkMap =
                                    LoadObjectInstancesToList(childRelation.ValueType, elementTable, pkToObjectMap, appendSelectWhereClauseMap, cachedValues,
                                                              mappingContext, command);
                                if (fkMap != null)
                                {
                                    foreach (KeyValuePair <object, IList> pair in fkMap)
                                    {
                                        object objectToSet = pkToObjectMap[pair.Key];
                                        if (childRelation.ParentToMemberChain != null)
                                        {
                                            foreach (SameTableElementInfo sameTableElementInfo in childRelation.ParentToMemberChain)
                                            {
                                                object childObjectToSet = sameTableElementInfo.GetMemberValue(objectToSet);
                                                if (childObjectToSet == null)
                                                {
                                                    childObjectToSet = Activator.CreateInstance(sameTableElementInfo.MemberType);
                                                }
                                                objectToSet = childObjectToSet;
                                            }
                                        }
                                        DebugUtils.AssertDebuggerBreak(pair.Value != null);
                                        childRelation.SetMemberValue(objectToSet, pair.Value);
                                        anyInstanceFieldsWereSetMap[objectToSet] = true;
                                    }
                                }
                            }
                            else // One to one
                            {
                                Dictionary <object, IList> fkMap =
                                    LoadObjectInstancesToList(childRelation.ValueType, elementTable, pkToObjectMap, appendSelectWhereClauseMap, cachedValues,
                                                              mappingContext, command);
                                if (fkMap != null)
                                {
                                    foreach (KeyValuePair <object, IList> pair in fkMap)
                                    {
                                        if (pair.Value.Count != 1)
                                        {
                                            throw new InvalidOperationException(string.Format("Relation is One-To-One but got more than one element: {0}",
                                                                                              childRelation.ToString()));
                                        }
                                        object itemToSet = CollectionUtils.FirstItem(pair.Value);
                                        DebugUtils.AssertDebuggerBreak(itemToSet != null);
                                        object objectToSet = pkToObjectMap[pair.Key];
                                        if (childRelation.ParentToMemberChain != null)
                                        {
                                            foreach (SameTableElementInfo sameTableElementInfo in childRelation.ParentToMemberChain)
                                            {
                                                object childObjectToSet = sameTableElementInfo.GetMemberValue(objectToSet);
                                                if (childObjectToSet == null)
                                                {
                                                    childObjectToSet = Activator.CreateInstance(sameTableElementInfo.MemberType);
                                                }
                                                objectToSet = childObjectToSet;
                                            }
                                        }
                                        childRelation.SetMemberValue(objectToSet, itemToSet);
                                        anyInstanceFieldsWereSetMap[objectToSet] = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
#if REMOVE_EMPTY_OBJECTS
            if (list != null)
            {
                List <string> removeKeys = new List <string>();
                foreach (KeyValuePair <string, IList> pair in list)
                {
                    if (pair.Value != null)
                    {
                        for (int i = pair.Value.Count - 1; i >= 0; --i)
                        {
                            object checkObject = pair.Value[i];
                            if (!anyInstanceFieldsWereSetMap[checkObject])
                            {
                                pair.Value.RemoveAt(i);
                            }
                        }
                    }
                    if (CollectionUtils.IsNullOrEmpty(pair.Value))
                    {
                        removeKeys.Add(pair.Key);
                    }
                }
                foreach (string removeKey in removeKeys)
                {
                    list.Remove(removeKey);
                }
            }
#endif // REMOVE_EMPTY_OBJECTS

            return(CollectionUtils.IsNullOrEmpty(list) ? null : list);
        }
        protected void ScheduleItemDataBound(RepeaterItem item, ScheduledItem scheduledItem)
        {
            Image         imageStatus          = item.FindControl("executeStatusImage") as Image;
            ImageButton   runNowButton         = item.FindControl("runNowImageButton") as ImageButton;
            HtmlTableRow  valueDescriptionRow  = item.FindControl("valueDescriptionRow") as HtmlTableRow;
            HtmlTableCell valueDescriptionItem = item.FindControl("valueDescriptionItem") as HtmlTableCell;
            Image         scheduleImage        = item.FindControl("scheduleImage") as Image;
            HiddenField   hiddenScheduleId     = item.FindControl("hiddenScheduleId") as HiddenField;
            HtmlTableRow  lastRunInfoRow       = item.FindControl("lastRunInfoRow") as HtmlTableRow;

            DebugUtils.AssertDebuggerBreak(runNowButton != null);
            DebugUtils.AssertDebuggerBreak(valueDescriptionRow != null);
            DebugUtils.AssertDebuggerBreak(valueDescriptionItem != null);
            DebugUtils.AssertDebuggerBreak(lastRunInfoRow != null);
            if (scheduledItem.ExecuteStatus == ScheduleExecuteStatus.Running)
            {
                valueDescriptionRow.Visible = false;
                runNowButton.Visible        = false;
                lastRunInfoRow.Visible      = false;
                scheduleImage.ImageUrl      = ((item.ItemIndex % 2) == 0) ?
                                              "../Images/UI/ajax-loader2_even.gif" : "../Images/UI/ajax-loader2_odd.gif";
            }
            else
            {
                valueDescriptionRow.Visible    = true;
                runNowButton.Visible           = true;
                scheduleImage.ImageUrl         = "../Images/UI/time.png";
                runNowButton.ToolTip           = string.Format("Run '{0}' Now", scheduledItem.Name);
                runNowButton.CommandArgument   = scheduledItem.Id;
                valueDescriptionItem.InnerText = scheduledItem.Description;
                if (!string.IsNullOrEmpty(scheduledItem.LastExecuteActivityId))
                {
                    imageStatus.ImageUrl   = GetImageUrlForExecuteStatus(scheduledItem.ExecuteStatus);
                    imageStatus.ToolTip    = "Status: " + EnumUtils.ToDescription(scheduledItem.ExecuteStatus);
                    lastRunInfoRow.Visible = true;
                    if (lastRunInfoRow != null)
                    {
                        ImageButton imageButton = item.FindControl("transactionImageButton") as ImageButton;
                        if (imageButton != null)
                        {
                            imageButton.ToolTip         = "View Transaction Detail";
                            imageButton.CommandArgument = scheduledItem.LastExecuteActivityId;
                        }
                    }
                    HtmlTableRow lastRunTextRow = item.FindControl("lastRunTextRow") as HtmlTableRow;
                    if (lastRunTextRow != null)
                    {
                        Label       infoLabel       = item.FindControl("infoTextLabel") as Label;
                        HiddenField activityIdField = item.FindControl("activityIdField") as HiddenField;
                        if ((infoLabel != null) && (activityIdField != null))
                        {
                            activityIdField.Value = scheduledItem.LastExecuteActivityId;
                        }
                    }
                }
                else
                {
                    imageStatus.Visible    = false;
                    lastRunInfoRow.Visible = false;
                }
            }
        }
Exemple #14
0
        public static ActivityDataType MapActivity(NamedNullMappingDataReader readerEx)
        {
            ActivityDataType activity = new ActivityDataType();

            activity.ActivityDescription = new ActivityDescriptionDataType();
            activity.ActivityDescription.ActivityIdentifier           = readerEx.GetString("ACTIVITYID");
            activity.ActivityDescription.ActivityTypeCode             = readerEx.GetString("ACTIVITYTYPECODE");
            activity.ActivityDescription.ActivityMediaName            = readerEx.GetString("ACTIVITYMEDIA");
            activity.ActivityDescription.ActivityMediaSubdivisionName = readerEx.GetNullString("ACTIVITYMEDIASUBDIVISION");
            activity.ActivityDescription.ActivityStartDate            = readerEx.GetDateTime("ACTIVITYSTARTDATE");
            activity.ActivityDescription.ActivityStartTime            = GetNullTimeData(readerEx, "STARTTIME", "STARTTIMEZONE");
            activity.ActivityDescription.ActivityEndDateSpecified     = !readerEx.IsDBNull("ACTIVITYENDDATE");
            if (activity.ActivityDescription.ActivityEndDateSpecified)
            {
                activity.ActivityDescription.ActivityEndDate = readerEx.GetDateTime("ACTIVITYENDDATE");
            }
            activity.ActivityDescription.ActivityEndTime            = GetNullTimeData(readerEx, "ENDTIME", "ENDTIMEZONE");
            activity.ActivityDescription.ActivityRelativeDepthName  = readerEx.GetNullString("RELATIVEDEPTH");
            activity.ActivityDescription.ActivityDepthHeightMeasure =
                GetNullMeasureCompactData(readerEx, "DEPTHHEIGHTMEASURE", "DEPTHHEIGHTMEASUREUNIT");
            activity.ActivityDescription.ActivityTopDepthHeightMeasure =
                GetNullMeasureCompactData(readerEx, "TOPDEPTHHEIGHTMEASURE", "TOPDEPTHHEIGHTMEASUREUNIT");
            activity.ActivityDescription.ActivityBottomDepthHeightMeasure =
                GetNullMeasureCompactData(readerEx, "BOTTOMDEPTHHEIGHTMEASURE", "BOTTOMDEPTHHEIGHTMEASUREUNIT");
            activity.ActivityDescription.ActivityDepthAltitudeReferencePointText = readerEx.GetNullString("DEPTHALTITUDEREFPOINT");
            activity.ActivityDescription.MonitoringLocationIdentifier            = readerEx.GetNullString("MONLOCID");
            activity.ActivityDescription.ActivityCommentText = readerEx.GetNullString("ACTIVITYCOMMENT");
            if (!readerEx.IsDBNull("LATITUDEMEASURE") || !readerEx.IsDBNull("LONGITUDEMEASURE") ||
                !readerEx.IsDBNull("HORIZCOLLMETHOD") || !readerEx.IsDBNull("HORIZCOORDREFSYSDATUM"))
            {
                activity.ActivityLocation = new ActivityLocationDataType();
                activity.ActivityLocation.LatitudeMeasure           = ToDecimal(readerEx.GetString("LATITUDEMEASURE"));
                activity.ActivityLocation.LongitudeMeasure          = ToDecimal(readerEx.GetString("LONGITUDEMEASURE"));
                activity.ActivityLocation.SourceMapScaleNumeric     = readerEx.GetNullString("SOURCEMAPSCALE");
                activity.ActivityLocation.HorizontalAccuracyMeasure =
                    GetNullMeasureCompactData(readerEx, "HORIZACCURACYMEASURE", "HORIZACCURACYMEASUREUNIT");
                activity.ActivityLocation.HorizontalCollectionMethodName = readerEx.GetString("HORIZCOLLMETHOD");
                activity.ActivityLocation.HorizontalCoordinateReferenceSystemDatumName = readerEx.GetString("HORIZCOORDREFSYSDATUM");
            }
            activity.BiologicalActivityDescription = new BiologicalActivityDescriptionDataType();
            activity.BiologicalActivityDescription.AssemblageSampledName = readerEx.GetNullString("BIOACTIVITYASSEMBLAGESAMPD");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation = new BiologicalHabitatCollectionInformationDataType();
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.CollectionDuration =
                GetNullMeasureCompactData(readerEx, "BIOHABCOLLDURATIONMEASURE", "BIOHABCOLLDURATIONMEASUREUNIT");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.SamplingComponentName =
                readerEx.GetNullString("BIOHABSAMPCOMP");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.SamplingComponentPlaceInSeriesNumeric =
                readerEx.GetNullString("BIOHABSAMPCOMPPLACEINSERIES");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.ReachWidthMeasure =
                GetNullMeasureCompactData(readerEx, "BIOHABREACHLENGTHMEASURE", "BIOHABREACHLENGTHMEASUREUNIT");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.ReachLengthMeasure =
                GetNullMeasureCompactData(readerEx, "BIOHABREACHWIDTHMEASURE", "BIOHABREACHWIDTHMEASUREUNIT");
            activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.PassCount = readerEx.GetNullString("BIOHABPASSCOUNT");
            if (!readerEx.IsDBNull("BIOHABNETTYPE") ||
                !readerEx.IsDBNull("BIOHABNETSURFACEAREAMEASURE") || !readerEx.IsDBNull("BIOHABNETSURFACEMEASUREUNIT") ||
                !readerEx.IsDBNull("BIOHABNETMESHSIZEMEASURE") || !readerEx.IsDBNull("BIOHABNETMESHMEASUREUNIT"))
            {
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation             = new NetInformationDataType();
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation.NetTypeName =
                    readerEx.GetString("BIOHABNETTYPE");
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation.NetSurfaceAreaMeasure =
                    GetNullMeasureCompactData(readerEx, "BIOHABNETSURFACEAREAMEASURE", "BIOHABNETSURFACEMEASUREUNIT");
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation.NetMeshSizeMeasure =
                    GetNullMeasureCompactData(readerEx, "BIOHABNETMESHSIZEMEASURE", "BIOHABNETMESHMEASUREUNIT");
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation.BoatSpeedMeasure =
                    GetNullMeasureCompactData(readerEx, "BIOHABNETBOATSPEEDMEASURE", "BIOHABNETBOATSPEEDMEASUREUNIT");
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation.CurrentSpeedMeasure =
                    GetNullMeasureCompactData(readerEx, "BIOHABNETCURRSPEEDMEASURE", "BIOHABNETCURRSPEEDMEASUREUNIT");
            }
            if ((activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.CollectionDuration == null) &&
                string.IsNullOrEmpty(activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.SamplingComponentName) &&
                string.IsNullOrEmpty(activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.SamplingComponentPlaceInSeriesNumeric) &&
                (activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.ReachWidthMeasure == null) &&
                (activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.ReachLengthMeasure == null) &&
                string.IsNullOrEmpty(activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.PassCount) &&
                (activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation.NetInformation == null))
            {
                activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation = null;
            }
            activity.BiologicalActivityDescription.ToxicityTestType = readerEx.GetNullString("BIOACTIVITYTOXICITYTESTTYPE");
            if (string.IsNullOrEmpty(activity.BiologicalActivityDescription.AssemblageSampledName) &&
                string.IsNullOrEmpty(activity.BiologicalActivityDescription.ToxicityTestType) &&
                (activity.BiologicalActivityDescription.BiologicalHabitatCollectionInformation == null))
            {
                activity.BiologicalActivityDescription = null;
            }
            activity.SampleDescription = new SampleDescriptionDataType();
            if (!readerEx.IsDBNull("SAMPCOLLMETHODID") || !readerEx.IsDBNull("SAMPCOLLMETHODIDCONTEXT") || !readerEx.IsDBNull("SAMPCOLLMETHOD"))
            {
                activity.SampleDescription.SampleCollectionMethod = new ReferenceMethodDataType();
                activity.SampleDescription.SampleCollectionMethod.MethodIdentifier        = readerEx.GetString("SAMPCOLLMETHODID");
                activity.SampleDescription.SampleCollectionMethod.MethodIdentifierContext = readerEx.GetString("SAMPCOLLMETHODIDCONTEXT");
                activity.SampleDescription.SampleCollectionMethod.MethodName = readerEx.GetString("SAMPCOLLMETHOD");
                activity.SampleDescription.SampleCollectionMethod.MethodQualifierTypeName = readerEx.GetNullString("SAMPCOLLMETHODQUALIFIER");
                activity.SampleDescription.SampleCollectionMethod.MethodDescriptionText   = readerEx.GetNullString("SAMPCOLLMETHODDESC");
            }
            activity.SampleDescription.SampleCollectionEquipmentName        = readerEx.GetString("SAMPCOLLEQUIPMENT");
            activity.SampleDescription.SampleCollectionEquipmentCommentText = readerEx.GetNullString("SAMPCOLLEQUIPMENTCOMMENT");
            if (!readerEx.IsDBNull("SAMPPREPCONTTYPE") || !readerEx.IsDBNull("SAMPPREPCONTCOLOR") || !readerEx.IsDBNull("SAMPPREPCONTSAMPTRANSSTORDESC") ||
                !readerEx.IsDBNull("SAMPPREPID") || !readerEx.IsDBNull("SAMPPREPIDCONTEXT") || !readerEx.IsDBNull("SAMPPREP"))
            {
                activity.SampleDescription.SamplePreparation = new SamplePreparationDataType();
                if (!readerEx.IsDBNull("SAMPPREPID") || !readerEx.IsDBNull("SAMPPREPIDCONTEXT") || !readerEx.IsDBNull("SAMPPREP"))
                {
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod = new ReferenceMethodDataType();
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod.MethodIdentifier        = readerEx.GetString("SAMPPREPID");
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod.MethodIdentifierContext = readerEx.GetString("SAMPPREPIDCONTEXT");
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod.MethodName = readerEx.GetString("SAMPPREP");
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod.MethodQualifierTypeName = readerEx.GetNullString("SAMPPREPQUALIFIERTYPE");
                    activity.SampleDescription.SamplePreparation.SamplePreparationMethod.MethodDescriptionText   = readerEx.GetNullString("SAMPPREPDESC");
                }
                activity.SampleDescription.SamplePreparation.SampleContainerTypeName           = readerEx.GetString("SAMPPREPCONTTYPE");
                activity.SampleDescription.SamplePreparation.SampleContainerColorName          = readerEx.GetString("SAMPPREPCONTCOLOR");
                activity.SampleDescription.SamplePreparation.ChemicalPreservativeUsedName      = readerEx.GetNullString("SAMPPREPCONTCHEMPRESERVUSED");
                activity.SampleDescription.SamplePreparation.ThermalPreservativeUsedName       = readerEx.GetNullString("SAMPPREPCONTTHERMALPRESERVUSED");
                activity.SampleDescription.SamplePreparation.SampleTransportStorageDescription = readerEx.GetString("SAMPPREPCONTSAMPTRANSSTORDESC");
            }
            if (activity.SampleDescription.SampleCollectionMethod == null)
            {
                DebugUtils.AssertDebuggerBreak(string.IsNullOrEmpty(activity.SampleDescription.SampleCollectionEquipmentName));
                // SampleCollectionMethod is required
                activity.SampleDescription = null;
            }
            activity.ResultCount = readerEx.GetNullString("RESULTCOUNT");
            // TODO: TMPACTIVITYTYPE and TMPPROJECTID not used
            return(activity);
        }
Exemple #15
0
 public void PublishUniqueId(Control control)
 {
     DebugUtils.AssertDebuggerBreak(!string.IsNullOrEmpty(control.ID));
     DebugUtils.AssertDebuggerBreak(!string.IsNullOrEmpty(control.UniqueID));
     UniqueIdsToPublish[control.ID] = control.UniqueID;
 }
Exemple #16
0
 public void PublishClientId(Control control)
 {
     DebugUtils.AssertDebuggerBreak(!string.IsNullOrEmpty(control.ID));
     DebugUtils.AssertDebuggerBreak(!string.IsNullOrEmpty(control.ClientID));
     ClientIdsToPublish[control.ID] = control.ClientID;
 }