コード例 #1
0
        private BWebServiceResponse DeleteRevision(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!CommonMethods.DoesRevisionExist(
                    Model,
                    RequestedRevisionIndex,
                    out Revision RevisionObject,
                    out int ModelRevisionListIx))
            {
                return(BWebResponse.NotFound("Revision does not exist."));
            }

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionFileEntryDeleteAll
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID,
                                                                   JObject.Parse(JsonConvert.SerializeObject(RevisionObject.FileEntry))
                                                               ),
                                                               _ErrorMessageAction);

            Model.ModelRevisions.RemoveAt(ModelRevisionListIx);
            Model.MRVLastUpdateTime = CommonMethods.GetTimeAsCreationTime();

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(Model)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionDeleted
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Revision has been deleted."));
        }
コード例 #2
0
        private BWebServiceResponse ProcessRequestLocked(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            var RequestedModelName = WebUtility.UrlDecode(RestfulUrlParameters[RestfulUrlParameter_ModelsKey]);

            if (!CommonMethods.TryGettingModelID(
                    DatabaseService,
                    RequestedModelName,
                    out RequestedModelID,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            RequestedUserID = RestfulUrlParameters[RestfulUrlParameter_UserIDKey];

            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            var OldSharedList = new List <string>(Model.ModelSharedWithUserIDs);

            if (!Model.ModelSharedWithUserIDs.Remove(RequestedUserID))
            {
                return(BWebResponse.NotFound("Given userId is not among sharees of the model."));
            }

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(Model)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelSharedWithUserIdsChanged
                                                               (
                                                                   RequestedModelID,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   OldSharedList,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Operation has been completed."));
        }
コード例 #3
0
        private BWebServiceResponse ListModels(Action <string> _ErrorMessageAction)
        {
            if (!DatabaseService.ScanTable(ModelDBEntry.DBSERVICE_MODELS_TABLE(), out List <JObject> ModelsJson, _ErrorMessageAction))
            {
                return(BWebResponse.InternalError("Scan-table operation has failed."));
            }

            var Result      = new JObject();
            var ModelsArray = new JArray();

            Result["models"] = ModelsArray;

            foreach (var ModelJson in ModelsJson)
            {
                var AsModel = JsonConvert.DeserializeObject <ModelDBEntry>(ModelJson.ToString());
                AsModel.Prune_NonGettableProperties();
                ModelsArray.Add(JObject.Parse(ModelJson.ToString()));
            }

            return(BWebResponse.StatusOK("List models operation has succeeded.", Result));
        }
コード例 #4
0
        public static bool TryGettingModelInfo(
            IBDatabaseServiceInterface _DatabaseService,
            string _ModelID,
            out JObject _SuccessResultJson,
            bool _bDeserialize, out ModelDBEntry _SuccessResultDeserialized,
            out BWebServiceResponse _FailureResponse,
            Action <string> _ErrorMessageAction = null)
        {
            _FailureResponse           = BWebResponse.InternalError("");
            _SuccessResultDeserialized = null;

            var ModelKey = new BPrimitiveType(_ModelID);

            if (!_DatabaseService.GetItem(
                    ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                    ModelDBEntry.KEY_NAME_MODEL_ID,
                    ModelKey,
                    ModelDBEntry.Properties,
                    out _SuccessResultJson,
                    _ErrorMessageAction))
            {
                _FailureResponse = BWebResponse.InternalError("Database fetch-model-info operation has failed.");
                return(false);
            }
            if (_SuccessResultJson == null)
            {
                _FailureResponse = BWebResponse.NotFound("Model does not exist.");
                return(false);
            }

            if (_bDeserialize)
            {
                _SuccessResultDeserialized = JsonConvert.DeserializeObject <ModelDBEntry>(_SuccessResultJson.ToString());
            }

            return(true);
        }
コード例 #5
0
            private void Cleanup_UniqueFileFields(Action <string> _ErrorMessageAction)
            {
                if (!DatabaseService.ScanTable(
                        UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                        out List <JObject> UniqueFieldsEntries,
                        _ErrorMessageAction))
                {
                    _ErrorMessageAction?.Invoke("Cleanup_UniqueFileFields: Table does not exist or ScanTable operation has failed.");
                    return;
                }
                if (UniqueFieldsEntries.Count == 0)
                {
                    return;
                }

                foreach (var Current in UniqueFieldsEntries)
                {
                    if (!Current.ContainsKey(ModelDBEntry.KEY_NAME_MODEL_ID))
                    {
                        continue;
                    }

                    if (!Current.ContainsKey(UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME))
                    {
                        continue;
                    }
                    var ModelUniqueName = (string)Current[UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME];

                    var ModelID = (string)Current[ModelDBEntry.KEY_NAME_MODEL_ID];
                    var Casted  = JsonConvert.DeserializeObject <UniqueFileFieldsDBEntry>(Current.ToString());

                    try
                    {
                        if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), ModelID, _ErrorMessageAction))
                        {
                            continue;
                        }

                        bool bDeleteEntry = false;

                        if (!DatabaseService.GetItem(
                                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                                ModelDBEntry.KEY_NAME_MODEL_ID,
                                new BPrimitiveType(ModelID),
                                ModelDBEntry.Properties,
                                out JObject ModelObject,
                                _ErrorMessageAction))
                        {
                            continue;
                        }
                        if (ModelObject == null)
                        {
                            //Model does not exist
                            bDeleteEntry = true;
                        }
                        else
                        {
                            var Model = JsonConvert.DeserializeObject <ModelDBEntry>(ModelObject.ToString());

                            bDeleteEntry = ModelUniqueName != Model.ModelName;
                        }

                        if (bDeleteEntry)
                        {
                            DatabaseService.DeleteItem(
                                UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                                UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                                new BPrimitiveType(ModelUniqueName),
                                out JObject _,
                                EBReturnItemBehaviour.DoNotReturn,
                                _ErrorMessageAction);
                        }
                    }
                    finally
                    {
                        Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), ModelID, _ErrorMessageAction);
                    }
                }
            }
