Esempio n. 1
0
        /// <summary>
        /// Create a ImmutableInstance of AgencySchema
        /// </summary>
        /// <param name="_AgencyObject">Agency Object</param>
        /// <param name="AgencyOrganisationNames">Agency Organisation Names (Get it from File Config)</param>
        /// <returns>IAgencyScheme</returns>
        public IAgencyScheme BuildAgencyScheme(IAgencyMutableObject _AgencyObject, List <SdmxObjectNameDescription> AgencyOrganisationNames)
        {
            try
            {
                IAgencyScheme defschema = AgencySchemeCore.CreateDefaultScheme();
                IAgencySchemeMutableObject mutabledefschema = defschema.MutableInstance;

                mutabledefschema.AgencyId = FlyConfiguration.MainAgencyId;
                mutabledefschema.Names.Clear();
                foreach (var item in AgencyOrganisationNames)
                {
                    mutabledefschema.AddName(item.Lingua, item.Name);
                }


                mutabledefschema.Items.Clear();
                mutabledefschema.AddItem(_AgencyObject);

                return(mutabledefschema.ImmutableInstance);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
        private IAgencySchemeMutableObject GetAgencyschemeForm(IAgencySchemeMutableObject agencyScheme)
        {
            if (agencyScheme == null) return GetAgencyschemeForm();

            bool isInError = false;                 // Indicatore di errore
            string messagesGroup = string.Empty;    // Stringa di raggruppamento errori
            int errorCounter = 1;                   // Contatore errori

            #region AGENCYSCHEME ID
            if (!ValidationUtils.CheckIdFormat(txtDSDID.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_id_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region AGENCYSCHEME AGENCY
            //if ( cmbAgencies.Text.Trim().Equals( string.Empty ) )
            //{
            //    messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_agency_missing + "<br /><br />";
            //    errorCounter++;
            //    isInError = true;
            //}
            #endregion

            #region AGENCYSCHEME VERSION
            if (!ValidationUtils.CheckVersionFormat(txtVersion.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_version_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            /* URI NOT REQUIRED */
            #region AGENCYSCHEME URI
            if ((txtDSDURI.Text != string.Empty) && !ValidationUtils.CheckUriFormat(txtDSDURI.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_uri_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region AGENCYSCHEME NAMES
            if (AddTextName.TextObjectList == null || AddTextName.TextObjectList.Count == 0)
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_list_name_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region AGENCYSCHEME START END DATE
            bool checkForDatesCombination = true;

            if (!txtValidFrom.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txtValidFrom.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_from_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txtValidTo.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txtValidTo.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_to_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txtValidFrom.Text.Trim().Equals(string.Empty) && !txtValidTo.Text.Trim().Equals(string.Empty))
            {
                // Controllo congruenza date
                if (checkForDatesCombination)
                {
                    if (!ValidationUtils.CheckDates(txtValidFrom.Text, txtValidTo.Text))
                    {
                        messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_diff + "<br /><br />";
                        errorCounter++;
                        isInError = true;
                    }
                }
            }
            #endregion

            if (isInError)
            {
                Utils.ShowDialog(messagesGroup, 300);
                return null;
            }

            #region CREATE AGENCYSCHEME FROM FORM

            agencyScheme.AgencyId = GetAgencyValue();
            agencyScheme.Id = txtDSDID.Text;
            agencyScheme.Version = txtVersion.Text;
            agencyScheme.FinalStructure = TertiaryBool.ParseBoolean(chkIsFinal.Checked);
            agencyScheme.Uri = (ValidationUtils.CheckUriFormat(txtDSDURI.Text) && !txtDSDURI.Text.Trim().Equals( string.Empty ) ) ? new Uri(txtDSDURI.Text) : null;
            if (!txtValidFrom.Text.Trim().Equals(string.Empty))
            {
                agencyScheme.StartDate = DateTime.ParseExact(txtValidFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            if (!txtValidTo.Text.Trim().Equals(string.Empty))
            {
                agencyScheme.EndDate = DateTime.ParseExact(txtValidTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            if (agencyScheme.Names.Count != 0)
            {
                agencyScheme.Names.Clear();
            }
            if (agencyScheme.Descriptions.Count != 0)
            {
                agencyScheme.Descriptions.Clear();
            }
            foreach (var tmpName in AddTextName.TextObjectList)
            {
                agencyScheme.AddName(tmpName.Locale, tmpName.Value);
            }
            if (AddTextDescription.TextObjectList != null)
                foreach (var tmpDescription in AddTextDescription.TextObjectList)
                {
                    agencyScheme.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }

            if (agencyScheme.Annotations.Count != 0)
            {
                agencyScheme.Annotations.Clear();
            }
            if (AnnotationGeneralControl.AnnotationObjectList != null)
                foreach (var annotation in AnnotationGeneralControl.AnnotationObjectList)
                {
                    agencyScheme.AddAnnotation(annotation);
                }

            #endregion

            return agencyScheme;
        }
        private bool SendQuerySubmit(IAgencySchemeMutableObject agencyScheme)
        {
            try
            {

                ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

                sdmxObjects.AddAgencyScheme(agencyScheme.ImmutableInstance);

                WSModel modelAgencyScheme = new WSModel();

                XmlDocument result = modelAgencyScheme.SubmitStructure(sdmxObjects);

                Utils.GetXMLResponseError(result);

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private bool SaveInMemory(IAgencySchemeMutableObject agencyScheme)
        {
            if (agencyScheme == null) return false;

            Session[KEY_PAGE_SESSION] = agencyScheme;

            return true;
        }
        private IAgencySchemeMutableObject InsertAgencyInAgencyscheme(IAgencySchemeMutableObject agencyScheme)
        {
            if (agencyScheme == null) return null;

            IAgencyMutableObject agency = new AgencyMutableCore();

            string agency_id = txt_id_new.Text.Trim();

            IList<ITextTypeWrapperMutableObject> agency_names = AddTextName_new.TextObjectList;
            IList<ITextTypeWrapperMutableObject> agency_descs = AddTextDescription_new.TextObjectList;
            // string code_order_str = txtOrderNewCode.Text.Trim();     ----- ORDINE

            #region AGENCYSCHEME ID
            if (ValidationUtils.CheckIdFormat(agency_id))
            {
                agency.Id = agency_id;
            }
            else
            {
                //lblErrorOnNewInsert.Text = Resources.Messages.err_id_format;
                Utils.AppendScript("location.href= '#agencies';");
                OpenAddAgencyPopUp();
                Utils.ShowDialog(Resources.Messages.err_id_format, 300);
                return null;
            }

            IEnumerable<IAgencyMutableObject> agencies = (from c in agencyScheme.Items where c.Id == agency_id select c).OfType<IAgencyMutableObject>();
            if (agencies.Count() > 0)
            {
                //lblErrorOnNewInsert.Text = Resources.Messages.err_id_exist;
                Utils.AppendScript("location.href= '#agencies';");
                OpenAddAgencyPopUp();
                Utils.ShowDialog(Resources.Messages.err_id_exist, 300);
                return null;
            }
            #endregion

            #region AGENCY NAMES
            if (agency_names != null)
            {
                foreach (var tmpName in agency_names)
                {
                    agency.AddName(tmpName.Locale, tmpName.Value);
                }
            }
            else
            {
                //lblErrorOnNewInsert.Text = Resources.Messages.err_list_name_format;
                Utils.AppendScript("location.href= '#agencies';");
                OpenAddAgencyPopUp();
                Utils.ShowDialog(Resources.Messages.err_list_name_format, 300);
                return null;
            }
            #endregion

            #region AGENCY DESCRIPTIONS
            if (agency_descs != null)
            {
                foreach (var tmpDescription in agency_descs)
                {
                    agency.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }
            }
            #endregion

            agencyScheme.Items.Add(agency);

            try
            {
                // Ultimo controllo se ottengo Immutable istanze validazione completa
                var canRead = agencyScheme.ImmutableInstance;
            }
            catch (Exception ex)
            {
                agencyScheme.Items.Remove(agency);

                return null;

            }
            return agencyScheme;
        }