コード例 #6
0
        private BWebServiceResponse ProcessRequestLocked(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            var RequestedModelName = WebUtility.UrlDecode(RestfulUrlParameters[RestfulUrlParameter_ModelsKey]);

            if (!CommonMethods.TryGettingModelID(
                    DatabaseService,
                    RequestedModelName,
                    out RequestedModelID,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            string  RequestPayload = null;
            JObject ParsedBody;

            using (var InputStream = _Context.Request.InputStream)
            {
                using var ResponseReader = new StreamReader(InputStream);
                try
                {
                    RequestPayload = ResponseReader.ReadToEnd();
                    ParsedBody     = JObject.Parse(RequestPayload);
                }
                catch (Exception e)
                {
                    _ErrorMessageAction?.Invoke("Model_ChangeSharingWithUsers-> Malformed request body. Body content: " + RequestPayload + ", Exception: " + e.Message + ", Trace: " + e.StackTrace);
                    return(BWebResponse.BadRequest("Malformed request body. Request must be a valid json form."));
                }
            }

            var bShareWithAllExists = ParsedBody.ContainsKey("shareWithAll");
            var bEmailsExist        = ParsedBody.ContainsKey("emails");
            var bUserIdsExist       = ParsedBody.ContainsKey("userIds");

            var FinalUserIds = new List <string>();

            bool bShareWithAll = false;

            if (bShareWithAllExists /*Exist*/)
            {
                if (ParsedBody["shareWithAll"].Type != JTokenType.Boolean)
                {
                    return(BWebResponse.BadRequest("Request is invalid."));
                }
                bShareWithAll = (bool)ParsedBody["shareWithAll"];

                if (bShareWithAll)
                {
                    if (bEmailsExist || bUserIdsExist)
                    {
                        return(BWebResponse.BadRequest("Request has shareWithAll field; therefore cannot have emails or userIds."));
                    }

                    FinalUserIds.Add("*");
                }
            }

            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!bShareWithAll)
            {
                var EmailAddresses = new List <string>();

                if (bEmailsExist)
                {
                    if (ParsedBody["emails"].Type != JTokenType.Array)
                    {
                        return(BWebResponse.BadRequest("Request is invalid."));
                    }
                    var AsJArray = (JArray)ParsedBody["emails"];

                    foreach (var Token in AsJArray)
                    {
                        if (Token.Type != JTokenType.String)
                        {
                            return(BWebResponse.BadRequest("Request is invalid."));
                        }

                        var Lowered = ((string)Token).ToLower();
                        if (!EmailAddresses.Contains(Lowered))
                        {
                            EmailAddresses.Add(Lowered);
                        }
                    }
                }
                if (bUserIdsExist)
                {
                    if (ParsedBody["userIds"].Type != JTokenType.Array)
                    {
                        return(BWebResponse.BadRequest("Request is invalid."));
                    }
                    var AsJArray = (JArray)ParsedBody["userIds"];

                    foreach (var Token in AsJArray)
                    {
                        if (Token.Type != JTokenType.String)
                        {
                            return(BWebResponse.BadRequest("Request is invalid."));
                        }

                        var Lowered = ((string)Token).ToLower();
                        if (!FinalUserIds.Contains(Lowered))
                        {
                            FinalUserIds.Add(Lowered);
                        }
                    }
                }

                if (EmailAddresses.Count > 0)
                {
                    GetTracingService()?.On_FromServiceToService_Sent(_Context, _ErrorMessageAction);

                    var EmailsJArray = new JArray();

                    foreach (var CurEmail in EmailAddresses)
                    {
                        EmailsJArray.Add(CurEmail);
                    }

                    var RequestObject = new JObject()
                    {
                        ["emailAddresses"] = EmailsJArray
                    };

                    var Result = BWebServiceExtraUtilities.InterServicesRequest(new BWebServiceExtraUtilities.InterServicesRequestRequest()
                    {
                        DestinationServiceUrl = AuthServiceEndpoint + "/auth/internal/fetch_user_ids_from_emails?secret=" + InternalCallPrivateKey,
                        RequestMethod         = "POST",
                        bWithAuthToken        = true,
                        UseContextHeaders     = _Context,
                        ContentType           = "application/json",
                        Content = new BStringOrStream(RequestObject.ToString()),
                        ExcludeHeaderKeysForRequest = null
                    },
                                                                                false,
                                                                                _ErrorMessageAction);

                    GetTracingService()?.On_FromServiceToService_Received(_Context, _ErrorMessageAction);

                    if (!Result.bSuccess || Result.ResponseCode >= 400)
                    {
                        return(new BWebServiceResponse(Result.ResponseCode, Result.Content, Result.ContentType));
                    }

                    string InterServicesRequestStringResponse = null;

                    JObject Map;
                    try
                    {
                        InterServicesRequestStringResponse = Result.Content.String;

                        var Json = JObject.Parse(InterServicesRequestStringResponse);
                        Map = (JObject)Json["map"];
                    }
                    catch (Exception e)
                    {
                        _ErrorMessageAction?.Invoke("Model_ChangeSharingWithUsers-> Malformed request body has been returned from auth service. Body content: " + InterServicesRequestStringResponse + ", Exception: " + e.Message + ", Trace: " + e.StackTrace);
                        return(BWebResponse.InternalError("Malformed request body has been returned from auth service."));
                    }

                    foreach (var UserIdToken in Map.Values())
                    {
                        if (UserIdToken.Type == JTokenType.String)
                        {
                            var UserId = (string)UserIdToken;
                            if (!FinalUserIds.Contains(UserId))
                            {
                                FinalUserIds.Add(UserId);
                            }
                        }
                    }
                }
            }

            if (Model.ModelSharedWithUserIDs.OrderBy(t => t).SequenceEqual(FinalUserIds.OrderBy(t => t)))
            {
                return(BWebResponse.StatusOK("No change has been done."));
            }

            var OldSharedList = new List <string>(Model.ModelSharedWithUserIDs);

            Model.ModelSharedWithUserIDs = FinalUserIds;

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(Model)));

            var bOldHasStar = OldSharedList.Contains("*");
            var bNewHasStar = FinalUserIds.Contains("*");

            if (bOldHasStar && !bNewHasStar)
            {
                Controller_DeliveryEnsurer.Get().DB_DeleteItem_FireAndForget(
                    _Context,
                    GloballySharedModelIDsDBEntry.DBSERVICE_GLOBALLY_SHARED_MODEL_IDS_TABLE(),
                    GloballySharedModelIDsDBEntry.KEY_NAME_MODEL_ID,
                    new BPrimitiveType(RequestedModelID));
            }
            else if (!bOldHasStar && bNewHasStar)
            {
                Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                    _Context,
                    GloballySharedModelIDsDBEntry.DBSERVICE_GLOBALLY_SHARED_MODEL_IDS_TABLE(),
                    GloballySharedModelIDsDBEntry.KEY_NAME_MODEL_ID,
                    new BPrimitiveType(RequestedModelID),
                    JObject.Parse(JsonConvert.SerializeObject(new GloballySharedModelIDsDBEntry())));
            }

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelSharedWithUserIdsChanged
                                                               (
                                                                   RequestedModelID,
                                                                   Model.ModelOwnerUserID,
                                                                   FinalUserIds,
                                                                   OldSharedList,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Operation has been completed."));
        }
コード例 #7
0
        private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            AuthorizedUser = ServiceUtilities.Common.Methods.GetAuthorizedRequester(_Context, _ErrorMessageAction);
            if (!AuthorizedUser.bParseSuccessful)
            {
                return(BWebResponse.InternalError(AuthorizedUser.ParseErrorMessage));
            }

            if (_Context.Request.HttpMethod != "GET" && _Context.Request.HttpMethod != "POST" && _Context.Request.HttpMethod != "DELETE")
            {
                _ErrorMessageAction?.Invoke("Model_GetUpdateDeleteRevision: GET, POST and DELETE methods are accepted. But received request method:  " + _Context.Request.HttpMethod);
                return(BWebResponse.MethodNotAllowed("GET, POST and DELETE methods are accepted. But received request method: " + _Context.Request.HttpMethod));
            }

            var RequestedModelName = WebUtility.UrlDecode(RestfulUrlParameters[RestfulUrlParameter_ModelsKey]);

            if (!CommonMethods.TryGettingModelID(
                    DatabaseService,
                    RequestedModelName,
                    out RequestedModelID,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!int.TryParse(RestfulUrlParameters[RestfulUrlParameter_RevisionsKey], out RequestedRevisionIndex))
            {
                return(BWebResponse.BadRequest("Revision index must be an integer."));
            }

            if (_Context.Request.HttpMethod == "GET")
            {
                return(GetRevisionInfo(_ErrorMessageAction));
            }
            else
            {
                if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), RequestedModelID, _ErrorMessageAction))
                {
                    return(BWebResponse.InternalError("Atomic operation control has failed."));
                }

                BWebServiceResponse Result;
                if (_Context.Request.HttpMethod == "DELETE")
                {
                    Result = DeleteRevision(_Context, _ErrorMessageAction);
                }
                else
                {
                    Result = UpdateRevisionInfo(_Context, _ErrorMessageAction);
                }

                Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), RequestedModelID, _ErrorMessageAction);

                return(Result);
            }
        }
コード例 #8
0
        private BWebServiceResponse UpdateRevisionInfo(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryParsingRequestFor(
                    _Context,
                    out JObject UpdatedRevisionJson,
                    true, out Revision UpdatedRevision,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!CommonMethods.DoesRevisionExist(
                    Model,
                    RequestedRevisionIndex,
                    out Revision RevisionObject,
                    out int _))
            {
                return(BWebResponse.NotFound("Revision does not exist."));
            }

            if (UpdatedRevision.RevisionName != null && UpdatedRevision.RevisionName.Length > 0 &&
                RevisionObject.RevisionName != UpdatedRevision.RevisionName)
            {
                //There is a change in the revision name
                foreach (var CurrentRev in Model.ModelRevisions)
                {
                    if (CurrentRev.RevisionName.ToUpper() == UpdatedRevision.RevisionName)
                    {
                        return(BWebResponse.Conflict("A revision with same " + Revision.REVISION_NAME_PROPERTY + " already exists."));
                    }
                }
            }

            RevisionObject.Merge(UpdatedRevisionJson);
            Model.MRVLastUpdateTime = CommonMethods.GetTimeAsCreationTime();

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(Model)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionUpdated
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID,
                                                                   UpdatedRevisionJson
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Revision has been updated."));
        }
コード例 #9
0
        public static bool GetProcessedFileNode(
            WebServiceBaseTimeoutable _Request,
            ENodeType _FileType,
            IBDatabaseServiceInterface _DatabaseService,
            IBFileServiceInterface _FileService,
            string _CadFileStorageBucketName,
            string _ModelID,
            int _RevisionIndex,
            bool _bRootNodeRequested, ulong _NodeID,
            out BWebServiceResponse _SuccessResponse,
            out BWebServiceResponse _FailureResponse,
            Action <string> _ErrorMessageAction = null)
        {
            _SuccessResponse = BWebResponse.InternalError("");

            uint StartIndex = 0, Size = 0;

            if (!_bRootNodeRequested)
            {
                Convert.UniqueIDToStartIndexAndSize(_NodeID, out StartIndex, out Size);
                if (StartIndex == 0 || Size == 0)
                {
                    _FailureResponse = BWebResponse.BadRequest("Invalid Node ID.");
                    return(false);
                }
            }

            if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction))
            {
                _FailureResponse = BWebResponse.InternalError("Atomic operation control has failed.");
                return(false);
            }

            var bResult = GetProcessedFileNode_Internal(
                _FileType,
                _DatabaseService,
                _FileService,
                _CadFileStorageBucketName,
                _ModelID,
                _RevisionIndex,
                _bRootNodeRequested,
                StartIndex,
                Size,
                out _SuccessResponse,
                out _FailureResponse,
                _ErrorMessageAction);

            Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction);

            return(bResult);
        }
コード例 #10
0
        private BWebServiceResponse UpdateRawFile(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryParsingRequestFor(
                    _Context,
                    out JObject UpdatedFileEntryJson,
                    true, out FileEntry CheckForGenerateUploadUrl,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }
            bool bGenerateUploadUrl = CheckForGenerateUploadUrl.bGenerateUploadUrl;

            if (bGenerateUploadUrl)
            {
                UpdatedFileEntryJson[FileEntry.FILE_ENTRY_FILE_TYPE_PROPERTY] = CheckForGenerateUploadUrl.FileEntryFileType.TrimStart('.').ToLower();
            }
            else
            {
                if (UpdatedFileEntryJson.ContainsKey(FileEntry.FILE_ENTRY_NAME_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.FILE_ENTRY_FILE_TYPE_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.ZIP_MAIN_ASSEMBLY_FILE_NAME_IF_ANY_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.DATA_SOURCE_PROPERTY))
                {
                    return(BWebResponse.BadRequest("Name|type related fields can only be set when " + FileEntry.GENERATE_UPLOAD_URL_PROPERTY + " option is true."));
                }
            }

            if (!CommonMethods.TryGettingAllInfo(
                    DatabaseService,
                    RequestedModelID,
                    RequestedRevisionIndex,
                    out ModelDBEntry ModelObject,
                    out Revision RevisionObject,
                    out int _,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (RevisionObject.FileEntry.FileEntryName != null && RevisionObject.FileEntry.FileEntryName.Length > 0)
            {
                if (UpdatedFileEntryJson.ContainsKey(FileEntry.FILE_ENTRY_NAME_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.FILE_ENTRY_FILE_TYPE_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.ZIP_MAIN_ASSEMBLY_FILE_NAME_IF_ANY_PROPERTY) ||
                    UpdatedFileEntryJson.ContainsKey(FileEntry.DATA_SOURCE_PROPERTY))
                {
                    return(BWebResponse.BadRequest("File entry (raw) must be deleted before updating."));
                }
            }

            RevisionObject.FileEntry.Merge(UpdatedFileEntryJson);

            RevisionObject.FileEntry.FileEntryFileType = RevisionObject.FileEntry.FileEntryFileType.ToLower().TrimStart('.');
            RevisionObject.FileEntry.SetRelativeUrls_GetCommonUrlPart_FileEntryFileTypePreSet(RequestedModelID, RequestedRevisionIndex);
            RevisionObject.FileEntry.FileEntryCreationTime = CommonMethods.GetTimeAsCreationTime();
            ModelObject.MRVLastUpdateTime = RevisionObject.FileEntry.FileEntryCreationTime;

            string UploadUrl_IfRequested = null;

            if (bGenerateUploadUrl &&

                !FileService.CreateSignedURLForUpload(
                    out UploadUrl_IfRequested,
                    CadFileStorageBucketName,
                    RevisionObject.FileEntry.RawFileRelativeUrl,
                    FileEntry.RAW_FILE_UPLOAD_CONTENT_TYPE,
                    FileEntry.EXPIRY_MINUTES,
                    _ErrorMessageAction))
            {
                return(BWebResponse.InternalError("Signed url generation has failed."));
            }

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(ModelObject)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionFileEntryUpdated
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   ModelObject.ModelOwnerUserID,
                                                                   ModelObject.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID,
                                                                   UpdatedFileEntryJson
                                                               ),
                                                               _ErrorMessageAction);

            var ResultObject = new JObject();

            if (bGenerateUploadUrl)
            {
                ResultObject[FileEntry.FILE_UPLOAD_URL_PROPERTY]                     = UploadUrl_IfRequested;
                ResultObject[FileEntry.FILE_UPLOAD_CONTENT_TYPE_PROPERTY]            = FileEntry.RAW_FILE_UPLOAD_CONTENT_TYPE;
                ResultObject[FileEntry.FILE_DOWNLOAD_UPLOAD_EXPIRY_MINUTES_PROPERTY] = FileEntry.EXPIRY_MINUTES;
            }

            return(BWebResponse.StatusAccepted("Update raw file request has been accepted.", ResultObject));
        }
コード例 #11
0
        private BWebServiceResponse UpdateModelInfo(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryParsingRequestFor(
                    _Context, out JObject UpdateFieldsModelEntry,
                    false, out ModelDBEntry _,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            //If there is a change in the model name
            bool   bGetClearanceForModelName_New = false;
            bool   bGetClearanceForModelName_Old = false;
            string ModelUniqueName_New           = null;
            string ModelUniqueName_Old           = null;

            try
            {
                if (UpdateFieldsModelEntry.ContainsKey(ModelDBEntry.MODEL_UNIQUE_NAME_PROPERTY) &&
                    Model.ModelName != (string)UpdateFieldsModelEntry[ModelDBEntry.MODEL_UNIQUE_NAME_PROPERTY])
                {
                    ModelUniqueName_New = (string)UpdateFieldsModelEntry[ModelDBEntry.MODEL_UNIQUE_NAME_PROPERTY];
                    if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + ModelUniqueName_New, _ErrorMessageAction))
                    {
                        return(BWebResponse.InternalError("Atomic operation control has failed."));
                    }
                    bGetClearanceForModelName_New = true;

                    ModelUniqueName_Old = Model.ModelName;
                    if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + ModelUniqueName_Old, _ErrorMessageAction))
                    {
                        return(BWebResponse.InternalError("Atomic operation control has failed."));
                    }
                    bGetClearanceForModelName_Old = true;

                    //Put the new one
                    if (!DatabaseService.UpdateItem(
                            UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                            UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                            new BPrimitiveType(ModelUniqueName_New),
                            new JObject()
                    {
                        [ModelDBEntry.KEY_NAME_MODEL_ID] = RequestedModelID
                    },
                            out JObject _,
                            EBReturnItemBehaviour.DoNotReturn,
                            DatabaseService.BuildAttributeNotExistCondition(UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME),
                            _ErrorMessageAction))
                    {
                        if (!DatabaseService.GetItem(
                                UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                                UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                                new BPrimitiveType(ModelUniqueName_New),
                                UniqueFileFieldsDBEntry.Properties,
                                out JObject ModelIDResponse,
                                _ErrorMessageAction) || !ModelIDResponse.ContainsKey(ModelDBEntry.KEY_NAME_MODEL_ID))
                        {
                            return(BWebResponse.InternalError("Model ID could not be retrieved upon conflict."));
                        }
                        var Result = JObject.Parse(BWebResponse.Error_Conflict_String("Attribute " + UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + " must be globally unique."));
                        Result[ModelDBEntry.KEY_NAME_MODEL_ID] = (string)ModelIDResponse[ModelDBEntry.KEY_NAME_MODEL_ID];
                        return(new BWebServiceResponse(
                                   BWebResponse.Error_Conflict_Code,
                                   new BStringOrStream(Result.ToString()),
                                   BWebResponse.Error_Conflict_ContentType));
                    }

                    //Delete the old one
                    Controller_DeliveryEnsurer.Get().DB_DeleteItem_FireAndForget(
                        _Context,
                        UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                        UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                        new BPrimitiveType(ModelUniqueName_Old));
                }

                var OldModelMetadataSet = Model.ModelMetadata;

                Model.Merge(UpdateFieldsModelEntry);

                var NewModelMetadataSet = Model.ModelMetadata;

                if (OldModelMetadataSet != NewModelMetadataSet)
                {
                    var MetaLocator = Controller_AttributeTables.MetadataLocator.ItIsModelMetadata(RequestedModelID);

                    //First remove all metadata sets
                    Controller_AttributeTables.Get().AddRemoveMetadataSets_AttributesTables(
                        InnerDeliveryEnsurerUserProcessor, Model.ModelOwnerUserID,
                        MetaLocator,
                        OldModelMetadataSet,
                        Controller_AttributeTables.EAddRemove.Remove,
                        Controller_AttributeTables.EKillProcedureIfGetClearanceFails.No,
                        out BWebServiceResponse _, _ErrorMessageAction);

                    //Then add new metadata sets
                    Controller_AttributeTables.Get().AddRemoveMetadataSets_AttributesTables(
                        InnerDeliveryEnsurerUserProcessor, Model.ModelOwnerUserID,
                        MetaLocator,
                        NewModelMetadataSet,
                        Controller_AttributeTables.EAddRemove.Add,
                        Controller_AttributeTables.EKillProcedureIfGetClearanceFails.No,
                        out BWebServiceResponse _, _ErrorMessageAction);
                }

                Model.MRVLastUpdateTime = CommonMethods.GetTimeAsCreationTime();

                Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                    _Context,
                    ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                    ModelDBEntry.KEY_NAME_MODEL_ID,
                    new BPrimitiveType(RequestedModelID),
                    JObject.Parse(JsonConvert.SerializeObject(Model)));

                Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelUpdated
                                                                   (
                                                                       RequestedModelID,
                                                                       Model.ModelOwnerUserID,
                                                                       Model.ModelSharedWithUserIDs,
                                                                       AuthorizedUser.UserID,
                                                                       UpdateFieldsModelEntry
                                                                   ),
                                                                   _ErrorMessageAction);

                return(BWebResponse.StatusOK("Model has been successfully updated."));
            }
            finally
            {
                if (bGetClearanceForModelName_New)
                {
                    Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + ModelUniqueName_New, _ErrorMessageAction);
                }
                if (bGetClearanceForModelName_Old)
                {
                    Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + ModelUniqueName_Old, _ErrorMessageAction);
                }
            }
        }
コード例 #12
0
        private BWebServiceResponse DeleteModel(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!Controller_AttributeTables.Get().AddRemoveMetadataSets_AttributesTables(
                    InnerDeliveryEnsurerUserProcessor, Model.ModelOwnerUserID,
                    Controller_AttributeTables.MetadataLocator.ItIsModelMetadata(RequestedModelID),
                    Model.ModelMetadata,
                    Controller_AttributeTables.EAddRemove.Remove,
                    Controller_AttributeTables.EKillProcedureIfGetClearanceFails.Yes,
                    out FailureResponse, _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            foreach (var Rev in Model.ModelRevisions)
            {
                Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionFileEntryDeleteAll
                                                                   (
                                                                       RequestedModelID,
                                                                       Rev.RevisionIndex,
                                                                       Model.ModelOwnerUserID,
                                                                       Model.ModelSharedWithUserIDs,
                                                                       AuthorizedUser.UserID,
                                                                       JObject.Parse(JsonConvert.SerializeObject(Rev.FileEntry))
                                                                   ),
                                                                   _ErrorMessageAction);
            }

            Controller_DeliveryEnsurer.Get().DB_DeleteItem_FireAndForget(
                _Context,
                UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                new BPrimitiveType(Model.ModelName));

            var RequestedModelIDPrimitive = new BPrimitiveType(RequestedModelID);

            Controller_DeliveryEnsurer.Get().DB_DeleteItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                RequestedModelIDPrimitive);

            if (Model.ModelSharedWithUserIDs.Contains("*"))
            {
                Controller_DeliveryEnsurer.Get().DB_DeleteItem_FireAndForget(
                    _Context,
                    GloballySharedModelIDsDBEntry.DBSERVICE_GLOBALLY_SHARED_MODEL_IDS_TABLE(),
                    GloballySharedModelIDsDBEntry.KEY_NAME_MODEL_ID,
                    RequestedModelIDPrimitive);
            }

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelDeleted
                                                               (
                                                                   RequestedModelID,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Model has been deleted."));
        }
コード例 #13
0
        private BWebServiceResponse CreateModel(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryParsingRequestFor(
                    _Context, out JObject _,
                    true, out ModelDBEntry NewModelObject,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }
            NewModelObject.ModelOwnerUserID = AuthorizedUser.UserID;

            if (!CommonMethods.GenerateNonExistentUniqueID(
                    this,
                    DatabaseService, ModelDBEntry.DBSERVICE_MODELS_TABLE(), ModelDBEntry.KEY_NAME_MODEL_ID, ModelDBEntry.MustHaveProperties,
                    CommonMethods.EGetClearance.Yes,
                    out string ModelID,
                    out BWebServiceResponse _FailureResponse,
                    _ErrorMessageAction))
            {
                return(_FailureResponse);
            }

            bool bGetClearanceForModelName = false;

            try
            {
                if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + NewModelObject.ModelName, _ErrorMessageAction))
                {
                    return(BWebResponse.InternalError("Atomic operation control has failed."));
                }
                bGetClearanceForModelName = true;

                if (!DatabaseService.UpdateItem(
                        UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                        UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                        new BPrimitiveType(NewModelObject.ModelName),
                        new JObject()
                {
                    [ModelDBEntry.KEY_NAME_MODEL_ID] = ModelID
                },
                        out JObject _,
                        EBReturnItemBehaviour.DoNotReturn,
                        DatabaseService.BuildAttributeNotExistCondition(UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME),
                        _ErrorMessageAction))
                {
                    if (!DatabaseService.GetItem(
                            UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(),
                            UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME,
                            new BPrimitiveType(NewModelObject.ModelName),
                            UniqueFileFieldsDBEntry.Properties,
                            out JObject ModelIDResponse,
                            _ErrorMessageAction) || !ModelIDResponse.ContainsKey(ModelDBEntry.KEY_NAME_MODEL_ID))
                    {
                        return(BWebResponse.InternalError("Model ID could not be retrieved upon conflict."));
                    }
                    var Result = JObject.Parse(BWebResponse.Error_Conflict_String("Attribute " + UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + " must be globally unique."));
                    Result[ModelDBEntry.KEY_NAME_MODEL_ID] = (string)ModelIDResponse[ModelDBEntry.KEY_NAME_MODEL_ID];
                    return(new BWebServiceResponse(
                               BWebResponse.Error_Conflict_Code,
                               new BStringOrStream(Result.ToString()),
                               BWebResponse.Error_Conflict_ContentType));
                }

                if (!Controller_AttributeTables.Get().AddRemoveMetadataSets_AttributesTables(
                        InnerDeliveryEnsurerUserProcessor, NewModelObject.ModelOwnerUserID,
                        Controller_AttributeTables.MetadataLocator.ItIsModelMetadata(ModelID),
                        NewModelObject.ModelMetadata,
                        Controller_AttributeTables.EAddRemove.Add,
                        Controller_AttributeTables.EKillProcedureIfGetClearanceFails.Yes,
                        out _FailureResponse,
                        _ErrorMessageAction))
                {
                    return(_FailureResponse);
                }

                NewModelObject.CreationTime      = CommonMethods.GetTimeAsCreationTime();
                NewModelObject.MRVLastUpdateTime = NewModelObject.CreationTime;

                Controller_DeliveryEnsurer.Get().DB_PutItem_FireAndForget(
                    _Context,
                    ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                    ModelDBEntry.KEY_NAME_MODEL_ID,
                    new BPrimitiveType(ModelID),
                    JObject.Parse(JsonConvert.SerializeObject(NewModelObject)));

                Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelCreated
                                                                   (
                                                                       ModelID,
                                                                       AuthorizedUser.UserID,
                                                                       new List <string>(),
                                                                       AuthorizedUser.AuthMethodKey
                                                                   ),
                                                                   _ErrorMessageAction);

                return(BWebResponse.StatusCreated("Model has been created.", new JObject()
                {
                    [ModelDBEntry.KEY_NAME_MODEL_ID] = ModelID
                }));
            }
            finally
            {
                Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), ModelID, _ErrorMessageAction);
                if (bGetClearanceForModelName)
                {
                    Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, UniqueFileFieldsDBEntry.DBSERVICE_UNIQUEFILEFIELDS_TABLE(), UniqueFileFieldsDBEntry.KEY_NAME_MODEL_UNIQUE_NAME + ":" + NewModelObject.ModelName, _ErrorMessageAction);
                }
            }
        }
コード例 #14
0
        private BWebServiceResponse DeleteRawFile(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryGettingAllInfo(
                    DatabaseService,
                    RequestedModelID,
                    RequestedRevisionIndex,
                    out ModelDBEntry ModelObject,
                    out Revision RevisionObject,
                    out int ModelRevisionListIx,
                    out BWebServiceResponse _FailureResponse,
                    _ErrorMessageAction))
            {
                return(_FailureResponse);
            }

            var PreviousProcessStage = RevisionObject.FileEntry.FileProcessStage;

            if (PreviousProcessStage == (int)Constants.EProcessStage.NotUploaded)
            {
                return(BWebResponse.NotFound("Raw files have not been uploaded."));
            }

            //if (RevisionObject.FileEntry.FileProcessStage == (int)Constants.EProcessStage.Uploaded_Processing)
            //{
            //    var RequestObject = new JObject()
            //    {
            //        ["bucketName"] = CadFileStorageBucketName,
            //        ["rawFileRelativeUrl"] = RevisionObject.FileEntry.RawFileRelativeUrl
            //    };

            //    GetTracingService()?.On_FromServiceToService_Sent(_Context, _ErrorMessageAction);

            //    var Result = BWebUtilities_GC_CloudRun.InterServicesRequest(new BWebUtilities_GC_CloudRun.InterServicesRequestRequest()
            //    {
            //        DestinationServiceUrl = CadProcessServiceEndpoint + "/3d/process/stop",
            //        RequestMethod = "POST",
            //        ContentType = "application/json",
            //        Content = new BStringOrStream(RequestObject.ToString()),
            //        bWithAuthToken = false, //Kubernetes Service
            //        UseContextHeaders = _Context,
            //        ExcludeHeaderKeysForRequest = null
            //    },
            //    false,
            //    _ErrorMessageAction);

            //    GetTracingService()?.On_FromServiceToService_Received(_Context, _ErrorMessageAction);

            //    if (!Result.bSuccess || Result.ResponseCode >= 400)
            //    {
            //        return new BWebServiceResponse(Result.ResponseCode, Result.Content, Result.ContentType);
            //    }
            //}

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionFileEntryDeleteAll
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   ModelObject.ModelOwnerUserID,
                                                                   ModelObject.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID,
                                                                   JObject.Parse(JsonConvert.SerializeObject(RevisionObject.FileEntry))
                                                               ),
                                                               _ErrorMessageAction);

            var FileType = RevisionObject.FileEntry.FileEntryFileType;

            RevisionObject.FileEntry = new FileEntry()
            {
                FileEntryFileType = FileType
            };
            RevisionObject.FileEntry.SetRelativeUrls_GetCommonUrlPart_FileEntryFileTypePreSet(RequestedModelID, RequestedRevisionIndex);

            ModelObject.MRVLastUpdateTime = CommonMethods.GetTimeAsCreationTime();

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(ModelObject)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionFileEntryDeleted
                                                               (
                                                                   RequestedModelID,
                                                                   RequestedRevisionIndex,
                                                                   ModelObject.ModelOwnerUserID,
                                                                   ModelObject.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusOK("Raw "
                                         + (PreviousProcessStage == (int)Constants.EProcessStage.Uploaded_Processed ? "and processed models have " : "model has ")
                                         + "been deleted."));
        }
コード例 #15
0
        private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            AuthorizedUser = ServiceUtilities.Common.Methods.GetAuthorizedRequester(_Context, _ErrorMessageAction);
            if (!AuthorizedUser.bParseSuccessful)
            {
                return(BWebResponse.InternalError(AuthorizedUser.ParseErrorMessage));
            }

            if (_Context.Request.HttpMethod != "DELETE")
            {
                _ErrorMessageAction?.Invoke("Model_RemoveModelShare: DELETE method is accepted. But received request method:  " + _Context.Request.HttpMethod);
                return(BWebResponse.MethodNotAllowed("DELETE method is accepted. But received request method: " + _Context.Request.HttpMethod));
            }

            if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), RequestedModelID, _ErrorMessageAction))
            {
                return(BWebResponse.InternalError("Atomic operation control has failed."));
            }
            try
            {
                return(ProcessRequestLocked(_Context, _ErrorMessageAction));
            }
            finally
            {
                Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), RequestedModelID, _ErrorMessageAction);
            }
        }
コード例 #16
0
        public static bool GetProcessedFile(
            WebServiceBaseTimeoutable _Request,
            EProcessedFileType _FileType,
            IBDatabaseServiceInterface _DatabaseService,
            IBFileServiceInterface _FileService,
            string _CadFileStorageBucketName,
            string _ModelID,
            int _RevisionIndex,
            out BWebServiceResponse _SuccessResponse,
            out BWebServiceResponse _FailureResponse,
            string _GeometryId = null,
            Action <string> _ErrorMessageAction = null)
        {
            _SuccessResponse = BWebResponse.InternalError("");

            if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction))
            {
                _FailureResponse = BWebResponse.InternalError("Atomic operation control has failed.");
                return(false);
            }

            var bResult = GetProcessedFile_Internal(
                _FileType,
                _DatabaseService,
                _FileService,
                _CadFileStorageBucketName,
                _ModelID,
                _RevisionIndex,
                out _SuccessResponse,
                out _FailureResponse,
                _GeometryId,
                _ErrorMessageAction);

            Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction);

            return(bResult);
        }
コード例 #17
0
        private BWebServiceResponse AddRevision(HttpListenerContext _Context, Action <string> _ErrorMessageAction)
        {
            if (!CommonMethods.TryParsingRequestFor(
                    _Context, out JObject _,
                    true, out Revision NewRevisionObject,
                    out BWebServiceResponse FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            if (!CommonMethods.TryGettingModelInfo(
                    DatabaseService,
                    RequestedModelID,
                    out JObject _,
                    true, out ModelDBEntry Model,
                    out FailureResponse,
                    _ErrorMessageAction))
            {
                return(FailureResponse);
            }

            var UpperCaseNewRevisionName = NewRevisionObject.RevisionName.ToUpper();

            int BiggestExistingIndex = -1;

            foreach (var CurrentRev in Model.ModelRevisions)
            {
                if (CurrentRev.RevisionName.ToUpper() == UpperCaseNewRevisionName)
                {
                    return(BWebResponse.Conflict("A revision with same " + Revision.REVISION_NAME_PROPERTY + " already exists."));
                }

                BiggestExistingIndex = BiggestExistingIndex < CurrentRev.RevisionIndex ? CurrentRev.RevisionIndex : BiggestExistingIndex;
            }
            int NewRevisionIndex = BiggestExistingIndex + 1;

            NewRevisionObject.RevisionIndex = NewRevisionIndex;
            NewRevisionObject.CreationTime  = CommonMethods.GetTimeAsCreationTime();
            Model.MRVLastUpdateTime         = NewRevisionObject.CreationTime;

            Model.ModelRevisions.Add(NewRevisionObject);

            Controller_DeliveryEnsurer.Get().DB_UpdateItem_FireAndForget(
                _Context,
                ModelDBEntry.DBSERVICE_MODELS_TABLE(),
                ModelDBEntry.KEY_NAME_MODEL_ID,
                new BPrimitiveType(RequestedModelID),
                JObject.Parse(JsonConvert.SerializeObject(Model)));

            Controller_ModelActions.Get().BroadcastModelAction(new Action_ModelRevisionCreated
                                                               (
                                                                   RequestedModelID,
                                                                   NewRevisionObject.RevisionIndex,
                                                                   Model.ModelOwnerUserID,
                                                                   Model.ModelSharedWithUserIDs,
                                                                   AuthorizedUser.UserID
                                                               ),
                                                               _ErrorMessageAction);

            return(BWebResponse.StatusCreated("Revision has been created.", new JObject()
            {
                [Revision.REVISION_INDEX_PROPERTY] = NewRevisionIndex
            }));
        }